The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

regexp.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

struct  regexp

Defines

#define MAGIC   0234
#define NSUBEXP   10

Typedefs

typedef regexp regexp

Functions

regexpregcomp (char *exp)
void regerror (char *s)
int regexec (regexp *prog, char *string)


Define Documentation

#define MAGIC   0234
 

Definition at line 29 of file regexp.h.

Referenced by regcomp().

#define NSUBEXP   10
 

Definition at line 10 of file regexp.h.


Typedef Documentation

typedef struct regexp regexp
 


Function Documentation

regexp* regcomp char *  exp  ) 
 

Definition at line 213 of file regexp.c.

References EXACTLY, FAIL, MAGIC, OP, OPERAND, regexp::program, r, reg(), regexp::reganch, regc(), regcode, regexp::regmlen, regexp::regmust, regnext(), regnpar, regparse, regsize, and regexp::regstart.

Referenced by regex_compile().

00214 {
00215         register regexp *r;
00216         register char *scan;
00217         register char *longest;
00218         register unsigned len;
00219         int flags;
00220 
00221         if (exp == NULL)
00222                 FAIL("NULL argument");
00223 
00224         /* First pass: determine size, legality. */
00225 #ifdef notdef
00226         if (exp[0] == '.' && exp[1] == '*') exp += 2;  /* aid grep */
00227 #endif
00228         regparse = (char *)exp;
00229         regnpar = 1;
00230         regsize = 0L;
00231         regcode = &regdummy;
00232         regc(MAGIC);
00233         if (reg(0, &flags) == NULL)
00234                 return(NULL);
00235 
00236         /* Small enough for pointer-storage convention? */
00237         if (regsize >= 32767L)          /* Probably could be 65535L. */
00238                 FAIL("regexp too big");
00239 
00240         /* Allocate space. */
00241         r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize);
00242         if (r == NULL)
00243                 FAIL("out of space");
00244 
00245         /* Second pass: emit code. */
00246         regparse = (char *)exp;
00247         regnpar = 1;
00248         regcode = r->program;
00249         regc(MAGIC);
00250         if (reg(0, &flags) == NULL)
00251                 return(NULL);
00252 
00253         /* Dig out information for optimizations. */
00254         r->regstart = '\0';     /* Worst-case defaults. */
00255         r->reganch = 0;
00256         r->regmust = NULL;
00257         r->regmlen = 0;
00258         scan = r->program+1;                    /* First BRANCH. */
00259         if (OP(regnext(scan)) == END) {         /* Only one top-level choice. */
00260                 scan = OPERAND(scan);
00261 
00262                 /* Starting-point info. */
00263                 if (OP(scan) == EXACTLY)
00264                         r->regstart = *OPERAND(scan);
00265                 else if (OP(scan) == BOL)
00266                         r->reganch++;
00267 
00268                 /*
00269                  * If there's something expensive in the r.e., find the
00270                  * longest literal string that must appear and make it the
00271                  * regmust.  Resolve ties in favor of later strings, since
00272                  * the regstart check works with the beginning of the r.e.
00273                  * and avoiding duplication strengthens checking.  Not a
00274                  * strong reason, but sufficient in the absence of others.
00275                  */
00276                 if (flags&SPSTART) {
00277                         longest = NULL;
00278                         len = 0;
00279                         for (; scan != NULL; scan = regnext(scan))
00280                                 if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
00281                                         longest = OPERAND(scan);
00282                                         len = strlen(OPERAND(scan));
00283                                 }
00284                         r->regmust = longest;
00285                         r->regmlen = len;
00286                 }
00287         }
00288 
00289         return(r);
00290 }

Here is the call graph for this function:

void regerror char *  s  ) 
 

Definition at line 189 of file headers.c.

References s.

Referenced by regexec(), regmatch(), and regrepeat().

00190 {
00191         printf( "re error %s\n", s );
00192 }

int regexec regexp prog,
char *  string
 

Referenced by builtin_match(), builtin_subst(), headers1(), and macro_headers().


Generated on Mon Nov 8 17:08:16 2004 for MPT by  doxygen 1.3.9.1