Annotation of 43BSDReno/contrib/isode-beta/quipu/parse2.c, revision 1.1

1.1     ! root        1: /* parse2.c - */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/quipu/RCS/parse2.c,v 7.3 90/07/09 14:46:27 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/quipu/RCS/parse2.c,v 7.3 90/07/09 14:46:27 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       parse2.c,v $
        !            12:  * Revision 7.3  90/07/09  14:46:27  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.2  90/01/11  18:37:23  mrose
        !            16:  * real-sync
        !            17:  * 
        !            18:  * Revision 7.1  89/12/19  16:20:42  mrose
        !            19:  * sync
        !            20:  * 
        !            21:  * Revision 7.0  89/11/23  22:17:57  mrose
        !            22:  * Release 6.0
        !            23:  * 
        !            24:  */
        !            25: 
        !            26: /*
        !            27:  *                               NOTICE
        !            28:  *
        !            29:  *    Acquisition, use, and distribution of this module and related
        !            30:  *    materials are subject to the restrictions of a license agreement.
        !            31:  *    Consult the Preface in the User's Manual for the full terms of
        !            32:  *    this agreement.
        !            33:  *
        !            34:  */
        !            35: 
        !            36: #include "quipu/util.h"
        !            37: #include "quipu/entry.h"
        !            38: #include "quipu/config.h"
        !            39: #include "cmd_srch.h"
        !            40: #include "quipu/malloc.h"
        !            41: #ifdef TURBO_DISK
        !            42: #include <gdbm.h>
        !            43: #endif
        !            44: 
        !            45: Entry getentry_block_aux (), get_entry_aux();
        !            46: extern LLog * log_dsap;
        !            47: char * getline ();
        !            48: int rdn_print ();
        !            49: int master_edbs = 0;
        !            50: int slave_edbs = 0;
        !            51: 
        !            52: #ifdef TURBO_DISK
        !            53: extern datum   turbo_header_key;
        !            54: #endif
        !            55: 
        !            56: Entry getentry_block (p_parent,fname)
        !            57: Entry p_parent;
        !            58: char * fname;
        !            59: {
        !            60: #ifdef TURBO_DISK
        !            61:        GDBM_FILE       db;
        !            62:        static char     gfname[1024];
        !            63:        int             save_heap;
        !            64: 
        !            65:        strcpy(gfname, fname);
        !            66:        strcat(gfname, ".gdbm");
        !            67:        save_heap = mem_heap;
        !            68:        GENERAL_HEAP;
        !            69:        db = gdbm_open(gfname, 0, GDBM_READER, 0, 0);
        !            70:        mem_heap = save_heap;
        !            71:        return getentry_block_aux (p_parent, gfname, db);
        !            72: #else
        !            73:        return getentry_block_aux (p_parent,fname, fopen (fname, "r"));
        !            74: #endif
        !            75: }
        !            76: 
        !            77: Entry getentry_block_aux (p_parent,fname,file)
        !            78: Entry p_parent;
        !            79: char * fname;
        !            80: #ifdef TURBO_DISK
        !            81: GDBM_FILE      file;
        !            82: #else
        !            83: FILE *file;
        !            84: #endif
        !            85: {
        !            86: extern char * parse_file;
        !            87: extern int parse_status;
        !            88: extern int parse_line;
        !            89: Entry entryptr;
        !            90: int   dtype;
        !            91: char *version;
        !            92: Entry get_entries_aux ();
        !            93: extern int errno;
        !            94: 
        !            95:        if (file == NULL) {
        !            96:                LLOG (log_dsap,LLOG_NOTICE,("WARNING - Can't open \"%s\" (%d)- should I be able to ?",fname,errno));
        !            97:                return (NULLENTRY);
        !            98:        }
        !            99: 
        !           100:        LLOG (log_dsap,LLOG_NOTICE,("Loading \"%s\"",fname));
        !           101: 
        !           102:        parse_status = 0;
        !           103:        parse_line   = 0;
        !           104:        parse_file = fname;
        !           105: 
        !           106:        if (get_header (file,&dtype,&version) != OK) {
        !           107:                parse_line = 0;
        !           108:                parse_error ("File %s not loaded",fname);
        !           109:                parse_file = NULLCP;
        !           110: #ifdef TURBO_DISK
        !           111:                save_heap = mem_heap;
        !           112:                GENERAL_HEAP;
        !           113:                (void) gdbm_close (file);
        !           114:                mem_heap = save_heap;
        !           115: #else
        !           116:                (void) fclose (file);
        !           117: #endif
        !           118:                return (NULLENTRY);
        !           119:        }
        !           120: 
        !           121:        entryptr = get_entries_aux (file,p_parent,version,dtype);
        !           122: 
        !           123:        if ((parse_status != 0) || (entryptr == NULLENTRY)) {
        !           124:                parse_line = 0;
        !           125:                parse_error ("File %s not loaded",fname);
        !           126:                parse_file = NULLCP;
        !           127: #ifdef TURBO_DISK
        !           128:                save_heap = mem_heap;
        !           129:                GENERAL_HEAP;
        !           130:                (void) gdbm_close (file);
        !           131:                mem_heap = save_heap;
        !           132: #else
        !           133:                (void) fclose (file);
        !           134: #endif
        !           135:                return (NULLENTRY);
        !           136:        }
        !           137: 
        !           138:         if ( p_parent != NULLENTRY ) {
        !           139:                        p_parent->e_edbversion = version;
        !           140:                        if ((dtype == E_DATA_MASTER) || (dtype == E_TYPE_SLAVE)) 
        !           141:                                p_parent->e_allchildrenpresent = TRUE;
        !           142:                }
        !           143: 
        !           144:        parse_file = NULLCP;
        !           145: 
        !           146:        if (dtype == E_DATA_MASTER)
        !           147:                master_edbs++;
        !           148:        if (dtype == E_TYPE_SLAVE)
        !           149:                slave_edbs++;
        !           150: 
        !           151: #ifdef TURBO_DISK
        !           152:        save_heap = mem_heap;
        !           153:        GENERAL_HEAP;
        !           154:        (void) gdbm_close (file);
        !           155:        mem_heap = save_heap;
        !           156: #else
        !           157:        (void) fclose (file);
        !           158: #endif
        !           159:        return (entryptr);
        !           160: }
        !           161: 
        !           162: #ifdef TURBO_DISK
        !           163: 
        !           164: get_header (db, typeptr, versionptr)
        !           165: GDBM_FILE      db;
        !           166: int            *typeptr;
        !           167: char           **versionptr;
        !           168: {
        !           169:        char            *v;
        !           170:        datum           h;
        !           171:        int             save_heap;
        !           172:        static CMD_TABLE cmd_header[] =  {
        !           173:                "MASTER",       E_DATA_MASTER,
        !           174:                "SLAVE",        E_TYPE_SLAVE,
        !           175:                "CACHE",        E_TYPE_CACHE_FROM_MASTER,
        !           176:                0,              -1,
        !           177:        };
        !           178:        extern char     *parse_entry;
        !           179: 
        !           180:        save_heap = mem_heap;
        !           181:        GENERAL_HEAP;
        !           182: 
        !           183:        parse_entry = turbo_header_key.dptr;
        !           184:        if (db == NULL) {
        !           185:                parse_error("NULL dbm file!!!", NULLCP);
        !           186:                mem_heap = save_heap;
        !           187:                return(NOTOK);
        !           188:        }
        !           189: 
        !           190:        h = gdbm_fetch(db, turbo_header_key);
        !           191:        if (h.dptr == NULL) {
        !           192:                parse_error("File has no header!!!", NULLCP);
        !           193:                mem_heap = save_heap;
        !           194:                return(NOTOK);
        !           195:        }
        !           196: 
        !           197:        v = index(h.dptr, '\n');
        !           198:        if (v == NULLCP) {
        !           199:                parse_error("Bad file header", NULLCP);
        !           200:                mem_heap = save_heap;
        !           201:                return(NOTOK);
        !           202:        }
        !           203:        *v++ = '\0';
        !           204: 
        !           205:        if ((*typeptr = cmd_srch(h.dptr, cmd_header)) == -1) {
        !           206:                parse_error("File type %s not recognised", h.dptr);
        !           207:                mem_heap = save_heap;
        !           208:                return(NOTOK);
        !           209:        }
        !           210: 
        !           211:        if (*v == '\0') {
        !           212:                parse_error("No version specified", NULLCP);
        !           213:                mem_heap = save_heap;
        !           214:                return(NOTOK);
        !           215:        }
        !           216:        *versionptr = strdup(v);
        !           217:        free(h.dptr);
        !           218: 
        !           219:        mem_heap = save_heap;
        !           220:        return(OK);
        !           221: }
        !           222: 
        !           223: #else
        !           224: 
        !           225: get_header (file,typeptr,versionptr)
        !           226: FILE * file;
        !           227: int * typeptr;
        !           228: char ** versionptr;
        !           229: {
        !           230: char * ptr;
        !           231: static CMD_TABLE cmd_header [] = {
        !           232:        "MASTER",       E_DATA_MASTER,
        !           233:        "SLAVE",        E_TYPE_SLAVE,
        !           234:        "CACHE",        E_TYPE_CACHE_FROM_MASTER,
        !           235:        0,              -1,
        !           236:        };
        !           237: 
        !           238:        if ((ptr = getline (file)) == NULLCP) {
        !           239:                parse_error ("NULL file !!!",NULLCP);
        !           240:                return (NOTOK);
        !           241:        }
        !           242: 
        !           243:        if ((*typeptr = cmd_srch (ptr,cmd_header)) == -1) {
        !           244:                parse_error ("File type %s not recognised",ptr);
        !           245:                return (NOTOK);
        !           246:        }
        !           247: 
        !           248:        if ((ptr = getline (file)) == NULLCP) {
        !           249:                parse_error ("No version specified",NULLCP);
        !           250:                return (NOTOK);
        !           251:        }
        !           252:        *versionptr = strdup (ptr);
        !           253:        
        !           254:        return (OK);
        !           255: }
        !           256: 
        !           257: #endif
        !           258: 
        !           259: /* ARGSUSED */
        !           260: Entry get_entries_aux (file,parent,version,dtype)
        !           261: #ifdef TURBO_DISK
        !           262: GDBM_FILE      file;
        !           263: #else
        !           264: FILE * file;
        !           265: #endif
        !           266: Entry parent;
        !           267: char * version;
        !           268: int dtype;
        !           269: {
        !           270: Entry eptr = NULLENTRY;
        !           271: Entry top = NULLENTRY;
        !           272: Entry trail;
        !           273: Entry find_sibling();
        !           274: 
        !           275: #ifdef TURBO_DISK
        !           276: extern int dbmeof;
        !           277: #endif
        !           278: #ifdef TURBO_LOAD
        !           279:        if ( ! turbo_start(file)) {
        !           280:                parse_error ("Turbo load failed",NULLCP);
        !           281:                return NULLENTRY;
        !           282:        }
        !           283: #endif
        !           284: 
        !           285: #ifdef TURBO_DISK
        !           286:        dbmeof = 0;
        !           287:        while (dbmeof == 0) {
        !           288: #else
        !           289:        while (feof(file) == 0) {
        !           290: #endif
        !           291:                if ((eptr = get_entry_aux (file,parent,dtype)) == NULLENTRY)
        !           292:                        continue;
        !           293:                if ( top == NULLENTRY) {
        !           294:                        top = eptr;
        !           295:                        trail = eptr;
        !           296:                } else {
        !           297: #ifdef TURBO_LOAD
        !           298:                        if ( turbo_insert(eptr->e_name) != OK )
        !           299: #else
        !           300:                         if (find_sibling (eptr->e_name,top) != NULLENTRY)
        !           301: #endif
        !           302:                        {
        !           303:                                pslog (log_dsap,LLOG_EXCEPTIONS,"Duplicate entry for",rdn_print,(caddr_t)eptr->e_name);
        !           304:                                parse_error ("Non Unique RDN",NULLCP);
        !           305:                        }
        !           306:                        trail->e_sibling = eptr;
        !           307:                        trail = eptr;
        !           308:                }
        !           309:        }
        !           310: 
        !           311: #ifdef TURBO_LOAD
        !           312:        turbo_end();
        !           313: #endif
        !           314: 
        !           315:        return (top);
        !           316: }
        !           317: 
        !           318: 
        !           319: Entry get_entries (file,parent,version,dtype)
        !           320: FILE * file;
        !           321: Entry parent;
        !           322: char * version;
        !           323: int dtype;
        !           324: {
        !           325: extern int parse_status;
        !           326: extern int parse_line;
        !           327: 
        !           328:        parse_status = 0;
        !           329:        parse_line   = 0;
        !           330: 
        !           331:        return (get_entries_aux (file,parent,version,dtype));
        !           332: }
        !           333: 
        !           334: Entry find_sibling (object,start)
        !           335: RDN object;
        !           336: Entry start;
        !           337: {
        !           338:        if (start == NULLENTRY) 
        !           339:                return (NULLENTRY);
        !           340: 
        !           341:        while (rdn_cmp (start->e_name, object) != OK) {
        !           342:                start = start->e_sibling ;
        !           343:                if ( start == NULLENTRY ) 
        !           344:                        return (NULLENTRY);
        !           345:        }
        !           346:        return (start);
        !           347: }
        !           348: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.