aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-10-13 18:55:06 +0000
committerMatt Kraai <kraai@debian.org>2000-10-13 18:55:06 +0000
commit567cdd1d517103e74153d0c45713f72457a702ab (patch)
treea127f8c2fb6ca98cc4e0708ac8510e38610c29d2 /findutils/grep.c
parent9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3 (diff)
downloadbusybox-w32-567cdd1d517103e74153d0c45713f72457a702ab.tar.gz
busybox-w32-567cdd1d517103e74153d0c45713f72457a702ab.tar.bz2
busybox-w32-567cdd1d517103e74153d0c45713f72457a702ab.zip
Fix handling of ^$ by removing the newline from input lines and by not
compiling with REG_NEWLINE.
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 003dae98e..c0193bce3 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -56,7 +56,7 @@ static void print_matched_line(char *line, int linenum)
56 if (print_line_num) 56 if (print_line_num)
57 printf("%i:", linenum); 57 printf("%i:", linenum);
58 58
59 printf("%s", line); 59 puts(line);
60} 60}
61 61
62static void grep_file(FILE *file) 62static void grep_file(FILE *file)
@@ -67,6 +67,8 @@ static void grep_file(FILE *file)
67 int nmatches = 0; 67 int nmatches = 0;
68 68
69 while ((line = get_line_from_file(file)) != NULL) { 69 while ((line = get_line_from_file(file)) != NULL) {
70 if (line[strlen(line)-1] == '\n')
71 line[strlen(line)-1] = '\0';
70 linenum++; 72 linenum++;
71 ret = regexec(&regex, line, 0, NULL, 0); 73 ret = regexec(&regex, line, 0, NULL, 0);
72 if (ret == 0 && !invert_search) { /* match */ 74 if (ret == 0 && !invert_search) { /* match */
@@ -144,7 +146,7 @@ extern int grep_main(int argc, char **argv)
144 /* compile the regular expression 146 /* compile the regular expression
145 * we're not going to mess with sub-expressions, and we need to 147 * we're not going to mess with sub-expressions, and we need to
146 * treat newlines right. */ 148 * treat newlines right. */
147 reflags = REG_NOSUB | REG_NEWLINE; 149 reflags = REG_NOSUB;
148 if (ignore_case) 150 if (ignore_case)
149 reflags |= REG_ICASE; 151 reflags |= REG_ICASE;
150 xregcomp(&regex, argv[optind], reflags); 152 xregcomp(&regex, argv[optind], reflags);