FreeCalypso > hg > ueda-linux
comparison ueda/uschem-print/prolog.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * The main work here is emitting the graphical symbol definitions | |
3 * and any user-requested additional procsets. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <strings.h> | |
9 #include "../libuschem/graphsym.h" | |
10 #include "../libuschem/schemstruct.h" | |
11 | |
12 extern FILE *find_symlib_file(); | |
13 | |
14 extern int total_graphsyms; | |
15 | |
16 extern struct schem **schem_pages; | |
17 extern int npages; | |
18 | |
19 extern char uschem_procset_pathname[]; | |
20 extern char transfont_procset_pathname[]; | |
21 | |
22 print_graphsym_def(sym) | |
23 struct graphsym *sym; | |
24 { | |
25 FILE *f; | |
26 | |
27 printf("/%s {\n", sym->gs_name); | |
28 f = fopen(sym->gs_pathname, "r"); | |
29 if (!f) { | |
30 fprintf(stderr, "Unable to reopen %s for printing: ", | |
31 sym->gs_pathname); | |
32 perror(NULL); | |
33 exit(1); | |
34 } | |
35 print_gschem_code_sym(f, sym); | |
36 fclose(f); | |
37 puts("} bind def"); | |
38 } | |
39 | |
40 emit_prolog() | |
41 { | |
42 register int i; | |
43 | |
44 puts("%%BeginProlog"); | |
45 emit_file(uschem_procset_pathname); | |
46 emit_file(transfont_procset_pathname); | |
47 for (i = 0; i < npages; i++) | |
48 emit_extra_procsets(schem_pages[i]); | |
49 printf("%d dict begin\n", total_graphsyms); | |
50 graphsym_forall(print_graphsym_def); | |
51 puts("currentdict end"); | |
52 puts("$uschem exch /symbols exch put"); | |
53 puts("%%EndProlog"); | |
54 } | |
55 | |
56 #define MAX_EXTRA_PROCSETS 128 | |
57 | |
58 emit_extra_procsets(schem) | |
59 struct schem *schem; | |
60 { | |
61 static char *procset_list[MAX_EXTRA_PROCSETS]; | |
62 static int nprocsets; | |
63 register struct schemobj *obj; | |
64 register char *psname; | |
65 register int i; | |
66 register FILE *f; | |
67 char buf[512]; | |
68 | |
69 for (obj = schem->obj_next; obj != (struct schemobj *)schem; | |
70 obj = obj->obj_next) { | |
71 if (obj->obj_type != OBJTYPE_COMMENT) | |
72 continue; | |
73 if (strncmp(obj->commentobj_text, "Need procset: ", 14)) | |
74 continue; | |
75 psname = obj->commentobj_text + 14; | |
76 if (!psname[0]) | |
77 continue; | |
78 /* have we already seen it? */ | |
79 for (i = 0; i < nprocsets; i++) | |
80 if (!strcmp(procset_list[i], psname)) | |
81 break; | |
82 if (i < nprocsets) | |
83 continue; | |
84 if (nprocsets >= MAX_EXTRA_PROCSETS) { | |
85 fprintf(stderr, "%s: line %d: too many procsets\n", | |
86 schem->orig_filename, obj->obj_lineno); | |
87 exit(1); | |
88 } | |
89 /* get it and put it out */ | |
90 f = find_symlib_file(psname, NULL); | |
91 if (!f) { | |
92 fprintf(stderr, "procset %s not found (%s line %d)\n", | |
93 psname, schem->orig_filename, obj->obj_lineno); | |
94 exit(1); | |
95 } | |
96 while ((i = fread(buf, 1, sizeof buf, f)) > 0) | |
97 fwrite(buf, 1, i, stdout); | |
98 fclose(f); | |
99 procset_list[nprocsets++] = psname; | |
100 } | |
101 } |