FOSSology  4.4.0
Open Source License Compliance by Open Source Software
nomos_regex.c File Reference

search using regex functions More...

#include "nomos_regex.h"
#include "nomos_gap.h"
#include "nomos_utils.h"
Include dependency graph for nomos_regex.c:

Go to the source code of this file.

Macros

#define CALL_IF_DEBUG_MODE(x)
 
#define _XC(q)   ((char) xascii[q])
 

Functions

void regexError (int ret, regex_t *regc, char *regex)
 Log an error caused by regex. More...
 
int endsIn (char *s, char *suffix)
 Check if a string ends with given suffix. More...
 
int lineInFile (char *pathname, char *regex)
 Check if a line exists in a file. More...
 
int textInFile (char *pathname, char *regex, int flags)
 Check if a regex passes in a file. More...
 
int strGrep (char *regex, char *data, int flags)
 General-purpose grep function, used for one-time-only searches. More...
 
int idxGrep (int index, char *data, int flags)
 compile a regex, and perform the search (on data?) More...
 
int idxGrep_recordPosition (int index, char *data, int flags)
 compile a regex, perform the search and record findings More...
 
int idxGrep_recordPositionDoctored (int index, char *data, int flags)
 compile a regex, perform the search and record findings More...
 
int idxGrep_recordIndex (int index, char *data, int flags)
 compile a regex, perform the search and record index More...
 
int matchOnce (int isPlain, char *data, char *regex, regex_t *rp, regmatch_t *regmatch)
 Perform a regex match on a given data and return only first match. More...
 
int storeOneMatch (regmatch_t currentRegMatch, int lastmatch, GArray *allmatches, char **tmpData, char *data)
 Store a single regex match to array. More...
 
int idxGrep_base (int index, char *data, int flags, int mode)
 compile a regex, and perform the search (on data?) More...
 
void recordIndex (GArray *indexList, int index)
 Add a given index to index list. More...
 
static int getOffset (int posInDoctoredBuffer)
 Get offset from doctored buffer. More...
 
regmatch_t * getRegmatch_t (GArray *in, int index)
 From a given array, get regex match from a given index. More...
 
void rememberWhatWeFound (GArray *highlight, GArray *regmatch_tArray, int index, int mode)
 Store regex matches in highlight array. More...
 
int strNbuf (char *data, char *str)
 Check if a string exists in buffer (case insensitive) More...
 
int strNbuf_noGlobals (char *data, char *str, regmatch_t *matchPos, int doSave, char *saveData)
 This is our own internal, case-insensitive version of strstr(). More...
 

Variables

static char regexErrbuf [myBUFSIZ]
 
regex_t idx_regc [NFOOTPRINTS]
 
regex_t regc [NFOOTPRINTS]
 

Detailed Description

search using regex functions

Functions for dealing with the regex clib functions. Performs the regex searchs on the data.

Definition in file nomos_regex.c.

Function Documentation

◆ endsIn()

int endsIn ( char *  s,
char *  suffix 
)

Check if a string ends with given suffix.

Parameters
sString to check
suffixSuffix to find
Returns
1 if suffix found, 0 otherwise

Definition at line 56 of file nomos_regex.c.

◆ getOffset()

static int getOffset ( int  posInDoctoredBuffer)
static

Get offset from doctored buffer.

Parameters
posInDoctoredBuffer
Returns
new offset
See also
uncollapsePosition()

Definition at line 462 of file nomos_regex.c.

◆ getRegmatch_t()

regmatch_t* getRegmatch_t ( GArray *  in,
int  index 
)

From a given array, get regex match from a given index.

Parameters
inArray to get regex match from
indexThe index in array required
Returns
Regex match @index

Definition at line 473 of file nomos_regex.c.

◆ idxGrep()

int idxGrep ( int  index,
char *  data,
int  flags 
)

compile a regex, and perform the search (on data?)

Parameters
indexnumber of licence/regex we are looking for (given in STRINGS.in)
datathe data to search
flagsregcomp cflags
Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.

Definition at line 205 of file nomos_regex.c.

◆ idxGrep_base()

int idxGrep_base ( int  index,
char *  data,
int  flags,
int  mode 
)

compile a regex, and perform the search (on data?)

Parameters
indexnumber of licence/regex we are looking for (given in STRINGS.in)
datathe data to search
flagsregcomp cflags
modeFlag to control recording of findings (0:No, 1: Yes, 2:Yes doctored buffer)
Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.
Todo:
is idx_regc needed? Here we set the pointer to our array and later we fill it, but we never reuse the regex_t

Now we have a match

All sanity checks have passed and we have at least one match

Definition at line 324 of file nomos_regex.c.

◆ idxGrep_recordIndex()

int idxGrep_recordIndex ( int  index,
char *  data,
int  flags 
)

