1#include "snowball_runtime.h"
3#ifdef SNOWBALL_RUNTIME_THROW_EXCEPTIONS
6# define SNOWBALL_RETURN_OK return
7# define SNOWBALL_RETURN_OR_THROW(R, E) throw E
8# define SNOWBALL_PROPAGATE_ERR(F) F
10# define SNOWBALL_RETURN_OK return 0
11# define SNOWBALL_RETURN_OR_THROW(R, E) return R
12# define SNOWBALL_PROPAGATE_ERR(F) do { \
13 int snowball_err = F; \
14 if (snowball_err < 0) return snowball_err; \
32 if (p ==
NULL)
return;
47 if (
c >= limit)
return -1;
52 if (
b >= 0xC0 ||
b < 0x80)
break;
72 if (
c <= limit)
return -1;
91 if (
b0 < 0xC0 ||
c == l) {
96 if (
b0 < 0xE0 ||
c == l) {
97 *slot = (
b0 & 0x1F) << 6 |
b1;
101 if (
b0 < 0xF0 ||
c == l) {
102 *slot = (
b0 & 0xF) << 12 |
b1 << 6 |
b2;
105 *slot = (
b0 & 0x7) << 18 |
b1 << 12 |
b2 << 6 | (p[
c] & 0x3F);
111 if (
c <= lb)
return 0;
113 if (
b < 0x80 ||
c == lb) {
119 if (
b >= 0xC0 ||
c == lb) {
120 *slot = (
b & 0x1F) << 6 |
a;
123 a |= (
b & 0x3F) << 6;
125 if (
b >= 0xE0 ||
c == lb) {
126 *slot = (
b & 0xF) << 12 |
a;
129 *slot = (p[--
c] & 0x7) << 18 | (
b & 0x3F) << 12 |
a;
138 if (
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0)
150 if (
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0)
162 if (!(
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0))
174 if (!(
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0))
186 if (z->
c >= z->
l)
return -1;
188 if (
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0)
198 if (z->
c <= z->
lb)
return -1;
200 if (
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0)
210 if (z->
c >= z->
l)
return -1;
212 if (!(
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0))
222 if (z->
c <= z->
lb)
return -1;
224 if (!(
ch > max || (
ch -= min) < 0 || (s[
ch >> 3] & (0X1 << (
ch & 0X7))) == 0))
232 if (z->
l - z->
c < s_size ||
memcmp(z->
p + z->
c, s, s_size *
sizeof(
symbol)) != 0)
return 0;
233 z->
c += s_size;
return 1;
237 if (z->
c - z->
lb < s_size ||
memcmp(z->
p + z->
c - s_size, s, s_size *
sizeof(
symbol)) != 0)
return 0;
238 z->
c -= s_size;
return 1;
255 int c = z->
c;
int l = z->
l;
258 const struct among * w;
266 int k =
i + ((
j -
i) >> 1);
271 int i2;
for (i2 = common; i2 < w->
s_size; i2++) {
272 if (
c + common == l) {
diff = -1;
break; }
273 diff = q[common] - w->
s[i2];
274 if (
diff != 0)
break;
321 int c = z->
c;
int lb = z->
lb;
324 const struct among * w;
332 int k =
i + ((
j -
i) >> 1);
337 int i2;
for (i2 = w->
s_size - 1 - common; i2 >= 0; i2--) {
338 if (
c - common == lb) {
diff = -1;
break; }
339 diff = q[- common] - w->
s[i2];
340 if (
diff != 0)
break;
411# define REPLACE_S(Z, B, K, SIZE, S) \
412 SNOWBALL_PROPAGATE_ERR(replace_s(Z, B, K, SIZE, S))
430# define SLICE_CHECK(Z) SNOWBALL_PROPAGATE_ERR(slice_check(Z))
456 else if (z->
c > z->
bra)
506 if (
b >= 0xC0 ||
b < 0x80) ++
len;
#define fprintf(file, fmt, msg)
static void repeat(struct vars *v, struct state *lp, struct state *rp, int m, int n)
#define REPLACE_S(Z, B, K, SIZE, S)
#define SNOWBALL_RETURN_OR_THROW(R, E)
int out_grouping_U(struct SN_env *z, const unsigned char *s, int min, int max, int repeat)
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)
#define SNOWBALL_PROPAGATE_ERR(F)
static SNOWBALL_ERR slice_check(struct SN_env *z)
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)
static int get_utf8(const symbol *p, int c, int l, int *slot)
int out_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(*call_among_func)(struct SN_env *))
#define SNOWBALL_RETURN_OK
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 len_utf8(const symbol *p)
static int get_b_utf8(const symbol *p, int c, int lb, int *slot)
static int increase_size(symbol **p, int n)
int find_among(struct SN_env *z, const struct among *v, int v_size, int(*call_among_func)(struct SN_env *))