]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sintstack.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / sorcerer / lib / sintstack.c
CommitLineData
3eb9473e 1/*\r
2 * sint.c\r
3 *\r
4 * SOFTWARE RIGHTS\r
5 *\r
6 * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public\r
7 * domain. An individual or company may do whatever they wish with\r
8 * source code distributed with SORCERER or the code generated by\r
9 * SORCERER, including the incorporation of SORCERER, or its output, into\r
10 * commerical software.\r
11 *\r
12 * We encourage users to develop software with SORCERER. However, we do\r
13 * ask that credit is given to us for developing SORCERER. By "credit",\r
14 * we mean that if you incorporate our source code into one of your\r
15 * programs (commercial product, research project, or otherwise) that you\r
16 * acknowledge this fact somewhere in the documentation, research report,\r
17 * etc... If you like SORCERER and have developed a nice tool with the\r
18 * output, please mention that you developed it using SORCERER. In\r
19 * addition, we ask that this header remain intact in our source code.\r
20 * As long as these guidelines are kept, we expect to continue enhancing\r
21 * this system and expect to make other tools available as they are\r
22 * completed.\r
23 *\r
24 * SORCERER 1.00B\r
25 * Terence Parr\r
26 * AHPCRC, University of Minnesota\r
27 * 1992-1994\r
28 */\r
29#include <stdio.h>\r
30#include <setjmp.h>\r
31\r
32#ifdef PCCTS_USE_STDARG\r
33#include <stdarg.h>\r
34#else\r
35#include <varargs.h>\r
36#endif\r
37\r
38#include "CASTBase.h"\r
39#include "sintstack.h"\r
40\r
41SIntStack *\r
42#ifdef __USE_PROTOS\r
43sint_newstack(int size)\r
44#else\r
45sint_newstack(size)\r
46int size;\r
47#endif\r
48{\r
49 SIntStack *p = (SIntStack *) calloc(1, sizeof(SIntStack));\r
50 require(p!=NULL, "sint_newstack: out of memory");\r
51 p->data = (int *) calloc(size, sizeof(int));\r
52 require(p!=NULL, "sint_newstack: out of memory");\r
53 p->size = size;\r
54 p->sp = size;\r
55 return p;\r
56}\r
57\r
58void\r
59#ifdef __USE_PROTOS\r
60sint_freestack(SIntStack *st)\r
61#else\r
62sint_freestack(st)\r
63SIntStack *st;\r
64#endif\r
65{\r
66 if ( st==NULL ) return;\r
67 if ( st->data==NULL ) return;\r
68 free(st->data);\r
69 free(st);\r
70}\r
71\r
72void\r
73#ifdef __USE_PROTOS\r
74sint_push(SIntStack *st,int i)\r
75#else\r
76sint_push(st,i)\r
77SIntStack *st;\r
78int i;\r
79#endif\r
80{\r
81 require(st->sp>0, "sint_push: stack overflow");\r
82 st->data[--(st->sp)] = i;\r
83}\r
84\r
85int\r
86#ifdef __USE_PROTOS\r
87sint_pop(SIntStack *st)\r
88#else\r
89sint_pop(st)\r
90SIntStack *st;\r
91#endif\r
92{\r
93 require(st->sp<st->size, "sint_pop: stack underflow");\r
94 return st->data[st->sp++];\r
95}\r
96\r
97int\r
98#ifdef __USE_PROTOS\r
99sint_stacksize(SIntStack *st)\r
100#else\r
101sint_stacksize(st)\r
102SIntStack *st;\r
103#endif\r
104{\r
105 return st->size - st->sp;\r
106}\r
107\r
108void\r
109#ifdef __USE_PROTOS\r
110sint_stackreset(SIntStack *st)\r
111#else\r
112sint_stackreset(st)\r
113SIntStack *st;\r
114#endif\r
115{\r
116 st->sp = st->size;\r
117}\r
118\r
119int\r
120#ifdef __USE_PROTOS\r
121sint_stackempty(SIntStack *st)\r
122#else\r
123sint_stackempty(st)\r
124SIntStack *st;\r
125#endif\r
126{\r
127 return st->sp==st->size;\r
128}\r
129\r
130int\r
131#ifdef __USE_PROTOS\r
132sint_top(SIntStack *st)\r
133#else\r
134sint_top(st)\r
135SIntStack *st;\r
136#endif\r
137{\r
138 require(st->sp<st->size, "sint_top: stack underflow");\r
139 return st->data[st->sp];\r
140}\r