Crossfire Server, Trunk
re-cmp.cpp File Reference
#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.cpp:

Go to the source code of this file.

Macros

#define exit_if_null
 

Functions

const char * re_cmp (const char *, const char *)
 
static Boolean re_cmp_step (const char *, const char *, unsigned, int)
 
static const char * re_get_token (selection *, const char *)
 
static void re_init (void)
 
static Boolean re_match_token (uchar, selection *)
 

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:

  • These tokens are not supported: | ( )
  • You will get the longest expansion of the first string which matches the RE, not the longest string which would be the proper behaviour for a RE-matcher.

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.cpp.

Macro Definition Documentation

◆ exit_if_null

#define exit_if_null

Function Documentation

◆ re_cmp()

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 68 of file re-cmp.cpp.

References Boolean, False, re_cmp(), re_cmp_step(), re_get_token(), re_init(), re_init_done, re_match_token(), re_substr, re_token, re_token_depth, rep_null_or_more, rep_null_or_once, rep_once, rep_once_or_more, make_face_from_files::str, 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:

◆ re_cmp_step()

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 189 of file re-cmp.cpp.

References Boolean, False, matches(), re_get_token(), re_match_token(), re_substr, re_token, re_token_depth, rep_null_or_more, rep_null_or_once, rep_once, rep_once_or_more, sel_end, make_face_from_files::str, True, and is_valid_types_gen::type.

Referenced by re_cmp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ re_get_token()

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 330 of file re-cmp.cpp.

References selection::array, Boolean, exit_if_null, False, say::previous, 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:

◆ re_init()

static void re_init ( void  )
static

Init the regular expression structures.

Note
will fatal() in case of memory error.

Definition at line 270 of file re-cmp.cpp.

References fatal(), OUT_OF_MEMORY, re_init_done, re_token, 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:

◆ re_match_token()

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 292 of file re-cmp.cpp.

References selection::array, c, 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

◆ re_init_done

Boolean re_init_done = False
static

Definition at line 49 of file re-cmp.cpp.

Referenced by re_cmp(), and re_init().

◆ re_substr

const char* re_substr[RE_TOKEN_MAX]
static

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

Referenced by re_cmp(), and re_cmp_step().

◆ re_token

selection* re_token[RE_TOKEN_MAX]
static

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

Referenced by re_cmp(), re_cmp_step(), and re_init().

◆ re_token_depth

unsigned int re_token_depth
static

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

Referenced by re_cmp(), and re_cmp_step().