Back to index

glibc  2.9
Defines | Functions | Variables
transbug.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <locale.h>
#include <regex.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define CHECK(exp)   if (exp) { puts (#exp); result = 1; }
#define TEST_FUNCTION   do_test ()

Functions

static int run_test (const char *pattern, struct re_registers *regs)
static int do_test (void)

Variables

static const char casetable []

Define Documentation

#define CHECK (   exp)    if (exp) { puts (#exp); result = 1; }
#define TEST_FUNCTION   do_test ()

Definition at line 141 of file transbug.c.


Function Documentation

static int do_test ( void  ) [static]

Definition at line 114 of file transbug.c.

{
  static const char lower[] = "[[:lower:]]+";
  static const char upper[] = "[[:upper:]]+";
  struct re_registers regs[4];

  setlocale (LC_ALL, "C");

  (void) re_set_syntax (RE_SYNTAX_GNU_AWK);

  int result;
#define CHECK(exp) \
  if (exp) { puts (#exp); result = 1; }

  result = run_test (lower, regs);
  result |= run_test (upper, &regs[2]);
  if (! result)
    {
      CHECK (regs[0].start[0] != regs[2].start[0]);
      CHECK (regs[0].end[0] != regs[2].end[0]);
      CHECK (regs[1].start[0] != regs[3].start[0]);
      CHECK (regs[1].end[0] != regs[3].end[0]);
    }

  return result;
}

Here is the call graph for this function:

static int run_test ( const char *  pattern,
struct re_registers *  regs 
) [static]

Definition at line 62 of file transbug.c.

{
  static char text[] = "1111AAAA2222bbbb";

  struct re_pattern_buffer pat;

  const char *err;
  int res;
  int start2;

  memset (&pat, '\0', sizeof (pat));
  memset (regs, '\0', 2 * sizeof (regs[0]));
  pat.allocated = 0;        /* regex will allocate the buffer */
  pat.fastmap = (char *) malloc (256);
  if (pat.fastmap == NULL)
    {
      puts ("out of memory");
      exit (1);
    }

  pat.translate = (unsigned char *) casetable;

  err = re_compile_pattern (pattern, strlen (pattern), &pat);
  if (err != NULL)
    {
      fprintf (stderr, "/%s/: %s\n", pattern, err);
      exit (1);
    }
  res = re_search (&pat, text, strlen (text), 0, strlen (text), &regs[0]);
  if (res < 0)
    printf ("search 1: res = %d\n", res);
  else
    printf ("search 1: res = %d, start = %d, end = %d\n",
           res, regs[0].start[0], regs[0].end[0]);

  if (regs[0].end == NULL)
    start2 = 8;
  else
    start2 = regs[0].end[0] + 1;
  regs[1] = regs[0];
  res = re_search (&pat, text, strlen (text), start2, strlen (text), &regs[1]);
  if (res < 0)
    printf ("search 2: res = %d\n", res);
  else
    printf ("search 2: res = %d, start = %d, end = %d\n",
           res, regs[1].start[0], regs[1].end[0]);

  return res < 0 ? 1 : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char casetable[] [static]

Definition at line 11 of file transbug.c.