Initial import into git.
[galago.git] / cpp / galago / contrib / libstemmer_c / runtime / api.c
blob40039ef4a50626da241df10ee64199cd12659316
2 #include <stdlib.h> /* for calloc, free */
3 #include "header.h"
5 extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
7 struct SN_env * z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
8 if (z == NULL) return NULL;
9 z->p = create_s();
10 if (z->p == NULL) goto error;
11 if (S_size)
13 int i;
14 z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
15 if (z->S == NULL) goto error;
17 for (i = 0; i < S_size; i++)
19 z->S[i] = create_s();
20 if (z->S[i] == NULL) goto error;
24 if (I_size)
26 z->I = (int *) calloc(I_size, sizeof(int));
27 if (z->I == NULL) goto error;
30 if (B_size)
32 z->B = (unsigned char *) calloc(B_size, sizeof(unsigned char));
33 if (z->B == NULL) goto error;
36 return z;
37 error:
38 SN_close_env(z, S_size);
39 return NULL;
42 extern void SN_close_env(struct SN_env * z, int S_size)
44 if (z == NULL) return;
45 if (S_size)
47 int i;
48 for (i = 0; i < S_size; i++)
50 lose_s(z->S[i]);
52 free(z->S);
54 free(z->I);
55 free(z->B);
56 if (z->p) lose_s(z->p);
57 free(z);
60 extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
62 int err = replace_s(z, 0, z->l, size, s, NULL);
63 z->c = 0;
64 return err;