IDZEBRA 2.2.11
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

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 MatchContext * mk_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
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

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.

Referenced by dict_lookup_grep().

◆ WORD_BITS

#define WORD_BITS   32

Definition at line 34 of file lookgrep.c.

Function Documentation

◆ dict_grep_cmap()

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

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.

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(* f )(char *name, const char *info, void *client) )

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(), init_pos(), MAX_LENGTH, mk_MatchContext(), MatchContext::n, DFA::no_states, MatchContext::range, rm_MatchContext(), 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()

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

Definition at line 64 of file lookgrep.c.

References INLINE, MatchContext::n, and WORD_BITS.

Referenced by dict_lookup_grep().

◆ grep()

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 )
static

◆ mask_shift()

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

◆ mk_MatchContext()

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

◆ move()

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 INLINE, mask_shift(), MatchContext::n, or(), MatchContext::range, and shift().

Referenced by grep().

◆ or()

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()

void rm_MatchContext ( MatchContext ** mc)
static

Definition at line 89 of file lookgrep.c.

Referenced by dict_lookup_grep().

◆ set_bit()

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

Definition at line 56 of file lookgrep.c.

References INLINE, MatchContext::n, and WORD_BITS.

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

◆ shift()

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