1 /* Main program for interactive testing. For maximum output, compile
2 this and regex.c with -DDEBUG. */
8 /* Don't bother to guess about <string.h> vs <strings.h>, etc. */
13 extern void printchar ();
16 static void scanstring ();
17 static void print_regs ();
25 struct re_pattern_buffer buf;
26 char fastmap[(1 << BYTEWIDTH)];
28 /* Allow a command argument to specify the style of syntax. You can
29 use the `syntax' program to decode integer syntax values. */
31 re_set_syntax (atoi (argv[1]));
35 buf.fastmap = fastmap;
36 buf.translate = upcase;
40 char pat[500], str[500];
41 struct re_registers regs;
43 /* Some C compilers don't like `char pat[500] = ""'. */
46 printf ("Pattern (%s) = ", pat);
58 re_compile_pattern (pat, strlen (pat), &buf);
59 re_compile_fastmap (&buf);
61 print_compiled_pattern (&buf);
66 gets (str); /* Now read the string to match against */
69 i = re_match (&buf, str, strlen (str), 0, ®s);
70 printf ("Match value %d.\t", i);
75 i = re_search (&buf, str, strlen (str), 0, strlen (str), ®s);
76 printf ("Search value %d.\t", i);
82 /* We never get here, but what the heck. */
103 case '0': case '1': case '2': case '3': case '4':
104 case '5': case '6': case '7': case '8': case '9':
107 if ('0' <= *s && *s <= '9')
109 *write = (*write << 3) + (*s++ - '0');
110 if ('0' <= *s && *s <= '9')
111 *write = (*write << 3) + (*s++ - '0');
138 /* Print REGS in human-readable form. */
142 struct re_registers regs;
146 printf ("Registers: ");
148 if (regs.num_regs == 0 || regs.start[0] == -1)
154 /* Find the last register pair that matched. */
155 for (end = regs.num_regs - 1; end >= 0; end--)
156 if (regs.start[end] != -1)
159 printf ("[%d ", regs.start[0]);
160 for (i = 1; i <= end; i++)
161 printf ("(%d %d) ", regs.start[i], regs.end[i]);
162 printf ("%d]", regs.end[0]);