X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=selector.git;a=blobdiff_plain;f=selector.c;h=945844fc80b9db117ecb3c35c7aef238c2955cab;hp=ac80d93db62646cf096fd40606a7f3973e0b10c1;hb=HEAD;hpb=247055c60e22d0347e5c46259163a9c7fdab5dee diff --git a/selector.c b/selector.c index ac80d93..945844f 100644 --- a/selector.c +++ b/selector.c @@ -46,7 +46,7 @@ #include #include -#define VERSION "1.1.7" +#define VERSION "1.1.8" #define BUFFER_SIZE 16384 @@ -65,6 +65,7 @@ int global_remove_duplicates = 0; int global_use_regexp = 0; int global_case_sensitive = 0; char *global_title = 0; +regex_t *global_prefix_regexp = 0; int global_error_flash = 0; int global_upper_caps_makes_case_sensitive = 0; int global_show_long_lines = 0; @@ -204,6 +205,8 @@ void usage(FILE *out) { fprintf(out, " make a flash instead of a beep on an edition error\n"); fprintf(out, " --bash\n"); fprintf(out, " setting for bash history search, same as -b -i -d -v -w -l ${HISTSIZE}\n"); + fprintf(out, " --delete-regexp \n"); + fprintf(out, " deletes in every line the portion matching the regexp\n"); fprintf(out, " --\n"); fprintf(out, " all following arguments are filenames\n"); fprintf(out, " -t , --title <title>\n"); @@ -877,9 +880,20 @@ void update_screen(int *current_focus_line, int *displayed_focus_line, /*********************************************************************/ void store_line(struct hash_table_t *hash_table, - const char *new_line, + char *new_line, int *nb_lines, char **lines) { int dup; + char *c, *d; + regmatch_t matches; + + /* Remove some parts matching a regexp */ + + if(global_prefix_regexp && regexec(global_prefix_regexp, new_line, 1, &matches, 0) == 0) { + c = new_line + matches.rm_so; + d = new_line + matches.rm_eo; + while(*d) { *c++ = *d++; } + *c = 0; + } /* Remove the zsh history prefix */ @@ -961,7 +975,8 @@ void read_file(struct hash_table_t *hash_table, /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum { - OPT_BASH_MODE = CHAR_MAX + 1 + OPT_BASH_MODE = CHAR_MAX + 1, + OPT_DELETE_REGEXP = CHAR_MAX + 2 }; static struct option long_options[] = { @@ -979,13 +994,14 @@ static struct option long_options[] = { { "regexp", no_argument, 0, 'e' }, { "case-sensitive", no_argument, 0, 'a' }, { "show-long-lines", no_argument, 0, 'j'}, - { "show-hits", no_argument, 0, 'j'}, + { "show-hits", no_argument, 0, 'y'}, { "upper-case-makes-case-sensitive", no_argument, 0, 'u' }, { "title", 1, 0, 't' }, { "pattern", 1, 0, 'r' }, { "number-of-lines", 1, 0, 'l' }, { "colors", 1, 0, 'c' }, { "bash", no_argument, 0, OPT_BASH_MODE }, + { "delete-regexp", 1, 0, OPT_DELETE_REGEXP }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; @@ -1107,6 +1123,16 @@ int main(int argc, char **argv) { strcpy(global_title, optarg); break; + case OPT_DELETE_REGEXP: + free(global_prefix_regexp); + global_prefix_regexp = safe_malloc(sizeof(*global_prefix_regexp)); + + if(regcomp(global_prefix_regexp, optarg, 0)) { + fprintf(stderr, "selector: Regexp syntax error `%s'.\n", optarg); + exit(EXIT_FAILURE); + } + break; + case 'r': strcpy(pattern, optarg); break; @@ -1442,5 +1468,10 @@ int main(int argc, char **argv) { free(lines); free(global_title); + if(global_prefix_regexp) { + regfree(global_prefix_regexp); + free(global_prefix_regexp); + } + exit(EXIT_SUCCESS); }