|
|
1.1 root 1: /* parse.c - */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/parse.c,v 7.1 90/07/09 14:34:54 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/dsap/common/RCS/parse.c,v 7.1 90/07/09 14:34:54 mrose Exp $
9: *
10: *
11: * $Log: parse.c,v $
12: * Revision 7.1 90/07/09 14:34:54 mrose
13: * sync
14: *
15: * Revision 7.0 89/11/23 22:17:56 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: #include "quipu/config.h"
32: #include "quipu/util.h"
33: #include "quipu/entry.h"
34: #include "quipu/ds_error.h"
35: #include "quipu/malloc.h"
36: #ifdef TURBO_DISK
37: #include <gdbm.h>
38: #endif
39:
40: #ifndef TURBO_DISK
41: #define PARSE_BUFFER 10000
42: static char parse_buffer [PARSE_BUFFER];
43: #endif
44:
45: Entry database_root;
46: int local_master_size = 0;
47: int local_slave_size = 0;
48: int local_cache_size = 0;
49:
50: #ifdef TURBO_DISK
51: extern char *parse_entry;
52: int dbmeof;
53: int dbmfirst = 1;
54: datum turbo_header_key = { "HEADER", sizeof("HEADER") };
55: #endif
56:
57: extern time_t time ();
58:
59: #ifdef TURBO_DISK
60: char *getline (db)
61: GDBM_FILE db;
62: {
63: static datum newkey, key, dat;
64: static char *line, *next, *save;
65: static int new_entry;
66: char *TidyString();
67: int save_heap;
68:
69: save_heap = mem_heap;
70: GENERAL_HEAP;
71:
72: if (dbmfirst) {
73: dbmfirst = 0;
74: key = gdbm_firstkey(db);
75: parse_entry = key.dptr;
76: new_entry = 1;
77: } else if (line == NULLCP || *line == '\0') {
78: newkey = gdbm_nextkey(db, key);
79: free(key.dptr);
80: key = newkey;
81: parse_entry = key.dptr;
82: new_entry = 1;
83: }
84:
85: if (key.dptr == NULLCP) {
86: dbmeof = 1;
87: dbmfirst = 1;
88: mem_heap = save_heap;
89: return(NULLCP);
90: }
91:
92: if (new_entry) {
93: /* gross, but we have to skip the header datum */
94: if (strcmp(key.dptr, turbo_header_key.dptr) == 0) {
95: newkey = gdbm_nextkey(db, key);
96: free(key.dptr);
97: key = newkey;
98: if (key.dptr == NULLCP) {
99: parse_entry = key.dptr;
100: dbmeof = 1;
101: dbmfirst = 1;
102: mem_heap = save_heap;
103: return(NULLCP);
104: }
105: }
106:
107: new_entry = 0;
108: parse_entry = key.dptr;
109: dat = gdbm_fetch(db, key);
110:
111: if ((line = dat.dptr) == NULLCP) {
112: parse_error("edb error - null dbm data");
113: return(NULLCP);
114: }
115: }
116:
117: if (*line == '\n') {
118: line = NULLCP;
119: free(dat.dptr);
120: mem_heap = save_heap;
121: return("");
122: }
123:
124: line = SkipSpace(line);
125: while (*line == '#') {
126: line = index(line, '\n') + 1;
127: if (*line == '\0') {
128: mem_heap = save_heap;
129: return(NULLCP);
130: }
131: line = SkipSpace(line);
132: }
133:
134: next = index(line, '\n');
135: *next++ = '\0';
136: save = line;
137: line = next;
138:
139: mem_heap = save_heap;
140: return(TidyString(save));
141: }
142:
143: #else
144:
145: char * getline (file)
146: FILE * file;
147: {
148: extern int parse_line;
149: char * ptr;
150: extern char * TidyString ();
151:
152: while ( fgets (parse_buffer,PARSE_BUFFER,file) != NULLCP) {
153: parse_line++;
154: ptr = SkipSpace (parse_buffer);
155: if (*ptr != '#')
156: return (TidyString(ptr));
157: }
158:
159: return (NULLCP);
160:
161: }
162:
163: #endif
164:
165: Attr_Sequence get_attributes_aux (file)
166: #ifdef TURBO_DISK
167: GDBM_FILE file;
168: #else
169: FILE * file;
170: #endif
171: {
172: Attr_Sequence as = NULLATTR;
173: Attr_Sequence as_combine ();
174: char * ptr;
175:
176: if ((ptr = getline (file)) == NULLCP)
177: return (NULLATTR);
178:
179: while ( *ptr != 0 ) {
180: as = as_combine (as,ptr);
181: if ((ptr = getline (file)) == NULLCP)
182: break;
183: }
184: return (as);
185: }
186:
187: Attr_Sequence get_attributes (file)
188: #ifdef TURBO_DISK
189: GDBM_FILE file;
190: #else
191: FILE * file;
192: #endif
193: {
194: extern int parse_status;
195: extern int parse_line;
196:
197: parse_status = 0;
198: parse_line = 0;
199:
200: return (get_attributes_aux (file));
201: }
202:
203:
204: Entry get_entry_aux (file,parent,dtype)
205: #ifdef TURBO_DISK
206: GDBM_FILE file;
207: #else
208: FILE * file;
209: #endif
210: Entry parent;
211: int dtype;
212: {
213: Entry eptr;
214: char * ptr;
215: extern RDN parse_rdn;
216: struct DSError err;
217: extern int print_parse_errors;
218: extern int parse_line;
219: int save;
220: extern PS opt;
221: char check = TRUE;
222:
223: DATABASE_HEAP;
224:
225: eptr = get_default_entry (parent);
226: eptr->e_data = dtype;
227:
228: if ((ptr = getline (file)) == NULLCP) {
229: GENERAL_HEAP;
230: return (NULLENTRY);
231: }
232:
233: while (*ptr == 0)
234: if ((ptr = getline (file)) == NULLCP) {
235: GENERAL_HEAP;
236: return (NULLENTRY);
237: }
238:
239: if ((eptr->e_name = str2rdn (ptr)) == NULLRDN) {
240: parse_error ("invalid rdn %s",ptr);
241: check = FALSE;
242: }
243:
244: parse_rdn = eptr->e_name;
245: eptr->e_attributes = get_attributes_aux (file);
246:
247: if (check) {
248: save = parse_line;
249: parse_line = 0;
250: if (unravel_attribute (eptr,&err) != OK) {
251: parse_error ("Error in entry ending line %d...",(char *) save);
252: if (print_parse_errors)
253: ds_error (opt,&err);
254: }
255: if (check_schema (eptr,NULLATTR,&err) != OK) {
256: parse_error ("Schema error in entry ending line %d...",(char *) save);
257: if (print_parse_errors)
258: ds_error (opt,&err);
259: }
260: parse_line = save;
261: }
262: parse_rdn = NULLRDN;
263:
264: GENERAL_HEAP;
265:
266: switch (dtype) {
267: case E_TYPE_SLAVE:
268: local_slave_size++; break;
269: case E_DATA_MASTER:
270: local_master_size++; break;
271: case E_TYPE_CACHE_FROM_MASTER:
272: eptr->e_age = time ((time_t *)0);
273: local_cache_size++; break;
274: }
275:
276: return (eptr);
277: }
278:
279:
280: Entry get_entry (file,parent,dtype)
281: #ifdef TURBO_DISK
282: GDBM_FILE file;
283: #else
284: FILE * file;
285: #endif
286: Entry parent;
287: int dtype;
288: {
289: extern int parse_status;
290: extern int parse_line;
291:
292: parse_status = 0;
293: parse_line = 0;
294:
295: return (get_entry_aux (file,parent,dtype));
296: }
297:
298:
299: Entry new_constructor (parent)
300: Entry parent;
301: {
302: Entry constructor;
303:
304: constructor = get_default_entry (parent);
305: constructor->e_leaf = FALSE;
306: constructor->e_complete = FALSE;
307: constructor->e_data = E_TYPE_CONSTRUCTOR;
308: constructor->e_acl = acl_alloc ();
309: constructor->e_acl->ac_child = acl_dflt ();
310: constructor->e_acl->ac_entry = acl_dflt ();
311: constructor->e_acl->ac_default = acl_dflt ();
312: constructor->e_acl->ac_attributes = NULLACL_ATTR;
313: return (constructor);
314: }
315:
316:
317: Entry make_path (dn)
318: DN dn;
319: {
320: Entry ptr;
321: register RDN a_rdn, b_rdn;
322:
323: if ((database_root == NULLENTRY) || (database_root->e_child == NULLENTRY)) {
324: database_root = new_constructor(NULLENTRY);
325: ptr = database_root;
326: for (; dn!= NULLDN; dn=dn->dn_parent) {
327: ptr->e_child = new_constructor(ptr);
328: ptr = ptr->e_child;
329: ptr->e_name = rdn_cpy (dn->dn_rdn);
330: }
331: return (ptr);
332: } else {
333: /* follow links as far as poss, then add new bits */
334:
335: if (dn == NULLDN)
336: return (database_root);
337:
338: ptr = database_root->e_child;
339: b_rdn = dn->dn_rdn;
340: a_rdn = ptr->e_name ;
341:
342: for(;;) { /* return out */
343: while (rdn_cmp (a_rdn, b_rdn) != OK) {
344: if (ptr->e_sibling == NULLENTRY) {
345: ptr->e_sibling = new_constructor(ptr->e_parent);
346: ptr = ptr->e_sibling;
347: ptr->e_name = rdn_cpy (dn->dn_rdn);
348: for (dn=dn->dn_parent; dn!= NULLDN; dn=dn->dn_parent) {
349: ptr->e_child = new_constructor(ptr);
350: ptr = ptr->e_child;
351: ptr->e_name = rdn_cpy (dn->dn_rdn);
352: }
353: return (ptr);
354: }
355: ptr = ptr->e_sibling;
356: a_rdn = ptr->e_name ;
357: }
358:
359: if ( dn->dn_parent == NULLDN)
360: return (ptr);
361:
362: dn = dn->dn_parent;
363: b_rdn = dn->dn_rdn;
364:
365: if ( ptr->e_child == NULLENTRY) {
366: for (; dn!= NULLDN; dn=dn->dn_parent) {
367: ptr->e_child = new_constructor(ptr);
368: ptr = ptr->e_child;
369: ptr->e_name = rdn_cpy (dn->dn_rdn);
370: }
371: return (ptr);
372: }
373: ptr = ptr->e_child;
374: a_rdn = ptr->e_name;
375: }
376:
377: }
378: /* NOTREACHED */
379:
380: }
381:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.