Back to index

glibc  2.9
Defines | Functions | Variables
bug-regex20.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>
#include "regex_internal.h"

Go to the source code of this file.

Defines

#define RE_NO_INTERNAL_PROTOTYPES   1
#define BRE   RE_SYNTAX_POSIX_BASIC
#define ERE   RE_SYNTAX_POSIX_EXTENDED

Functions

int main (void)

Variables

struct {
int syntax
const char * pattern
const char * string
int res
int optimize
tests []

Define Documentation

#define BRE   RE_SYNTAX_POSIX_BASIC

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

#define ERE   RE_SYNTAX_POSIX_EXTENDED

Definition at line 33 of file bug-regex20.c.

#define RE_NO_INTERNAL_PROTOTYPES   1

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


Function Documentation

int main ( void  )

Definition at line 190 of file bug-regex20.c.

{
  struct re_pattern_buffer regbuf;
  const char *err;
  size_t i;
  int ret = 0;

  mtrace ();

  setlocale (LC_ALL, "de_DE.UTF-8");
  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
    {
      int res, optimized;

      re_set_syntax (tests[i].syntax);
      memset (&regbuf, '\0', sizeof (regbuf));
      err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern),
                                &regbuf);
      if (err != NULL)
       {
         printf ("re_compile_pattern failed: %s\n", err);
         ret = 1;
         continue;
       }

      /* Check if re_search will be done as multi-byte or single-byte.  */
      optimized = ((re_dfa_t *) regbuf.buffer)->mb_cur_max == 1;
      if (optimized != tests[i].optimize)
        {
          printf ("pattern %zd %soptimized while it should%s be\n",
                i, optimized ? "" : "not ", tests[i].optimize ? "" : " not");
         ret = 1;
        }

      int str_len = strlen (tests[i].string);
      res = re_search (&regbuf, tests[i].string, str_len, 0, str_len, NULL);
      if (res != tests[i].res)
       {
         printf ("re_search %zd failed: %d\n", i, res);
         ret = 1;
         regfree (&regbuf);
         continue;
       }

      res = re_search (&regbuf, tests[i].string, str_len, str_len, -str_len,
                     NULL);
      if (res != tests[i].res)
       {
         printf ("backward re_search %zd failed: %d\n", i, res);
         ret = 1;
         regfree (&regbuf);
         continue;
       }
      regfree (&regbuf);

      re_set_syntax (tests[i].syntax | RE_ICASE);
      memset (&regbuf, '\0', sizeof (regbuf));
      err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern),
                                &regbuf);
      if (err != NULL)
       {
         printf ("re_compile_pattern failed: %s\n", err);
         ret = 1;
         continue;
       }

      /* Check if re_search will be done as multi-byte or single-byte.  */
      optimized = ((re_dfa_t *) regbuf.buffer)->mb_cur_max == 1;
      if (optimized)
        {
          printf ("pattern %zd optimized while it should not be when case insensitive\n",
                i);
         ret = 1;
        }

      res = re_search (&regbuf, tests[i].string, str_len, 0, str_len, NULL);
      if (res != tests[i].res)
       {
         printf ("ICASE re_search %zd failed: %d\n", i, res);
         ret = 1;
         regfree (&regbuf);
         continue;
       }

      res = re_search (&regbuf, tests[i].string, str_len, str_len, -str_len,
                     NULL);
      if (res != tests[i].res)
       {
         printf ("ICASE backward re_search %zd failed: %d\n", i, res);
         ret = 1;
         regfree (&regbuf);
         continue;
       }
      regfree (&regbuf);
    }

  return ret;
}

Here is the call graph for this function:


Variable Documentation

struct { ... } tests[] [static]