home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume22 / gawk2.11 / part05 / regex.c.02 < prev   
Encoding:
Text File  |  1990-06-07  |  2.0 KB  |  94 lines

  1.     0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
  2.     0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  3.   };
  4.  
  5. main (argc, argv)
  6.      int argc;
  7.      char **argv;
  8. {
  9.   char pat[80];
  10.   struct re_pattern_buffer buf;
  11.   int i;
  12.   char c;
  13.   char fastmap[(1 << BYTEWIDTH)];
  14.  
  15.   /* Allow a command argument to specify the style of syntax.  */
  16.   if (argc > 1)
  17.     obscure_syntax = atoi (argv[1]);
  18.  
  19.   buf.allocated = 40;
  20.   buf.buffer = (char *) malloc (buf.allocated);
  21.   buf.fastmap = fastmap;
  22.   buf.translate = upcase;
  23.  
  24.   while (1)
  25.     {
  26.       gets (pat);
  27.  
  28.       if (*pat)
  29.     {
  30.           re_compile_pattern (pat, strlen(pat), &buf);
  31.  
  32.       for (i = 0; i < buf.used; i++)
  33.         printchar (buf.buffer[i]);
  34.  
  35.       putchar ('\n');
  36.  
  37.       printf ("%d allocated, %d used.\n", buf.allocated, buf.used);
  38.  
  39.       re_compile_fastmap (&buf);
  40.       printf ("Allowed by fastmap: ");
  41.       for (i = 0; i < (1 << BYTEWIDTH); i++)
  42.         if (fastmap[i]) printchar (i);
  43.       putchar ('\n');
  44.     }
  45.  
  46.       gets (pat);    /* Now read the string to match against */
  47.  
  48.       i = re_match (&buf, pat, strlen (pat), 0, 0);
  49.       printf ("Match value %d.\n", i);
  50.     }
  51. }
  52.  
  53. #ifdef NOTDEF
  54. print_buf (bufp)
  55.      struct re_pattern_buffer *bufp;
  56. {
  57.   int i;
  58.  
  59.   printf ("buf is :\n----------------\n");
  60.   for (i = 0; i < bufp->used; i++)
  61.     printchar (bufp->buffer[i]);
  62.   
  63.   printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  64.   
  65.   printf ("Allowed by fastmap: ");
  66.   for (i = 0; i < (1 << BYTEWIDTH); i++)
  67.     if (bufp->fastmap[i])
  68.       printchar (i);
  69.   printf ("\nAllowed by translate: ");
  70.   if (bufp->translate)
  71.     for (i = 0; i < (1 << BYTEWIDTH); i++)
  72.       if (bufp->translate[i])
  73.     printchar (i);
  74.   printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  75.   printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  76. }
  77. #endif
  78.  
  79. printchar (c)
  80.      char c;
  81. {
  82.   if (c < 041 || c >= 0177)
  83.     {
  84.       putchar ('\\');
  85.       putchar (((c >> 6) & 3) + '0');
  86.       putchar (((c >> 3) & 7) + '0');
  87.       putchar ((c & 7) + '0');
  88.     }
  89.   else
  90.     putchar (c);
  91. }
  92.  
  93. #endif /* test */
  94.