FreeCalypso > hg > ueda-linux
comparison ueda/uschem-netlist/pcbout.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 * Netlist output in the gEDA/PCB format | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <strings.h> | |
7 #include "../libueda/mcl.h" | |
8 #include "netlist.h" | |
9 | |
10 extern struct net **sorted_named_nets; | |
11 extern int total_named_nets; | |
12 extern struct net *unnamed_net_list; | |
13 | |
14 extern FILE *outfile; | |
15 extern int allow_unnamed_nets, check_completeness, sort_netlist_output; | |
16 | |
17 static int unnamed_net_count; | |
18 | |
19 static | |
20 emit_net(netname, points) | |
21 char *netname; | |
22 struct pinconn *points; | |
23 { | |
24 register struct pinconn *pc; | |
25 int linelen, linefresh; | |
26 register int i; | |
27 | |
28 fprintf(outfile, "%s\t", netname); | |
29 linelen = (strlen(netname) + 8) & ~7; | |
30 for (pc = points, linefresh = 1; pc; pc = pc->next_in_net) { | |
31 i = strlen(pc->comp->mclcomp->name) + strlen(pc->pinnum) + 2; | |
32 if (!linefresh && linelen + i > 78) { | |
33 fputs(" \\\n\t", outfile); | |
34 linelen = 8; | |
35 linefresh = 1; | |
36 } | |
37 if (linefresh) | |
38 i--; | |
39 else | |
40 putc(' ', outfile); | |
41 fprintf(outfile, "%s-%s", pc->comp->mclcomp->name, pc->pinnum); | |
42 linelen += i; | |
43 linefresh = 0; | |
44 } | |
45 putc('\n', outfile); | |
46 } | |
47 | |
48 static | |
49 emit_named_net(net) | |
50 register struct net *net; | |
51 { | |
52 if (net->npoints == 0) { | |
53 fprintf(stderr, "Net %s has no points, discarded\n", | |
54 net->netname); | |
55 return; | |
56 } | |
57 if (net->npoints == 1 && check_completeness) | |
58 fprintf(stderr, "Warning: net %s has only 1 point\n", | |
59 net->netname); | |
60 emit_net(net->netname, net->pins); | |
61 } | |
62 | |
63 static | |
64 do_sorted_named_nets() | |
65 { | |
66 register struct net **np; | |
67 register int i; | |
68 | |
69 for (np = sorted_named_nets, i = 0; i < total_named_nets; np++, i++) | |
70 emit_named_net(*np); | |
71 } | |
72 | |
73 static | |
74 report_singular_unnamed_net(net) | |
75 struct net *net; | |
76 { | |
77 register struct pinconn *pc; | |
78 | |
79 pc = net->pins; | |
80 fprintf(stderr, | |
81 "Pin %s-%s assigned to a singular unnamed net (%s line %d)\n", | |
82 pc->comp->mclcomp->name, pc->pinnum, pc->origin_file, | |
83 pc->origin_line); | |
84 } | |
85 | |
86 static | |
87 do_unnamed_nets() | |
88 { | |
89 register struct net *net; | |
90 char bogonetname[32]; | |
91 | |
92 for (net = unnamed_net_list; net; net = net->next) { | |
93 if (net->npoints == 0) { | |
94 /* | |
95 * These can only result from previous errors, | |
96 * i.e., we thought we had a pin going to an unnamed | |
97 * net, allocated a nethead for it, but the pin | |
98 * turned out to be invalid. | |
99 * | |
100 * Here we silently discard these aberrations w/o | |
101 * printing anything because the original error | |
102 * must have already been reported. | |
103 */ | |
104 continue; | |
105 } | |
106 if (net->npoints == 1) { | |
107 report_singular_unnamed_net(net); | |
108 /* don't emit these */ | |
109 continue; | |
110 } | |
111 /* a *real* unnamed net */ | |
112 unnamed_net_count++; | |
113 if (allow_unnamed_nets) { | |
114 sprintf(bogonetname, "unnamed_net_%d", | |
115 unnamed_net_count); | |
116 emit_net(bogonetname, net->pins); | |
117 } | |
118 } | |
119 if (unnamed_net_count && !allow_unnamed_nets) | |
120 fprintf(stderr, "%d unnamed nets left out\n", | |
121 unnamed_net_count); | |
122 } | |
123 | |
124 pcb_netlist_output() | |
125 { | |
126 open_output_file(); | |
127 if (sort_netlist_output) { | |
128 sort_named_nets(); | |
129 do_sorted_named_nets(); | |
130 } else | |
131 named_net_forall(emit_named_net); | |
132 do_unnamed_nets(); | |
133 if (check_completeness) | |
134 check_for_unused_comps(); | |
135 } |