Back to index

glibc  2.9
Classes | Defines | Functions | Variables
bug-regex19.c File Reference
#include <sys/types.h>
#include <mcheck.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

Go to the source code of this file.

Classes

struct  test_s

Defines

#define BRE   RE_SYNTAX_POSIX_BASIC
#define ERE   RE_SYNTAX_POSIX_EXTENDED

Functions

int do_one_test (const struct test_s *test, const char *fail)
static char * replace (char *p, char c)
int do_mb_tests (const struct test_s *test)
int main (void)

Variables

static struct test_s tests []

Class Documentation

struct test_s

Definition at line 32 of file bug-regex19.c.

Class Members
const char * pattern
int res
int start
const char * string
int syntax

Define Documentation

#define BRE   RE_SYNTAX_POSIX_BASIC

Definition at line 29 of file bug-regex19.c.

#define ERE   RE_SYNTAX_POSIX_EXTENDED

Definition at line 30 of file bug-regex19.c.


Function Documentation

int do_mb_tests ( const struct test_s test)

Definition at line 324 of file bug-regex19.c.

{
  int i, j;
  struct test_s t;
  const char *const chars = "ABCD!=~";
  char repl[8], *p;
  char pattern[strlen (test->pattern) * 4 + 1];
  char string[strlen (test->string) * 4 + 1];
  char fail[8 + sizeof ("UTF-8 ")];

  t = *test;
  t.pattern = pattern;
  t.string = string;
  strcpy (fail, "UTF-8 ");
  for (i = 1; i < 128; ++i)
    {
      p = repl;
      for (j = 0; j < 7; ++j)
       if (i & (1 << j))
         {
           if (!strchr (test->pattern, chars[j])
              && !strchr (test->string, chars[j]))
             break;
           *p++ = chars[j];
         }
      if (j < 7)
       continue;
      *p = '\0';

      for (j = 0, p = pattern; test->pattern[j]; ++j)
       if (strchr (repl, test->pattern[j]))
         p = replace (p, test->pattern[j]);
       else if (test->pattern[j] == '\\' && test->pattern[j + 1])
         {
           *p++ = test->pattern[j++];
           *p++ = test->pattern[j];
         }
       else
         *p++ = test->pattern[j];
      *p = '\0';

      t.start = test->start;
      t.res = test->res;

      for (j = 0, p = string; test->string[j]; ++j)
       if (strchr (repl, test->string[j]))
         {
           char *d = replace (p, test->string[j]);
           if (test->start > j)
             t.start += d - p - 1;
           if (test->res > j)
             t.res += d - p - 1;
           p = d;
         }
       else
         *p++ = test->string[j];
      *p = '\0';

      p = stpcpy (fail + strlen ("UTF-8 "), repl);
      *p++ = ' ';
      *p = '\0';

      if (do_one_test (&t, fail))
       return 1;
    }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int do_one_test ( const struct test_s test,
const char *  fail 
)

Definition at line 255 of file bug-regex19.c.

{
  int res;
  const char *err;
  struct re_pattern_buffer regbuf;

  re_set_syntax (test->syntax);
  memset (&regbuf, '\0', sizeof (regbuf));
  err = re_compile_pattern (test->pattern, strlen (test->pattern),
                         &regbuf);
  if (err != NULL)
    {
      printf ("%sre_compile_pattern \"%s\" failed: %s\n", fail, test->pattern,
             err);
      return 1;
    }

  res = re_search (&regbuf, test->string, strlen (test->string),
                 test->start, strlen (test->string) - test->start, NULL);
  if (res != test->res)
    {
      printf ("%sre_search \"%s\" \"%s\" failed: %d (expected %d)\n",
             fail, test->pattern, test->string, res, test->res);
      regfree (&regbuf);
      return 1;
    }

  if (test->res > 0 && test->start == 0)
    {
      res = re_search (&regbuf, test->string, strlen (test->string),
                     test->res, strlen (test->string) - test->res, NULL);
      if (res != test->res)
       {
         printf ("%sre_search from expected \"%s\" \"%s\" failed: %d (expected %d)\n",
                fail, test->pattern, test->string, res, test->res);
         regfree (&regbuf);
         return 1;
       }
    }

  regfree (&regbuf);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

Definition at line 393 of file bug-regex19.c.

{
  size_t i;
  int ret = 0;

  mtrace ();

  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
    {
      if (setlocale (LC_ALL, "de_DE.ISO-8859-1") == NULL)
       {
         puts ("setlocale de_DE.ISO-8859-1 failed");
         ret = 1;
       }
      ret |= do_one_test (&tests[i], "");
      if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
       {
         puts ("setlocale de_DE.UTF-8 failed");
         ret = 1;
       }
      ret |= do_one_test (&tests[i], "UTF-8 ");
      ret |= do_mb_tests (&tests[i]);
    }

  return ret;
}

Here is the call graph for this function:

static char* replace ( char *  p,
char  c 
) [static]

Definition at line 300 of file bug-regex19.c.

{
  switch (c)
    {
      /* A -> A" */
      case 'A': *p++ = '\xc3'; *p++ = '\x84'; break;
      /* B -> O" */
      case 'B': *p++ = '\xc3'; *p++ = '\x96'; break;
      /* C -> U" */
      case 'C': *p++ = '\xc3'; *p++ = '\x9c'; break;
      /* D -> a" */
      case 'D': *p++ = '\xc3'; *p++ = '\xa4'; break;
      /* ! -> MULTIPLICATION SIGN */
      case '!': *p++ = '\xc3'; *p++ = '\x97'; break;
      /* = -> EM DASH */
      case '=': *p++ = '\xe2'; *p++ = '\x80'; *p++ = '\x94'; break;
      /* ~ -> MUSICAL SYMBOL HALF NOTE */
      case '~': *p++ = '\xf0'; *p++ = '\x9d'; *p++ = '\x85'; *p++ = '\x9e';
      break;
    }
  return p;
}

Here is the caller graph for this function:


Variable Documentation

struct test_s tests[] [static]