Debian Codegraph @

terps/alan2/params.c

raw symbols SCIP
1 /*----------------------------------------------------------------------*\
2
3 params.c
4
5 Various utility functions for handling parameters:
6
7 compact() Compact a list, i.e remove any NULL elements
8 lstlen() Count number of elements
9 inlst() Check if an element is in the list
10 sublst() Subract two lists
11 lstcpy() Copy one list onto another
12 mrglst() Merge the paramElems of one list into the first
13 isect() Take the intersection of two lists
14 cpyrefs() Copy the refs (in dictionary) to a paramList
15
16 \*----------------------------------------------------------------------*/
17
18 #include "types.h"
19
20 #include "params.h"
21
22
23 #ifdef _PROTOTYPES_
24 void compact(ParamElem a[])
25 #else
26 void compact(a)
27 ParamElem a[];
28 #endif
29 {
30 int i, j;
31
32 for (i = 0, j = 0; a[j].code != EOF; j++)
33 if (a[j].code != 0)
34 a[i++] = a[j];
35 a[i].code = EOF;
36 }
37
38
39 #ifdef _PROTOTYPES_
40 int lstlen(ParamElem a[])
41 #else
42 int lstlen(a)
43 ParamElem a[];
44 #endif
45 {
46 int i = 0;
47
48 while (a[i].code != EOF)
49 i++;
50 return (i);
51 }
52
53
54 #ifdef _PROTOTYPES_
55 Boolean inlst(ParamElem l[], Aword e)
56 #else
57 Boolean inlst(l, e)
58 ParamElem l[];
59 Aword e;
60 #endif
61 {
62 int i;
63
64 for (i = 0; l[i].code != EOF && l[i].code != e; i++);
65 return (l[i].code == e);
66 }
67
68
69 #ifdef _PROTOTYPES_
70 void lstcpy(ParamElem a[], ParamElem b[])
71 #else
72 void lstcpy(a, b)
73 ParamElem a[], b[];
74 #endif
75 {
76 int i;
77
78 for (i = 0; b[i].code != EOF; i++)
79 a[i] = b[i];
80 a[i].code = EOF;
81 }
82
83
84 #ifdef _PROTOTYPES_
85 void sublst(ParamElem a[], ParamElem b[])
86 #else
87 void sublst(a, b)
88 ParamElem a[], b[];
89 #endif
90 {
91 int i;
92
93 for (i = 0; a[i].code != EOF; i++)
94 if (inlst(b, a[i].code))
95 a[i].code = 0; /* Mark empty */
96 compact(a);
97 }
98
99
100 #ifdef _PROTOTYPES_
101 void mrglst(ParamElem a[], ParamElem b[])
102 #else
103 void mrglst(a, b)
104 ParamElem a[], b[];
105 #endif
106 {
107 int i,last;
108
109 for (last = 0; a[last].code != EOF; last++); /* Find end of list */
110 for (i = 0; b[i].code != EOF; i++)
111 if (!inlst(a, b[i].code)) {
112 a[last++] = b[i];
113 a[last].code = EOF;
114 }
115 }
116
117
118 #ifdef _PROTOTYPES_
119 void isect(ParamElem a[], ParamElem b[])
120 #else
121 void isect(a, b)
122 ParamElem a[], b[];
123 #endif
124 {
125 int i, last = 0;
126
127 for (i = 0; a[i].code != EOF; i++)
128 if (inlst(b, a[i].code))
129 a[last++] = a[i];
130 a[last].code = EOF;
131 }
132
133
134 #ifdef _PROTOTYPES_
135 void cpyrefs(ParamElem p[], Aword r[])
136 #else
137 void cpyrefs(p, r)
138 ParamElem p[];
139 Aword r[];
140 #endif
141 {
142 int i;
143
144 for (i = 0; r[i] != EOF; i++) {
145 p[i].code = r[i];
146 p[i].firstWord = EOF;
147 }
148 p[i].code = EOF;
149 }
150
151