tracker-0.16.2/src/libstemmer/api.c

No issues found

 1 /*
 2  * Copyright (c) 2001, Dr Martin Porter
 3  * All rights reserved.
 4  *
 5  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 6  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 7  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 8  * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 9  *
10  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11  */
12 
13 
14 
15 #include <stdlib.h> /* for calloc, free */
16 #include "header.h"
17 
18 extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
19 {
20     struct SN_env * z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
21     if (z == NULL) return NULL;
22     z->p = create_s();
23     if (z->p == NULL) goto error;
24     if (S_size)
25     {
26 	int i;
27 	z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
28 	if (z->S == NULL) goto error;
29 
30 	for (i = 0; i < S_size; i++)
31 	{
32 	    z->S[i] = create_s();
33 	    if (z->S[i] == NULL) goto error;
34 	}
35 	z->S_size = S_size;
36     }
37 
38     if (I_size)
39     {
40 	z->I = (int *) calloc(I_size, sizeof(int));
41 	if (z->I == NULL) goto error;
42 	z->I_size = I_size;
43     }
44 
45     if (B_size)
46     {
47 	z->B = (symbol *) calloc(B_size, sizeof(symbol));
48 	if (z->B == NULL) goto error;
49 	z->B_size = B_size;
50     }
51 
52     return z;
53 error:
54     SN_close_env(z);
55     return NULL;
56 }
57 
58 extern void SN_close_env(struct SN_env * z)
59 {
60     if (z == NULL) return;
61     if (z->S_size)
62     {
63 	int i;
64 	for (i = 0; i < z->S_size; i++)
65 	{
66 	    lose_s(z->S[i]);
67 	}
68 	free(z->S);
69     }
70     if (z->I_size) free(z->I);
71     if (z->B_size) free(z->B);
72     if (z->p) lose_s(z->p);
73     free(z);
74 }
75 
76 extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
77 {
78     int err = replace_s(z, 0, z->l, size, s, NULL);
79     z->c = 0;
80     return err;
81 }