FreeCalypso > hg > ueda-linux
comparison ueda/unet-utils/unet2protel.c @ 143:7c0fd80782c8
unet2protel utility added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 19 Sep 2020 23:46:46 +0000 |
parents | ueda/unet-utils/unet2pcb.c@47b5b8310cac |
children |
comparison
equal
deleted
inserted
replaced
142:7bdce91da1a5 | 143:7c0fd80782c8 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <strings.h> | |
5 #include "../libunet/unetrd.h" | |
6 #include "../libunet/nethash.h" | |
7 | |
8 extern struct net *enter_net_object(); | |
9 extern struct net *find_net_by_name(); | |
10 extern struct net *net_list_head; | |
11 | |
12 static char *input_filename, *output_filename; | |
13 static struct unetrd_state rdstate; | |
14 static struct unetrd_out rdout; | |
15 static FILE *outFILE; | |
16 | |
17 struct netextra { | |
18 struct netmember *head; | |
19 struct netmember **tailp; | |
20 }; | |
21 | |
22 struct netmember { | |
23 char *name; | |
24 struct netmember *next; | |
25 }; | |
26 | |
27 static void | |
28 process_pin_connect(compname) | |
29 char *compname; | |
30 { | |
31 register struct net *n; | |
32 register struct netextra *nx; | |
33 register struct netmember *nm; | |
34 | |
35 n = find_net_by_name(rdout.connect_to_net); | |
36 nx = (struct netextra *)(n + 1); | |
37 nm = (struct netmember *) malloc(sizeof(struct netmember) + | |
38 strlen(compname) + | |
39 strlen(rdout.objname) + 2); | |
40 if (!nm) { | |
41 perror("malloc"); | |
42 exit(1); | |
43 } | |
44 nm->name = (char *)(nm + 1); | |
45 sprintf(nm->name, "%s-%s", compname, rdout.objname); | |
46 nm->next = 0; | |
47 *nx->tailp = nm; | |
48 nx->tailp = &nm->next; | |
49 } | |
50 | |
51 static void | |
52 process_component() | |
53 { | |
54 char compname[64]; | |
55 | |
56 strcpy(compname, rdout.objname); | |
57 for (;;) { | |
58 if (!read_unet_line(&rdstate, &rdout)) { | |
59 fprintf(stderr, "%s error: EOF in COMPONENT block\n", | |
60 input_filename); | |
61 exit(1); | |
62 } | |
63 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) | |
64 break; | |
65 switch(rdout.typecode) { | |
66 case UNETOBJ_PRIMITIVE: | |
67 case UNETOBJ_ALTNAME: | |
68 case UNETOBJ_ATTR: | |
69 continue; | |
70 case UNETOBJ_PIN: | |
71 if (rdout.connect_to_net) | |
72 process_pin_connect(compname); | |
73 continue; | |
74 case UNETOBJ_PINMAP: | |
75 fprintf(stderr, | |
76 "%s line %d: PINMAP objects not expected in unet2protel input\n", | |
77 input_filename, rdstate.lineno); | |
78 exit(1); | |
79 default: | |
80 fprintf(stderr, | |
81 "%s line %d: object type %s unexpected in COMPONENT block\n", | |
82 input_filename, rdstate.lineno, rdout.keyword); | |
83 exit(1); | |
84 } | |
85 } | |
86 } | |
87 | |
88 static void | |
89 process_input_unet() | |
90 { | |
91 struct net *n; | |
92 struct netextra *nx; | |
93 | |
94 open_unet_input_file(input_filename, &rdstate); | |
95 while (read_unet_line(&rdstate, &rdout)) { | |
96 switch(rdout.typecode) { | |
97 case UNETOBJ_CLOSINGBRACE: | |
98 fprintf(stderr, | |
99 "%s line %d: unexpected '}' outside of component block\n", | |
100 input_filename, rdstate.lineno); | |
101 exit(1); | |
102 case UNETOBJ_NET: | |
103 n = enter_net_object(rdout.objname, | |
104 sizeof(struct netextra)); | |
105 nx = (struct netextra *)(n + 1); | |
106 nx->head = 0; | |
107 nx->tailp = &nx->head; | |
108 continue; | |
109 case UNETOBJ_COMPONENT: | |
110 process_component(); | |
111 continue; | |
112 case UNETOBJ_STARPOINT: | |
113 fprintf(stderr, | |
114 "error: STARPOINT objects not expected in unet2protel input (%s line %d)\n", | |
115 input_filename, rdstate.lineno); | |
116 exit(1); | |
117 default: | |
118 fprintf(stderr, | |
119 "%s line %d: unexpected object type %s\n", | |
120 input_filename, rdstate.lineno, rdout.keyword); | |
121 exit(1); | |
122 } | |
123 } | |
124 } | |
125 | |
126 static | |
127 emit_net(net) | |
128 struct net *net; | |
129 { | |
130 struct netextra *nx; | |
131 register struct netmember *nm; | |
132 | |
133 nx = (struct netextra *)(net + 1); | |
134 fprintf(outFILE, "(\n%s\n", net->name); | |
135 for (nm = nx->head; nm; nm = nm->next) | |
136 fprintf(outFILE, "%s\n", nm->name); | |
137 fputs(")\n", outFILE); | |
138 } | |
139 | |
140 static void | |
141 generate_output() | |
142 { | |
143 register struct net *n; | |
144 | |
145 if (output_filename) { | |
146 outFILE = fopen(output_filename, "w"); | |
147 if (!outFILE) { | |
148 perror(output_filename); | |
149 exit(1); | |
150 } | |
151 } else | |
152 outFILE = stdout; | |
153 for (n = net_list_head; n; n = n->nextinlist) | |
154 emit_net(n); | |
155 if (outFILE != stdout) | |
156 fclose(outFILE); | |
157 } | |
158 | |
159 main(argc, argv) | |
160 char **argv; | |
161 { | |
162 if (argc < 2 || argc > 3) { | |
163 fprintf(stderr, "usage: %s input.unet [output-file]\n", | |
164 argv[0]); | |
165 exit(1); | |
166 } | |
167 input_filename = argv[1]; | |
168 output_filename = argv[2]; | |
169 process_input_unet(); | |
170 generate_output(); | |
171 exit(0); | |
172 } |