FreeCalypso > hg > ueda-linux
comparison pads2gpcb/decals.c @ 40:1c37bec20596
pads2gpcb: slowly working on the decal processing logic
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 11 Jan 2016 08:12:40 +0000 |
parents | |
children | a2d304ec3817 |
comparison
equal
deleted
inserted
replaced
39:242f73e61ef0 | 40:1c37bec20596 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <ctype.h> | |
4 #include <string.h> | |
5 #include <strings.h> | |
6 #include "globals.h" | |
7 #include "struct.h" | |
8 | |
9 extern long convert_input_dim(); | |
10 | |
11 static struct part_decal *current_decal; | |
12 static struct footprint_body fpbody; | |
13 static struct footprint_pad *pins_array; | |
14 static int num_drawing_pieces, num_padstack_defs; | |
15 static int num_text_items, num_attr_labels; | |
16 | |
17 static void | |
18 enter_decal() | |
19 { | |
20 struct part_decal *p, **pp; | |
21 char *name = input_line_fields[0]; | |
22 | |
23 for (pp = &part_decal_list; p = *pp; pp = &p->next) | |
24 if (!strcmp(p->name, name)) { | |
25 fprintf(stderr, | |
26 "%s line %d: decal name \"%s\" already defined\n", | |
27 input_filename, input_lineno, name); | |
28 exit(1); | |
29 } | |
30 p = malloc(sizeof(struct part_decal) + strlen(name) + 1); | |
31 if (!p) { | |
32 perror("malloc of struct part_decal"); | |
33 exit(1); | |
34 } | |
35 p->name = (char *)(p + 1); | |
36 strcpy(p->name, name); | |
37 p->body = 0; | |
38 p->next = 0; | |
39 **pp = p; | |
40 current_decal = p; | |
41 } | |
42 | |
43 static void | |
44 get_line_internal() | |
45 { | |
46 if (!get_input_line()) { | |
47 fprintf(stderr, | |
48 "error: EOF in the middle of a part decal definition\n"); | |
49 exit(1); | |
50 } | |
51 } | |
52 | |
53 static void | |
54 one_drawing_piece() | |
55 { | |
56 int ncoord, i; | |
57 | |
58 /* just skip it for now */ | |
59 get_line_internal(); | |
60 parse_input_line_fields(); | |
61 if (input_line_nfields < 2) { | |
62 fprintf(stderr, | |
63 "%s line %d: expected piece header line giving # of coords\n", | |
64 input_filename, input_lineno); | |
65 exit(1); | |
66 } | |
67 ncoord = atoi(input_line_fields[1]); | |
68 for (i = 0; i < ncoord; i++) | |
69 get_line_internal(); | |
70 } | |
71 | |
72 static void | |
73 one_text_item() | |
74 { | |
75 /* just skip it for now */ | |
76 get_line_internal(); | |
77 get_line_internal(); | |
78 get_line_internal(); | |
79 } | |
80 | |
81 static void | |
82 one_attr_label() | |
83 { | |
84 /* just skip it for now */ | |
85 get_line_internal(); | |
86 get_line_internal(); | |
87 get_line_internal(); | |
88 } | |
89 | |
90 static void | |
91 read_pindef_line(idx) | |
92 { | |
93 get_line_internal(); | |
94 if (input_line_buf[0] != 'T') { | |
95 fprintf(stderr, "%s line %d: 'T' line expected\n", | |
96 input_filename, input_lineno); | |
97 exit(1); | |
98 } | |
99 parse_input_line_fields(); | |
100 if (input_line_nfields != 5) { | |
101 fprintf(stderr, "%s line %d: expected 5 fields in 'T' line\n", | |
102 input_filename, input_lineno); | |
103 exit(1); | |
104 } | |
105 input_line_fields[0]++; | |
106 | |
107 if (atoi(input_line_fields[4]) != i + 1) { | |
108 fprintf(stderr, | |
109 "%s line %d: expected %d in the pin number field\n", | |
110 input_filename, input_lineno); | |
111 exit(1); | |
112 } | |
113 pins_array[i].x1 = convert_input_dim(input_line_fields[0]); | |
114 pins_array[i].y1 = -convert_input_dim(input_line_fields[1]); | |
115 } | |
116 | |
117 static void | |
118 one_padstack_def() | |
119 { | |
120 | |
121 | |
122 } | |
123 | |
124 static void | |
125 process_one_decal() | |
126 { | |
127 int i; | |
128 | |
129 if (input_line_nfields < 7 || input_line_nfields > 9) { | |
130 fprintf(stderr, | |
131 "%s line %d: expected beginning of part decal definition, wrong # of fields\n", | |
132 input_filename, input_lineno); | |
133 exit(1); | |
134 } | |
135 enter_decal(); | |
136 bzero(&fpbody, sizeof fpbody); | |
137 if (input_line_fields[1][0] != 'I' && input_line_fields[1][0] != 'M' | |
138 || input_line_fields[1][1]) { | |
139 fprintf(stderr, "%s line %d: expected 'I' or 'M' in field 1\n", | |
140 input_filename, input_lineno); | |
141 exit(1); | |
142 } | |
143 fpbody.src_units = input_line_fields[1][0]; | |
144 if (input_units_global == 'B') | |
145 input_units_current = 'B'; | |
146 else | |
147 input_units_current = fpbody.src_units; | |
148 fpbody.mark_x = convert_input_dim(input_line_fields[2]); | |
149 fpbody.mark_y = -convert_input_dim(input_line_fields[3]); | |
150 num_drawing_pieces = atoi(input_line_fields[4]); | |
151 fpbody.npins = atoi(input_line_fields[5]); | |
152 num_padstack_defs = atoi(input_line_fields[6]); | |
153 if (input_line_nfields > 7) | |
154 num_text_items = atoi(input_line_fields[7]); | |
155 else | |
156 num_text_items = 0; | |
157 if (input_line_nfields > 8) | |
158 num_attr_labels = atoi(input_line_fields[8]); | |
159 else | |
160 num_attr_labels = 0; | |
161 | |
162 /* sanity checks */ | |
163 if (fpbody.npins < 1) { | |
164 fprintf(stderr, "%s line %d: # of terminals %d < 1\n", | |
165 input_filename, input_lineno, fpbody.npins); | |
166 exit(1); | |
167 } | |
168 if (num_padstack_defs < 1) { | |
169 fprintf(stderr, "%s line %d: # of pad stack defs %d < 1\n", | |
170 input_filename, input_lineno, num_padstack_defs); | |
171 exit(1); | |
172 } | |
173 | |
174 /* done parsing the header line, initialize some misc */ | |
175 fpbody.refdes_scale = 100; | |
176 | |
177 /* read and process the miscellany */ | |
178 for (i = 0; i < num_drawing_pieces; i++) | |
179 one_drawing_piece(); | |
180 for (i = 0; i < num_text_items; i++) | |
181 one_text_item(); | |
182 for (i = 0; i < num_attr_labels; i++) | |
183 one_attr_label(); | |
184 | |
185 /* the meat: allocate and fill the pins array */ | |
186 pins_array = malloc(sizeof(struct footprint_pad) * fpbody.npins); | |
187 if (!pins_array) { | |
188 perror("malloc of the pins array"); | |
189 exit(1); | |
190 } | |
191 fpbody.pins = pins_array; | |
192 bzero(pins_array, sizeof(struct footprint_pad) * fpbody.npins); | |
193 for (i = 0; i < fpbody.npins; i++) | |
194 read_pindef_line(i); | |
195 /* read and process the pad stack definitions */ | |
196 for (i = 0; i < num_padstack_defs; i++) | |
197 one_padstack_def(); | |
198 | |
199 | |
200 } | |
201 | |
202 process_partdecal_section() | |
203 { | |
204 for (;;) { | |
205 if (!get_input_line()) { | |
206 fprintf(stderr, "error: EOF in PARTDECAL section\n"); | |
207 exit(1); | |
208 } | |
209 if (input_line_buf[0] == '*') { | |
210 parse_starline(); | |
211 if (strcmp(input_line_starkw, "REMARK")) | |
212 break; | |
213 else | |
214 continue; | |
215 } | |
216 parse_input_line_fields(); | |
217 if (input_line_nfields) | |
218 process_one_decal(); | |
219 } | |
220 } |