Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_query.c File Reference

Implementation of the small boolean field-query language. More...

#include "nilorea/n_query.h"
#include "nilorea/n_log.h"
#include "nilorea/n_pcre.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
+ Include dependency graph for n_query.c:

Go to the source code of this file.

Data Structures

struct  N_QUERY
 Opaque compiled query (see n_query_compile / n_query_eval / n_query_free). More...
 
struct  PARSER
 
struct  QNODE
 

Enumerations

enum  {
  OP_EQ , OP_NE , OP_CONT , OP_NCONT ,
  OP_REGEX , OP_GT , OP_LT , OP_GE ,
  OP_LE
}
 
enum  { N_AND , N_OR , N_NOT , N_CMP }
 
enum  {
  TK_END , TK_WORD , TK_AND , TK_OR ,
  TK_NOT , TK_LP , TK_RP , TK_OP
}
 

Functions

static int ci_contains (const char *hay, const char *needle)
 
static char * dupn (const char *s, size_t n)
 
static int eval_node (const QNODE *n, N_QUERY_GET get, void *ud)
 
static int is_op_char (char c)
 
static void lex_next (PARSER *P)
 
N_QUERYn_query_compile (const char *expr, char *errbuf, size_t errlen)
 Compile an expression into a query.
 
int n_query_eval (const N_QUERY *query, N_QUERY_GET get, void *user_data)
 Evaluate a compiled query against one record via get.
 
void n_query_free (N_QUERY **query)
 Free a compiled query and set the pointer to NULL.
 
static void node_free (QNODE *n)
 
static QNODEnode_new (int kind)
 
static QNODEparse_and (PARSER *P)
 
static QNODEparse_not (PARSER *P)
 
static QNODEparse_or (PARSER *P)
 
static QNODEparse_primary (PARSER *P)
 

Detailed Description

Implementation of the small boolean field-query language.

Definition in file n_query.c.


Data Structure Documentation

◆ N_QUERY

struct N_QUERY

Opaque compiled query (see n_query_compile / n_query_eval / n_query_free).

Examples
ex_query.c.

Definition at line 62 of file n_query.c.

+ Collaboration diagram for N_QUERY:
Data Fields
QNODE * root

◆ PARSER

struct PARSER

Definition at line 77 of file n_query.c.

+ Collaboration diagram for PARSER:
Data Fields
char err[160]
const char * p
int tok
int top
char * tval

◆ QNODE

struct QNODE

Definition at line 52 of file n_query.c.

+ Collaboration diagram for QNODE:
Data Fields
struct QNODE * a
struct QNODE * b
char * field
int kind
int op
N_PCRE * re
char * value

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OP_EQ 
OP_NE 
OP_CONT 
OP_NCONT 
OP_REGEX 
OP_GT 
OP_LT 
OP_GE 
OP_LE 

Definition at line 35 of file n_query.c.

◆ anonymous enum

anonymous enum
Enumerator
N_AND 
N_OR 
N_NOT 
N_CMP 

Definition at line 46 of file n_query.c.

◆ anonymous enum

anonymous enum
Enumerator
TK_END 
TK_WORD 
TK_AND 
TK_OR 
TK_NOT 
TK_LP 
TK_RP 
TK_OP 

Definition at line 67 of file n_query.c.

Function Documentation

◆ ci_contains()

static int ci_contains ( const char *  hay,
const char *  needle 
)
static

Definition at line 101 of file n_query.c.

Referenced by eval_node().

+ Here is the caller graph for this function:

◆ dupn()

static char * dupn ( const char *  s,
size_t  n 
)
static

Definition at line 86 of file n_query.c.

Referenced by lex_next(), and parse_primary().

+ Here is the caller graph for this function:

◆ eval_node()

static int eval_node ( const QNODE n,
N_QUERY_GET  get,
void *  ud 
)
static

Definition at line 416 of file n_query.c.

References QNODE::a, QNODE::b, ci_contains(), eval_node(), QNODE::field, QNODE::kind, N_AND, N_CMP, N_NOT, N_OR, npcre_match(), QNODE::op, OP_CONT, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LT, OP_NCONT, OP_NE, OP_REGEX, QNODE::re, and QNODE::value.

Referenced by eval_node(), and n_query_eval().

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

◆ is_op_char()

static int is_op_char ( char  c)
static

Definition at line 96 of file n_query.c.

Referenced by lex_next().

+ Here is the caller graph for this function:

◆ lex_next()

static void lex_next ( PARSER P)
static

Definition at line 116 of file n_query.c.

References dupn(), is_op_char(), OP_CONT, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LT, OP_NCONT, OP_NE, OP_REGEX, PARSER::p, TK_AND, TK_END, TK_LP, TK_NOT, TK_OP, TK_OR, TK_RP, TK_WORD, PARSER::tok, PARSER::top, and PARSER::tval.

Referenced by n_query_compile(), parse_and(), parse_not(), parse_or(), and parse_primary().

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

◆ node_free()

static void node_free ( QNODE n)
static

Definition at line 229 of file n_query.c.

References QNODE::a, QNODE::b, QNODE::field, node_free(), npcre_delete(), QNODE::re, and QNODE::value.

Referenced by n_query_compile(), n_query_free(), node_free(), parse_and(), parse_not(), parse_or(), and parse_primary().

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

◆ node_new()

static QNODE * node_new ( int  kind)
static

Definition at line 222 of file n_query.c.

References QNODE::kind.

Referenced by parse_and(), parse_not(), parse_or(), and parse_primary().

+ Here is the caller graph for this function:

◆ parse_and()

static QNODE * parse_and ( PARSER P)
static

Definition at line 323 of file n_query.c.

References QNODE::a, QNODE::b, lex_next(), N_AND, node_free(), node_new(), parse_not(), TK_AND, and PARSER::tok.

Referenced by parse_or().

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

◆ parse_not()

static QNODE * parse_not ( PARSER P)
static

Definition at line 304 of file n_query.c.

References QNODE::a, lex_next(), N_NOT, node_free(), node_new(), parse_not(), parse_primary(), TK_NOT, and PARSER::tok.

Referenced by parse_and(), and parse_not().

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

◆ parse_or()

static QNODE * parse_or ( PARSER P)
static

Definition at line 349 of file n_query.c.

References QNODE::a, QNODE::b, lex_next(), N_OR, node_free(), node_new(), parse_and(), TK_OR, and PARSER::tok.

Referenced by n_query_compile(), and parse_primary().

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

◆ parse_primary()

static QNODE * parse_primary ( PARSER P)
static

Definition at line 243 of file n_query.c.

References dupn(), PARSER::err, QNODE::field, lex_next(), N_CMP, node_free(), node_new(), npcre_new(), QNODE::op, OP_REGEX, parse_or(), QNODE::re, TK_AND, TK_LP, TK_NOT, TK_OP, TK_OR, TK_RP, TK_WORD, PARSER::tok, PARSER::top, PARSER::tval, and QNODE::value.

Referenced by parse_not().

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