home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 22 gnu
/
22-gnu.zip
/
GNUGRE.ZIP
/
grep16.bug
< prev
next >
Wrap
Internet Message Format
|
1992-07-18
|
4KB
From NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert Wed Jun 10 02:22:56 MESZ 1992
Article: 3020 of gnu.utils.bug
Path: NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Newsgroups: gnu.utils.bug
Subject: grep 1.6 issues wrong error messages for some bad patterns
Message-ID: <9206090003.AA29600@farside.twinsun.com>
Date: 9 Jun 92 00:03:51 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 37
Approved: bug-gnu-utils@prep.ai.mit.edu
With the -w and -x options, grep 1.6 issues the wrong error messages
for some bad patterns. For example:
$ grep -x '\'
grep: Unbalanced (
$ egrep -x ')('
egrep: Unmatched \)
The problem is that the regular expression syntax is not being checked
at the proper point. Here is a patch.
*** old/grep.c Tue May 5 19:40:20 1992
--- new/grep.c Mon Jun 8 16:57:49 1992
***************
*** 724,729 ****
--- 724,732 ----
}
else
regexp_len = strlen(the_regexp);
+
+ if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
+ regerror(regex_errmesg);
if (whole_word || whole_line)
{
***************
*** 768,776 ****
else
regcompile(the_regexp, regexp_len, ®, 1);
-
- if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
- regerror(regex_errmesg);
/*
Find the longest metacharacter-free string which must occur in the
--- 771,776 ----
From NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert Wed Jun 10 02:22:27 MESZ 1992
Article: 3018 of gnu.utils.bug
Path: NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Newsgroups: gnu.utils.bug
Subject: grep 1.6 -w silently overrides -x
Message-ID: <9206090014.AA29620@farside.twinsun.com>
Date: 9 Jun 92 00:14:36 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 86
Approved: bug-gnu-utils@prep.ai.mit.edu
In GNU grep 1.6, the -w option silently overrides the -x option.
But from the documentation, one would expect -w -x to cause the pattern
to match only if the match is a whole word _and_ a whole line.
For example, if the input is
a
a b c
then `grep -w -x a' should output just the first line `a';
but currently it outputs both lines.
Here is an (untested) patch.
*** old/grep.c Tue May 5 19:40:20 1992
--- new/grep.c Mon Jun 8 17:12:26 1992
***************
*** 734,766 ****
BUG: Using [A-Za-z_] is locale-dependent! */
char *n = malloc(regexp_len + 50);
! int i = 0;
#ifdef EGREP
if (whole_word)
! strcpy(n, "(^|[^A-Za-z_])(");
! else
! strcpy(n, "^(");
#else
/* Todo: Make *sure* this is the right syntax. Down with grep! */
if (whole_word)
! strcpy(n, "\\(^\\|[^A-Za-z_]\\)\\(");
! else
! strcpy(n, "^\\(");
#endif
i = strlen(n);
bcopy(the_regexp, n + i, regexp_len);
i += regexp_len;
#ifdef EGREP
if (whole_word)
! strcpy(n + i, ")([^A-Za-z_]|$)");
! else
! strcpy(n + i, ")$");
#else
if (whole_word)
! strcpy(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
! else
! strcpy(n + i, "\\)$");
#endif
i += strlen(n + i);
regcompile(n, i, ®, 1);
--- 737,771 ----
BUG: Using [A-Za-z_] is locale-dependent! */
char *n = malloc(regexp_len + 50);
! int i;
+ n[0] = 0;
#ifdef EGREP
+ if (whole_line)
+ strcat(n, "^(");
if (whole_word)
! strcat(n, "(^|[^A-Za-z_])(");
#else
/* Todo: Make *sure* this is the right syntax. Down with grep! */
+ if (whole_line)
+ strcat(n, "^\\(");
if (whole_word)
! strcat(n, "\\(^\\|[^A-Za-z_]\\)\\(");
#endif
i = strlen(n);
bcopy(the_regexp, n + i, regexp_len);
i += regexp_len;
+ n[i] = 0;
#ifdef EGREP
if (whole_word)
! strcat(n + i, ")([^A-Za-z_]|$)");
! if (whole_line)
! strcat(n + i, ")$");
#else
if (whole_word)
! strcat(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
! if (whole_line)
! strcat(n + i, "\\)$");
#endif
i += strlen(n + i);
regcompile(n, i, ®, 1);