PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
utilities.c File Reference
#include "header.h"
Include dependency graph for utilities.c:

Go to the source code of this file.

Macros

#define unless(C)   if(!(C))
 
#define CREATE_SIZE   1
 

Functions

symbolcreate_s (void)
 
void lose_s (symbol *p)
 
int skip_utf8 (const symbol *p, int c, int lb, int l, int n)
 
static int get_utf8 (const symbol *p, int c, int l, int *slot)
 
static int get_b_utf8 (const symbol *p, int c, int lb, int *slot)
 
int in_grouping_U (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 out_grouping_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping_b_U (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int in_grouping (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int in_grouping_b (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int out_grouping_b (struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
 
int eq_s (struct SN_env *z, int s_size, const symbol *s)
 
int eq_s_b (struct SN_env *z, int s_size, const symbol *s)
 
int eq_v (struct SN_env *z, const symbol *p)
 
int eq_v_b (struct SN_env *z, const symbol *p)
 
int find_among (struct SN_env *z, const struct among *v, int v_size)
 
int find_among_b (struct SN_env *z, const struct among *v, int v_size)
 
static symbolincrease_size (symbol *p, int n)
 
int replace_s (struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjptr)
 
static int slice_check (struct SN_env *z)
 
int slice_from_s (struct SN_env *z, int s_size, const symbol *s)
 
int slice_from_v (struct SN_env *z, const symbol *p)
 
int slice_del (struct SN_env *z)
 
int insert_s (struct SN_env *z, int bra, int ket, int s_size, const symbol *s)
 
int insert_v (struct SN_env *z, int bra, int ket, const symbol *p)
 
symbolslice_to (struct SN_env *z, symbol *p)
 
symbolassign_to (struct SN_env *z, symbol *p)
 

Macro Definition Documentation

#define CREATE_SIZE   1

Definition at line 5 of file utilities.c.

Referenced by create_s().

#define unless (   C)    if(!(C))

Function Documentation

symbol* assign_to ( struct SN_env z,
symbol p 
)

Definition at line 441 of file utilities.c.

References CAPACITY, increase_size(), SN_env::l, memmove, NULL, SN_env::p, and SET_SIZE.

441  {
442  int len = z->l;
443  if (CAPACITY(p) < len) {
444  p = increase_size(p, len);
445  if (p == NULL)
446  return NULL;
447  }
448  memmove(p, z->p, len * sizeof(symbol));
449  SET_SIZE(p, len);
450  return p;
451 }
symbol * p
Definition: api.h:15
#define CAPACITY(p)
Definition: header.h:13
#define memmove(d, s, c)
Definition: c.h:1059
#define NULL
Definition: c.h:229
static symbol * increase_size(symbol *p, int n)
Definition: utilities.c:324
#define SET_SIZE(p, n)
Definition: header.h:12
int l
Definition: api.h:16
unsigned char symbol
Definition: api.h:2
symbol* create_s ( void  )

Definition at line 7 of file utilities.c.

References CAPACITY, CREATE_SIZE, HEAD, malloc, NULL, SN_env::p, and SET_SIZE.

Referenced by replace_s(), and SN_create_env().

7  {
8  symbol * p;
9  void * mem = malloc(HEAD + (CREATE_SIZE + 1) * sizeof(symbol));
10  if (mem == NULL) return NULL;
11  p = (symbol *) (HEAD + (char *) mem);
12  CAPACITY(p) = CREATE_SIZE;
14  return p;
15 }
#define HEAD
Definition: header.h:9
symbol * p
Definition: api.h:15
#define CAPACITY(p)
Definition: header.h:13
#define malloc(a)
Definition: header.h:50
#define CREATE_SIZE
Definition: utilities.c:5
#define NULL
Definition: c.h:229
#define SET_SIZE(p, n)
Definition: header.h:12
unsigned char symbol
Definition: api.h:2
int eq_s ( struct SN_env z,
int  s_size,
const symbol s 
)

Definition at line 189 of file utilities.c.

References SN_env::c, SN_env::l, and SN_env::p.

Referenced by eq_v(), porter_ISO_8859_1_stem(), porter_UTF_8_stem(), r_is_reserved_word(), r_postlude(), and r_prelude().

189  {
190  if (z->l - z->c < s_size || memcmp(z->p + z->c, s, s_size * sizeof(symbol)) != 0) return 0;
191  z->c += s_size; return 1;
192 }
symbol * p
Definition: api.h:15
int c
Definition: api.h:16
int l
Definition: api.h:16
unsigned char symbol
Definition: api.h:2
int eq_v ( struct SN_env z,
const symbol p 
)

Definition at line 199 of file utilities.c.

References eq_s(), and SIZE.

199  {
200  return eq_s(z, SIZE(p), p);
201 }
symbol * p
Definition: api.h:15
int eq_s(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:189
#define SIZE(p)
Definition: header.h:11
int eq_v_b ( struct SN_env z,
const symbol p 
)

Definition at line 203 of file utilities.c.

References eq_s_b(), and SIZE.

Referenced by r_tidy(), and r_undouble().

203  {
204  return eq_s_b(z, SIZE(p), p);
205 }
symbol * p
Definition: api.h:15
int eq_s_b(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:194
#define SIZE(p)
Definition: header.h:11
int find_among ( struct SN_env z,
const struct among v,
int  v_size 
)

Definition at line 207 of file utilities.c.

References SN_env::c, among::function, i, SN_env::l, SN_env::p, among::result, among::s, among::s_size, and among::substring_i.

Referenced by r_exception1(), r_mark_regions(), r_postlude(), and r_prelude().

207  {
208 
209  int i = 0;
210  int j = v_size;
211 
212  int c = z->c; int l = z->l;
213  symbol * q = z->p + c;
214 
215  const struct among * w;
216 
217  int common_i = 0;
218  int common_j = 0;
219 
220  int first_key_inspected = 0;
221 
222  while(1) {
223  int k = i + ((j - i) >> 1);
224  int diff = 0;
225  int common = common_i < common_j ? common_i : common_j; /* smaller */
226  w = v + k;
227  {
228  int i2; for (i2 = common; i2 < w->s_size; i2++) {
229  if (c + common == l) { diff = -1; break; }
230  diff = q[common] - w->s[i2];
231  if (diff != 0) break;
232  common++;
233  }
234  }
235  if (diff < 0) { j = k; common_j = common; }
236  else { i = k; common_i = common; }
237  if (j - i <= 1) {
238  if (i > 0) break; /* v->s has been inspected */
239  if (j == i) break; /* only one item in v */
240 
241  /* - but now we need to go round once more to get
242  v->s inspected. This looks messy, but is actually
243  the optimal approach. */
244 
245  if (first_key_inspected) break;
246  first_key_inspected = 1;
247  }
248  }
249  while(1) {
250  w = v + i;
251  if (common_i >= w->s_size) {
252  z->c = c + w->s_size;
253  if (w->function == 0) return w->result;
254  {
255  int res = w->function(z);
256  z->c = c + w->s_size;
257  if (res) return w->result;
258  }
259  }
260  i = w->substring_i;
261  if (i < 0) return 0;
262  }
263 }
int s_size
Definition: header.h:16
symbol * p
Definition: api.h:15
int substring_i
Definition: header.h:18
int c
Definition: api.h:16
char * c
int(* function)(struct SN_env *)
Definition: header.h:20
Definition: header.h:15
int result
Definition: header.h:19
const symbol * s
Definition: header.h:17
int i
int l
Definition: api.h:16
unsigned char symbol
Definition: api.h:2
int find_among_b ( struct SN_env z,
const struct among v,
int  v_size 
)

Definition at line 267 of file utilities.c.

References SN_env::c, among::function, i, SN_env::lb, SN_env::p, among::result, among::s, among::s_size, and among::substring_i.

Referenced by r_adjectival(), r_adjective(), r_attached_pronoun(), r_case(), r_case_ending(), r_case_other(), r_case_special(), r_combo_suffix(), r_consonant_pair(), r_derivational(), r_double(), r_exception2(), r_factive(), r_i_plural(), r_i_verb_suffix(), r_instrum(), r_LONG(), r_main_suffix(), r_mark_cAsInA(), r_mark_DA(), r_mark_DAn(), r_mark_DUr(), r_mark_lAr(), r_mark_lArI(), r_mark_nA(), r_mark_ncA(), r_mark_ndA(), r_mark_ndAn(), r_mark_nU(), r_mark_nUn(), r_mark_nUz(), r_mark_possessives(), r_mark_sUn(), r_mark_sUnUz(), r_mark_yA(), r_mark_yDU(), r_mark_ylA(), r_mark_ymUs_(), r_mark_ysA(), r_mark_yUm(), r_mark_yUz(), r_noun(), r_other_endings(), r_other_suffix(), r_owned(), r_particle_etc(), r_perfective_gerund(), r_plur_owner(), r_plural(), r_possessive(), r_post_process_last_consonants(), r_reflexive(), r_residual_form(), r_residual_suffix(), r_sing_owner(), r_standard_suffix(), r_step_0(), r_Step_1a(), r_Step_1b(), r_Step_2(), r_Step_3(), r_Step_4(), r_Step_5(), r_t_plural(), r_tidy_up(), r_un_double(), r_undouble(), r_v_ending(), r_verb(), r_verb_suffix(), r_vowel_suffix(), and r_y_verb_suffix().

267  {
268 
269  int i = 0;
270  int j = v_size;
271 
272  int c = z->c; int lb = z->lb;
273  symbol * q = z->p + c - 1;
274 
275  const struct among * w;
276 
277  int common_i = 0;
278  int common_j = 0;
279 
280  int first_key_inspected = 0;
281 
282  while(1) {
283  int k = i + ((j - i) >> 1);
284  int diff = 0;
285  int common = common_i < common_j ? common_i : common_j;
286  w = v + k;
287  {
288  int i2; for (i2 = w->s_size - 1 - common; i2 >= 0; i2--) {
289  if (c - common == lb) { diff = -1; break; }
290  diff = q[- common] - w->s[i2];
291  if (diff != 0) break;
292  common++;
293  }
294  }
295  if (diff < 0) { j = k; common_j = common; }
296  else { i = k; common_i = common; }
297  if (j - i <= 1) {
298  if (i > 0) break;
299  if (j == i) break;
300  if (first_key_inspected) break;
301  first_key_inspected = 1;
302  }
303  }
304  while(1) {
305  w = v + i;
306  if (common_i >= w->s_size) {
307  z->c = c - w->s_size;
308  if (w->function == 0) return w->result;
309  {
310  int res = w->function(z);
311  z->c = c - w->s_size;
312  if (res) return w->result;
313  }
314  }
315  i = w->substring_i;
316  if (i < 0) return 0;
317  }
318 }
int s_size
Definition: header.h:16
symbol * p
Definition: api.h:15
int substring_i
Definition: header.h:18
int c
Definition: api.h:16
int lb
Definition: api.h:16
char * c
int(* function)(struct SN_env *)
Definition: header.h:20
Definition: header.h:15
int result
Definition: header.h:19
const symbol * s
Definition: header.h:17
int i
unsigned char symbol
Definition: api.h:2
static int get_b_utf8 ( const symbol p,
int  c,
int  lb,
int *  slot 
)
static

Definition at line 77 of file utilities.c.

Referenced by in_grouping_b_U(), and out_grouping_b_U().

77  {
78  int b0, b1;
79  if (c <= lb) return 0;
80  b0 = p[--c];
81  if (b0 < 0x80 || c == lb) { /* 1000 0000 */
82  * slot = b0; return 1;
83  }
84  b1 = p[--c];
85  if (b1 >= 0xC0 || c == lb) { /* 1100 0000 */
86  * slot = (b1 & 0x1F) << 6 | (b0 & 0x3F); return 2;
87  }
88  * slot = (p[c] & 0xF) << 12 | (b1 & 0x3F) << 6 | (b0 & 0x3F); return 3;
89 }
char * c
static int get_utf8 ( const symbol p,
int  c,
int  l,
int *  slot 
)
static

Definition at line 63 of file utilities.c.

Referenced by in_grouping_U(), and out_grouping_U().

63  {
64  int b0, b1;
65  if (c >= l) return 0;
66  b0 = p[c++];
67  if (b0 < 0xC0 || c == l) { /* 1100 0000 */
68  * slot = b0; return 1;
69  }
70  b1 = p[c++];
71  if (b0 < 0xE0 || c == l) { /* 1110 0000 */
72  * slot = (b0 & 0x1F) << 6 | (b1 & 0x3F); return 2;
73  }
74  * slot = (b0 & 0xF) << 12 | (b1 & 0x3F) << 6 | (p[c] & 0x3F); return 3;
75 }
char * c
int in_grouping ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 141 of file utilities.c.

References SN_env::c, SN_env::l, and SN_env::p.

Referenced by porter_ISO_8859_1_stem(), r_mark_regions(), and r_prelude().

141  {
142  do {
143  int ch;
144  if (z->c >= z->l) return -1;
145  ch = z->p[z->c];
146  if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
147  return 1;
148  z->c++;
149  } while (repeat);
150  return 0;
151 }
symbol * p
Definition: api.h:15
int c
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
const symbol * s
Definition: header.h:17
int l
Definition: api.h:16
int in_grouping_b ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 153 of file utilities.c.

References SN_env::c, SN_env::lb, and SN_env::p.

Referenced by r_case_ending(), r_main_suffix(), r_particle_etc(), r_shortv(), r_standard_suffix(), r_Step_2(), r_t_plural(), r_tidy(), r_VI(), and r_vowel_suffix().

153  {
154  do {
155  int ch;
156  if (z->c <= z->lb) return -1;
157  ch = z->p[z->c - 1];
158  if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
159  return 1;
160  z->c--;
161  } while (repeat);
162  return 0;
163 }
symbol * p
Definition: api.h:15
int c
Definition: api.h:16
int lb
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
const symbol * s
Definition: header.h:17
int in_grouping_b_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 103 of file utilities.c.

References SN_env::c, get_b_utf8(), SN_env::lb, SN_env::p, and unless.

Referenced by r_case_ending(), r_main_suffix(), r_mark_sU(), r_mark_suffix_with_optional_n_consonant(), r_mark_suffix_with_optional_s_consonant(), r_mark_suffix_with_optional_U_vowel(), r_mark_suffix_with_optional_y_consonant(), r_mark_yU(), r_particle_etc(), r_shortv(), r_standard_suffix(), r_Step_2(), r_t_plural(), r_tidy(), r_VI(), and r_vowel_suffix().

103  {
104  do {
105  int ch;
106  int w = get_b_utf8(z->p, z->c, z->lb, & ch);
107  unless (w) return -1;
108  if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
109  return w;
110  z->c -= w;
111  } while (repeat);
112  return 0;
113 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
int lb
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
static int get_b_utf8(const symbol *p, int c, int lb, int *slot)
Definition: utilities.c:77
int in_grouping_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 91 of file utilities.c.

References SN_env::c, get_utf8(), SN_env::l, SN_env::p, and unless.

Referenced by porter_UTF_8_stem(), r_mark_regions(), and r_prelude().

91  {
92  do {
93  int ch;
94  int w = get_utf8(z->p, z->c, z->l, & ch);
95  unless (w) return -1;
96  if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
97  return w;
98  z->c += w;
99  } while (repeat);
100  return 0;
101 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
static int get_utf8(const symbol *p, int c, int l, int *slot)
Definition: utilities.c:63
int l
Definition: api.h:16
static symbol* increase_size ( symbol p,
int  n 
)
static

Definition at line 324 of file utilities.c.

References CAPACITY, HEAD, lose_s(), NULL, and realloc.

Referenced by assign_to(), replace_s(), and slice_to().

324  {
325  symbol * q;
326  int new_size = n + 20;
327  void * mem = realloc((char *) p - HEAD,
328  HEAD + (new_size + 1) * sizeof(symbol));
329  if (mem == NULL) {
330  lose_s(p);
331  return NULL;
332  }
333  q = (symbol *) (HEAD + (char *)mem);
334  CAPACITY(q) = new_size;
335  return q;
336 }
#define HEAD
Definition: header.h:9
void lose_s(symbol *p)
Definition: utilities.c:17
#define CAPACITY(p)
Definition: header.h:13
#define NULL
Definition: c.h:229
#define realloc(a, b)
Definition: header.h:60
unsigned char symbol
Definition: api.h:2
int insert_s ( struct SN_env z,
int  bra,
int  ket,
int  s_size,
const symbol s 
)

Definition at line 405 of file utilities.c.

References SN_env::bra, SN_env::ket, and replace_s().

Referenced by r_append_U_to_stems_ending_with_d_or_g(), and r_Step_1b().

405  {
406  int adjustment;
407  if (replace_s(z, bra, ket, s_size, s, &adjustment))
408  return -1;
409  if (bra <= z->bra) z->bra += adjustment;
410  if (bra <= z->ket) z->ket += adjustment;
411  return 0;
412 }
int s_size
Definition: header.h:16
int ket
Definition: api.h:16
int bra
Definition: api.h:16
int replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjptr)
Definition: utilities.c:343
const symbol * s
Definition: header.h:17
int insert_v ( struct SN_env z,
int  bra,
int  ket,
const symbol p 
)

Definition at line 414 of file utilities.c.

References SN_env::bra, SN_env::ket, replace_s(), and SIZE.

414  {
415  int adjustment;
416  if (replace_s(z, bra, ket, SIZE(p), p, &adjustment))
417  return -1;
418  if (bra <= z->bra) z->bra += adjustment;
419  if (bra <= z->ket) z->ket += adjustment;
420  return 0;
421 }
int ket
Definition: api.h:16
int bra
Definition: api.h:16
#define SIZE(p)
Definition: header.h:11
int replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjptr)
Definition: utilities.c:343
void lose_s ( symbol p)

Definition at line 17 of file utilities.c.

References free, HEAD, and NULL.

Referenced by increase_size(), slice_to(), and SN_close_env().

17  {
18  if (p == NULL) return;
19  free((char *) p - HEAD);
20 }
#define HEAD
Definition: header.h:9
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
int out_grouping ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 165 of file utilities.c.

References SN_env::c, SN_env::l, SN_env::p, and unless.

Referenced by porter_ISO_8859_1_stem(), and r_mark_regions().

165  {
166  do {
167  int ch;
168  if (z->c >= z->l) return -1;
169  ch = z->p[z->c];
170  unless (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
171  return 1;
172  z->c++;
173  } while (repeat);
174  return 0;
175 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
int l
Definition: api.h:16
int out_grouping_b ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 177 of file utilities.c.

References SN_env::c, SN_env::lb, SN_env::p, and unless.

Referenced by r_case_ending(), r_e_ending(), r_en_ending(), r_i_verb_suffix(), r_main_suffix(), r_residual_suffix(), r_shortv(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_tidy(), r_un_accent(), r_undouble(), and r_verb_suffix().

177  {
178  do {
179  int ch;
180  if (z->c <= z->lb) return -1;
181  ch = z->p[z->c - 1];
182  unless (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
183  return 1;
184  z->c--;
185  } while (repeat);
186  return 0;
187 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
int lb
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
int out_grouping_b_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 127 of file utilities.c.

References SN_env::c, get_b_utf8(), SN_env::lb, SN_env::p, and unless.

Referenced by r_append_U_to_stems_ending_with_d_or_g(), r_case_ending(), r_check_vowel_harmony(), r_e_ending(), r_en_ending(), r_i_verb_suffix(), r_main_suffix(), r_mark_suffix_with_optional_U_vowel(), r_residual_suffix(), r_shortv(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_tidy(), r_un_accent(), r_undouble(), and r_verb_suffix().

127  {
128  do {
129  int ch;
130  int w = get_b_utf8(z->p, z->c, z->lb, & ch);
131  unless (w) return -1;
132  unless (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
133  return w;
134  z->c -= w;
135  } while (repeat);
136  return 0;
137 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
int lb
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
static int get_b_utf8(const symbol *p, int c, int lb, int *slot)
Definition: utilities.c:77
int out_grouping_U ( struct SN_env z,
const unsigned char *  s,
int  min,
int  max,
int  repeat 
)

Definition at line 115 of file utilities.c.

References SN_env::c, get_utf8(), SN_env::l, SN_env::p, and unless.

Referenced by porter_UTF_8_stem(), r_mark_regions(), and r_more_than_one_syllable_word().

115  {
116  do {
117  int ch;
118  int w = get_utf8(z->p, z->c, z->l, & ch);
119  unless (w) return -1;
120  unless (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
121  return w;
122  z->c += w;
123  } while (repeat);
124  return 0;
125 }
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
int c
Definition: api.h:16
Datum repeat(PG_FUNCTION_ARGS)
char * c
const symbol * s
Definition: header.h:17
static int get_utf8(const symbol *p, int c, int l, int *slot)
Definition: utilities.c:63
int l
Definition: api.h:16
int replace_s ( struct SN_env z,
int  c_bra,
int  c_ket,
int  s_size,
const symbol s,
int *  adjptr 
)

Definition at line 343 of file utilities.c.

References SN_env::c, CAPACITY, create_s(), increase_size(), SN_env::l, memmove, NULL, SN_env::p, SET_SIZE, SIZE, and unless.

Referenced by insert_s(), insert_v(), slice_from_s(), and SN_set_current().

344 {
345  int adjustment;
346  int len;
347  if (z->p == NULL) {
348  z->p = create_s();
349  if (z->p == NULL) return -1;
350  }
351  adjustment = s_size - (c_ket - c_bra);
352  len = SIZE(z->p);
353  if (adjustment != 0) {
354  if (adjustment + len > CAPACITY(z->p)) {
355  z->p = increase_size(z->p, adjustment + len);
356  if (z->p == NULL) return -1;
357  }
358  memmove(z->p + c_ket + adjustment,
359  z->p + c_ket,
360  (len - c_ket) * sizeof(symbol));
361  SET_SIZE(z->p, adjustment + len);
362  z->l += adjustment;
363  if (z->c >= c_ket)
364  z->c += adjustment;
365  else
366  if (z->c > c_bra)
367  z->c = c_bra;
368  }
369  unless (s_size == 0) memmove(z->p + c_bra, s, s_size * sizeof(symbol));
370  if (adjptr != NULL)
371  *adjptr = adjustment;
372  return 0;
373 }
int s_size
Definition: header.h:16
symbol * p
Definition: api.h:15
#define unless(C)
Definition: utilities.c:3
#define CAPACITY(p)
Definition: header.h:13
int c
Definition: api.h:16
#define memmove(d, s, c)
Definition: c.h:1059
#define SIZE(p)
Definition: header.h:11
const symbol * s
Definition: header.h:17
#define NULL
Definition: c.h:229
static symbol * increase_size(symbol *p, int n)
Definition: utilities.c:324
#define SET_SIZE(p, n)
Definition: header.h:12
int l
Definition: api.h:16
symbol * create_s(void)
Definition: utilities.c:7
unsigned char symbol
Definition: api.h:2
int skip_utf8 ( const symbol p,
int  c,
int  lb,
int  l,
int  n 
)

Definition at line 30 of file utilities.c.

Referenced by english_UTF_8_stem(), porter_UTF_8_stem(), r_case_ending(), r_consonant_pair(), r_is_reserved_word(), r_mark_regions(), r_mark_suffix_with_optional_n_consonant(), r_mark_suffix_with_optional_s_consonant(), r_mark_suffix_with_optional_U_vowel(), r_mark_suffix_with_optional_y_consonant(), r_postlude(), r_prelude(), r_standard_suffix(), r_Step_1a(), r_Step_1b(), r_tidy(), r_un_double(), and r_undouble().

30  {
31  int b;
32  if (n >= 0) {
33  for (; n > 0; n--) {
34  if (c >= l) return -1;
35  b = p[c++];
36  if (b >= 0xC0) { /* 1100 0000 */
37  while (c < l) {
38  b = p[c];
39  if (b >= 0xC0 || b < 0x80) break;
40  /* break unless b is 10------ */
41  c++;
42  }
43  }
44  }
45  } else {
46  for (; n < 0; n++) {
47  if (c <= lb) return -1;
48  b = p[--c];
49  if (b >= 0x80) { /* 1000 0000 */
50  while (c > lb) {
51  b = p[c];
52  if (b >= 0xC0) break; /* 1100 0000 */
53  c--;
54  }
55  }
56  }
57  }
58  return c;
59 }
char * c
static int slice_check ( struct SN_env z)
static

Definition at line 375 of file utilities.c.

References SN_env::bra, debug, SN_env::ket, SN_env::l, NULL, SN_env::p, and SIZE.

Referenced by slice_from_s(), and slice_to().

375  {
376 
377  if (z->bra < 0 ||
378  z->bra > z->ket ||
379  z->ket > z->l ||
380  z->p == NULL ||
381  z->l > SIZE(z->p)) /* this line could be removed */
382  {
383 #if 0
384  fprintf(stderr, "faulty slice operation:\n");
385  debug(z, -1, 0);
386 #endif
387  return -1;
388  }
389  return 0;
390 }
symbol * p
Definition: api.h:15
int ket
Definition: api.h:16
int bra
Definition: api.h:16
bool debug
Definition: pg_standby.c:46
#define SIZE(p)
Definition: header.h:11
#define NULL
Definition: c.h:229
int l
Definition: api.h:16
int slice_from_s ( struct SN_env z,
int  s_size,
const symbol s 
)

Definition at line 392 of file utilities.c.

References SN_env::bra, SN_env::ket, NULL, replace_s(), and slice_check().

Referenced by french_ISO_8859_1_stem(), french_UTF_8_stem(), porter_ISO_8859_1_stem(), porter_UTF_8_stem(), r_attached_pronoun(), r_case_other(), r_case_special(), r_combo_suffix(), r_exception1(), r_main_suffix(), r_other_suffix(), r_owned(), r_plur_owner(), r_plural(), r_possessive(), r_post_process_last_consonants(), r_postlude(), r_prelude(), r_residual_form(), r_residual_suffix(), r_sing_owner(), r_standard_suffix(), r_step_0(), r_Step_1a(), r_Step_1b(), r_Step_1c(), r_Step_2(), r_Step_3(), r_un_accent(), r_v_ending(), slice_del(), and slice_from_v().

392  {
393  if (slice_check(z)) return -1;
394  return replace_s(z, z->bra, z->ket, s_size, s, NULL);
395 }
int s_size
Definition: header.h:16
int ket
Definition: api.h:16
int bra
Definition: api.h:16
int replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjptr)
Definition: utilities.c:343
const symbol * s
Definition: header.h:17
#define NULL
Definition: c.h:229
static int slice_check(struct SN_env *z)
Definition: utilities.c:375
int slice_from_v ( struct SN_env z,
const symbol p 
)

Definition at line 397 of file utilities.c.

References SIZE, and slice_from_s().

397  {
398  return slice_from_s(z, SIZE(p), p);
399 }
int slice_from_s(struct SN_env *z, int s_size, const symbol *s)
Definition: utilities.c:392
#define SIZE(p)
Definition: header.h:11
symbol* slice_to ( struct SN_env z,
symbol p 
)

Definition at line 423 of file utilities.c.

References SN_env::bra, CAPACITY, increase_size(), SN_env::ket, lose_s(), memmove, NULL, SN_env::p, SET_SIZE, and slice_check().

Referenced by r_tidy(), and r_undouble().

423  {
424  if (slice_check(z)) {
425  lose_s(p);
426  return NULL;
427  }
428  {
429  int len = z->ket - z->bra;
430  if (CAPACITY(p) < len) {
431  p = increase_size(p, len);
432  if (p == NULL)
433  return NULL;
434  }
435  memmove(p, z->p + z->bra, len * sizeof(symbol));
436  SET_SIZE(p, len);
437  }
438  return p;
439 }
void lose_s(symbol *p)
Definition: utilities.c:17
symbol * p
Definition: api.h:15
int ket
Definition: api.h:16
int bra
Definition: api.h:16
#define CAPACITY(p)
Definition: header.h:13
#define memmove(d, s, c)
Definition: c.h:1059
#define NULL
Definition: c.h:229
static symbol * increase_size(symbol *p, int n)
Definition: utilities.c:324
#define SET_SIZE(p, n)
Definition: header.h:12
static int slice_check(struct SN_env *z)
Definition: utilities.c:375
unsigned char symbol
Definition: api.h:2