home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / RegexLibrary_v1.0 / tester.c < prev    next >
C/C++ Source or Header  |  1989-08-06  |  2KB  |  107 lines

  1. /*
  2.  *  Test file for the GNU regular expression package.
  3.  *  Edwin Hoogerbeets 18/07/89
  4.  *
  5.  *  This file may be copied and distributed under the GNU Public
  6.  *  Licence. See the comment at the top of regex.c for details.
  7.  *
  8.  *  Adapted from Elib by Jim Mackraz, mklib by Edwin Hoogerbeets, and the
  9.  *  GNU regular expression package by the Free Software Foundation.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include "regex.h"
  14.  
  15. extern char *malloc();
  16. extern char *OpenLibrary();
  17.  
  18. /* Indexed by a character, gives the upper case equivalent of the character */
  19.  
  20. main (argc, argv)
  21. int argc;
  22. char **argv;
  23. {
  24.   char pat[80];
  25.   struct re_pattern_buffer buf;
  26.   int i;
  27.   char c;
  28.   char *fastmap;
  29.  
  30.   if ( (RegexBase =
  31.         (struct RegexBase *) OpenLibrary("regex.library",0L)) == NULL) {
  32.     printf("Could not open regex.library");
  33.     exit(1);
  34.   }
  35.  
  36.   printf("This is the RegexBase pointer: 0x%lx\n",RegexBase);
  37.  
  38.   re_initialize_buffer(&buf,__Upcase);
  39.   fastmap = buf.fastmap;
  40.  
  41.   while ( *pat != '%' )
  42.     {
  43.       printf("Enter pattern, or %% to exit: ");
  44.       gets(pat);
  45.  
  46.       if ( pat[0] == '%' )
  47.         break;
  48.  
  49.       if (*pat)
  50.         {
  51.           re_compile_pattern (pat, strlen(pat), &buf, RE_SYNTAX_GREP);
  52.  
  53.           for (i = 0; i < buf.used; i++)
  54.             printchar (buf.buffer[i]);
  55.  
  56.           putchar ('\n');
  57.  
  58.           printf ("%d allocated, %d used.\n", buf.allocated, buf.used);
  59.  
  60.           re_compile_fastmap (&buf);
  61.           printf ("Allowed by fastmap: ");
  62.           for (i = 0; i < (1 << BYTEWIDTH); i++)
  63.             if (fastmap[i]) {
  64.               printchar (i);
  65.             }
  66.           putchar ('\n');
  67.         }
  68.  
  69.       printf("Now enter a string to match against, or %% to exit\n");
  70.       gets(pat); /* Now read the string to match against */
  71.  
  72.       i = re_match(&buf, pat, strlen (pat), 0L, 0L);
  73.       printf("Match value %d.\n", i);
  74.     }
  75.  
  76.   re_terminate_buffer(&buf);
  77.   CloseLibrary(RegexBase);
  78. }
  79.  
  80.  
  81. _abort()
  82. {
  83.   puts("Enter % to stop");
  84. }
  85.  
  86. printchar (c)
  87.      char c;
  88. {
  89.   if (c < 041 || c >= 0177)
  90.     {
  91.       putchar ('\\');
  92.       putchar (((c >> 6) & 3) + '0');
  93.       putchar (((c >> 3) & 7) + '0');
  94.       putchar ((c & 7) + '0');
  95.     }
  96.   else
  97.     putchar (c);
  98. }
  99.  
  100. error (string)
  101.      char *string;
  102. {
  103.   puts (string);
  104.   exit (1);
  105. }
  106.  
  107.