1/*
2  randtest.c - tests with random regexps
3
4  This software is released under a BSD-style license.
5  See the file LICENSE for details and copyright.
6
7*/
8
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif /* HAVE_CONFIG_H */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <regex.h>
17#include <time.h>
18
19#undef MALLOC_DEBUGGING
20#ifdef MALLOC_DEBUGGING
21#include "xmalloc.h"
22#endif /* MALLOC_DEBUGGING */
23
24#define REGEXP_MAX_LEN 16
25
26int
27main(int argc, char **argv)
28{
29  int len, i, flags, n;
30  char regex[50];
31  char *buf;
32  regex_t preg;
33  int status, seed;
34
35  seed = time(NULL);
36  seed = 1028358583;
37  printf("seed = %d\n", seed);
38  srand(seed);
39  n = 0;
40
41  for (n = 0; n < 0; n++)
42    rand();
43
44  while (1)
45    {
46      printf("*");
47      fflush(stdout);
48
49      printf("n = %d\n", n);
50      len = 1 + (int)(REGEXP_MAX_LEN * (rand() / (RAND_MAX + 1.0)));
51      n++;
52
53      for (i = 0; i < len; i++)
54	{
55	  regex[i] = 1 + (int)(255 * (rand() / (RAND_MAX + 1.0)));
56	  n++;
57	}
58      regex[i] = L'\0';
59
60      printf("len = %d, regexp = \"%s\"\n", len, regex);
61
62      for (flags = 0;
63	   flags < (REG_EXTENDED | REG_ICASE | REG_NEWLINE | REG_NOSUB);
64	   flags++)
65	{
66	  buf = malloc(sizeof(*buf) * len);
67	  strncpy(buf, regex, len - 1);
68	  status = tre_regncomp(&preg, buf, len, flags);
69	  if (status == REG_OK)
70	    tre_regfree(&preg);
71	}
72      printf("\n");
73    }
74
75  return 0;
76}
77