xapian-core  2.1.0
snowball_runtime.h
Go to the documentation of this file.
1 #ifndef SNOWBALL_INCLUDED_SNOWBALL_RUNTIME_H
2 #define SNOWBALL_INCLUDED_SNOWBALL_RUNTIME_H
3 
4 #include "api.h"
5 
6 #include <limits.h>
7 
8 #ifdef __cplusplus
9 /* Use reinterpret_cast<> to avoid -Wcast-align warnings from clang++. */
10 # define SIZE(p) (reinterpret_cast<const int *>(p))[-1]
11 # define SET_SIZE(p, n) (reinterpret_cast<int *>(p))[-1] = n
12 # define CAPACITY(p) (reinterpret_cast<int *>(p))[-2]
13 #else
14 # define SIZE(p) ((const int *)(p))[-1]
15 # define SET_SIZE(p, n) ((int *)(p))[-1] = n
16 # define CAPACITY(p) ((int *)(p))[-2]
17 #endif
18 
19 #ifdef SNOWBALL_RUNTIME_THROW_EXCEPTIONS
20 # define SNOWBALL_ERR void
21 #else
22 # define SNOWBALL_ERR int
23 #endif
24 
25 #ifdef SNOWBALL_DEBUG_COMMAND_USED
26 # include <stdio.h>
27 static void debug(struct SN_env * z, int n, int line) {
28  int i;
29  int len = SIZE(z->p);
30  printf("%3d (line %4d): [%d]'", n, line, len);
31  for (i = 0; i <= len; i++) {
32  if (z->lb == i) putc('{', stdout);
33  if (z->bra == i) putc('[', stdout);
34  if (z->c == i) putc('|', stdout);
35  if (z->ket == i) putc(']', stdout);
36  if (z->l == i) putc('}', stdout);
37  if (i < len) {
38  int ch = z->p[i];
39  if (ch == 0) ch = '#';
40  putc(ch, stdout);
41  }
42  }
43  printf("'\n");
44  fflush(stdout);
45 }
46 #endif
47 
48 struct among
49 {
50  /* Number of symbols in s. */
51  int s_size;
52  /* Search string. */
53  const symbol * s;
54  /* Delta of index to longest matching substring, or 0 if none. */
56  /* Result of the lookup. */
57  int result;
58  /* Optional condition routine index, or 0 if none. */
59  int function;
60 };
61 
62 /* MSVC doesn't like functions declared `extern "C"` throwing exceptions. */
63 #if defined __cplusplus && !defined SNOWBALL_RUNTIME_THROW_EXCEPTIONS
64 extern "C" {
65 #endif
66 
67 extern symbol * create_s(void);
68 extern void lose_s(symbol * p);
69 
70 extern int skip_utf8(const symbol * p, int c, int limit, int n);
71 
72 extern int skip_b_utf8(const symbol * p, int c, int limit, int n);
73 
74 extern int in_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
75 extern int in_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
76 extern int out_grouping_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
77 extern int out_grouping_b_U(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
78 
79 extern int in_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
80 extern int in_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
81 extern int out_grouping(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
82 extern int out_grouping_b(struct SN_env * z, const unsigned char * s, int min, int max, int repeat);
83 
84 extern int eq_s(struct SN_env * z, int s_size, const symbol * s);
85 extern int eq_s_b(struct SN_env * z, int s_size, const symbol * s);
86 extern int eq_v(struct SN_env * z, const symbol * p);
87 extern int eq_v_b(struct SN_env * z, const symbol * p);
88 
89 extern int find_among(struct SN_env * z, const struct among * v, int v_size,
90  int (*)(struct SN_env *));
91 extern int find_among_b(struct SN_env * z, const struct among * v, int v_size,
92  int (*)(struct SN_env *));
93 
94 extern SNOWBALL_ERR replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const symbol * s);
95 extern SNOWBALL_ERR slice_from_s(struct SN_env * z, int s_size, const symbol * s);
96 extern SNOWBALL_ERR slice_from_v(struct SN_env * z, const symbol * p);
97 extern SNOWBALL_ERR slice_del(struct SN_env * z);
98 
99 extern SNOWBALL_ERR insert_s(struct SN_env * z, int bra, int ket, int s_size, const symbol * s);
100 extern SNOWBALL_ERR insert_v(struct SN_env * z, int bra, int ket, const symbol * p);
101 
102 extern SNOWBALL_ERR slice_to(struct SN_env * z, symbol ** p);
103 extern SNOWBALL_ERR assign_to(struct SN_env * z, symbol ** p);
104 
105 extern int len_utf8(const symbol * p);
106 
107 #if defined __cplusplus && !defined SNOWBALL_RUNTIME_THROW_EXCEPTIONS
108 }
109 #endif
110 
111 #endif
unsigned char symbol
Definition: api.h:4
PositionList * p
@ c_ket
Definition: header.h:140
@ c_bra
Definition: header.h:136
int out_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
#define SIZE(p)
int in_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR insert_s(struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
int eq_v_b(struct SN_env *z, const symbol *p)
SNOWBALL_ERR slice_from_s(struct SN_env *z, int s_size, const symbol *s)
int in_grouping(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR slice_to(struct SN_env *z, symbol **p)
SNOWBALL_ERR assign_to(struct SN_env *z, symbol **p)
SNOWBALL_ERR slice_from_v(struct SN_env *z, const symbol *p)
int eq_s(struct SN_env *z, int s_size, const symbol *s)
SNOWBALL_ERR insert_v(struct SN_env *z, int bra, int ket, const symbol *p)
int eq_v(struct SN_env *z, const symbol *p)
SNOWBALL_ERR replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s)
void lose_s(symbol *p)
symbol * create_s(void)
int out_grouping_b(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int in_grouping_b_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int skip_b_utf8(const symbol *p, int c, int limit, int n)
int eq_s_b(struct SN_env *z, int s_size, const symbol *s)
int out_grouping(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
SNOWBALL_ERR slice_del(struct SN_env *z)
int out_grouping_b_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int skip_utf8(const symbol *p, int c, int limit, int n)
int in_grouping_b(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
int find_among_b(struct SN_env *z, const struct among *v, int v_size, int(*)(struct SN_env *))
int len_utf8(const symbol *p)
int find_among(struct SN_env *z, const struct among *v, int v_size, int(*)(struct SN_env *))
#define SNOWBALL_ERR
Definition: api.h:12
int lb
Definition: api.h:14
symbol * p
Definition: api.h:13
int ket
Definition: api.h:14
int c
Definition: api.h:14
int bra
Definition: api.h:14
int l
Definition: api.h:14
Definition: header.h:295
int substring_i
const symbol * s