Blame posix/bug-regex24.c

Packit 6c4009
#include <regex.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
#define str "civic"
Packit 6c4009
Packit 6c4009
#define N 10
Packit 6c4009
static const char *expected[N] =
Packit 6c4009
  {
Packit 6c4009
    str, "c", "i", "", "", "", "", "", "", ""
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  regex_t rbuf;
Packit 6c4009
  static const char pat[] = "\
Packit 6c4009
^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$";
Packit 6c4009
Packit 6c4009
  int err = regcomp (&rbuf, pat, REG_EXTENDED);
Packit 6c4009
  if (err != 0)
Packit 6c4009
    {
Packit 6c4009
      char errstr[300];
Packit 6c4009
      regerror (err, &rbuf, errstr, sizeof (errstr));
Packit 6c4009
      puts (errstr);
Packit 6c4009
      return err;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  regmatch_t m[N];
Packit 6c4009
  err = regexec (&rbuf, str, N, m, 0);
Packit 6c4009
  if (err != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("regexec failed");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  int result = 0;
Packit 6c4009
  for (int i = 0; i < N; ++i)
Packit 6c4009
    if (m[i].rm_so == -1)
Packit 6c4009
      {
Packit 6c4009
	printf ("m[%d] unused\n", i);
Packit 6c4009
	result = 1;
Packit 6c4009
      }
Packit 6c4009
    else
Packit 6c4009
      {
Packit 6c4009
	int len = m[i].rm_eo - m[i].rm_so;
Packit 6c4009
Packit 6c4009
	printf ("m[%d] = \"%.*s\"\n", i, len, str + m[i].rm_so);
Packit 6c4009
Packit 6c4009
	if (strlen (expected[i]) != len
Packit 6c4009
	    || memcmp (expected[i], str + m[i].rm_so, len) != 0)
Packit 6c4009
	  result = 1;
Packit 6c4009
      }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TIMEOUT 30
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"