Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / backend / snowball / libstemmer / api.c
blob530b427a466ce92a87214a9997626c64f7925bf5
1 #include "header.h"
3 extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
5 struct SN_env * z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
6 if (z == NULL) return NULL;
7 z->p = create_s();
8 if (z->p == NULL) goto error;
9 if (S_size)
11 int i;
12 z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
13 if (z->S == NULL) goto error;
15 for (i = 0; i < S_size; i++)
17 z->S[i] = create_s();
18 if (z->S[i] == NULL) goto error;
22 if (I_size)
24 z->I = (int *) calloc(I_size, sizeof(int));
25 if (z->I == NULL) goto error;
28 if (B_size)
30 z->B = (unsigned char *) calloc(B_size, sizeof(unsigned char));
31 if (z->B == NULL) goto error;
34 return z;
35 error:
36 SN_close_env(z, S_size);
37 return NULL;
40 extern void SN_close_env(struct SN_env * z, int S_size)
42 if (z == NULL) return;
43 if (S_size)
45 int i;
46 for (i = 0; i < S_size; i++)
48 lose_s(z->S[i]);
50 free(z->S);
52 free(z->I);
53 free(z->B);
54 if (z->p) lose_s(z->p);
55 free(z);
58 extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
60 int err = replace_s(z, 0, z->l, size, s, NULL);
61 z->c = 0;
62 return err;