summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai2000-10-13 18:55:06 +0000
committerMatt Kraai2000-10-13 18:55:06 +0000
commit567cdd1d517103e74153d0c45713f72457a702ab (patch)
treea127f8c2fb6ca98cc4e0708ac8510e38610c29d2
parent9a6e67c9602ebe7e2e4463827ce8d02a237dbcc3 (diff)
downloadbusybox-567cdd1d517103e74153d0c45713f72457a702ab.zip
busybox-567cdd1d517103e74153d0c45713f72457a702ab.tar.gz
Fix handling of ^$ by removing the newline from input lines and by not
compiling with REG_NEWLINE.
-rw-r--r--findutils/grep.c6
-rw-r--r--grep.c6
2 files changed, 8 insertions, 4 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 003dae9..c0193bc 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -56,7 +56,7 @@ static void print_matched_line(char *line, int linenum)
if (print_line_num)
printf("%i:", linenum);
- printf("%s", line);
+ puts(line);
}
static void grep_file(FILE *file)
@@ -67,6 +67,8 @@ static void grep_file(FILE *file)
int nmatches = 0;
while ((line = get_line_from_file(file)) != NULL) {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
linenum++;
ret = regexec(&regex, line, 0, NULL, 0);
if (ret == 0 && !invert_search) { /* match */
@@ -144,7 +146,7 @@ extern int grep_main(int argc, char **argv)
/* compile the regular expression
* we're not going to mess with sub-expressions, and we need to
* treat newlines right. */
- reflags = REG_NOSUB | REG_NEWLINE;
+ reflags = REG_NOSUB;
if (ignore_case)
reflags |= REG_ICASE;
xregcomp(&regex, argv[optind], reflags);
diff --git a/grep.c b/grep.c
index 003dae9..c0193bc 100644
--- a/grep.c
+++ b/grep.c
@@ -56,7 +56,7 @@ static void print_matched_line(char *line, int linenum)
if (print_line_num)
printf("%i:", linenum);
- printf("%s", line);
+ puts(line);
}
static void grep_file(FILE *file)
@@ -67,6 +67,8 @@ static void grep_file(FILE *file)
int nmatches = 0;
while ((line = get_line_from_file(file)) != NULL) {
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
linenum++;
ret = regexec(&regex, line, 0, NULL, 0);
if (ret == 0 && !invert_search) { /* match */
@@ -144,7 +146,7 @@ extern int grep_main(int argc, char **argv)
/* compile the regular expression
* we're not going to mess with sub-expressions, and we need to
* treat newlines right. */
- reflags = REG_NOSUB | REG_NEWLINE;
+ reflags = REG_NOSUB;
if (ignore_case)
reflags |= REG_ICASE;
xregcomp(&regex, argv[optind], reflags);