Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / lib / libregex / test / syntax.skel
1 /* Print which syntax bits are set.  */
2
3 #include <sys/types.h>
4 #include <stdio.h>
5 #include "regex.h"
6
7 /* It's coincidental that these two are currently the same.  */
8 #define LONGEST_BIT_NAME "RE_UNMATCHED_RIGHT_PAREN_ORD"
9 #define LAST_BIT RE_UNMATCHED_RIGHT_PAREN_ORD
10
11 /* Sum of above, when printed.  Assigned in main.  */
12 static unsigned longest;
13
14
15 static void
16 test_bit (syntax, bit, name)
17     reg_syntax_t syntax;
18     unsigned bit;
19     char *name;
20 {
21   char padding[100], test_str[100];
22   int padding_count;
23   
24   sprintf (test_str, "%s (%d=0x%x)", name, bit, bit);
25   padding_count = longest - strlen (test_str);
26
27   padding[padding_count] = 0;
28   while (padding_count--)
29     {
30       padding[padding_count] = ' ';
31     }
32   
33   printf ("%s%s (%d=0x%x): %c\n",
34           name, padding, bit, bit, syntax & bit ? 'y' : 'n');
35 }
36
37
38 /* Macro to abbreviate the constant arguments.  */
39 #define TEST_BIT(bit) test_bit (syntax, bit, #bit)
40
41 int
42 main (argc, argv)
43     int argc;
44     char *argv[];
45 {
46   reg_syntax_t syntax;
47   char syntax_str[1000], test_str[100];
48   
49   switch (argc)
50     {
51     case 1:
52       printf ("Syntax? ");
53       scanf ("%s", syntax_str);
54       break;
55     
56     case 2:
57       strcpy (syntax_str, argv[1]);
58       break;
59
60     default:
61       fprintf (stderr, "Usage: syntax [syntax].\n");
62       exit (1);
63     }
64
65   sscanf (syntax_str, "%i", &syntax);
66   
67   /* Figure out the longest name, so we can align the output nicely.  */
68   sprintf (test_str, "%s (%d=0x%x)", LONGEST_BIT_NAME, LAST_BIT, LAST_BIT);
69   longest = strlen (test_str);
70
71   /* [[[replace with bit tests]]] */
72   
73   return 0;
74 }