YAZ 5.35.1
api.c
Go to the documentation of this file.
1
2#include <stdlib.h> /* for calloc, free */
3#include "header.h"
4
5extern struct SN_env *
6SN_create_env (int S_size, int I_size, int B_size)
7{
8 struct SN_env *z = (struct SN_env *) calloc (1, sizeof (struct SN_env));
9 if (z == NULL)
10 return NULL;
11 z->p = create_s ();
12 if (z->p == NULL)
13 goto error;
14 if (S_size)
15 {
16 int i;
17 z->S = (symbol * *)calloc (S_size, sizeof (symbol *));
18 if (z->S == NULL)
19 goto error;
20
21 for (i = 0; i < S_size; i++)
22 {
23 z->S[i] = create_s ();
24 if (z->S[i] == NULL)
25 goto error;
26 }
27 }
28
29 if (I_size)
30 {
31 z->I = (int *) calloc (I_size, sizeof (int));
32 if (z->I == NULL)
33 goto error;
34 }
35
36 if (B_size)
37 {
38 z->B = (unsigned char *) calloc (B_size, sizeof (unsigned char));
39 if (z->B == NULL)
40 goto error;
41 }
42
43 return z;
44error:
45 SN_close_env (z, S_size);
46 return NULL;
47}
48
49extern void
50SN_close_env (struct SN_env *z, int S_size)
51{
52 if (z == NULL)
53 return;
54 if (S_size)
55 {
56 int i;
57 for (i = 0; i < S_size; i++)
58 {
59 lose_s (z->S[i]);
60 }
61 free (z->S);
62 }
63 free (z->I);
64 free (z->B);
65 if (z->p)
66 lose_s (z->p);
67 free (z);
68}
69
70extern int
71SN_set_current (struct SN_env *z, int size, const symbol *s)
72{
73 int err = replace_s (z, 0, z->l, size, s, NULL);
74 z->c = 0;
75 return err;
76}
struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
Definition api.c:6
int SN_set_current(struct SN_env *z, int size, const symbol *s)
Definition api.c:71
void SN_close_env(struct SN_env *z, int S_size)
Definition api.c:50
unsigned char symbol
Definition api.h:2
void free(void *)
int replace_s(struct SN_env *z, int c_bra, int c_ket, int s_size, const symbol *s, int *adjustment)
Definition utilities.c:507
void lose_s(symbol *p)
Definition utilities.c:26
symbol * create_s(void)
Definition utilities.c:13
Definition api.h:14
unsigned char * B
Definition api.h:19
symbol * p
Definition api.h:15
int * I
Definition api.h:18
int c
Definition api.h:16
int l
Definition api.h:16
symbol ** S
Definition api.h:17