/* build_active_list: add line matching a pattern to the global-active list */ int build_active_list(int isgcmd) { regex_t *pat; line_t *lp; int n; char *s; char delimiter; if ((delimiter = *ibufp) == ' ' || delimiter == '\n') { seterrmsg("invalid pattern delimiter"); return ERR; } else if ((pat = get_compiled_pattern()) == NULL) return ERR; else if (*ibufp == delimiter) ibufp++; clear_active_list(); lp = get_addressed_line_node(first_addr); for (n = first_addr; n <= second_addr; n++, lp = lp->q_forw) { if ((s = get_sbuf_line(lp)) == NULL) return ERR; if (isbinary) NUL_TO_NEWLINE(s, lp->len); if (!regexec(pat, s, 0, NULL, 0) == isgcmd && set_active_node(lp) < 0) return ERR; } return 0; }
char new_compiled_pattern( const char **ibufpp ) { regex_t *tpat = global_pat; disable_interrupts(); tpat = get_compiled_pattern( ibufpp ); if( !tpat ) { enable_interrupts(); return 0; } if( tpat != global_pat ) { if( global_pat ) { regfree( global_pat ); free( global_pat ); } global_pat = tpat; patlock = 1; /* reserve pattern */ } enable_interrupts(); return 1; }
/* return the address of the next line matching a pattern in a given direction. wrap around begin/end of editor buffer if necessary */ int get_matching_node_addr( const char **ibufpp, const char forward ) { regex_t *pat = get_compiled_pattern( ibufpp ); int addr = current_addr(); if( !pat ) return -1; do { addr = ( forward ? inc_addr( addr ) : dec_addr( addr ) ); if( addr ) { line_t *lp = search_line_node( addr ); char *s = get_sbuf_line( lp ); if( !s ) return -1; if( isbinary() ) nul_to_newline( s, lp->len ); if( !regexec( pat, s, 0, 0, 0 ) ) return addr; } } while( addr != current_addr() ); set_error_msg( "No match" ); return -1; }
/* add line matching a pattern to the global-active list */ char build_active_list( const char **ibufpp, const int first_addr, const int second_addr, const char match ) { regex_t *pat; line_t *lp; int addr; const char delimiter = **ibufpp; if( delimiter == ' ' || delimiter == '\n' ) { set_error_msg( "Invalid pattern delimiter" ); return 0; } if( !( pat = get_compiled_pattern( ibufpp ) ) ) return 0; if( **ibufpp == delimiter ) ++(*ibufpp); clear_active_list(); lp = search_line_node( first_addr ); for( addr = first_addr; addr <= second_addr; ++addr, lp = lp->q_forw ) { char *s = get_sbuf_line( lp ); if( !s ) return 0; if( isbinary() ) nul_to_newline( s, lp->len ); if( !regexec( pat, s, 0, 0, 0 ) == match && !set_active_node( lp ) ) return 0; } return 1; }