/* valid.c * last revised at 14, Nov. 1994 * * GED connectivity file input * * Copyright (C) 1994, All rights reserved. * written by Gyudong Kim(chilly@iclab.snu.ac.kr) * */ #include "findhier.h" extern FILE *dbfile; extern struct names *nametop; extern struct branch *subtop; extern struct branch *trees; extern char *dbdir; static char *GEDgets(file) FILE *file; { static char buf[BUFSIZ]; char *cptr; int c; int parenthesis=0; cptr = buf; while((c=fgetc(file))!=EOF) { switch (c) { case '{': /* begin comment */ seek_char('}',file); break; case ';': /* end word */ cptr[0] = 0; return(buf); case '\n': if (cptr==buf) break; c = ' '; case ',': if (!parenthesis) c = ' '; default: if (c=='(') parenthesis=1; else if (c==')') parenthesis=0; *cptr = c; cptr++; break; } } if (cptr==buf) return(NULL); cptr[0] = 0; return(buf); } static char *GEDname(tok) char *tok; { char *tmp; tmp = tok; while (*tok=='"' || *tok=='\'') { tok++;tmp++; } while (*tmp!='"' && *tok!='\'') { if (*tmp) tmp++; else break; } *tmp=0; return(tok); } /* * make the list of the names.. nothing about subcells */ void GED_init() { char *word; char *tok; char *dir_name; while((word=GEDgets(dbfile))!=NULL) { if (word[0]!='"') continue; tok = strtok(word+1," "); if (tok!=NULL) create(GEDname(tok)); /* GED directory */ tok = strtok((char *)NULL," \n'"); if (tok!=NULL) tok = GEDname(tok); dir_name = (char *)myalloc((SIZE)strlen(tok),"GED_init"); (void)strcpy(dir_name,tok); nametop->direntry=dir_name; } (void)rewind(dbfile); } #define SPICECN "spice_cn.1.1" static void GEDanal_cell(cell) struct names *cell; { FILE *Fcell; struct branch *parent; char cellname[BUFSIZ]; char *word,*tok; if (dbdir!=NULL) (void)sprintf(cellname,"%s/%s/%s",dbdir,cell->direntry,SPICECN); else (void)sprintf(cellname,"%s/%s",cell->direntry,SPICECN); Fcell=fopen(cellname,"r"); if (Fcell==NULL) { vacant(cell->name); return; } while((word=GEDgets(Fcell))!=NULL) { if (word[0]!='%') continue; tok = strtok((char *)(word+1)," "); if (tok!=NULL) word=GEDname(tok); /* cell name */ else { warning("invalid format in cell %s\n",cellname); exit(-1); } (void)strtok((char *)NULL," "); /* mag ? */ (void)strtok((char *)NULL," "); /* coordinate ? */ (void)strtok((char *)NULL," "); /* angle ? */ tok = strtok((char *)NULL," "); if (tok!=NULL) tok=GEDname(tok); /* wrk file name */ else { warning("invalid format in cell %s\n",cellname); exit(-1); } if (!strcmp(extension(tok),"wrk")) { add_cell(word,cell->name,&subtop); } } (void)fclose(Fcell); parent = (struct branch *)myalloc(sizeof(struct branch),"GEDanal_cell"); parent->name = cell->name; parent->offspring = subtop; subtop = (struct branch *)NULL; /* clean subtop but not free */ parent->next = trees; trees = parent; } void GED_tree() { struct names *tmp; for(tmp=nametop;tmp!=NULL;tmp=tmp->next) { if (!isvacant(tmp->name)) GEDanal_cell(tmp); } } /* valid.c */