FreeCalypso > hg > ueda-linux
view ueda/uschem-print/prolog.c @ 8:640ba9db0e9d
ueda/sverp-bind/struct.h started
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sat, 01 Aug 2015 03:57:31 +0000 |
parents | cd92449fdb51 |
children |
line wrap: on
line source
/* * The main work here is emitting the graphical symbol definitions * and any user-requested additional procsets. */ #include <sys/types.h> #include <stdio.h> #include <strings.h> #include "../libuschem/graphsym.h" #include "../libuschem/schemstruct.h" extern FILE *find_symlib_file(); extern int total_graphsyms; extern struct schem **schem_pages; extern int npages; extern char uschem_procset_pathname[]; extern char transfont_procset_pathname[]; print_graphsym_def(sym) struct graphsym *sym; { FILE *f; printf("/%s {\n", sym->gs_name); f = fopen(sym->gs_pathname, "r"); if (!f) { fprintf(stderr, "Unable to reopen %s for printing: ", sym->gs_pathname); perror(NULL); exit(1); } print_gschem_code_sym(f, sym); fclose(f); puts("} bind def"); } emit_prolog() { register int i; puts("%%BeginProlog"); emit_file(uschem_procset_pathname); emit_file(transfont_procset_pathname); for (i = 0; i < npages; i++) emit_extra_procsets(schem_pages[i]); printf("%d dict begin\n", total_graphsyms); graphsym_forall(print_graphsym_def); puts("currentdict end"); puts("$uschem exch /symbols exch put"); puts("%%EndProlog"); } #define MAX_EXTRA_PROCSETS 128 emit_extra_procsets(schem) struct schem *schem; { static char *procset_list[MAX_EXTRA_PROCSETS]; static int nprocsets; register struct schemobj *obj; register char *psname; register int i; register FILE *f; char buf[512]; for (obj = schem->obj_next; obj != (struct schemobj *)schem; obj = obj->obj_next) { if (obj->obj_type != OBJTYPE_COMMENT) continue; if (strncmp(obj->commentobj_text, "Need procset: ", 14)) continue; psname = obj->commentobj_text + 14; if (!psname[0]) continue; /* have we already seen it? */ for (i = 0; i < nprocsets; i++) if (!strcmp(procset_list[i], psname)) break; if (i < nprocsets) continue; if (nprocsets >= MAX_EXTRA_PROCSETS) { fprintf(stderr, "%s: line %d: too many procsets\n", schem->orig_filename, obj->obj_lineno); exit(1); } /* get it and put it out */ f = find_symlib_file(psname, NULL); if (!f) { fprintf(stderr, "procset %s not found (%s line %d)\n", psname, schem->orig_filename, obj->obj_lineno); exit(1); } while ((i = fread(buf, 1, sizeof buf, f)) > 0) fwrite(buf, 1, i, stdout); fclose(f); procset_list[nprocsets++] = psname; } }