1: # include "../ingres.h"
2: # include "../aux.h"
3: # include "../tree.h"
4: # include "parser.h"
5: # include "../catalog.h"
6: # include "../symbol.h"
7:
8: /*
9: ** P_UTIL -- parser utility functions
10: **
11: ** These functions are generally unrelated except that they are
12: ** needed to operate the parser and are too small to be considered
13: ** seperate modules.
14: **
15: ** Defined Constants:
16: **
17: ** Defines:
18: ** timeofday -- convert arguments to minutes since midnight
19: ** tlprepend -- attach two target list components
20: ** header -- prints the header for a retrieve to terminal
21: ** patmat -- converts pattern matching characters in a string
22: ** permcom -- adds a command to the permit command vector
23: **
24: ** Requires:
25: ** nothing
26: **
27: ** Required By:
28: ** y.tab.c -- the grammar
29: **
30: ** Files:
31: ** none
32: **
33: ** Compilation Flags:
34: ** none
35: **
36: ** Trace Flags:
37: ** none at present
38: **
39: ** History:
40: ** 20 Dec 1978 -- written (rick)
41: */
42:
43:
44:
45:
46:
47:
48:
49:
50: /*
51: ** TIMEOFDAY -- convert 2 integers to minutes since midnight
52: **
53: ** Converts the hours and minutes parameters to minutes since midnight
54: ** performing some error (bounds) checking on the time.
55: **
56: ** To answer the question about what is midnight, both 0:00 and 24:00
57: ** are handled, but not the same way. The former is zero minutes from
58: ** midnight and the latter is 1440 minutes from midnight. (1440 is
59: ** 24 hrs times 60 minutes, or 1 minute past the end of the day.)
60: **
61: ** Parameters:
62: ** hrs -- an integer pointer to the hour
63: ** mins -- an integer pointer to the minutes
64: **
65: ** Returns:
66: ** integer time since midnight
67: **
68: ** Side Effects:
69: ** may detect an error and call yyerror which never returns.
70: **
71: ** Requires:
72: ** that the pointers be on integer boundaries
73: **
74: ** Called By:
75: ** y.tab.c -- the grammar
76: **
77: ** Trace Flags:
78: ** none
79: **
80: ** Diagnostics:
81: ** BADHOURS -- No such hour
82: ** BADMINS -- No such minute
83: ** BAD24TIME -- only 24:00 allowed
84: **
85: ** Syserrs:
86: ** none
87: **
88: ** History:
89: ** 20 Dec 1978 -- written (rick)
90: */
91: timeofday(hrs, mins)
92: int *hrs;
93: int *mins;
94: {
95: register int h;
96: register int m;
97: register int rtval;
98:
99: h = *hrs;
100: m = *mins;
101: if (h > 24 || h < 0)
102: /* no such hour */
103: yyerror(BADHOURS, iocv(h), 0);
104: if (m > 59 || h < 0)
105: /* no such minute */
106: yyerror(BADMINS, iocv(m), 0);
107: if (h == 24)
108: {
109: h = 1440;
110: if (m != 0)
111: /* can only use 24:00 */
112: yyerror(BAD24TIME, iocv(m), 0);
113: }
114: rtval = (h * 60) + m;
115: return (rtval);
116: }
117:
118:
119: /*
120: ** TLPREPEND -- combine two target list components
121: **
122: ** Attach two target list components to each other.
123: ** Neither component need be a single element. The
124: ** 'a' component will be attached at the extreme left
125: ** of the 'b' component.
126: **
127: ** Parameters:
128: ** a -- tl component to attach
129: ** b -- tl base for attaching
130: **
131: ** Returns:
132: ** nothing
133: **
134: ** Side Effects:
135: ** this routine is a side effect. It attaches a to b
136: ** and when it returns a is attached to b but the pointer
137: ** to b never changes (neither does the pointer to a)
138: **
139: ** Requires:
140: ** nothing
141: **
142: ** Called By:
143: ** y.tab.c -- the grammar
144: **
145: ** Trace Flags:
146: ** none
147: **
148: ** Diagnostics:
149: ** none
150: **
151: ** Syserrs:
152: ** none
153: **
154: ** History:
155: ** 20 Dec 1978 -- written (rick)
156: */
157:
158: struct querytree *
159: tlprepend(a, b)
160: struct querytree *a;
161: struct querytree *b;
162: {
163: register struct querytree *q;
164:
165: /* scan to the left end of b */
166: for (q = b; q->left != NULL; q = q->left)
167: ; /* no action */
168:
169: /* attach a to the end of b */
170: q->left = a;
171: return (b);
172: }
173:
174:
175:
176:
177:
178:
179: /*
180: ** HEADER.C -- print header for retrieve to terminal
181: **
182: ** header scans the parameter list managed with "initp" and
183: ** "setp" to reconstruct the field names and types and passing
184: ** them to the normal printhdr etc.
185: **
186: ** Defines:
187: ** header()
188: **
189: ** Requires:
190: ** printhdr - utility lib
191: ** beginhdr - utility lib
192: ** printeol - utility lib
193: ** printeh - utility lib
194: ** initp - soon to become utility lib
195: ** atoi - utility lib
196: ** Pc - vble, number of params in list
197: ** Pv - vble, list of parameters
198: **
199: ** History:
200: ** written (ancient history) (rick)
201: */
202: ()
203: {
204: register char *ptr;
205: register int i;
206: int j;
207:
208: beginhdr();
209: for (i = 0; i < Pc; i += 2)
210: {
211: atoi(&Pv[i + 1][1], &j);
212: printhdr(Pv[i + 1][0] & I1MASK, j, Pv[i]);
213: }
214: printeol();
215: printeh();
216: initp();
217: }
218:
219:
220:
221:
222:
223:
224: /*
225: ** PATMAT -- converts pattern matching characters in a string
226: **
227: ** Searches a string up to a null byte for one of the pattern
228: ** matching characters '*', '?', '[', and ']'. It then converts
229: ** these characters to their internal control character equivalents.
230: **
231: ** Parameters:
232: ** str -- the string to search
233: **
234: ** Returns:
235: ** 0 -- no pattern matching in string
236: ** 1 -- at least one pattern matching character
237: **
238: ** Side Effects:
239: ** none
240: **
241: ** Requires:
242: ** symbol.h
243: **
244: ** Called By:
245: ** y.tab.c -- grammar
246: **
247: ** Trace Flags:
248: ** none
249: **
250: ** Diagnostics:
251: ** none
252: **
253: ** Syserrs:
254: ** none
255: **
256: ** History:
257: ** written (ancient history) (rick)
258: */
259:
260:
261: /*
262: ** PATMAT
263: ** hunts through a string and converts the pattern matching
264: ** characters and replaces with the corresponding cntrl chars
265: */
266: patmat(str)
267: char *str;
268: {
269: register char *p, *q;
270: register int flag;
271:
272: flag = 0;
273: q = str;
274: for (p = str; *p; p++)
275: {
276: if (*p == '\\')
277: {
278: *q++ = *++p;
279: continue;
280: }
281: switch (*p)
282: {
283: case '*':
284: *q++ = PAT_ANY;
285: flag = 1;
286: continue;
287:
288: case '?':
289: *q++ = PAT_ONE;
290: flag = 1;
291: continue;
292:
293: case '[':
294: *q++ = PAT_LBRAC;
295: flag = 1;
296: continue;
297:
298: case ']':
299: *q++ = PAT_RBRAC;
300: flag = 1;
301: continue;
302: }
303: *q++ = *p;
304: }
305: *q = '\0';
306: return (flag);
307: }
308: /*
309: ** PERMCOM -- map command allowed into protection catalog bits
310: **
311: ** translates the QMODE type symbols into the appropriate counterparts
312: ** for the permit statement allowed command vector. The manifest
313: ** constants are designed to be inclusive or'd together to form a
314: ** composite bit map of OK actions.
315: **
316: ** Parameters:
317: ** a -- the QMODE type symbol for the command to add
318: **
319: ** Returns:
320: ** none
321: **
322: ** Side Effects:
323: ** changes the variable Permcomd to reflect the additional permission
324: **
325: ** Requires:
326: ** Permcomd must be define globally
327: ** catalog.h for the proper constants
328: **
329: ** Called By:
330: ** y.tab.c -- the grammar
331: **
332: ** Trace Flags:
333: ** none
334: **
335: ** Diagnostics:
336: ** none
337: **
338: ** Syserrs:
339: ** bad QMODE(%d) -- a bad symbol has been passed for mapping
340: **
341: ** History:
342: ** 28 Dec 1978 -- written (rick)
343: */
344:
345: permcom(a)
346: int a;
347: {
348: switch (a)
349: {
350: case mdRETR:
351: Permcomd |= PRO_RETR;
352: break;
353:
354: case mdAPP:
355: Permcomd |= PRO_APP;
356: break;
357:
358: case mdREPL:
359: Permcomd |= PRO_REPL;
360: break;
361:
362: case mdDEL:
363: Permcomd |= PRO_DEL;
364: break;
365:
366: case -1:
367: Permcomd |= 0177777; /* all bits set */
368: break;
369:
370: default:
371: syserr("permcom: bad QMODE(%d)", a);
372: }
373: }
Defined functions
defined in line
202; used 1 times