summaryrefslogtreecommitdiffstats
path: root/gnu/lib/libregex/test/syntax.skel
blob: a3fbf64c5983cbbcce6d959ce6fe539cf95d9a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Print which syntax bits are set.  */

#include <sys/types.h>
#include <stdio.h>
#include "regex.h"

/* It's coincidental that these two are currently the same.  */
#define LONGEST_BIT_NAME "RE_UNMATCHED_RIGHT_PAREN_ORD"
#define LAST_BIT RE_UNMATCHED_RIGHT_PAREN_ORD

/* Sum of above, when printed.  Assigned in main.  */
static unsigned longest;


static void
test_bit (syntax, bit, name)
    reg_syntax_t syntax;
    unsigned bit;
    char *name;
{
  char padding[100], test_str[100];
  int padding_count;
  
  sprintf (test_str, "%s (%d=0x%x)", name, bit, bit);
  padding_count = longest - strlen (test_str);

  padding[padding_count] = 0;
  while (padding_count--)
    {
      padding[padding_count] = ' ';
    }
  
  printf ("%s%s (%d=0x%x): %c\n",
          name, padding, bit, bit, syntax & bit ? 'y' : 'n');
}


/* Macro to abbreviate the constant arguments.  */
#define TEST_BIT(bit) test_bit (syntax, bit, #bit)

int
main (argc, argv)
    int argc;
    char *argv[];
{
  reg_syntax_t syntax;
  char syntax_str[1000], test_str[100];
  
  switch (argc)
    {
    case 1:
      printf ("Syntax? ");
      scanf ("%s", syntax_str);
      break;
    
    case 2:
      strcpy (syntax_str, argv[1]);
      break;

    default:
      fprintf (stderr, "Usage: syntax [syntax].\n");
      exit (1);
    }

  sscanf (syntax_str, "%i", &syntax);
  
  /* Figure out the longest name, so we can align the output nicely.  */
  sprintf (test_str, "%s (%d=0x%x)", LONGEST_BIT_NAME, LAST_BIT, LAST_BIT);
  longest = strlen (test_str);

  /* [[[replace with bit tests]]] */
  
  return 0;
}
OpenPOWER on IntegriCloud