postgresql/contrib/tsearch2/snowball/api.c

90 lines
1.2 KiB
C
Raw Normal View History

#include <stdlib.h>
2003-07-21 18:27:44 +08:00
#include "header.h"
struct SN_env *
2003-08-04 08:43:34 +08:00
SN_create_env(int S_size, int I_size, int B_size)
{
struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
struct SN_env *z2 = z;
if (!z)
return z;
2003-08-04 08:43:34 +08:00
z->p = create_s();
if (!z->p)
z = NULL;
if (z && S_size)
2003-08-04 08:43:34 +08:00
{
if ((z->S = (symbol * *) calloc(S_size, sizeof(symbol *))))
2003-08-04 08:43:34 +08:00
{
int i;
for (i = 0; i < S_size; i++)
{
if (!(z->S[i] = create_s()))
{
z = NULL;
break;
}
}
z2->S_size = i;
2003-08-04 08:43:34 +08:00
}
else
z = NULL;
2003-08-04 08:43:34 +08:00
}
if (z && I_size)
2003-08-04 08:43:34 +08:00
{
z->I = (int *) calloc(I_size, sizeof(int));
if (z->I)
z->I_size = I_size;
else
z = NULL;
2003-08-04 08:43:34 +08:00
}
if (z && B_size)
2003-08-04 08:43:34 +08:00
{
z->B = (symbol *) calloc(B_size, sizeof(symbol));
if (z->B)
z->B_size = B_size;
else
z = NULL;
2003-08-04 08:43:34 +08:00
}
if (!z)
SN_close_env(z2);
2003-08-04 08:43:34 +08:00
return z;
2003-07-21 18:27:44 +08:00
}
void
2003-08-04 08:43:34 +08:00
SN_close_env(struct SN_env * z)
2003-07-21 18:27:44 +08:00
{
if (z->S && z->S_size)
2003-08-04 08:43:34 +08:00
{
{
int i;
for (i = 0; i < z->S_size; i++)
lose_s(z->S[i]);
}
free(z->S);
}
if (z->I_size)
free(z->I);
if (z->B_size)
free(z->B);
if (z->p)
lose_s(z->p);
free(z);
2003-07-21 18:27:44 +08:00
}
void
2003-08-04 08:43:34 +08:00
SN_set_current(struct SN_env * z, int size, const symbol * s)
2003-07-21 18:27:44 +08:00
{
2003-08-04 08:43:34 +08:00
replace_s(z, 0, z->l, size, s);
z->c = 0;
2003-07-21 18:27:44 +08:00
}