libarmutils  1.4
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups
Regex Utils

Data Structures

struct  REList
 Regular Expressions List. More...

Functions

int re_compile (regex_t *preg, const char *pattern, int cflags)
 Wrapper function for regcomp().
char * re_error (int errcode, regex_t *preg)
 Wrapper function for regerror().
int re_execute (regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
 Wrapper function for regexec().
void re_free (regex_t *preg)
 Wrapper function for regfree().
void re_free_substrings (size_t nmatch, char **substrings)
 Free the substring list returned by re_substrings().
char ** re_substrings (const char *string, size_t nmatch, regmatch_t *pmatch)
 Extract the substrings from a regular expression match.
REListrelist_compile (REList *re_list, int npatterns, const char **patterns, int cflags)
 Compile a list of regular expression patterns.
int relist_execute (REList *re_list, const char *string, int eflags, int *mindex, size_t *nsubs, regmatch_t **pmatch, char ***substrings)
 Compare a string with a list of regular expressions.
void relist_free (REList *re_list)
 Free a regular expressions list.

Detailed Description


Function Documentation

int re_compile ( regex_t *  preg,
const char *  pattern,
int  cflags 
)

Wrapper function for regcomp().

See the regcomp man page for more detailed argument descriptions.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
preg- pointer to the regex structure to use
pattern- pattern string to compile
cflags- compile flags
Returns:
  • 1 if successful
  • 0 if an error occurred

Definition at line 78 of file regex_utils.c.

char* re_error ( int  errcode,
regex_t *  preg 
)

Wrapper function for regerror().

The memory used by the returned string is dynamically allocated. It is the responsibility of the calling process to free this memory.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
errcode- error code returned by re_comp() or re_exec()
preg- pointer to the regular expression that failed
Returns:
  • regex error message
  • NULL if an error occurred

Definition at line 118 of file regex_utils.c.

int re_execute ( regex_t *  preg,
const char *  string,
size_t  nmatch,
regmatch_t  pmatch[],
int  eflags 
)

Wrapper function for regexec().

See the regexec man page for more detailed argument descriptions.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
preg- pointer to the compiled regular expression
string- string to compare with the regular expression
nmatch- number of substrings to match
pmatch- arrary to store the matching substring offsets
eflags- execute flags
Returns:
  • 1 if match
  • 0 if no match
  • -1 if an error occurred

Definition at line 169 of file regex_utils.c.

void re_free ( regex_t *  preg)

Wrapper function for regfree().

Parameters:
preg- pointer to the compiled regular expression

Definition at line 207 of file regex_utils.c.

void re_free_substrings ( size_t  nmatch,
char **  substrings 
)

Free the substring list returned by re_substrings().

Parameters:
nmatch- number of substrings in match request
substrings- array of substrings returned by re_substrings()

Definition at line 218 of file regex_utils.c.

char** re_substrings ( const char *  string,
size_t  nmatch,
regmatch_t *  pmatch 
)

Extract the substrings from a regular expression match.

The array of substrings returned by this function must me freed with re_free_substrings().

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
string- string that matched the regular expression
nmatch- number of substrings in match request
pmatch- arrary that the matching substring offsets were stored in
Returns:
  • pointer to array of substrings
  • NULL if an error occurred

Definition at line 247 of file regex_utils.c.

REList* relist_compile ( REList re_list,
int  npatterns,
const char **  patterns,
int  cflags 
)

Compile a list of regular expression patterns.

See the regcomp man page for the descriptions of the pattern strings and compile flags.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
re_list- pointer to the regular expressions list to add the patterns to, or NULL to create a new list
npatterns- number of patterns to compile
patterns- list of patterns to compile
cflags- compile flags
Returns:
  • pointer to the regular expressions list
  • NULL if an error occurred

Definition at line 318 of file regex_utils.c.

int relist_execute ( REList re_list,
const char *  string,
int  eflags,
int *  mindex,
size_t *  nsubs,
regmatch_t **  pmatch,
char ***  substrings 
)

Compare a string with a list of regular expressions.

For the outputs that are not NULL, this function will return the results for the first regular expression that matches the specified string. The returned pointers to the pmatch and substrings arrays will be valid until the next call to relist_execute() or relist_free().

The pmatch and substrings arrays will have an entry for every parenthesised subexpression for the pattern that was matched (starting at index 1). Entries at index 0 correspond to the entire regular expression. For subexpressions that were not matched, the offsets in the pmatch entry will be -1 and the substrings entry will be NULL.

See the regexec man page for more detailed descriptions of the execute flags and output pmatch array.

Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).

Parameters:
re_list- pointer to the regular expressions list
string- string to compare with the regular expression
eflags- execute flags
mindex- output: index of the pattern that was matched
nsubs- output: number of parenthesised subexpressions
pmatch- output: pointer to array of substring offsets
substrings- output: pointer to array of substrings
Returns:
  • 1 if match
  • 0 if no match
  • -1 if an error occurred

Definition at line 452 of file regex_utils.c.

void relist_free ( REList re_list)

Free a regular expressions list.

Parameters:
re_list- pointer to the regular expressions list

Definition at line 574 of file regex_utils.c.