changeset 13:2fb87616ab65

rcg.c: fix bug when dealing with ".*"
author paulo@thepaulopc
date Sat, 06 Nov 2010 02:57:06 -0700
parents 9ec52ba4b994
children 669266246c6b
files rcg.c
diffstat 1 files changed, 9 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/rcg.c	Sat Nov 06 00:21:23 2010 -0700
     1.2 +++ b/rcg.c	Sat Nov 06 02:57:06 2010 -0700
     1.3 @@ -130,7 +130,7 @@
     1.4  
     1.5  	int re_err;
     1.6  	regex_t *re = calloc(1, sizeof(regex_t));
     1.7 -	re_err = regcomp(re, re_expression, REG_EXTENDED);
     1.8 +	re_err = regcomp(re, re_expression, REG_EXTENDED | REG_NEWLINE);
     1.9  	if (re_err != 0)
    1.10  		exit(re_error(re_err, re));
    1.11  
    1.12 @@ -200,18 +200,17 @@
    1.13  			if (!out)
    1.14  				exit(realloc_error());
    1.15  
    1.16 -			if (colorLine)
    1.17 +			so = rem[0].rm_so;
    1.18 +			eo = rem[0].rm_eo;
    1.19 +
    1.20 +			int match_len = eo - so;
    1.21 +
    1.22 +			if (colorLine && match_len > 0)
    1.23  			{
    1.24  				so = 0;
    1.25  				eo = out_len - 2;
    1.26 +				match_len = eo - so;
    1.27  			}
    1.28 -			else
    1.29 -			{
    1.30 -				so = rem[0].rm_so;
    1.31 -				eo = rem[0].rm_eo;
    1.32 -			}
    1.33 -
    1.34 -			int match_len = eo - so;
    1.35  
    1.36  			//fprintf(stderr, "%d %d \n", so, eo);		//d// 20100327 PBA
    1.37  
    1.38 @@ -241,6 +240,7 @@
    1.39  			{
    1.40  				strncpy(&out[out_pos], &buf[buf_pos], out_len - out_pos);
    1.41  				out[out_len - 1] = '\0';
    1.42 +				re_err = REG_NOMATCH;
    1.43  			}
    1.44  		}
    1.45