home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / grep.pat < prev    next >
Text File  |  1992-01-19  |  27KB  |  981 lines

  1. diff -cbBw orig/dfa.c grep/dfa.c
  2. *** orig/dfa.c    Mon May 07 09:08:54 1990
  3. --- grep/dfa.c    Sun Jan 19 18:42:02 1992
  4. ***************
  5. *** 109,114 ****
  6. --- 109,115 ----
  7.   #include <assert.h>
  8.   #include <ctype.h>
  9.   #include "dfa.h"
  10. + #include "regex.h"
  11.   
  12.   #ifdef __STDC__
  13.   typedef void *ptr_t;
  14. diff -cbBw orig/dfa.h grep/dfa.h
  15. *** orig/dfa.h    Mon May 07 09:08:54 1990
  16. --- grep/dfa.h    Sun Jan 19 18:40:38 1992
  17. ***************
  18. *** 115,126 ****
  19.   #ifdef __STDC__
  20.   
  21.   /* Missing include files for GNU C. */
  22. ! /* #include <stdlib.h> */
  23.   typedef int size_t;
  24.   extern void *calloc(int, size_t);
  25.   extern void *malloc(size_t);
  26.   extern void *realloc(void *, size_t);
  27.   extern void free(void *);
  28.   
  29.   extern char *bcopy(), *bzero();
  30.   
  31. --- 115,129 ----
  32.   #ifdef __STDC__
  33.   
  34.   /* Missing include files for GNU C. */
  35. ! #ifdef OS2
  36. ! #include <stdlib.h>
  37. ! #else
  38.   typedef int size_t;
  39.   extern void *calloc(int, size_t);
  40.   extern void *malloc(size_t);
  41.   extern void *realloc(void *, size_t);
  42.   extern void free(void *);
  43. + #endif
  44.   
  45.   extern char *bcopy(), *bzero();
  46.   
  47. ***************
  48. *** 149,154 ****
  49. --- 152,159 ----
  50.   
  51.   #endif /* ! __STDC__ */
  52.   
  53. + #if 0 /* This is really defined in regex.h */
  54.   /* 1 means plain parentheses serve as grouping, and backslash
  55.        parentheses are needed for literal searching.
  56.      0 means backslash-parentheses are grouping, and plain parentheses
  57. ***************
  58. *** 186,193 ****
  59. --- 191,202 ----
  60.   #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  61.   #define RE_SYNTAX_EMACS 0
  62.   
  63. + #endif
  64.   /* The NULL pointer. */
  65. + #ifndef OS2
  66.   #define NULL 0
  67. + #endif
  68.   
  69.   /* Number of bits in an unsigned char. */
  70.   #define CHARBITS 8
  71. diff -cbBw orig/grep.c grep/grep.c
  72. *** orig/grep.c    Mon May 07 09:08:54 1990
  73. --- grep/grep.c    Sun Jan 19 18:40:38 1992
  74. ***************
  75. *** 127,134 ****
  76. --- 127,136 ----
  77.   
  78.   extern char *optarg;
  79.   extern optind, opterr;
  80. + #ifndef OS2
  81.   extern errno;
  82.   extern char *sys_errlist[];
  83. + #endif
  84.   
  85.   #define MAX(a, b) ((a) > (b) ? (a) : (b))
  86.   
  87. ***************
  88. *** 373,378 ****
  89. --- 375,382 ----
  90.                          next_line - matching_line - 1,
  91.                          NULL) < 0)
  92.           {
  93. +           --match_count;        /* debugged by kaoru.  August 15, 1990. */
  94. +           ++line_count;        /* debugged by kaoru.  August 15, 1990. */
  95.             resume = next_line;
  96.             if (resume == search_limit)
  97.           break;
  98. ***************
  99. *** 533,549 ****
  100.     return nonmatching_lines ? (line_count - 1) - match_count : match_count;
  101.   }
  102.   
  103.   void
  104.   usage_and_die()
  105.   {
  106. !   fprintf(stderr,
  107. ! "usage: %s [-CVbchilnsvwx] [-<num>] [-AB <num>] [-f file] [-e] expr [files]\n",
  108. !           prog);
  109.     exit(ERROR);
  110.   }
  111.   
  112. - static char version[] = "GNU e?grep, version 1.5";
  113.   main(argc, argv)
  114.        int argc;
  115.        char **argv;
  116. --- 537,581 ----
  117.     return nonmatching_lines ? (line_count - 1) - match_count : match_count;
  118.   }
  119.   
  120. + #ifdef EGREP
  121. + static char version[] = "GNU egrep, version 1.5";
  122. + #else
  123. + static char version[] = "GNU grep, version 1.5";
  124. + #endif
  125.   void
  126.   usage_and_die()
  127.   {
  128. !   printf("\n%s\n", version);
  129. !   printf("\nUsage: %s [-CVbchilnsvwx] [-<num>] [-AB <num>]"
  130. !                     " [-f file] [-e] expr [files]\n\n", prog);
  131. !   printf(
  132. !   "  -A <num>  print <num> lines of context after every matching line\n"
  133. !   "  -B <num>  print <num> lines of context before every matching line\n"
  134. !   "  -C        print 2 lines of context on each side of every match\n"
  135. !   "  -<num>    print <num> lines of context on each side\n"
  136. !   "  -V        print the version number on stderr\n"
  137. !   );
  138. !   printf(
  139. !   "  -b        print every match preceded by its byte offset\n"
  140. !   "  -c        print a total count of matching lines only\n"
  141. !   "  -e <expr> search for <expr>; useful if <expr> begins with -\n"
  142. !   "  -f <file> take <expr> from the given <file>\n"
  143. !   "  -h        don't display filenames on matches\n"
  144. !   "  -i        ignore case difference when comparing strings\n"
  145. !   );
  146. !   printf(
  147. !   "  -l        list files containing matches only\n"
  148. !   "  -n        print each match preceded by its line number\n"
  149. !   "  -s        run silently producing no output except error messages\n"
  150. !   "  -v        print only lines that contain no matches for the <expr>\n"
  151. !   "  -w        print only lines where the match is a complete word\n"
  152. !   "  -x        print only lines where the match is a whole line\n");
  153.     exit(ERROR);
  154.   }
  155.   
  156.   main(argc, argv)
  157.        int argc;
  158.        char **argv;
  159. ***************
  160. *** 607,613 ****
  161.       break;
  162.   
  163.         case 'V':
  164. !     fprintf(stderr, "%s\n", version);
  165.       break;
  166.   
  167.         case 'b':
  168. --- 639,646 ----
  169.       break;
  170.   
  171.         case 'V':
  172. !         fprintf(stderr, "\n%s\n", version);
  173. !         exit(ERROR);
  174.       break;
  175.   
  176.         case 'b':
  177. diff -cbBw orig/regex.c grep/regex.c
  178. *** orig/regex.c    Mon May 07 09:08:56 1990
  179. --- grep/regex.c    Sun Jan 19 14:30:04 1992
  180. ***************
  181. *** 20,25 ****
  182. --- 20,26 ----
  183.      You are forbidden to forbid anyone else to use, share and improve
  184.      what you give them.   Help stamp out software-hoarding!  */
  185.   
  186. + #define USG
  187.   
  188.   /* To test, compile with -Dtest.
  189.    This Dtestable feature turns this into a self-contained program
  190. ***************
  191. *** 39,48 ****
  192. --- 40,51 ----
  193.   #else  /* not emacs */
  194.   
  195.   #ifdef USG
  196. + #ifndef BSTRING
  197.   #define bcopy(s,d,n)    memcpy((d),(s),(n))
  198.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  199.   #define bzero(s,n)    memset((s),0,(n))
  200.   #endif
  201. + #endif
  202.   
  203.   /* Make alloca work the best possible way.  */
  204.   #ifdef __GNUC__
  205. ***************
  206. *** 53,58 ****
  207. --- 56,68 ----
  208.   #endif
  209.   #endif
  210.   
  211. + #ifdef OS2
  212. + #include <stdlib.h>
  213. + #include <string.h>
  214. + #include <memory.h>
  215. + #include <malloc.h>
  216. + #endif
  217.   /*
  218.    * Define the syntax stuff, so we can do the \<...\> things.
  219.    */
  220. ***************
  221. *** 72,78 ****
  222.   static char re_syntax_table[256];
  223.   
  224.   static void
  225. ! init_syntax_once ()
  226.   {
  227.      register int c;
  228.      static int done = 0;
  229. --- 82,88 ----
  230.   static char re_syntax_table[256];
  231.   
  232.   static void
  233. ! init_syntax_once (void)
  234.   {
  235.      register int c;
  236.      static int done = 0;
  237. ***************
  238. *** 91,96 ****
  239. --- 101,108 ----
  240.      for (c = '0'; c <= '9'; c++)
  241.        re_syntax_table[c] = Sword;
  242.   
  243. +    re_syntax_table['_'] = Sword;
  244.      done = 1;
  245.   }
  246.   
  247. ***************
  248. *** 112,120 ****
  249.   #define BYTEWIDTH 8
  250.   
  251.   #ifndef SIGN_EXTEND_CHAR
  252. ! #define SIGN_EXTEND_CHAR(x) (x)
  253.   #endif
  254.   static int obscure_syntax = 0;
  255.   
  256.   /* Specify the precise syntax of regexp for compilation.
  257. --- 124,132 ----
  258.   #define BYTEWIDTH 8
  259.   
  260.   #ifndef SIGN_EXTEND_CHAR
  261. ! #define SIGN_EXTEND_CHAR(x) ((int) (signed char) x)
  262.   #endif
  263.   static int obscure_syntax = 0;
  264.   
  265.   /* Specify the precise syntax of regexp for compilation.
  266. ***************
  267. *** 125,131 ****
  268.      RE_NO_BK_PARENS and RE_NO_BK_VBAR.  */
  269.   
  270.   int
  271. ! re_set_syntax (syntax)
  272.   {
  273.     int ret;
  274.   
  275. --- 137,143 ----
  276.      RE_NO_BK_PARENS and RE_NO_BK_VBAR.  */
  277.   
  278.   int
  279. ! re_set_syntax (int syntax)
  280.   {
  281.     int ret;
  282.   
  283. ***************
  284. *** 133,139 ****
  285.     obscure_syntax = syntax;
  286.     return ret;
  287.   }
  288.   /* re_compile_pattern takes a regular-expression string
  289.      and converts it into a buffer full of byte commands for matching.
  290.   
  291. --- 145,151 ----
  292.     obscure_syntax = syntax;
  293.     return ret;
  294.   }
  295.   /* re_compile_pattern takes a regular-expression string
  296.      and converts it into a buffer full of byte commands for matching.
  297.   
  298. ***************
  299. *** 163,187 ****
  300.   
  301.   #define PATUNFETCH p--
  302.   
  303.   #define EXTEND_BUFFER \
  304.     { char *old_buffer = bufp->buffer; \
  305. !     if (bufp->allocated == (1<<16)) goto too_big; \
  306.       bufp->allocated *= 2; \
  307. !     if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \
  308. !     if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \
  309.         goto memory_exhausted; \
  310. !     c = bufp->buffer - old_buffer; \
  311. !     b += c; \
  312.       if (fixup_jump) \
  313. !       fixup_jump += c; \
  314.       if (laststart) \
  315. !       laststart += c; \
  316. !     begalt += c; \
  317.       if (pending_exact) \
  318. !       pending_exact += c; \
  319.     }
  320.   
  321. - static int store_jump (), insert_jump ();
  322.   
  323.   char *
  324.   re_compile_pattern (pattern, size, bufp)
  325. --- 175,248 ----
  326.   
  327.   #define PATUNFETCH p--
  328.   
  329. + #ifndef OS2
  330. + #define EXTEND_BUFFER                            \
  331. +   { char *old_buffer = bufp->buffer;                    \
  332. +     if (bufp->allocated == (1L<<16)) goto too_big;            \
  333. +     bufp->allocated *= 2;                        \
  334. +     if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16);        \
  335. +     bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);    \
  336. +     if (bufp->buffer == 0)                        \
  337. +       goto memory_exhausted;                        \
  338. +     b = (b - old_buffer) + bufp->buffer;                \
  339. +     if (fixup_jump)                            \
  340. +       fixup_jump = (fixup_jump - old_buffer) + bufp->buffer;        \
  341. +     if (laststart)                            \
  342. +       laststart = (laststart - old_buffer) + bufp->buffer;        \
  343. +     begalt = (begalt - old_buffer) + bufp->buffer;            \
  344. +     if (pending_exact)                            \
  345. +       pending_exact = (pending_exact - old_buffer) + bufp->buffer;    \
  346. +   }
  347. + #else
  348.   #define EXTEND_BUFFER                            \
  349.     { char *old_buffer = bufp->buffer;                    \
  350. !     if (bufp->allocated == (1L<<15)) goto too_big;                      \
  351.       bufp->allocated *= 2;                        \
  352. !     if (bufp->allocated > (1L<<15)) bufp->allocated = (1L<<15);         \
  353. !     bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);    \
  354. !     if (bufp->buffer == 0)                        \
  355.         goto memory_exhausted;                        \
  356. !     b = (b - old_buffer) + bufp->buffer;                \
  357.       if (fixup_jump)                            \
  358. !       fixup_jump = (fixup_jump - old_buffer) + bufp->buffer;        \
  359.       if (laststart)                            \
  360. !       laststart = (laststart - old_buffer) + bufp->buffer;        \
  361. !     begalt = (begalt - old_buffer) + bufp->buffer;            \
  362.       if (pending_exact)                            \
  363. !       pending_exact = (pending_exact - old_buffer) + bufp->buffer;    \
  364. !   }
  365. ! #endif
  366. ! /* Store where `from' points a jump operation to jump to where `to' points.
  367. !   `opcode' is the opcode to store. */
  368. ! static void
  369. ! store_jump (char *from, char opcode, char *to)
  370. ! {
  371. !   from[0] = opcode;
  372. !   from[1] = (char) ((to - (from + 3)) & 0377);
  373. !   from[2] = (char) ((to - (from + 3)) >> 8);
  374. ! }
  375. ! /* Open up space at char FROM, and insert there a jump to TO.
  376. !    CURRENT_END gives te end of the storage no in use,
  377. !    so we know how much data to copy up.
  378. !    OP is the opcode of the jump to insert.
  379. !    If you call this function, you must zero out pending_exact.  */
  380. ! static void
  381. ! insert_jump (char op, char *from, char *to, char *current_end)
  382. ! {
  383. !   register char *pto = current_end + 3;
  384. !   register char *pfrom = current_end;
  385. !   while (pfrom != from)
  386. !     *--pto = *--pfrom;
  387. !   store_jump (from, op, to);
  388.   }
  389.   
  390.   
  391.   char *
  392.   re_compile_pattern (pattern, size, bufp)
  393. ***************
  394. *** 254,260 ****
  395.   #endif
  396.   #endif
  397.   
  398. !   if (bufp->allocated == 0)
  399.       {
  400.         bufp->allocated = 28;
  401.         if (bufp->buffer)
  402. --- 315,321 ----
  403.   #endif
  404.   #endif
  405.   
  406. !   if (bufp->allocated < 28)
  407.       {
  408.         bufp->allocated = 28;
  409.         if (bufp->buffer)
  410. ***************
  411. *** 420,425 ****
  412. --- 481,495 ----
  413.         while (1)
  414.           {
  415.             PATFETCH (c);
  416. +           /* If awk, \ escapes characters when inside [...].  */
  417. +           if ((obscure_syntax & RE_AWK_CLASS_HACK) && c == '\\')
  418. +             {
  419. +               PATFETCH(c1);
  420. +               b[c1 / BYTEWIDTH] |= 1 << (c1 % BYTEWIDTH);
  421. +               continue;
  422. +             }
  423.             if (c == ']' && p != p1 + 1) break;
  424.             if (*p == '-' && p[1] != ']')
  425.           {
  426. ***************
  427. *** 587,596 ****
  428.           case '8':
  429.           case '9':
  430.             c1 = c - '0';
  431. !           if (c1 >= regnum)
  432.           goto normal_char;
  433.             for (stackt = stackp - 2;  stackt > stackb;  stackt -= 4)
  434. !          if (*stackt == c1)
  435.             goto normal_char;
  436.             laststart = b;
  437.             PATPUSH (duplicate);
  438. --- 657,666 ----
  439.           case '8':
  440.           case '9':
  441.             c1 = c - '0';
  442. !           if ((int) c1 >= regnum)
  443.           goto normal_char;
  444.             for (stackt = stackp - 2;  stackt > stackb;  stackt -= 4)
  445. !          if (*stackt == (int) c1)
  446.             goto normal_char;
  447.             laststart = b;
  448.             PATPUSH (duplicate);
  449. ***************
  450. *** 660,697 ****
  451.     return "Memory exhausted";
  452.   }
  453.   
  454. - /* Store where `from' points a jump operation to jump to where `to' points.
  455. -   `opcode' is the opcode to store. */
  456. - static int
  457. - store_jump (from, opcode, to)
  458. -      char *from, *to;
  459. -      char opcode;
  460. - {
  461. -   from[0] = opcode;
  462. -   from[1] = (to - (from + 3)) & 0377;
  463. -   from[2] = (to - (from + 3)) >> 8;
  464. - }
  465. - /* Open up space at char FROM, and insert there a jump to TO.
  466. -    CURRENT_END gives te end of the storage no in use,
  467. -    so we know how much data to copy up.
  468. -    OP is the opcode of the jump to insert.
  469. -    If you call this function, you must zero out pending_exact.  */
  470. - static int
  471. - insert_jump (op, from, to, current_end)
  472. -      char op;
  473. -      char *from, *to, *current_end;
  474. - {
  475. -   register char *pto = current_end + 3;
  476. -   register char *pfrom = current_end;
  477. -   while (pfrom != from)
  478. -     *--pto = *--pfrom;
  479. -   store_jump (from, op, to);
  480. - }
  481.   /* Given a pattern, compute a fastmap from it.
  482.    The fastmap records which of the (1 << BYTEWIDTH) possible characters
  483.    can start a string that matches the pattern.
  484. --- 730,735 ----
  485. ***************
  486. *** 706,716 ****
  487.        struct re_pattern_buffer *bufp;
  488.   {
  489.     unsigned char *pattern = (unsigned char *) bufp->buffer;
  490. !   int size = bufp->used;
  491.     register char *fastmap = bufp->fastmap;
  492.     register unsigned char *p = pattern;
  493.     register unsigned char *pend = pattern + size;
  494. !   register int j, k;
  495.     unsigned char *translate = (unsigned char *) bufp->translate;
  496.   
  497.     unsigned char *stackb[NFAILURES];
  498. --- 744,757 ----
  499.        struct re_pattern_buffer *bufp;
  500.   {
  501.     unsigned char *pattern = (unsigned char *) bufp->buffer;
  502. !   int size = (int) bufp->used;
  503.     register char *fastmap = bufp->fastmap;
  504.     register unsigned char *p = pattern;
  505.     register unsigned char *pend = pattern + size;
  506. !   register int j;
  507. ! #ifdef emacs
  508. !   register int k;
  509. ! #endif
  510.     unsigned char *translate = (unsigned char *) bufp->translate;
  511.   
  512.     unsigned char *stackb[NFAILURES];
  513. ***************
  514. *** 879,885 ****
  515.       break;
  516.       }
  517.   }
  518.   /* Like re_search_2, below, but only one string is specified. */
  519.   
  520.   int
  521. --- 920,926 ----
  522.       break;
  523.       }
  524.   }
  525.   /* Like re_search_2, below, but only one string is specified. */
  526.   
  527.   int
  528. ***************
  529. *** 986,996 ****
  530.   
  531.         val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, regs, mstop);
  532.         if (0 <= val)
  533. !     {
  534.         if (val == -2)
  535.           return -2;
  536. -       return startpos;
  537. -     }
  538.   
  539.   #ifdef C_ALLOCA
  540.         alloca (0);
  541. --- 1027,1035 ----
  542.   
  543.         val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, regs, mstop);
  544.         if (0 <= val)
  545. !     return startpos;
  546.         if (val == -2)
  547.       return -2;
  548.   
  549.   #ifdef C_ALLOCA
  550.         alloca (0);
  551. ***************
  552. *** 1002,1008 ****
  553.       }
  554.     return -1;
  555.   }
  556.   #ifndef emacs   /* emacs never uses this */
  557.   int
  558.   re_match (pbufp, string, size, pos, regs)
  559. --- 1041,1047 ----
  560.       }
  561.     return -1;
  562.   }
  563.   #ifndef emacs   /* emacs never uses this */
  564.   int
  565.   re_match (pbufp, string, size, pos, regs)
  566. ***************
  567. *** 1019,1025 ****
  568.   
  569.   int re_max_failures = 2000;
  570.   
  571. ! static int bcmp_translate();
  572.   /* Match the pattern described by PBUFP
  573.      against data which is the virtual concatenation of STRING1 and STRING2.
  574.      SIZE1 and SIZE2 are the sizes of the two data strings.
  575. --- 1058,1066 ----
  576.   
  577.   int re_max_failures = 2000;
  578.   
  579. ! static int bcmp_translate (unsigned char *s1, unsigned char *s2, int len,
  580. !                            unsigned char *translate);
  581.   /* Match the pattern described by PBUFP
  582.      against data which is the virtual concatenation of STRING1 and STRING2.
  583.      SIZE1 and SIZE2 are the sizes of the two data strings.
  584. ***************
  585. *** 1037,1045 ****
  586.      of the substring which was matched.  */
  587.   
  588.   int
  589. ! re_match_2 (pbufp, string1, size1, string2, size2, pos, regs, mstop)
  590.        struct re_pattern_buffer *pbufp;
  591. !      unsigned char *string1, *string2;
  592.        int size1, size2;
  593.        int pos;
  594.        struct re_registers *regs;
  595. --- 1078,1086 ----
  596.      of the substring which was matched.  */
  597.   
  598.   int
  599. ! re_match_2 (pbufp, string1_arg, size1, string2_arg, size2, pos, regs, mstop)
  600.        struct re_pattern_buffer *pbufp;
  601. !      char *string1_arg, *string2_arg;
  602.        int size1, size2;
  603.        int pos;
  604.        struct re_registers *regs;
  605. ***************
  606. *** 1047,1052 ****
  607. --- 1088,1095 ----
  608.   {
  609.     register unsigned char *p = (unsigned char *) pbufp->buffer;
  610.     register unsigned char *pend = p + pbufp->used;
  611. +   unsigned char *string1 = (unsigned char *) string1_arg;
  612. +   unsigned char *string2 = (unsigned char *) string2_arg;
  613.     /* End of first string */
  614.     unsigned char *end1;
  615.     /* End of second string */
  616. ***************
  617. *** 1191,1202 ****
  618.   
  619.       case start_memory:
  620.         regstart[*p] = d;
  621. !        regstart_seg1[*p++] = (dend == end_match_1);
  622.         break;
  623.   
  624.       case stop_memory:
  625.         regend[*p] = d;
  626. !        regend_seg1[*p++] = (dend == end_match_1);
  627.         break;
  628.   
  629.       case duplicate:
  630. --- 1234,1245 ----
  631.   
  632.       case start_memory:
  633.         regstart[*p] = d;
  634. !           regstart_seg1[*p++] = (char) (dend == end_match_1);
  635.         break;
  636.   
  637.       case stop_memory:
  638.         regend[*p] = d;
  639. !           regend_seg1[*p++] = (char) (dend == end_match_1);
  640.         break;
  641.   
  642.       case duplicate:
  643. ***************
  644. *** 1341,1347 ****
  645.           register unsigned char *p1 = p + mcnt;
  646.           /* p1[0] ... p1[2] are an on_failure_jump.
  647.              Examine what follows that */
  648. !         if (p1[3] == (unsigned char) exactn && p1[5] != c)
  649.             p[-3] = (unsigned char) finalize_jump;
  650.           else if (p1[3] == (unsigned char) charset
  651.                || p1[3] == (unsigned char) charset_not)
  652. --- 1384,1390 ----
  653.           register unsigned char *p1 = p + mcnt;
  654.           /* p1[0] ... p1[2] are an on_failure_jump.
  655.              Examine what follows that */
  656. !                 if (p1[3] == (unsigned char) exactn && p1[5] != (char) c)
  657.             p[-3] = (unsigned char) finalize_jump;
  658.           else if (p1[3] == (unsigned char) charset
  659.                || p1[3] == (unsigned char) charset_not)
  660. ***************
  661. *** 1545,1554 ****
  662.   }
  663.   
  664.   static int
  665. ! bcmp_translate (s1, s2, len, translate)
  666. !      unsigned char *s1, *s2;
  667. !      register int len;
  668. !      unsigned char *translate;
  669.   {
  670.     register unsigned char *p1 = s1, *p2 = s2;
  671.     while (len)
  672. --- 1588,1594 ----
  673.   }
  674.   
  675.   static int
  676. ! bcmp_translate (unsigned char *s1, unsigned char *s2, int len, unsigned char *translate)
  677.   {
  678.     register unsigned char *p1 = s1, *p2 = s2;
  679.     while (len)
  680. ***************
  681. *** 1558,1564 ****
  682.       }
  683.     return 0;
  684.   }
  685.   /* Entry points compatible with bsd4.2 regex library */
  686.   
  687.   #ifndef emacs
  688. --- 1598,1604 ----
  689.       }
  690.     return 0;
  691.   }
  692.   /* Entry points compatible with bsd4.2 regex library */
  693.   
  694.   #ifndef emacs
  695. ***************
  696. *** 1596,1602 ****
  697.   }
  698.   
  699.   #endif /* emacs */
  700.   #ifdef test
  701.   
  702.   #include <stdio.h>
  703. --- 1636,1642 ----
  704.   }
  705.   
  706.   #endif /* emacs */
  707.   #ifdef test
  708.   
  709.   #include <stdio.h>
  710. ***************
  711. *** 1638,1651 ****
  712.       0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  713.     };
  714.   
  715. ! main (argc, argv)
  716. !      int argc;
  717. !      char **argv;
  718.   {
  719.     char pat[80];
  720.     struct re_pattern_buffer buf;
  721.     int i;
  722. -   char c;
  723.     char fastmap[(1 << BYTEWIDTH)];
  724.   
  725.     /* Allow a command argument to specify the style of syntax.  */
  726. --- 1678,1733 ----
  727.       0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  728.     };
  729.   
  730. ! #ifdef NOTDEF
  731. ! print_buf (bufp)
  732. !      struct re_pattern_buffer *bufp;
  733. ! {
  734. !   int i;
  735. !   printf ("buf is :\n----------------\n");
  736. !   for (i = 0; i < bufp->used; i++)
  737. !     printchar (bufp->buffer[i]);
  738. !   printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  739. !   printf ("Allowed by fastmap: ");
  740. !   for (i = 0; i < (1 << BYTEWIDTH); i++)
  741. !     if (bufp->fastmap[i])
  742. !       printchar (i);
  743. !   printf ("\nAllowed by translate: ");
  744. !   if (bufp->translate)
  745. !     for (i = 0; i < (1 << BYTEWIDTH); i++)
  746. !       if (bufp->translate[i])
  747. !     printchar (i);
  748. !   printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  749. !   printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  750. ! }
  751. ! #endif
  752. ! void printchar (int c)
  753. ! {
  754. !   if (c < 041 || c >= 0177)
  755. !     {
  756. !       putchar ('\\');
  757. !       putchar (((c >> 6) & 3) + '0');
  758. !       putchar (((c >> 3) & 7) + '0');
  759. !       putchar ((c & 7) + '0');
  760. !     }
  761. !   else
  762. !     putchar (c);
  763. ! }
  764. ! void error (char *string)
  765. ! {
  766. !   puts (string);
  767. !   exit (1);
  768. ! }
  769. ! void main (int argc, char **argv)
  770.   {
  771.     char pat[80];
  772.     struct re_pattern_buffer buf;
  773.     int i;
  774.     char fastmap[(1 << BYTEWIDTH)];
  775.   
  776.     /* Allow a command argument to specify the style of syntax.  */
  777. ***************
  778. *** 1684,1736 ****
  779.         i = re_match (&buf, pat, strlen (pat), 0, 0);
  780.         printf ("Match value %d.\n", i);
  781.       }
  782. - }
  783. - #ifdef NOTDEF
  784. - print_buf (bufp)
  785. -      struct re_pattern_buffer *bufp;
  786. - {
  787. -   int i;
  788. -   printf ("buf is :\n----------------\n");
  789. -   for (i = 0; i < bufp->used; i++)
  790. -     printchar (bufp->buffer[i]);
  791. -   printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  792. -   printf ("Allowed by fastmap: ");
  793. -   for (i = 0; i < (1 << BYTEWIDTH); i++)
  794. -     if (bufp->fastmap[i])
  795. -       printchar (i);
  796. -   printf ("\nAllowed by translate: ");
  797. -   if (bufp->translate)
  798. -     for (i = 0; i < (1 << BYTEWIDTH); i++)
  799. -       if (bufp->translate[i])
  800. -     printchar (i);
  801. -   printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  802. -   printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  803. - }
  804. - #endif
  805. - printchar (c)
  806. -      char c;
  807. - {
  808. -   if (c < 041 || c >= 0177)
  809. -     {
  810. -       putchar ('\\');
  811. -       putchar (((c >> 6) & 3) + '0');
  812. -       putchar (((c >> 3) & 7) + '0');
  813. -       putchar ((c & 7) + '0');
  814. -     }
  815. -   else
  816. -     putchar (c);
  817. - }
  818. - error (string)
  819. -      char *string;
  820. - {
  821. -   puts (string);
  822. -   exit (1);
  823.   }
  824.   
  825.   #endif /* test */
  826. --- 1766,1771 ----
  827. diff -cbBw orig/regex.h grep/regex.h
  828. *** orig/regex.h    Mon May 07 09:08:56 1990
  829. --- grep/regex.h    Sun Jan 19 18:59:04 1992
  830. ***************
  831. *** 1,4 ****
  832. ! /* Definitions for data structures callers pass the regex library.
  833.      Copyright (C) 1985, 1989 Free Software Foundation, Inc.
  834.   
  835.      This program is free software; you can redistribute it and/or modify
  836. --- 1,6 ----
  837. ! /* GNU regex library
  838. !    Definitions for data structures callers pass the regex library.
  839.      Copyright (C) 1985, 1989 Free Software Foundation, Inc.
  840.   
  841.      This program is free software; you can redistribute it and/or modify
  842. ***************
  843. *** 18,24 ****
  844.   
  845.      In other words, you are welcome to use, share and improve this program.
  846.      You are forbidden to forbid anyone else to use, share and improve
  847. !    what you give them.   Help stamp out software-hoarding!  */
  848.   
  849.   
  850.   /* Define number of parens for which we record the beginnings and ends.
  851. --- 20,27 ----
  852.   
  853.      In other words, you are welcome to use, share and improve this program.
  854.      You are forbidden to forbid anyone else to use, share and improve
  855. !    what you give them.   Help stamp out software-hoarding!
  856. ! */
  857.   
  858.   
  859.   /* Define number of parens for which we record the beginnings and ends.
  860. ***************
  861. *** 61,69 ****
  862.       *, +, ? - only special when not after the beginning, (, or | */
  863.   #define RE_CONTEXT_INDEP_OPS 32
  864.   
  865.   /* Now define combinations of bits for the standard possibilities.  */
  866. ! #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS)
  867. ! #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  868.   #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  869.   #define RE_SYNTAX_EMACS 0
  870.   
  871. --- 64,79 ----
  872.       *, +, ? - only special when not after the beginning, (, or | */
  873.   #define RE_CONTEXT_INDEP_OPS 32
  874.   
  875. + /* 0 means that \ before anything inside [ and ] is taken as a real \.
  876. +    1 means that such a \ escapes the following character.  This is a
  877. +    special case for AWK. */
  878. + #define RE_AWK_CLASS_HACK 64
  879.   /* Now define combinations of bits for the standard possibilities.  */
  880. ! #define RE_SYNTAX_AWK \
  881. !   (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS | RE_AWK_CLASS_HACK)
  882. ! #define RE_SYNTAX_EGREP \
  883. !   (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR)
  884.   #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  885.   #define RE_SYNTAX_EMACS 0
  886.   
  887. ***************
  888. *** 169,185 ****
  889.               followed by a byte which contains a syntax code, Sword or such like */
  890.       notsyntaxspec /* Matches any character whose syntax differs from the specified. */
  891.     };
  892. - extern char *re_compile_pattern ();
  893. - /* Is this really advertised? */
  894. - extern void re_compile_fastmap ();
  895. - extern int re_search (), re_search_2 ();
  896. - extern int re_match (), re_match_2 ();
  897.   
  898. ! /* 4.2 bsd compatibility (yuck) */
  899. ! extern char *re_comp ();
  900. ! extern int re_exec ();
  901.   
  902. ! #ifdef SYNTAX_TABLE
  903. ! extern char *re_syntax_table;
  904. ! #endif
  905. --- 179,203 ----
  906.                     followed by a byte which contains a syntax code, Sword or such like */
  907.     notsyntaxspec /* Matches any character whose syntax differs from the specified. */
  908.   };
  909.   
  910. ! extern char *re_compile_pattern(char *pattern, int size,
  911. !   struct re_pattern_buffer *bufp);
  912.   
  913. ! extern void re_compile_fastmap(struct re_pattern_buffer *bufp);
  914. ! extern int re_search(struct re_pattern_buffer *pbufp, char *string, int size,
  915. !   int startpos, int range, struct re_registers *regs);
  916. ! extern int re_search_2(struct re_pattern_buffer *pbufp, char *string1,
  917. !   int size1, char *string2, int size2, int startpos, int range,
  918. !   struct re_registers *regs, int mstop);
  919. ! extern int re_match(struct re_pattern_buffer *pbufp, char *string, int size,
  920. !   int pos, struct re_registers *regs);
  921. ! extern int re_match_2(struct re_pattern_buffer *pbufp, char *string1_arg, int size1,
  922. !   char *string2_arg, int size2, int pos, struct re_registers *regs, int mstop);
  923. ! /* 4.2 bsd compatibility (yuck) */
  924. ! extern char *re_comp(char *s);
  925. ! extern int re_exec(char *s);
  926.