]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorcerer.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / sorcerer / lib / sorcerer.c
1 /*
2 * sorcerer.c -- support code for SORCERER output
3 *
4 * Define your own or compile and link this in.
5 *
6 * Terence Parr
7 * U of MN, AHPCRC
8 * February 1994
9 */
10
11 /***********************************************************************
12 2-Oct-97 The routine ast_dup() appeared to have a bug in it. Instead
13 of providing a deep copy of its argument it made a bushy copy
14 of its argument - by duplicating the nodes pointed to by
15 its right link. This is certainly not deliberate and does
16 not match code in PCCTSAST.cpp (which had its own bug). This
17 has been changed to do a deep copy in the traditional sense.
18 ***********************************************************************/
19
20 #ifdef OLD
21 /* Given a result pointer, return the same one if *t is NULL,
22 * else find the end of the sibling list and return the address
23 * the 'next[write]' field in that last node.
24 */
25 AST **
26 #ifdef __USE_PROTOS
27 _nextresult(STreeParser *_parser, AST **t)
28 #else
29 _nextresult(_parser, t)
30 AST **t;
31 STreeParser *_parser;
32 #endif
33 {
34 AST *p = *t;
35
36 if ( p==NULL ) return t;
37 while ( p->ast_right(_parser->write) != NULL )
38 {
39 p = p->ast_right(_parser->write);
40 }
41 return &(p->ast_right(_parser->write));
42 }
43
44 /*
45 * Copy the read pointers to the write pointers for a node or entire subtree
46 */
47 void
48 #ifdef __USE_PROTOS
49 _copy_wildcard(STreeParser *_parser, AST *t, int root)
50 #else
51 _copy_wildcard(_parser, t, root)
52 STreeParser *_parser;
53 AST *t;
54 int root;
55 #endif
56 {
57 while ( t!=NULL )
58 {
59 if ( !root ) t->ast_right(_parser->write) = t->ast_right(_parser->read);
60 t->ast_down(_parser->write) = t->ast_down(_parser->read);
61 if ( t->ast_down(_parser->read)!=NULL )
62 _copy_wildcard(_parser, t->ast_down(_parser->read), 0);
63 if ( root ) return;
64 else root=0;
65 t = t->ast_right(_parser->read);
66 }
67 }
68 #endif
69
70 void
71 #ifdef __USE_PROTOS
72 _mkroot(SORAST **r, SORAST **s, SORAST **e, SORAST *t)
73 #else
74 _mkroot(r,s,e,t)
75 SORAST **r, **s, **e, *t;
76 #endif
77 {
78 *r = t;
79 }
80
81 void
82 #ifdef __USE_PROTOS
83 _mkchild(SORAST **r, SORAST **s, SORAST **e, SORAST *t)
84 #else
85 _mkchild(r,s,e,t)
86 SORAST **r, **s, **e, *t;
87 #endif
88 {
89 /* if no sibling list, must attach to any existing root */
90 if ( *s==NULL )
91 {
92 *s = *e = t;
93 /* If r is NULL, then there was no root defined--must be sibling list */
94 if ( *r==NULL ) *r = *s;
95 else (*r)->ast_down = t;
96 }
97 else { (*e)->ast_right = t; *e = t; }
98 }
99
100 /* THESE FUNCS HAVE TO GO HERE BECAUSE THEY ARE SENSITIVE TO USER'S SORAST DEF */
101 SORAST *
102 #ifdef __USE_PROTOS
103 ast_alloc(void)
104 #else
105 ast_alloc()
106 #endif
107 {
108 SORAST *t = (SORAST *)calloc(1, sizeof(SORAST));
109 if ( t==NULL ) sorcerer_panic("out of memory");
110 return t;
111 }
112
113 SORAST *
114 #ifdef __USE_PROTOS
115 ast_dup_bushy(SORAST *t)
116 #else
117 ast_dup_bushy(t)
118 SORAST *t;
119 #endif
120 {
121 SORAST *u;
122
123 if ( t == NULL ) return NULL;
124 u = ast_alloc();
125 *u = *t; /* copy contents */
126 u->ast_down = ast_dup_bushy(t->ast_down); /* copy the rest of the tree */
127 u->ast_right = ast_dup_bushy(t->ast_right);
128 return u;
129 }
130
131
132 /* Assume t is a root node of a tree--duplicate that node and what's below */
133
134 SORAST *
135 #ifdef __USE_PROTOS
136 ast_dup(SORAST *t)
137 #else
138 ast_dup(t)
139 SORAST *t;
140 #endif
141 {
142 SORAST *u;
143
144 if ( t == NULL ) return NULL;
145 u = ast_alloc();
146 *u = *t; /* copy contents */
147 u->ast_down = ast_dup_bushy(t->ast_down); /* copy the rest of the tree */
148 u->ast_right = NULL;
149 return u;
150 }
151
152 /* Assume t is a root node of a tree--duplicate that node and what's below */
153 SORAST *
154 #ifdef __USE_PROTOS
155 ast_dup_node(SORAST *t)
156 #else
157 ast_dup_node(t)
158 SORAST *t;
159 #endif
160 {
161 SORAST *u;
162
163 if ( t == NULL ) return NULL;
164 u = ast_alloc();
165 *u = *t; /* copy contents */
166 u->down = NULL;
167 u->right = NULL;
168 return u;
169 }