home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNUGRE.ZIP / grep16.bug < prev    next >
Internet Message Format  |  1992-07-18  |  4KB

  1. 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
  2. Article: 3020 of gnu.utils.bug
  3. Path: NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
  4. From: eggert@twinsun.COM (Paul Eggert)
  5. Newsgroups: gnu.utils.bug
  6. Subject: grep 1.6 issues wrong error messages for some bad patterns
  7. Message-ID: <9206090003.AA29600@farside.twinsun.com>
  8. Date: 9 Jun 92 00:03:51 GMT
  9. Sender: gnulists@ai.mit.edu
  10. Distribution: gnu
  11. Organization: GNUs Not Usenet
  12. Lines: 37
  13. Approved: bug-gnu-utils@prep.ai.mit.edu
  14.  
  15. With the -w and -x options, grep 1.6 issues the wrong error messages
  16. for some bad patterns.  For example:
  17.  
  18.     $ grep -x '\'
  19.     grep: Unbalanced (
  20.     $ egrep -x ')('
  21.     egrep: Unmatched \)
  22.  
  23. The problem is that the regular expression syntax is not being checked
  24. at the proper point.  Here is a patch.
  25.  
  26. *** old/grep.c    Tue May  5 19:40:20 1992
  27. --- new/grep.c    Mon Jun  8 16:57:49 1992
  28. ***************
  29. *** 724,729 ****
  30. --- 724,732 ----
  31.       }
  32.     else
  33.       regexp_len = strlen(the_regexp);
  34. +   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
  35. +     regerror(regex_errmesg);
  36.     
  37.     if (whole_word || whole_line)
  38.       {
  39. ***************
  40. *** 768,776 ****
  41.     else
  42.       regcompile(the_regexp, regexp_len, ®, 1);
  43.   
  44. -   
  45. -   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
  46. -     regerror(regex_errmesg);
  47.     
  48.     /*
  49.       Find the longest metacharacter-free string which must occur in the
  50. --- 771,776 ----
  51.  
  52.  
  53. 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
  54. Article: 3018 of gnu.utils.bug
  55. Path: NewsServ!reseq!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
  56. From: eggert@twinsun.COM (Paul Eggert)
  57. Newsgroups: gnu.utils.bug
  58. Subject: grep 1.6 -w silently overrides -x
  59. Message-ID: <9206090014.AA29620@farside.twinsun.com>
  60. Date: 9 Jun 92 00:14:36 GMT
  61. Sender: gnulists@ai.mit.edu
  62. Distribution: gnu
  63. Organization: GNUs Not Usenet
  64. Lines: 86
  65. Approved: bug-gnu-utils@prep.ai.mit.edu
  66.  
  67. In GNU grep 1.6, the -w option silently overrides the -x option.
  68. But from the documentation, one would expect -w -x to cause the pattern
  69. to match only if the match is a whole word _and_ a whole line.
  70. For example, if the input is
  71.  
  72. a
  73. a b c
  74.  
  75. then `grep -w -x a' should output just the first line `a';
  76. but currently it outputs both lines.
  77.  
  78. Here is an (untested) patch.
  79.  
  80. *** old/grep.c    Tue May  5 19:40:20 1992
  81. --- new/grep.c    Mon Jun  8 17:12:26 1992
  82. ***************
  83. *** 734,766 ****
  84.        BUG: Using [A-Za-z_] is locale-dependent!  */
  85.   
  86.         char *n = malloc(regexp_len + 50);
  87. !       int i = 0;
  88.   
  89.   #ifdef EGREP
  90.         if (whole_word)
  91. !     strcpy(n, "(^|[^A-Za-z_])(");
  92. !       else
  93. !     strcpy(n, "^(");
  94.   #else
  95.         /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
  96.         if (whole_word)
  97. !     strcpy(n, "\\(^\\|[^A-Za-z_]\\)\\(");
  98. !       else
  99. !     strcpy(n, "^\\(");
  100.   #endif
  101.         i = strlen(n);
  102.         bcopy(the_regexp, n + i, regexp_len);
  103.         i += regexp_len;
  104.   #ifdef EGREP
  105.         if (whole_word)
  106. !     strcpy(n + i, ")([^A-Za-z_]|$)");
  107. !       else
  108. !     strcpy(n + i, ")$");
  109.   #else
  110.         if (whole_word)
  111. !     strcpy(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
  112. !       else
  113. !     strcpy(n + i, "\\)$");
  114.   #endif
  115.         i += strlen(n + i);
  116.         regcompile(n, i, ®, 1);
  117. --- 737,771 ----
  118.        BUG: Using [A-Za-z_] is locale-dependent!  */
  119.   
  120.         char *n = malloc(regexp_len + 50);
  121. !       int i;
  122.   
  123. +       n[0] = 0;
  124.   #ifdef EGREP
  125. +       if (whole_line)
  126. +     strcat(n, "^(");
  127.         if (whole_word)
  128. !     strcat(n, "(^|[^A-Za-z_])(");
  129.   #else
  130.         /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
  131. +       if (whole_line)
  132. +     strcat(n, "^\\(");
  133.         if (whole_word)
  134. !     strcat(n, "\\(^\\|[^A-Za-z_]\\)\\(");
  135.   #endif
  136.         i = strlen(n);
  137.         bcopy(the_regexp, n + i, regexp_len);
  138.         i += regexp_len;
  139. +       n[i] = 0;
  140.   #ifdef EGREP
  141.         if (whole_word)
  142. !     strcat(n + i, ")([^A-Za-z_]|$)");
  143. !       if (whole_line)
  144. !     strcat(n + i, ")$");
  145.   #else
  146.         if (whole_word)
  147. !     strcat(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
  148. !       if (whole_line)
  149. !     strcat(n + i, "\\)$");
  150.   #endif
  151.         i += strlen(n + i);
  152.         regcompile(n, i, ®, 1);
  153.  
  154.  
  155.