Back to index

glibc  2.9
Classes | Defines | Typedefs | Enumerations | Functions | Variables
regex.h File Reference
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  re_pattern_buffer
struct  regmatch_t

Defines

#define REG_EXTENDED   1
#define REG_ICASE   (REG_EXTENDED << 1)
#define REG_NEWLINE   (REG_ICASE << 1)
#define REG_NOSUB   (REG_NEWLINE << 1)
#define REG_NOTBOL   1
#define REG_NOTEOL   (1 << 1)
#define REG_STARTEND   (1 << 2)
#define __RE_TRANSLATE_TYPE   unsigned char *
#define __REPB_PREFIX(name)   __##name
#define __restrict
#define __restrict_arr

Typedefs

typedef long int s_reg_t
typedef unsigned long int active_reg_t
typedef unsigned long int reg_syntax_t
typedef struct re_pattern_buffer
typedef int regoff_t

Enumerations

enum  reg_errcode_t {
  REG_NOERROR = 0, REG_NOMATCH, REG_BADPAT, REG_ECOLLATE,
  REG_ECTYPE, REG_EESCAPE, REG_ESUBREG, REG_EBRACK,
  REG_EPAREN, REG_EBRACE, REG_BADBR, REG_ERANGE,
  REG_ESPACE, REG_BADRPT, REG_EEND, REG_ESIZE,
  REG_ERPAREN
}

Functions

int regcomp (regex_t *__restrict __preg, const char *__restrict __pattern, int __cflags)
int regexec (const regex_t *__restrict __preg, const char *__restrict __string, size_t __nmatch, regmatch_t __pmatch[__restrict_arr], int __eflags)
size_t regerror (int __errcode, const regex_t *__restrict __preg, char *__restrict __errbuf, size_t __errbuf_size)
void regfree (regex_t *__preg)

Variables

reg_syntax_t re_syntax_options

Class Documentation

struct regmatch_t

Definition at line 451 of file regex.h.

Class Members
regoff_t rm_eo
regoff_t rm_so

Define Documentation

#define __RE_TRANSLATE_TYPE   unsigned char *

Definition at line 344 of file regex.h.

#define __REPB_PREFIX (   name)    __##name

Definition at line 353 of file regex.h.

#define __restrict

Definition at line 541 of file regex.h.

#define __restrict_arr

Definition at line 551 of file regex.h.

#define REG_EXTENDED   1

Definition at line 272 of file regex.h.

#define REG_ICASE   (REG_EXTENDED << 1)

Definition at line 276 of file regex.h.

#define REG_NEWLINE   (REG_ICASE << 1)

Definition at line 281 of file regex.h.

#define REG_NOSUB   (REG_NEWLINE << 1)

Definition at line 285 of file regex.h.

#define REG_NOTBOL   1

Definition at line 295 of file regex.h.

#define REG_NOTEOL   (1 << 1)

Definition at line 298 of file regex.h.

#define REG_STARTEND   (1 << 2)

Definition at line 302 of file regex.h.


Typedef Documentation

typedef unsigned long int active_reg_t

Definition at line 37 of file regex.h.

typedef struct re_pattern_buffer

Definition at line 422 of file regex.h.

typedef unsigned long int reg_syntax_t

Definition at line 44 of file regex.h.

typedef int regoff_t

Definition at line 425 of file regex.h.

typedef long int s_reg_t

Definition at line 36 of file regex.h.


Enumeration Type Documentation

Enumerator:
REG_NOERROR 
REG_NOMATCH 
REG_BADPAT 
REG_ECOLLATE 
REG_ECTYPE 
REG_EESCAPE 
REG_ESUBREG 
REG_EBRACK 
REG_EPAREN 
REG_EBRACE 
REG_BADBR 
REG_ERANGE 
REG_ESPACE 
REG_BADRPT 
REG_EEND 
REG_ESIZE 
REG_ERPAREN 

Definition at line 307 of file regex.h.

