~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/backend/snowball/libstemmer/api.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "header.h"
 
2
 
 
3
extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
 
4
{
 
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)
 
10
    {
 
11
        int i;
 
12
        z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
 
13
        if (z->S == NULL) goto error;
 
14
 
 
15
        for (i = 0; i < S_size; i++)
 
16
        {
 
17
            z->S[i] = create_s();
 
18
            if (z->S[i] == NULL) goto error;
 
19
        }
 
20
    }
 
21
 
 
22
    if (I_size)
 
23
    {
 
24
        z->I = (int *) calloc(I_size, sizeof(int));
 
25
        if (z->I == NULL) goto error;
 
26
    }
 
27
 
 
28
    if (B_size)
 
29
    {
 
30
        z->B = (unsigned char *) calloc(B_size, sizeof(unsigned char));
 
31
        if (z->B == NULL) goto error;
 
32
    }
 
33
 
 
34
    return z;
 
35
error:
 
36
    SN_close_env(z, S_size);
 
37
    return NULL;
 
38
}
 
39
 
 
40
extern void SN_close_env(struct SN_env * z, int S_size)
 
41
{
 
42
    if (z == NULL) return;
 
43
    if (S_size)
 
44
    {
 
45
        int i;
 
46
        for (i = 0; i < S_size; i++)
 
47
        {
 
48
            lose_s(z->S[i]);
 
49
        }
 
50
        free(z->S);
 
51
    }
 
52
    free(z->I);
 
53
    free(z->B);
 
54
    if (z->p) lose_s(z->p);
 
55
    free(z);
 
56
}
 
57
 
 
58
extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
 
59
{
 
60
    int err = replace_s(z, 0, z->l, size, s, NULL);
 
61
    z->c = 0;
 
62
    return err;
 
63
}
 
64