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