IDZEBRA  2.2.7
Data Structures | Macros | Typedefs | Functions
lookgrep.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <dfa.h>
#include "dict-p.h"

Go to the source code of this file.

Data Structures

struct  MatchContext
 

Macros

#define WORD_BITS   32
 
#define MAX_LENGTH   1024
 
#define INLINE
 

Typedefs

typedef unsigned MatchWord
 

Functions

static INLINE void set_bit (MatchContext *mc, MatchWord *m, int ch, int state)
 
static INLINE MatchWord get_bit (MatchContext *mc, MatchWord *m, int ch, int state)
 
static MatchContextmk_MatchContext (struct DFA *dfa, int range)
 
static void rm_MatchContext (MatchContext **mc)
 
static void mask_shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa, int ch)
 
static void shift (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa)
 
static void or (MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc1, MatchWord *Rsrc2)
 
static INLINE int move (MatchContext *mc, MatchWord *Rj1, MatchWord *Rj, Dict_char ch, struct DFA *dfa, MatchWord *Rtmp, int range)
 
static int grep (Dict dict, Dict_ptr ptr, MatchContext *mc, MatchWord *Rj, int pos, void *client, int(*userfunc)(char *, const char *, void *), Dict_char *prefix, struct DFA *dfa, int *max_pos, int init_pos)
 
int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, int *max_pos, int init_pos, int(*userfunc)(char *name, const char *info, void *client))
 regular expression search with error correction More...
 
void dict_grep_cmap (Dict dict, void *vp, const char **(*cmap)(void *vp, const char **from, int len))
 install character mapping handler for dict_lookup_grep More...
 

Macro Definition Documentation

◆ INLINE

#define INLINE

Definition at line 54 of file lookgrep.c.

◆ MAX_LENGTH

#define MAX_LENGTH   1024

Definition at line 35 of file lookgrep.c.

◆ WORD_BITS

#define WORD_BITS   32

Definition at line 34 of file lookgrep.c.

Typedef Documentation

◆ MatchWord

typedef unsigned MatchWord

Definition at line 33 of file lookgrep.c.

Function Documentation

◆ dict_grep_cmap()

void dict_grep_cmap ( Dict  dict,
void *  vp,
const char **(*)(void *vp, const char **from, int len)  cmap 
)

install character mapping handler for dict_lookup_grep

Parameters
dictdictionary handle
vpclient data to be passed to cmap function handler
cmapfunction be called for each character

This function must be called prior to using dict_grep_lookup. If vp is NULL, no character mapping takes place for dict_lookup_grep.

Definition at line 445 of file lookgrep.c.

References dict, Dict_struct::grep_cmap, and Dict_struct::grep_cmap_data.

Referenced by rpn_char_map_prepare(), and rpn_search_xpath().

◆ dict_lookup_grep()

int dict_lookup_grep ( Dict  dict,
const char *  p,
int  range,
void *  client,
int *  max_pos,
int  init_pos,
int(*)(char *name, const char *info, void *client)  f 
)

regular expression search with error correction

Parameters
dictdictionary handle
pregular expression string-z
rangenumber of allowed errors(extra/substituted/missing char)
clientclient data pointer to be passed to match function f
max_poson return holds maximum number of chars that match (prefix)
init_posnumber of leading non-error corrected chars.
ffunction be called for each match
Return values
0Operation complete. Function f returned zero value always
>0Operation incomplete. Function f returned a non-zero value
-1error (such as bad regular expression)

The function f is called for each match. If function f returns non-zero value the grep operation is stopped and the returned non-zero value is also returned by dict_lookup_ec.

Definition at line 374 of file lookgrep.c.

References debug_dfa_followpos, debug_dfa_tran, debug_dfa_trav, dfa_anyset_includes_nl(), dfa_delete(), dfa_init(), dfa_mkstate(), dfa_parse(), dfa_set_cmap(), dfa_verbose, dict, MatchContext::fact, get_bit(), grep(), Dict_struct::grep_cmap, Dict_struct::grep_cmap_data, Dict_struct::head, init_pos(), MAX_LENGTH, mk_MatchContext(), MatchContext::n, DFA::no_states, MatchContext::range, rm_MatchContext(), Dict_head::root, set_bit(), DFA::states, DFA_tran::to, DFA_state::tran_no, and DFA_state::trans.

Referenced by main(), numeric_relation(), string_term(), and xpath_trunc().

◆ get_bit()

static INLINE MatchWord get_bit ( MatchContext mc,
MatchWord m,
int  ch,
int  state 
)
static

Definition at line 64 of file lookgrep.c.

References MatchContext::n, and WORD_BITS.

Referenced by dict_lookup_grep().

◆ grep()

static int grep ( Dict  dict,
Dict_ptr  ptr,
MatchContext mc,
MatchWord Rj,
int  pos,
void *  client,
int(*)(char *, const char *, void *)  userfunc,
Dict_char prefix,
struct DFA dfa,
int *  max_pos,
int  init_pos 
)
static

◆ mask_shift()

static void mask_shift ( MatchContext mc,
MatchWord Rdst,
MatchWord Rsrc,
struct DFA dfa,
int  ch 
)
static

◆ mk_MatchContext()

static MatchContext* mk_MatchContext ( struct DFA dfa,
int  range 
)
static

◆ move()

static INLINE int move ( MatchContext mc,
MatchWord Rj1,
MatchWord Rj,
Dict_char  ch,
struct DFA dfa,
MatchWord Rtmp,
int  range 
)
static

Definition at line 215 of file lookgrep.c.

References mask_shift(), MatchContext::n, or(), MatchContext::range, and shift().

Referenced by grep().

◆ or()

static void or ( MatchContext mc,
MatchWord Rdst,
MatchWord Rsrc1,
MatchWord Rsrc2 
)
static

Definition at line 207 of file lookgrep.c.

References MatchContext::n.

Referenced by move().

◆ rm_MatchContext()

static void rm_MatchContext ( MatchContext **  mc)
static

Definition at line 89 of file lookgrep.c.

Referenced by dict_lookup_grep().

◆ set_bit()

static INLINE void set_bit ( MatchContext mc,
MatchWord m,
int  ch,
int  state 
)
static

Definition at line 56 of file lookgrep.c.

References MatchContext::n, and WORD_BITS.

Referenced by dict_lookup_grep(), mask_shift(), mk_MatchContext(), and shift().

◆ shift()

static void shift ( MatchContext mc,
MatchWord Rdst,
MatchWord Rsrc,
struct DFA dfa 
)
static