Mercurial > hg > index.fcgi > rcg > rcg-1
comparison rcg.c @ 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 |
comparison
equal
deleted
inserted
replaced
10:acb4b8c29fe4 | 11:68f77fa02162 |
---|---|
128 | 128 |
129 char *buf = calloc(BUFSIZE, sizeof(char)); | 129 char *buf = calloc(BUFSIZE, sizeof(char)); |
130 | 130 |
131 int re_err; | 131 int re_err; |
132 regex_t *re = calloc(1, sizeof(regex_t)); | 132 regex_t *re = calloc(1, sizeof(regex_t)); |
133 re_err = regcomp(re, re_expression, REG_EXTENDED); | 133 re_err = regcomp(re, re_expression, REG_EXTENDED | REG_NEWLINE); |
134 if (re_err != 0) | 134 if (re_err != 0) |
135 exit(re_error(re_err, re)); | 135 exit(re_error(re_err, re)); |
136 | 136 |
137 regmatch_t *rem = calloc(1, sizeof(regmatch_t)); | 137 regmatch_t *rem = calloc(1, sizeof(regmatch_t)); |
138 | 138 |
198 | 198 |
199 out = realloc(out, out_len*sizeof(char)); | 199 out = realloc(out, out_len*sizeof(char)); |
200 if (!out) | 200 if (!out) |
201 exit(realloc_error()); | 201 exit(realloc_error()); |
202 | 202 |
203 if (colorLine) | 203 so = rem[0].rm_so; |
204 eo = rem[0].rm_eo; | |
205 | |
206 int match_len = eo - so; | |
207 | |
208 if (colorLine && match_len > 0) | |
204 { | 209 { |
205 so = 0; | 210 so = 0; |
206 eo = out_len - 2; | 211 eo = out_len - 2; |
212 match_len = eo - so; | |
207 } | 213 } |
208 else | |
209 { | |
210 so = rem[0].rm_so; | |
211 eo = rem[0].rm_eo; | |
212 } | |
213 | |
214 int match_len = eo - so; | |
215 | 214 |
216 //fprintf(stderr, "%d %d \n", so, eo); //d// 20100327 PBA | 215 //fprintf(stderr, "%d %d \n", so, eo); //d// 20100327 PBA |
217 | 216 |
218 if (re_err != REG_NOMATCH && so >= 0 && eo >= 0 && match_len > 0) | 217 if (re_err != REG_NOMATCH && so >= 0 && eo >= 0 && match_len > 0) |
219 { | 218 { |
239 } | 238 } |
240 else | 239 else |
241 { | 240 { |
242 strncpy(&out[out_pos], &buf[buf_pos], out_len - out_pos); | 241 strncpy(&out[out_pos], &buf[buf_pos], out_len - out_pos); |
243 out[out_len - 1] = '\0'; | 242 out[out_len - 1] = '\0'; |
243 re_err = REG_NOMATCH; | |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 fputs(out, stdout); | 247 fputs(out, stdout); |
248 fflush(stdout); | 248 fflush(stdout); |