comparison netdiff/convert/protel2donl.c @ 132:31ae8105aaa0

netdiff project started with protel2donl
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 06 Sep 2020 22:48:09 +0000
parents
children 603d8da32fd0
comparison
equal deleted inserted replaced
131:125fc4ef7eb0 132:31ae8105aaa0
1 /*
2 * This program converts a Protel netlist (exported from Altium) into our
3 * Diff-Oriented Netlist (DONL) format.
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10
11 static char *infname;
12 static FILE *inf;
13 static char linebuf[80], netname[80];
14 static int lineno;
15
16 static
17 get_line()
18 {
19 char *cp;
20
21 if (!fgets(linebuf, sizeof linebuf, inf))
22 return(0);
23 lineno++;
24 cp = index(linebuf, '\n');
25 if (!cp) {
26 fprintf(stderr, "%s line %d: missing newline\n",
27 infname, lineno);
28 exit(1);
29 }
30 *cp = '\0';
31 if (cp > linebuf && cp[-1] == '\r')
32 *--cp = '\0';
33 return(1);
34 }
35
36 static void
37 get_line_notfirst()
38 {
39 if (!get_line()) {
40 fprintf(stderr, "error: unexpected EOF in input\n");
41 exit(1);
42 }
43 if (!strcmp(linebuf, "[")) {
44 fprintf(stderr, "%s line %d: [ NOT expected\n",
45 infname, lineno);
46 exit(1);
47 }
48 if (!strcmp(linebuf, "(")) {
49 fprintf(stderr, "%s line %d: ( NOT expected\n",
50 infname, lineno);
51 exit(1);
52 }
53 }
54
55 static void
56 skip_component_block()
57 {
58 int i;
59
60 for (i = 0; i < 6; i++) {
61 get_line_notfirst();
62 if (!strcmp(linebuf, "]")) {
63 fprintf(stderr, "%s line %d: ] NOT expected\n",
64 infname, lineno);
65 exit(1);
66 }
67 if (!strcmp(linebuf, ")")) {
68 fprintf(stderr, "%s line %d: ) NOT expected\n",
69 infname, lineno);
70 exit(1);
71 }
72 }
73 get_line_notfirst();
74 if (strcmp(linebuf, "]")) {
75 fprintf(stderr, "%s line %d: expected ]\n", infname, lineno);
76 exit(1);
77 }
78 }
79
80 static void
81 process_net_point()
82 {
83 char *cp;
84
85 cp = index(linebuf, '-');
86 if (!cp) {
87 fprintf(stderr, "%s line %d: missing \'-\' in net point\n",
88 infname, lineno);
89 exit(1);
90 }
91 if (cp == linebuf) {
92 fprintf(stderr, "%s line %d: refdes part is empty\n",
93 infname, lineno);
94 exit(1);
95 }
96 if (!cp[1]) {
97 fprintf(stderr, "%s line %d: pin number part is empty\n",
98 infname, lineno);
99 exit(1);
100 }
101 *cp = '.'; /* our PADS-like convention */
102 printf("%s\t%s\n", netname, lineno);
103 }
104
105 static void
106 process_net_block()
107 {
108 get_line_notfirst();
109 if (!strcmp(linebuf, "]")) {
110 fprintf(stderr, "%s line %d: ] NOT expected\n",
111 infname, lineno);
112 exit(1);
113 }
114 if (!strcmp(linebuf, ")")) {
115 fprintf(stderr, "%s line %d: ) NOT expected\n",
116 infname, lineno);
117 exit(1);
118 }
119 if (!linebuf[0]) {
120 fprintf(stderr, "%s line %d: empty net name\n",
121 infname, lineno);
122 exit(1);
123 }
124 strcpy(netname, linebuf);
125 for (;;) {
126 get_line_notfirst();
127 if (!strcmp(linebuf, "]")) {
128 fprintf(stderr, "%s line %d: ] NOT expected\n",
129 infname, lineno);
130 exit(1);
131 }
132 if (!strcmp(linebuf, ")"))
133 break;
134 process_net_point();
135 }
136 }
137
138 main(argc, argv)
139 char **argv;
140 {
141 if (argc != 2) {
142 fprintf(stderr, "usage: %s protel-netlist-file\n", argv[0]);
143 exit(1);
144 }
145 infname = argv[1];
146 inf = fopen(infname, "r");
147 if (!inf) {
148 perror(infname);
149 exit(1);
150 }
151 for (;;) {
152 if (!get_line())
153 break;
154 if (!strcmp(linebuf, "["))
155 skip_component_block();
156 else if (!strcmp(linebuf, "("))
157 process_net_block();
158 else {
159 fprintf(stderr,
160 "%s line %d: expected beginning of block\n",
161 infname, lineno);
162 exit(1);
163 }
164 }
165 exit(0);
166 }