{
#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
  REG_ENOSYS = -1,   /* This will never happen for this implementation.  */
#endif

  REG_NOERROR = 0,   /* Success.  */
  REG_NOMATCH,              /* Didn't find a match (for regexec).  */

  /* POSIX regcomp return error codes.  (In the order listed in the
     standard.)  */
  REG_BADPAT,        /* Invalid pattern.  */
  REG_ECOLLATE,             /* Inalid collating element.  */
  REG_ECTYPE,        /* Invalid character class name.  */
  REG_EESCAPE,              /* Trailing backslash.  */
  REG_ESUBREG,              /* Invalid back reference.  */
  REG_EBRACK,        /* Unmatched left bracket.  */
  REG_EPAREN,        /* Parenthesis imbalance.  */
  REG_EBRACE,        /* Unmatched \{.  */
  REG_BADBR,         /* Invalid contents of \{\}.  */
  REG_ERANGE,        /* Invalid range end.  */
  REG_ESPACE,        /* Ran out of memory.  */
  REG_BADRPT,        /* No preceding re for repetition op.  */

  /* Error codes we've added.  */
  REG_EEND,          /* Premature end.  */
  REG_ESIZE,         /* Compiled pattern bigger than 2^16 bytes.  */
  REG_ERPAREN        /* Unmatched ) or \); not returned from regcomp.  */
} reg_errcode_t;

Function Documentation

int regcomp ( regex_t *__restrict  __preg,
const char *__restrict  __pattern,
int  __cflags 
)

Definition at line 447 of file regcomp.c.

{
  reg_errcode_t ret;
  reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
                      : RE_SYNTAX_POSIX_BASIC);

  preg->buffer = NULL;
  preg->allocated = 0;
  preg->used = 0;

  /* Try to allocate space for the fastmap.  */
  preg->fastmap = re_malloc (char, SBC_MAX);
  if (BE (preg->fastmap == NULL, 0))
    return REG_ESPACE;

  syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;

  /* If REG_NEWLINE is set, newlines are treated differently.  */
  if (cflags & REG_NEWLINE)
    { /* REG_NEWLINE implies neither . nor [^...] match newline.  */
      syntax &= ~RE_DOT_NEWLINE;
      syntax |= RE_HAT_LISTS_NOT_NEWLINE;
      /* It also changes the matching behavior.  */
      preg->newline_anchor = 1;
    }
  else
    preg->newline_anchor = 0;
  preg->no_sub = !!(cflags & REG_NOSUB);
  preg->translate = NULL;

  ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);

  /* POSIX doesn't distinguish between an unmatched open-group and an
     unmatched close-group: both are REG_EPAREN.  */
  if (ret == REG_ERPAREN)
    ret = REG_EPAREN;

  /* We have already checked preg->fastmap != NULL.  */
  if (BE (ret == REG_NOERROR, 1))
    /* Compute the fastmap now, since regexec cannot modify the pattern
       buffer.  This function never fails in this implementation.  */
    (void) re_compile_fastmap (preg);
  else
    {
      /* Some error occurred while compiling the expression.  */
      re_free (preg->fastmap);
      preg->fastmap = NULL;
    }

  return (int) ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

size_t regerror ( int  __errcode,
const regex_t *__restrict  __preg,
char *__restrict  __errbuf,
size_t  __errbuf_size 
)

Definition at line 509 of file regcomp.c.

{
  const char *msg;
  size_t msg_size;

  if (BE (errcode < 0
         || errcode >= (int) (sizeof (__re_error_msgid_idx)
                            / sizeof (__re_error_msgid_idx[0])), 0))
    /* Only error codes returned by the rest of the code should be passed
       to this routine.  If we are given anything else, or if other regex
       code generates an invalid error code, then the program has a bug.
       Dump core so we can fix it.  */
    abort ();

  msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);

  msg_size = strlen (msg) + 1; /* Includes the null.  */

  if (BE (errbuf_size != 0, 1))
    {
      if (BE (msg_size > errbuf_size, 0))
       {
#if defined HAVE_MEMPCPY || defined _LIBC
         *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0';
#else
         memcpy (errbuf, msg, errbuf_size - 1);
         errbuf[errbuf_size - 1] = 0;
#endif
       }
      else
       memcpy (errbuf, msg, msg_size);
    }

  return msg_size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int regexec ( const regex_t *__restrict  __preg,
const char *__restrict  __string,
size_t  __nmatch,
regmatch_t  __pmatch[__restrict_arr],
int  __eflags 
)

Here is the caller graph for this function:

void regfree ( regex_t *  __preg)

Definition at line 617 of file regcomp.c.

{
  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
  if (BE (dfa != NULL, 1))
    free_dfa_content (dfa);
  preg->buffer = NULL;
  preg->allocated = 0;

  re_free (preg->fastmap);
  preg->fastmap = NULL;

  re_free (preg->translate);
  preg->translate = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 244 of file regcomp.c.