From: Francois Fleuret Date: Fri, 10 Feb 2012 10:37:25 +0000 (+0100) Subject: Cosmetics. The debug check for interval order is still there. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=5bf2fa971b48efef58ec6127b26f259c55ebc16d;p=selector.git Cosmetics. The debug check for interval order is still there. --- diff --git a/selector.c b/selector.c index 81286d6..cf90315 100644 --- a/selector.c +++ b/selector.c @@ -410,18 +410,19 @@ int match(struct matcher *matcher, char *string, int *nb_switches, int *switches *nb_switches = add_interval(*nb_switches, switches, (int) (where - string), (int) (where - string) + strlen(matcher->patterns[n])); - #warning CHECK THE INTERVALS +#warning CHECK THE INTERVALS { - int k, i; - FILE *out = fopen("/tmp/intervals", "w"); - for(k = 0; k < (*nb_switches)/2; k++) { - i = 0; - for(; i < switches[2 * k]; i++) fprintf(out, "-"); - for(; i < switches[2 * k + 1]; i++) fprintf(out, "%c", string[i]); - for(; i < strlen(string); i++) fprintf(out, "-"); - fprintf(out, "\n"); - } - fclose(out); + /* int i; */ + /* FILE *out = fopen("/tmp/intervals", "w"); */ + /* for(k = 0; k < (*nb_switches)/2; k++) { */ + /* i = 0; */ + /* for(; i < switches[2 * k]; i++) fprintf(out, "-"); */ + /* for(; i < switches[2 * k + 1]; i++) fprintf(out, "%c", string[i]); */ + /* for(; i < strlen(string); i++) fprintf(out, "-"); */ + /* fprintf(out, "\n"); */ + /* } */ + /* fclose(out); */ + int k; for(k = 0; k < *nb_switches - 1; k++) { if(switches[k] > switches[k+1]) { abort(); @@ -433,15 +434,17 @@ int match(struct matcher *matcher, char *string, int *nb_switches, int *switches } return 1; } else { - if(regexec(&matcher->preg, string, 1, &matches, 0) == 0) { - if(switches) { + if(switches) { + if(regexec(&matcher->preg, string, 1, &matches, 0) == 0) { *nb_switches = 2; switches[0] = matches.rm_so; switches[1] = matches.rm_eo; + return 1; + } else { + return 0; } - return 1; } else { - return 0; + return regexec(&matcher->preg, string, 0, 0, 0) == 0; } } } @@ -974,6 +977,7 @@ 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'}, { "upper-case-makes-case-sensitive", no_argument, 0, 'u' }, { "title", 1, 0, 't' }, { "number-of-lines", 1, 0, 'l' },