compile a regex, perform the search and record index

If OPTS_NO_HIGHLIGHTINFO is set, do not record. If not set, record the finding index

Parameters
indexnumber of licence/regex we are looking for (given in STRINGS.in)
datathe data to search
flagsregcomp cflags
Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.

Definition at line 263 of file nomos_regex.c.

◆ idxGrep_recordPosition()

int idxGrep_recordPosition ( int  index,
char *  data,
int  flags 
)

compile a regex, perform the search and record findings

If OPTS_NO_HIGHLIGHTINFO is set, do not record. If not set, record the findings

Parameters
indexnumber of licence/regex we are looking for (given in STRINGS.in)
datathe data to search
flagsregcomp cflags
Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.

Definition at line 220 of file nomos_regex.c.

◆ idxGrep_recordPositionDoctored()

int idxGrep_recordPositionDoctored ( int  index,
char *  data,
int  flags 
)

compile a regex, perform the search and record findings

If OPTS_NO_HIGHLIGHTINFO is set, do not record. If not set, record the doctored findings

Parameters
indexnumber of licence/regex we are looking for (given in STRINGS.in)
datathe data to search
flagsregcomp cflags
Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.

Definition at line 241 of file nomos_regex.c.

◆ lineInFile()

int lineInFile ( char *  pathname,
char *  regex 
)

Check if a line exists in a file.

Parameters
pathnameFile location
regexRegex to check
Returns
True if regex satisfied, false otherwise

Definition at line 81 of file nomos_regex.c.

◆ matchOnce()

int matchOnce ( int  isPlain,
char *  data,
char *  regex,
regex_t *  rp,
regmatch_t *  regmatch 
)

Perform a regex match on a given data and return only first match.

Parameters
isPlainDo a plain match?
dataThe string to perform search on
regexThe regex string
rpRegex buffer
[out]regmatchRegex matches
Returns

Definition at line 282 of file nomos_regex.c.

◆ recordIndex()

void recordIndex ( GArray *  indexList,
int  index 
)

Add a given index to index list.

Parameters
[in,out]indexListList to add index to
[in]indexIndex to be appended

Definition at line 452 of file nomos_regex.c.

◆ regexError()

void regexError ( int  ret,
regex_t *  regc,
char *  regex 
)

Log an error caused by regex.

Calls regerror()

Parameters
retError code
regcCompiled regex
regexRegex string

Definition at line 38 of file nomos_regex.c.

◆ rememberWhatWeFound()

void rememberWhatWeFound ( GArray *  highlight,
GArray *  regmatch_tArray,
int  index,
int  mode 
)

Store regex matches in highlight array.

Parameters
[in,out]highlightThe array holding the regex matches
[in]regmatch_tArrayArray of regex matches to store
[in]indexIndex of license (from STRINGS.in)
[in]modeMode to store (1=>get the byte position|2=>get the offset)

Definition at line 485 of file nomos_regex.c.

◆ storeOneMatch()

int storeOneMatch ( regmatch_t  currentRegMatch,
int  lastmatch,
GArray *  allmatches,
char **  tmpData,
char *  data 
)

Store a single regex match to array.

Parameters
[in]currentRegMatchMatch to store
[in]lastmatchIndex of last match
[in,out]allmatchesArray of all matches
[in,out]tmpData
[in]data
Returns
New lastmatch index

Definition at line 301 of file nomos_regex.c.

◆ strGrep()

int strGrep ( char *  regex,
char *  data,
int  flags 
)

General-purpose grep function, used for one-time-only searches.

Returns
-1 on regex-compile failure, 1 if regex search fails, and 0 if regex search is successful.

Definition at line 139 of file nomos_regex.c.

◆ strNbuf()

int strNbuf ( char *  data,
char *  str 
)

Check if a string exists in buffer (case insensitive)

Parameters
dataHaystack
strNeedle
Returns
1 on success, 0 otherwise
See also
strNbuf_noGlobals()

Definition at line 528 of file nomos_regex.c.

◆ strNbuf_noGlobals()

int strNbuf_noGlobals ( char *  data,
char *  str,
regmatch_t *  matchPos,
int  doSave,
char *  saveData 
)

This is our own internal, case-insensitive version of strstr().

No open-source code was consulted/used in the construction of this function.

Definition at line 538 of file nomos_regex.c.

◆ textInFile()

int textInFile ( char *  pathname,
char *  regex,
int  flags 
)

Check if a regex passes in a file.

Parameters
pathnameFile location
regexRegex to check
flagsAdditional regex flags
Returns
True if regex satisfied, false otherwise

Definition at line 100 of file nomos_regex.c.

Variable Documentation

◆ regexErrbuf

char regexErrbuf[myBUFSIZ]
static

Buffer to hold regex error

Definition at line 25 of file nomos_regex.c.