home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / cutils / Regex / Changes
Encoding:
Text File  |  1991-09-19  |  7.7 KB  |  263 lines

  1. *** SCSI::SCSIDisc4.$.Programs.Utils.Regex.C.Regex  Sun May 12 15:07:30 1991
  2. --- SCSI::SCSIDisc4.$.Programs.Utils.Regex.C.Regex1 Thu Sep 19 01:27:55 1991
  3. *************** enum regexpcod
  4. *** 149,154 ****
  5. --- 149,156 ----
  6.       notspacechar, /* Matches any non-whitespace character */
  7.       digit,        /* Matches any digit character */
  8.       notdigit,     /* Matches any non-digit character */
  9. +     begword,      /* Succeeds if at beginning of word.  */
  10. +     endword,      /* Succeeds if at end of word.  */
  11.       wordbound,    /* Succeeds if at a word boundary */
  12.       notwordbound  /* Succeeds if not at a word boundary */
  13.     };
  14. *************** enum regexpcod
  15. *** 167,173 ****
  16.   /* Store NUMBER in two contiguous bytes starting at DESTINATION.  */
  17.   #define STORE_NUMBER(destination, number)\
  18.     { (destination)[0] = (number) & 0377;\
  19. !     (destination)[1] = (number) >> 8; }
  20.     
  21.   /* Same as STORE_NUMBER, except increment the destination pointer to
  22.      the byte after where the number is stored.  Watch out that values for
  23. --- 169,175 ----
  24.   /* Store NUMBER in two contiguous bytes starting at DESTINATION.  */
  25.   #define STORE_NUMBER(destination, number)\
  26.     { (destination)[0] = (number) & 0377;\
  27. !     (destination)[1] = ((number) >> 8) & 0377; }
  28.     
  29.   /* Same as STORE_NUMBER, except increment the destination pointer to
  30.      the byte after where the number is stored.  Watch out that values for
  31. *************** int obscure_syntax = 0
  32. *** 221,226 ****
  33. --- 223,229 ----
  34.   #define PATFETCH(c)\
  35.     {if (p == pend) goto end_of_pattern;\
  36.     c = * (unsigned char *) p++;\
  37. + fprintf(stderr,"%c",c);\
  38.     if (translate) c = translate[c]; }
  39.   
  40.   /* Fetch the next character in the uncompiled pattern, with no
  41. *************** char *re_compile_pattern (char *pattern, int size
  42. *** 787,793 ****
  43.                     /* When hit this when matching, reset the
  44.                        preceding jump_n's n to upper_bound - 1.  */
  45.                     BUFPUSH (set_number_at);
  46. !           GET_BUFFER_SPACE (2);
  47.                     STORE_NUMBER_AND_INCR (b, -5);
  48.                     STORE_NUMBER_AND_INCR (b, upper_bound - 1);
  49.                   }
  50. --- 790,796 ----
  51.                     /* When hit this when matching, reset the
  52.                        preceding jump_n's n to upper_bound - 1.  */
  53.                     BUFPUSH (set_number_at);
  54. !           GET_BUFFER_SPACE (4);
  55.                     STORE_NUMBER_AND_INCR (b, -5);
  56.                     STORE_NUMBER_AND_INCR (b, upper_bound - 1);
  57.                   }
  58. *************** char *re_compile_pattern (char *pattern, int size
  59. *** 936,941 ****
  60. --- 939,952 ----
  61.         BUFPUSH (notwordbound);
  62.         break;
  63.   
  64. +     case '<':
  65. +       BUFPUSH (begword);
  66. +       break;
  67. +     case '>':
  68. +       BUFPUSH (endword);
  69. +       break;
  70.       case '`':
  71.         BUFPUSH (begbuf);
  72.         break;
  73. *************** static void insert_op_2 (char op, char *there, char *current
  74. *** 1136,1142 ****
  75.      quickly over totally implausible text.
  76.   
  77.      The caller must supply the address of a CHAR_NUM-byte data 
  78. !    area as bufp->fastmap.
  79.      The other components of bufp describe the pattern to be used.  */
  80.   
  81.   void re_compile_fastmap (struct re_pattern_buffer *bufp)
  82. --- 1147,1154 ----
  83.      quickly over totally implausible text.
  84.   
  85.      The caller must supply the address of a CHAR_NUM-byte data 
  86. !    area as bufp->fastmap, or NULL (in which case, re_compile_fastmap
  87. !    will allocate an area, using malloc()).
  88.      The other components of bufp describe the pattern to be used.  */
  89.   
  90.   void re_compile_fastmap (struct re_pattern_buffer *bufp)
  91. *************** void re_compile_fastmap (struct re_pattern_buffer *bufp
  92. *** 1154,1161 ****
  93.   
  94.     unsigned is_a_succeed_n;
  95.   
  96. -   bzero (fastmap, CHAR_NUM);
  97.     bufp->fastmap_accurate = 1;
  98.     bufp->can_be_null = 0;
  99.         
  100.     while (p)
  101. --- 1166,1187 ----
  102.   
  103.     unsigned is_a_succeed_n;
  104.   
  105.     bufp->fastmap_accurate = 1;
  106. +   if (fastmap == NULL)
  107. +     {
  108. +       fastmap = malloc(CHAR_NUM);
  109. +       /* If no luck, return without a fastmap (but with fastmap_accurate set,
  110. +  so that callers know we tried).  */
  111. +       if (fastmap == NULL)
  112. + return;
  113. +       bufp->fastmap = fastmap;
  114. +     }
  115. +   bzero (fastmap, CHAR_NUM);
  116.     bufp->can_be_null = 0;
  117.         
  118.     while (p)
  119. *************** void re_compile_fastmap (struct re_pattern_buffer *bufp
  120. *** 1179,1184 ****
  121. --- 1205,1212 ----
  122.           case begline:
  123.   case begbuf:
  124.   case endbuf:
  125. + case begword:
  126. + case endword:
  127.   case wordbound:
  128.   case notwordbound:
  129.             continue;
  130. *************** int re_search_2 (struct re_pattern_buffer *pbufp, char *stri
  131. *** 1383,1388 ****
  132. --- 1411,1421 ----
  133.     if (startpos < 0  ||  startpos > total_size)
  134.       return -1;
  135.       
  136. +   /* A range of zero means "as far as possible" (use re_match for an
  137. +      anchored match).  */
  138. +   if (range == 0)
  139. +     range = total_size - startpos;
  140.     /* Fix up range if it would eventually take startpos outside of the
  141.        virtual concatenation of string1 and string2.  */
  142.     if (endpos < -1)
  143. *************** int re_search_2 (struct re_pattern_buffer *pbufp, char *stri
  144. *** 1391,1398 ****
  145.       range = total_size - startpos;
  146.   
  147.     /* Update the fastmap now if not correct already.  */
  148. !   if (fastmap && !pbufp->fastmap_accurate)
  149. !     re_compile_fastmap (pbufp);
  150.     
  151.     /* If the search isn't to be a backwards one, don't waste time in a
  152.        long search for a pattern that says it is anchored.  */
  153. --- 1424,1435 ----
  154.       range = total_size - startpos;
  155.   
  156.     /* Update the fastmap now if not correct already.  */
  157. !   if (!pbufp->fastmap_accurate)
  158. !     {
  159. !       re_compile_fastmap (pbufp);
  160. !       /* Re-assign fastmap, in case re_compile_fastmap() allocated it */
  161. !       fastmap = pbufp->fastmap;
  162. !     }
  163.     
  164.     /* If the search isn't to be a backwards one, don't waste time in a
  165.        long search for a pattern that says it is anchored.  */
  166. *************** struct register_inf
  167. *** 1640,1645 ****
  168. --- 1677,1688 ----
  169.   #define IS_A_LETTER(d)\
  170.     (HAS_SYNTAX (CURRENT_CHAR(d),Sword))
  171.   
  172. + #define AT_WORD_BEG\
  173. +   (AT_STRINGS_BEG || (!IS_A_LETTER (d - 1) && IS_A_LETTER (d)))
  174. + #define AT_WORD_END\
  175. +   (AT_STRINGS_END || (IS_A_LETTER (d - 1) && !IS_A_LETTER (d)))
  176.   #define AT_WORD_BOUNDARY\
  177.     (AT_STRINGS_BEG || AT_STRINGS_END || IS_A_LETTER (d - 1) != IS_A_LETTER (d))
  178.   
  179. *************** int re_match_2 (struct re_pattern_buffer *pbufp, char *strin
  180. *** 2265,2270 ****
  181. --- 2308,2323 ----
  182.     d++;
  183.     break;
  184.   
  185. + case begword:
  186. +           if (AT_WORD_BEG)
  187. +             break;
  188. +           goto fail;
  189. +         case endword:
  190. +   if (AT_WORD_END)
  191. +     break;
  192. +   goto fail;
  193.   case begbuf:
  194.             if (AT_STRINGS_BEG)
  195.               break;
  196. *************** int main (void
  197. *** 2493,2499 ****
  198.   {
  199.     char pat[80];
  200.     struct re_pattern_buffer buf;
  201. !   int i;
  202.     char fastmap[CHAR_NUM];
  203.   
  204.     buf.allocated = 40;
  205. --- 2546,2554 ----
  206.   {
  207.     char pat[80];
  208.     struct re_pattern_buffer buf;
  209. !   struct re_registers regs;
  210. !   int i, j;
  211. !   char *p;
  212.     char fastmap[CHAR_NUM];
  213.   
  214.     buf.allocated = 40;
  215. *************** int main (void
  216. *** 2534,2541 ****
  217.     if (*pat == 0)
  218.       break;
  219.   
  220. !   i = re_match (&buf, pat, strlen (pat), 0, 0);
  221. !   printf ("Match value %d.\n", i);
  222.   }
  223.       }
  224.   }
  225. --- 2589,2598 ----
  226.     if (*pat == 0)
  227.       break;
  228.   
  229. !   i = re_search (&buf, pat, strlen (pat), 0, 0, ®s);
  230. !   j = regs.end[0] - regs.start[0];
  231. !   p = pat + regs.start[0];
  232. !   printf ("Found \"%.*s\" at %d.\n", j, p, i);
  233.   }
  234.       }
  235.   }
  236. *************** static void dump_buffer (struct re_pattern_buffer *bufp
  237. *** 2629,2634 ****
  238. --- 2686,2697 ----
  239.         break;
  240.       case duplicate:
  241.         printf("Duplicate (%d)", *p++);
  242. +       break;
  243. +     case begword:
  244. +       printf("Start of word");
  245. +       break;
  246. +     case endword:
  247. +       printf("End of word");
  248.         break;
  249.       case begbuf:
  250.         printf("Start of buffer");
  251.