2003-07-21 18:27:44 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
#include <stdlib.h> /* for calloc, free */
|
2003-07-21 18:27:44 +08:00
|
|
|
#include "header.h"
|
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
extern struct SN_env *
|
|
|
|
SN_create_env(int S_size, int I_size, int B_size)
|
2003-08-04 08:43:34 +08:00
|
|
|
{
|
2005-10-15 10:49:52 +08:00
|
|
|
struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
|
2003-09-30 02:54:38 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
if (z == NULL)
|
|
|
|
return NULL;
|
|
|
|
z->p = create_s();
|
|
|
|
if (z->p == NULL)
|
|
|
|
goto error;
|
|
|
|
if (S_size)
|
|
|
|
{
|
|
|
|
int i;
|
2003-08-04 08:43:34 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
|
|
|
|
if (z->S == NULL)
|
|
|
|
goto error;
|
2003-09-30 02:54:38 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
for (i = 0; i < S_size; i++)
|
|
|
|
{
|
|
|
|
z->S[i] = create_s();
|
|
|
|
if (z->S[i] == NULL)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
z->S_size = S_size;
|
|
|
|
}
|
2003-08-04 08:43:34 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
if (I_size)
|
|
|
|
{
|
|
|
|
z->I = (int *) calloc(I_size, sizeof(int));
|
|
|
|
if (z->I == NULL)
|
|
|
|
goto error;
|
|
|
|
z->I_size = I_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (B_size)
|
|
|
|
{
|
|
|
|
z->B = (symbol *) calloc(B_size, sizeof(symbol));
|
|
|
|
if (z->B == NULL)
|
|
|
|
goto error;
|
|
|
|
z->B_size = B_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return z;
|
2005-09-15 19:14:18 +08:00
|
|
|
error:
|
2005-10-15 10:49:52 +08:00
|
|
|
SN_close_env(z);
|
|
|
|
return NULL;
|
2003-07-21 18:27:44 +08:00
|
|
|
}
|
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
extern void
|
|
|
|
SN_close_env(struct SN_env * z)
|
2003-07-21 18:27:44 +08:00
|
|
|
{
|
2005-10-15 10:49:52 +08:00
|
|
|
if (z == NULL)
|
|
|
|
return;
|
|
|
|
if (z->S_size)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
extern int
|
|
|
|
SN_set_current(struct SN_env * z, int size, const symbol * s)
|
2003-07-21 18:27:44 +08:00
|
|
|
{
|
2005-10-15 10:49:52 +08:00
|
|
|
int err = replace_s(z, 0, z->l, size, s, NULL);
|
2005-09-15 19:14:18 +08:00
|
|
|
|
2005-10-15 10:49:52 +08:00
|
|
|
z->c = 0;
|
|
|
|
return err;
|
|
|
|
}
|