Header And Logo

PostgreSQL
| The world's most advanced open source database.

api.c

Go to the documentation of this file.
00001 #include "header.h"
00002 
00003 extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
00004 {
00005     struct SN_env * z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
00006     if (z == NULL) return NULL;
00007     z->p = create_s();
00008     if (z->p == NULL) goto error;
00009     if (S_size)
00010     {
00011         int i;
00012         z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
00013         if (z->S == NULL) goto error;
00014 
00015         for (i = 0; i < S_size; i++)
00016         {
00017             z->S[i] = create_s();
00018             if (z->S[i] == NULL) goto error;
00019         }
00020     }
00021 
00022     if (I_size)
00023     {
00024         z->I = (int *) calloc(I_size, sizeof(int));
00025         if (z->I == NULL) goto error;
00026     }
00027 
00028     if (B_size)
00029     {
00030         z->B = (unsigned char *) calloc(B_size, sizeof(unsigned char));
00031         if (z->B == NULL) goto error;
00032     }
00033 
00034     return z;
00035 error:
00036     SN_close_env(z, S_size);
00037     return NULL;
00038 }
00039 
00040 extern void SN_close_env(struct SN_env * z, int S_size)
00041 {
00042     if (z == NULL) return;
00043     if (S_size)
00044     {
00045         int i;
00046         for (i = 0; i < S_size; i++)
00047         {
00048             lose_s(z->S[i]);
00049         }
00050         free(z->S);
00051     }
00052     free(z->I);
00053     free(z->B);
00054     if (z->p) lose_s(z->p);
00055     free(z);
00056 }
00057 
00058 extern int SN_set_current(struct SN_env * z, int size, const symbol * s)
00059 {
00060     int err = replace_s(z, 0, z->l, size, s, NULL);
00061     z->c = 0;
00062     return err;
00063 }
00064