home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNUGRE.ZIP / grep.patch < prev    next >
Text File  |  1992-07-18  |  7KB  |  252 lines

  1. diff -cbr orig/grep/dfa.c new/grep/dfa.c
  2. *** orig/grep/dfa.c    Tue May 05 19:32:05 1992
  3. --- new/grep/dfa.c    Thu Jun 18 15:42:18 1992
  4. ***************
  5. *** 31,36 ****
  6. --- 31,37 ----
  7.   #endif
  8.   
  9.   #include "dfa.h"
  10. + #include "regex.h"
  11.   
  12.   #if __STDC__
  13.   typedef void *ptr_t;
  14. diff -cbr orig/grep/dfa.h new/grep/dfa.h
  15. *** orig/grep/dfa.h    Mon May 04 13:43:28 1992
  16. --- new/grep/dfa.h    Thu Jun 18 15:45:13 1992
  17. ***************
  18. *** 48,53 ****
  19. --- 48,55 ----
  20.   #define ISLOWER(c) (isascii(c) && islower(c))
  21.   #endif
  22.   
  23. + #if 0 /* This is really defined in regex.h */
  24.   /* 1 means plain parentheses serve as grouping, and backslash
  25.        parentheses are needed for literal searching.
  26.      0 means backslash-parentheses are grouping, and plain parentheses
  27. ***************
  28. *** 84,89 ****
  29. --- 86,94 ----
  30.   #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  31.   #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  32.   #define RE_SYNTAX_EMACS 0
  33. + #endif
  34.   
  35.   /* Number of bits in an unsigned char. */
  36.   #define CHARBITS 8
  37. diff -cbr orig/grep/grep.c new/grep/grep.c
  38. *** orig/grep/grep.c    Tue May 05 19:40:10 1992
  39. --- new/grep/grep.c    Thu Jun 18 16:11:12 1992
  40. ***************
  41. *** 38,47 ****
  42.   
  43.   #ifndef STDC_HEADERS
  44.   extern char *getenv();
  45. - #endif
  46.   extern int errno;
  47.   extern char *sys_errlist[];
  48.   
  49.   #include "dfa.h"
  50.   #include "regex.h"
  51. --- 38,46 ----
  52.   
  53.   #ifndef STDC_HEADERS
  54.   extern char *getenv();
  55.   extern int errno;
  56.   extern char *sys_errlist[];
  57. + #endif
  58.   
  59.   #include "dfa.h"
  60.   #include "regex.h"
  61. ***************
  62. *** 534,550 ****
  63.     return match_count;
  64.   }
  65.   
  66.   void
  67.   usage_and_die()
  68.   {
  69. !   fprintf(stderr, "\
  70. ! Usage: %s [-CVbchilnsvwx] [-num] [-A num] [-B num] [-f file]\n\
  71. !        [-e] expr [file...]\n", prog);
  72.     exit(ERROR);
  73.   }
  74.   
  75. - static char version[] = "GNU e?grep, version 1.6";
  76.   int
  77.   main(argc, argv)
  78.        int argc;
  79. --- 533,572 ----
  80.     return match_count;
  81.   }
  82.   
  83. + static char version[] = "GNU e?grep, version 1.6";
  84.   void
  85.   usage_and_die()
  86.   {
  87. !   printf("\n%s\n", version);
  88. !   printf("\nUsage: %s [-CVbchilnsvwx] [-<num>] [-A <num>] [-B <num>]"
  89. !          "\n       [-f file] [-e] expr [files]\n\n", prog);
  90. !   printf(
  91. !   "  -A <num>  print <num> lines of context after every matching line\n"
  92. !   "  -B <num>  print <num> lines of context before every matching line\n"
  93. !   "  -C        print 2 lines of context on each side of every match\n"
  94. !   "  -<num>    print <num> lines of context on each side\n"
  95. !   "  -V        print the version number on stderr\n"
  96. !   );
  97. !   printf(
  98. !   "  -b        print every match preceded by its byte offset\n"
  99. !   "  -c        print a total count of matching lines only\n"
  100. !   "  -e <expr> search for <expr>; useful if <expr> begins with -\n"
  101. !   "  -f <file> take <expr> from the given <file>\n"
  102. !   "  -h        don't display filenames on matches\n"
  103. !   "  -i        ignore case difference when comparing strings\n"
  104. !   );
  105. !   printf(
  106. !   "  -l        list files containing matches only\n"
  107. !   "  -n        print each match preceded by its line number\n"
  108. !   "  -s        run silently producing no output except error messages\n"
  109. !   "  -v        print only lines that contain no matches for the <expr>\n"
  110. !   "  -w        print only lines where the match is a complete word\n"
  111. !   "  -x        print only lines where the match is a whole line\n");
  112.     exit(ERROR);
  113.   }
  114.   
  115.   int
  116.   main(argc, argv)
  117.        int argc;
  118. ***************
  119. *** 563,568 ****
  120. --- 585,595 ----
  121.     char translate[_NOTCHAR];    /* Translate table for case conversion
  122.                      (needed by the backtracking matcher). */
  123.   
  124. + #ifdef __EMX__
  125. +   _wildcard(&argc, &argv);
  126. +   setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
  127. + #endif
  128.     if (prog = index(argv[0], '/'))
  129.       ++prog;
  130.     else
  131. ***************
  132. *** 607,613 ****
  133.       break;
  134.   
  135.         case 'V':
  136. !     fprintf(stderr, "%s\n", version);
  137.       break;
  138.   
  139.         case 'b':
  140. --- 634,641 ----
  141.       break;
  142.   
  143.         case 'V':
  144. !         fprintf(stderr, "\n%s\n", version);
  145. !         exit(ERROR);
  146.       break;
  147.   
  148.         case 'b':
  149. ***************
  150. *** 725,730 ****
  151. --- 753,761 ----
  152.     else
  153.       regexp_len = strlen(the_regexp);
  154.   
  155. +   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
  156. +     regerror(regex_errmesg);
  157.     if (whole_word || whole_line)
  158.       {
  159.         /* In the whole-word case, we use the pattern:
  160. ***************
  161. *** 734,766 ****
  162.        BUG: Using [A-Za-z_] is locale-dependent!  */
  163.   
  164.         char *n = malloc(regexp_len + 50);
  165. !       int i = 0;
  166.   
  167.   #ifdef EGREP
  168.         if (whole_word)
  169. !     strcpy(n, "(^|[^A-Za-z_])(");
  170. !       else
  171. !     strcpy(n, "^(");
  172.   #else
  173.         /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
  174.         if (whole_word)
  175. !     strcpy(n, "\\(^\\|[^A-Za-z_]\\)\\(");
  176. !       else
  177. !     strcpy(n, "^\\(");
  178.   #endif
  179.         i = strlen(n);
  180.         bcopy(the_regexp, n + i, regexp_len);
  181.         i += regexp_len;
  182.   #ifdef EGREP
  183.         if (whole_word)
  184. !     strcpy(n + i, ")([^A-Za-z_]|$)");
  185. !       else
  186. !     strcpy(n + i, ")$");
  187.   #else
  188.         if (whole_word)
  189. !     strcpy(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
  190. !       else
  191. !     strcpy(n + i, "\\)$");
  192.   #endif
  193.         i += strlen(n + i);
  194.         regcompile(n, i, ®, 1);
  195. --- 765,799 ----
  196.        BUG: Using [A-Za-z_] is locale-dependent!  */
  197.   
  198.         char *n = malloc(regexp_len + 50);
  199. !       int i;
  200.   
  201. +       n[0] = 0;
  202.   #ifdef EGREP
  203. +       if (whole_line)
  204. +     strcat(n, "^(");
  205.         if (whole_word)
  206. !     strcat(n, "(^|[^A-Za-z_])(");
  207.   #else
  208.         /* Todo:  Make *sure* this is the right syntax.  Down with grep! */
  209. +       if (whole_line)
  210. +     strcat(n, "^\\(");
  211.         if (whole_word)
  212. !     strcat(n, "\\(^\\|[^A-Za-z_]\\)\\(");
  213.   #endif
  214.         i = strlen(n);
  215.         bcopy(the_regexp, n + i, regexp_len);
  216.         i += regexp_len;
  217. +       n[i] = 0;
  218.   #ifdef EGREP
  219.         if (whole_word)
  220. !     strcat(n + i, ")([^A-Za-z_]|$)");
  221. !       if (whole_line)
  222. !     strcat(n + i, ")$");
  223.   #else
  224.         if (whole_word)
  225. !     strcat(n + i, "\\)\\([^A-Za-z_]\\|$\\)");
  226. !       if (whole_line)
  227. !     strcat(n + i, "\\)$");
  228.   #endif
  229.         i += strlen(n + i);
  230.         regcompile(n, i, ®, 1);
  231. ***************
  232. *** 768,776 ****
  233.     else
  234.       regcompile(the_regexp, regexp_len, ®, 1);
  235.   
  236. -   if (regex_errmesg = re_compile_pattern(the_regexp, regexp_len, ®ex))
  237. -     regerror(regex_errmesg);
  238.   
  239.     /*
  240.       Find the longest metacharacter-free string which must occur in the
  241. --- 801,806 ----
  242.