Crossfire Server, Trunk  R20513
Macros | Functions | Variables
re-cmp.c File Reference

Pattern match a string, parsing some of the common RE-metacharacters. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <re-cmp.h>
#include <ctype.h>
#include <global.h>
#include <define.h>
Include dependency graph for re-cmp.c:

Go to the source code of this file.

Macros

#define exit_if_null
 

Functions

const char * re_cmp (const char *str, const char *regexp)
 re-cmp - get regular expression match. More...
 
static Boolean re_cmp_step (const char *str, const char *regexp, unsigned slot, int matches)
 Tries to match a string with a regexp. More...
 
static const char * re_get_token (selection *sel, const char *regexp)
 Get the first regular expression token found in regexp in sel. More...
 
static void re_init (void)
 Init the regular expression structures. More...
 
static Boolean re_match_token (uchar c, selection *sel)
 Tests if a char matches a token. More...
 

Variables

static Boolean re_init_done = False
 
static const char * re_substr [RE_TOKEN_MAX]
 
static selectionre_token [RE_TOKEN_MAX]
 
static unsigned int re_token_depth
 

Detailed Description

Pattern match a string, parsing some of the common RE-metacharacters.

This code is public domain, but I would appreciate to hear of improvements or even the fact that you use it in your program.

Deliberate BUGS:

Author: Kjetil T. Homme (kjeti.nosp@m.lho@.nosp@m.ifi.u.nosp@m.io.n.nosp@m.o) May 1993

Definition in file re-cmp.c.

Macro Definition Documentation

#define exit_if_null

Referenced by re_get_token().

Function Documentation

const char * re_cmp ( const char *  str,
const char *  regexp 
)

re-cmp - get regular expression match.

Parameters
strstring that will be matched against the regexp.
regexpregular expression.
Returns
  • no match or error in regexp.
  • pointer to beginning of matching string

Definition at line 69 of file re-cmp.c.

References Boolean, False, re_cmp(), re_cmp_step(), re_get_token(), re_init(), re_init_done, re_match_token(), re_substr, re_token_depth, rep_null_or_more, rep_null_or_once, rep_once, rep_once_or_more, and True.

Referenced by cfapi_system_re_cmp(), matches(), and re_cmp().

Here is the call graph for this function:

Here is the caller graph for this function:

static Boolean re_cmp_step ( const char *  str,
const char *  regexp,
unsigned  slot,
int  matches 
)
static

Tries to match a string with a regexp.

Parameters
strstring to match
regexppattern
slotnumber of the token which under consideration
matcheshow many times the token has matched
Returns
True if match, False else.

Definition at line 190 of file re-cmp.c.

References Boolean, False, matches(), re_get_token(), re_match_token(), re_substr, re_token_depth, rep_null_or_more, rep_null_or_once, rep_once, rep_once_or_more, sel_end, and True.

Referenced by re_cmp().

Here is the call graph for this function:

Here is the caller graph for this function:

static const char * re_get_token ( selection sel,
const char *  regexp 
)
static

Get the first regular expression token found in regexp in sel.

Parameters
[out]selwhere to store the token.
regexpregular expression.
Returns
  • NULL: syntax error
  • pointer to first character past token.

Definition at line 331 of file re-cmp.c.

References selection::array, Boolean, exit_if_null, False, selection::range, rep_null_or_more, rep_null_or_once, rep_once, rep_once_or_more, selection::repeat, sel_any, sel_array, sel_end, sel_not_range, sel_not_single, sel_range, sel_single, selection::single, True, selection::type, selection::u, and uchar.

Referenced by re_cmp(), and re_cmp_step().

Here is the caller graph for this function:

static void re_init ( void  )
static

Init the regular expression structures.

Note
will fatal() in case of memory error.

Definition at line 271 of file re-cmp.c.

References fatal(), OUT_OF_MEMORY, re_init_done, RE_TOKEN_MAX, and True.

Referenced by re_cmp().

Here is the call graph for this function:

Here is the caller graph for this function:

static Boolean re_match_token ( uchar  c,
selection sel 
)
static

Tests if a char matches a token.

Parameters
cchar to test.
seltoken to test.
Returns
True if matches, False else.

Definition at line 293 of file re-cmp.c.

References selection::array, False, selection::range, sel_any, sel_array, sel_end, sel_not_range, sel_not_single, sel_range, sel_single, selection::single, tolower, True, selection::type, and selection::u.

Referenced by re_cmp(), and re_cmp_step().

Here is the caller graph for this function:

Variable Documentation

Boolean re_init_done = False
static

Definition at line 50 of file re-cmp.c.

Referenced by re_cmp(), and re_init().

const char* re_substr[RE_TOKEN_MAX]
static

Definition at line 52 of file re-cmp.c.

Referenced by re_cmp(), and re_cmp_step().

selection* re_token[RE_TOKEN_MAX]
static

Definition at line 51 of file re-cmp.c.

unsigned int re_token_depth
static

Definition at line 53 of file re-cmp.c.

Referenced by re_cmp(), and re_cmp_step().