comparison ueda/libuschem/wrschem.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 * Schematic write-out
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include "schemstruct.h"
8 #include "writerint.h"
9
10 extern FILE *reopen_schem_for_graphblocks();
11
12 extern struct drawing_size_kwtab drawing_size_keywords[];
13
14 struct schem_write_state schem_write_state;
15
16 write_schem(schem, outf)
17 struct schem *schem;
18 FILE *outf;
19 {
20 register struct schemobj *obj;
21
22 schem_write_state.schem = schem;
23 schem_write_state.outf = outf;
24 schem_write_state.orig_file = reopen_schem_for_graphblocks(schem);
25 wrschem_emit_schemline(schem);
26 putc('\n', outf);
27
28 for (obj = schem->obj_next; obj != (struct schemobj *)schem;
29 obj = obj->obj_next)
30 wrschem_emit_object(obj);
31
32 if (schem_write_state.orig_file)
33 fclose(schem_write_state.orig_file);
34 }
35
36 wrschem_emit_schemline(schem)
37 register struct schem *schem;
38 {
39 register struct drawing_size_kwtab *kwp;
40
41 if (!schem->is_graph) {
42 fprintf(schem_write_state.outf, "Schem nograph;\n");
43 return;
44 }
45 for (kwp = drawing_size_keywords; kwp->keyword; kwp++)
46 if (schem->graph_xsize == kwp->xdim &&
47 schem->graph_ysize == kwp->ydim) {
48 fprintf(schem_write_state.outf, "Schem graph %s;\n",
49 kwp->keyword);
50 return;
51 }
52 fprintf(schem_write_state.outf, "Schem graph %dx%d;\n",
53 schem->graph_xsize, schem->graph_ysize);
54 }
55
56 wrschem_emit_qstring(str)
57 char *str;
58 {
59 register char *cp;
60 register int c;
61
62 putc('\"', schem_write_state.outf);
63 for (cp = str; c = *cp; cp++) {
64 if (c == '\"' || c == '\\')
65 putc('\\', schem_write_state.outf);
66 putc(c, schem_write_state.outf);
67 }
68 putc('\"', schem_write_state.outf);
69 }
70
71 wrschem_emit_string(str)
72 register char *str;
73 {
74 if (schem_string_needs_quote(str))
75 wrschem_emit_qstring(str);
76 else
77 fputs(str, schem_write_state.outf);
78 }
79
80 schem_string_needs_quote(str)
81 char *str;
82 {
83 register char *cp;
84 register int c;
85
86 cp = str;
87 if (!*cp)
88 return(1); /* null strings can only be quoted */
89 while (c = *cp++)
90 switch (c) {
91 case ' ':
92 case '\t':
93 case '\n':
94 case '"':
95 case '%':
96 case '(':
97 case ')':
98 case ',':
99 case ';':
100 case '=':
101 case '{':
102 case '}':
103 return(1);
104 }
105 return(0);
106 }
107
108 wrschem_emit_object(obj)
109 register struct schemobj *obj;
110 {
111 switch (obj->obj_type) {
112 case OBJTYPE_COMPINST:
113 fputs("Component ", schem_write_state.outf);
114 wrschem_emit_string(obj->compobj_instname);
115 if (obj->compobj_isgraph) {
116 fputs(" graph ", schem_write_state.outf);
117 wrschem_emit_qstring(obj->compobj_graph_symname);
118 fprintf(schem_write_state.outf, " %d %d",
119 obj->compobj_x, obj->compobj_y);
120 if (obj->compobj_rotate)
121 fprintf(schem_write_state.outf, " rot %d",
122 obj->compobj_rotate);
123 if (obj->compobj_mirror)
124 fputs(" mirror", schem_write_state.outf);
125 }
126 if (obj->obj_decorations)
127 wrschem_emit_decor_block(obj);
128 fputs(";\n", schem_write_state.outf);
129 return;
130
131 case OBJTYPE_GRAPHSYM:
132 fputs("GraphSym ", schem_write_state.outf);
133 wrschem_emit_qstring(obj->compobj_graph_symname);
134 fprintf(schem_write_state.outf, " %d %d",
135 obj->compobj_x, obj->compobj_y);
136 if (obj->compobj_rotate)
137 fprintf(schem_write_state.outf, " rot %d",
138 obj->compobj_rotate);
139 if (obj->compobj_mirror)
140 fputs(" mirror", schem_write_state.outf);
141 if (obj->obj_decorations)
142 wrschem_emit_decor_block(obj);
143 fputs(";\n", schem_write_state.outf);
144 return;
145
146 case OBJTYPE_NET:
147 wrschem_emit_net(obj, "Net", 0);
148 return;
149
150 case OBJTYPE_GRAPHNET:
151 wrschem_emit_net(obj, "GraphNet", 1);
152 return;
153
154 case OBJTYPE_NETLINE:
155 fprintf(schem_write_state.outf, "NetLine (%d,%d) (%d,%d)",
156 obj->lineobj_x1, obj->lineobj_y1,
157 obj->lineobj_x2, obj->lineobj_y2);
158 if (obj->obj_decorations)
159 wrschem_emit_decor_block(obj);
160 fputs(";\n", schem_write_state.outf);
161 return;
162
163 case OBJTYPE_BUSSEG:
164 fprintf(schem_write_state.outf, "BusSeg (%d,%d) (%d,%d)",
165 obj->lineobj_x1, obj->lineobj_y1,
166 obj->lineobj_x2, obj->lineobj_y2);
167 if (obj->obj_decorations)
168 wrschem_emit_decor_block(obj);
169 fputs(";\n", schem_write_state.outf);
170 return;
171
172 case OBJTYPE_GRAPHBLOCK:
173 wrschem_emit_graphblock(obj->graphblockobj_body);
174 return;
175
176 case OBJTYPE_COMMENT:
177 fputs("Comment ", schem_write_state.outf);
178 wrschem_emit_qstring(obj->commentobj_text);
179 fputs(";\n", schem_write_state.outf);
180 return;
181
182 default:
183 fprintf(stderr,
184 "Fatal internal error: unknown obj type in wrschem_emit_object()\n");
185 abort();
186 }
187 }
188
189 /* for Net and GraphNet */
190 wrschem_emit_net(obj, keyword, isgraphnet)
191 register struct schemobj *obj;
192 char *keyword;
193 int isgraphnet;
194 {
195 register struct netpoint *netpt;
196
197 fprintf(schem_write_state.outf, "%s ", keyword);
198 if (obj->netobj_grouphead && obj->netobj_grouphead->netobj_netname)
199 wrschem_emit_string(obj->netobj_grouphead->netobj_netname);
200 else if (obj->netobj_netname)
201 wrschem_emit_string(obj->netobj_netname);
202 else
203 fputs("\"\"", schem_write_state.outf);
204
205 for (netpt = obj->netobj_points; netpt; netpt = netpt->netpt_next) {
206 putc(' ', schem_write_state.outf);
207 switch (netpt->netpt_type) {
208 case NETPT_TYPE_POINT:
209 fprintf(schem_write_state.outf, "(%d,%d)",
210 netpt->netpt_x, netpt->netpt_y);
211 break;
212 case NETPT_TYPE_PIN:
213 if (isgraphnet) {
214 fputs("Pin", schem_write_state.outf);
215 if (netpt->netpt_coord_valid)
216 fprintf(schem_write_state.outf,
217 "(%d,%d)",
218 netpt->netpt_x, netpt->netpt_y);
219 if (netpt->netpt_pin_nameref)
220 putc('=', schem_write_state.outf);
221 }
222 if (netpt->netpt_pin_nameref)
223 wrschem_emit_string(netpt->netpt_pin_nameref);
224 break;
225 case NETPT_TYPE_TJOIN:
226 fprintf(schem_write_state.outf, "Tjoin(%d,%d)",
227 netpt->netpt_x, netpt->netpt_y);
228 break;
229 case NETPT_TYPE_PSEUDO:
230 fprintf(schem_write_state.outf, "Pseudo(%d,%d)",
231 netpt->netpt_x, netpt->netpt_y);
232 break;
233 }
234 }
235
236 if (obj->obj_decorations)
237 wrschem_emit_decor_block(obj);
238 fputs(";\n", schem_write_state.outf);
239 }
240
241 wrschem_emit_graphblock(blk)
242 struct graphblock *blk;
243 {
244 char *keyword;
245
246 switch (blk->type) {
247 case GRAPHBLOCK_TYPE_PS:
248 keyword = "GraphBlockPS";
249 break;
250 case GRAPHBLOCK_TYPE_GSCHEM:
251 keyword = "GraphBlockG";
252 break;
253 default:
254 fprintf(stderr,
255 "Fatal internal error: unknown type in wrschem_emit_graphblock()\n");
256 abort();
257 }
258 fprintf(schem_write_state.outf, "%s {\n", keyword);
259 write_graphblock_to_file(blk, schem_write_state.orig_file,
260 schem_write_state.outf);
261 fputs("}\n", schem_write_state.outf);
262 }
263
264 wrschem_emit_decor_block(obj)
265 struct schemobj *obj;
266 {
267 register struct decoration *decor;
268
269 fputs(" {\n", schem_write_state.outf);
270 for (decor = obj->obj_decorations; decor; decor = decor->decor_next)
271 wrschem_emit_decor(decor);
272 putc('}', schem_write_state.outf);
273 }
274
275 wrschem_emit_decor(decor)
276 register struct decoration *decor;
277 {
278 switch (decor->decor_type) {
279 case DECOR_TYPE_ATTR:
280 fputs("\t(", schem_write_state.outf);
281 wrschem_emit_string(decor->decorattr_name);
282 putc('=', schem_write_state.outf);
283 wrschem_emit_qstring(decor->decorattr_value);
284 fputs(")\n", schem_write_state.outf);
285 return;
286
287 case DECOR_TYPE_DISPLAYATTR:
288 fputs("\tDisplayAttr ", schem_write_state.outf);
289 wrschem_emit_string(decor->decordisp_attr);
290 fprintf(schem_write_state.outf, " %d %d %d %d %d;\n",
291 decor->decordisp_x, decor->decordisp_y,
292 decor->decordisp_ptsize, decor->decordisp_rotate,
293 decor->decordisp_alignment);
294 return;
295
296 case DECOR_TYPE_DISPLAYNETNAME:
297 fprintf(schem_write_state.outf,
298 "\tDisplayNetName %d %d %d %d %d;\n",
299 decor->decordisp_x, decor->decordisp_y,
300 decor->decordisp_ptsize, decor->decordisp_rotate,
301 decor->decordisp_alignment);
302 return;
303
304 case DECOR_TYPE_PINTONET:
305 fputs("\tPinToNet ", schem_write_state.outf);
306 wrschem_emit_string(decor->decorpincon_pin);
307 putc(' ', schem_write_state.outf);
308 wrschem_emit_string(decor->decorpincon_netname);
309 fputs(";\n", schem_write_state.outf);
310 return;
311
312 case DECOR_TYPE_NOCONNECT:
313 fputs("\tNoConnect ", schem_write_state.outf);
314 wrschem_emit_string(decor->decorpincon_pin);
315 fputs(";\n", schem_write_state.outf);
316 return;
317
318 case DECOR_TYPE_SYMONPIN:
319 fputs("\tSymOnPin ", schem_write_state.outf);
320 wrschem_emit_string(decor->decorpinsym_pin);
321 putc(' ', schem_write_state.outf);
322 wrschem_emit_qstring(decor->decorpinsym_symname);
323 if (decor->decorpinsym_mirror)
324 fputs(" mirror", schem_write_state.outf);
325 fputs(";\n", schem_write_state.outf);
326 return;
327
328 case DECOR_TYPE_GRAPHBLOCK:
329 putc('\t', schem_write_state.outf);
330 wrschem_emit_graphblock(decor->decorgraph_body);
331 return;
332
333 case DECOR_TYPE_COMMENT:
334 fputs("\tComment ", schem_write_state.outf);
335 wrschem_emit_qstring(decor->decorcomment_text);
336 fputs(";\n", schem_write_state.outf);
337 return;
338
339 default:
340 fprintf(stderr,
341 "Fatal internal error: unknown decoration type in wrschem_emit_decor()\n");
342 abort();
343 }
344 }