Date: Wed, 25 Jun 2008 14:51:14 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 144098 for review Message-ID: <200806251451.m5PEpEWA007995@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144098 Change 144098 by gabor@gabor_server on 2008/06/25 14:50:37 - Reimplement --color and -o Obtained from: NetBSD Project Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#29 edit .. //depot/projects/soc2008/gabor_textproc/grep/queue.c#5 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#43 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#29 (text+ko) ==== @@ -101,7 +101,7 @@ void *grep_malloc(size_t size); void *grep_calloc(size_t nmemb, size_t size); void *grep_realloc(void *ptr, size_t size); -void printline(struct str *line, int sep); +void printline(struct str *line, int sep, regmatch_t *matches, int m); /* queue.c */ void initqueue(void); ==== //depot/projects/soc2008/gabor_textproc/grep/queue.c#5 (text+ko) ==== @@ -116,7 +116,7 @@ struct queue *item; while ((item = dequeue()) != NULL) { - printline(&item->data, '-'); + printline(&item->data, '-', (regmatch_t *)NULL, 0); free_item(item); } } ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#43 (text+ko) ==== @@ -214,8 +214,6 @@ pmatch.rm_eo = l->len; for (i = 0; i < patterns; i++) { - pmatch.rm_so = 0; - pmatch.rm_eo = l->len; r = regexec(&r_pattern[i], l->dat, 1, &pmatch, eflags); if (r == REG_NOMATCH && t == 0) continue; @@ -259,9 +257,9 @@ printqueue(); } linesqueued = 0; - printline(l, ':'); + printline(l, ':', matches, m); } else { - printline(l, '-'); + printline(l, '-', matches, m); tail--; } } @@ -305,9 +303,10 @@ } void -printline(struct str *line, int sep) +printline(struct str *line, int sep, regmatch_t *matches, int m) { - int n = 0; + int i, n = 0; + size_t a = 0; if (!hflag) { if (nullflag == 0) @@ -332,6 +331,28 @@ } if (n) putchar(sep); - fwrite(line->dat, line->len, 1, stdout); - putchar('\n'); + if ((oflag || color) && m > 0) { + for (i = 0; i < m; i++) { + if (!oflag) + fwrite(line->dat + a, matches[i].rm_so - a, 1, stdout); + if (color) + fprintf(stdout, "\33[%sm", color); + fwrite(line->dat + matches[i].rm_so, + matches[i].rm_eo - matches[i].rm_so, 1, stdout); + if (color) + fprintf(stdout, "\33[00m"); + a = matches[i].rm_eo; + if (oflag) + putchar('\n'); + } + if (!oflag) { + if (line->len - a > 0) + fwrite(line->dat + a, line->len - a, 1, stdout); + putchar('\n'); + } + } else { + fwrite(line->dat, line->len, 1, stdout); + putchar('\n'); + } + }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806251451.m5PEpEWA007995>