Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 11 | ||
---|---|---|---|
Line 60... | Line 60... | ||
60 | * Mike put it here |
60 | * Mike put it here |
61 | * |
61 | * |
62 | * |
62 | * |
63 | * Revision 1.24 2000/10/04 10:37:10 10:37:10 mjames (Mike James) |
63 | * Revision 1.24 2000/10/04 10:37:10 10:37:10 mjames (Mike James) |
64 | * Modified for Vertical2 : support COMPONENTS and SIGNALS |
64 | * Modified for Vertical2 : support COMPONENTS and SIGNALS |
65 | * |
65 | * |
66 | * Revision 1.24 2000/10/04 10:37:10 10:37:10 mjames (Mike James) |
66 | * Revision 1.24 2000/10/04 10:37:10 10:37:10 mjames (Mike James) |
67 | * Part of Release PSAVAT01 |
67 | * Part of Release PSAVAT01 |
68 | * |
68 | * |
69 | * Revision 1.23 2000/10/02 11:04:21 11:04:21 mjames (Mike James) |
69 | * Revision 1.23 2000/10/02 11:04:21 11:04:21 mjames (Mike James) |
70 | * new_vhdl |
70 | * new_vhdl |
71 | * |
71 | * |
72 | * Revision 1.22 2000/09/27 14:42:21 14:42:21 mjames (Mike James) |
72 | * Revision 1.22 2000/09/27 14:42:21 14:42:21 mjames (Mike James) |
73 | * Part of Release Sep_27_ST_2000 |
73 | * Part of Release Sep_27_ST_2000 |
74 | * |
74 | * |
75 | * Revision 1.21 2000/09/21 10:15:51 10:15:51 mjames (Mike James) |
75 | * Revision 1.21 2000/09/21 10:15:51 10:15:51 mjames (Mike James) |
76 | * Part of Release Sep21Alpha |
76 | * Part of Release Sep21Alpha |
77 | * |
77 | * |
78 | * Revision 1.20 2000/08/25 09:57:16 09:57:16 mjames (Mike James) |
78 | * Revision 1.20 2000/08/25 09:57:16 09:57:16 mjames (Mike James) |
79 | * Part of Release Aug25_alpha |
79 | * Part of Release Aug25_alpha |
80 | * |
80 | * |
81 | * Revision 1.19 2000/08/16 08:57:33 08:57:33 mjames (Mike James) |
81 | * Revision 1.19 2000/08/16 08:57:33 08:57:33 mjames (Mike James) |
82 | * Part of Release CD01_Aug2000 |
82 | * Part of Release CD01_Aug2000 |
83 | * |
83 | * |
84 | * Revision 1.18 2000/08/14 14:45:13 14:45:13 mjames (Mike James) |
84 | * Revision 1.18 2000/08/14 14:45:13 14:45:13 mjames (Mike James) |
85 | * Part of Release Aug_14_2000 |
85 | * Part of Release Aug_14_2000 |
86 | * |
86 | * |
87 | * Revision 1.17 2000/08/11 08:30:34 08:30:34 mjames (Mike James) |
87 | * Revision 1.17 2000/08/11 08:30:34 08:30:34 mjames (Mike James) |
88 | * Part of Release Aug_11_2000 |
88 | * Part of Release Aug_11_2000 |
89 | * |
89 | * |
90 | * Revision 1.16 2000/08/09 10:31:49 10:31:49 mjames (Mike James) |
90 | * Revision 1.16 2000/08/09 10:31:49 10:31:49 mjames (Mike James) |
91 | * Part of Release Aug__9_2000 |
91 | * Part of Release Aug__9_2000 |
92 | * |
92 | * |
93 | * Revision 1.15 2000/05/31 11:43:00 11:43:00 mjames (Mike James) |
93 | * Revision 1.15 2000/05/31 11:43:00 11:43:00 mjames (Mike James) |
94 | * Part of Release May_31_2000 |
94 | * Part of Release May_31_2000 |
95 | * |
95 | * |
96 | * Revision 1.14 2000/05/08 17:01:40 17:01:40 mjames (Mike James) |
96 | * Revision 1.14 2000/05/08 17:01:40 17:01:40 mjames (Mike James) |
97 | * Part of Release May__8_2000 |
97 | * Part of Release May__8_2000 |
98 | * |
98 | * |
99 | * Revision 1.13 2000/05/08 16:59:33 16:59:33 mjames (Mike James) |
99 | * Revision 1.13 2000/05/08 16:59:33 16:59:33 mjames (Mike James) |
100 | * Part of Release May__8_2000 |
100 | * Part of Release May__8_2000 |
101 | * |
101 | * |
102 | * Revision 1.12 2000/05/08 16:57:10 16:57:10 mjames (Mike James) |
102 | * Revision 1.12 2000/05/08 16:57:10 16:57:10 mjames (Mike James) |
103 | * Part of Release May__8_2000 |
103 | * Part of Release May__8_2000 |
104 | * |
104 | * |
105 | * Revision 1.11 2000/03/08 16:19:31 16:19:31 mjames (Mike James) |
105 | * Revision 1.11 2000/03/08 16:19:31 16:19:31 mjames (Mike James) |
106 | * New version including PC |
106 | * New version including PC |
107 | * |
107 | * |
108 | * Revision 1.8 2000/01/20 15:58:50 15:58:50 mjames (Mike James) |
108 | * Revision 1.8 2000/01/20 15:58:50 15:58:50 mjames (Mike James) |
109 | * Part of Release R22 |
109 | * Part of Release R22 |
110 | * |
110 | * |
111 | * Revision 1.7 99/12/22 11:15:31 11:15:31 mjames (Mike James) |
111 | * Revision 1.7 99/12/22 11:15:31 11:15:31 mjames (Mike James) |
112 | * Part of Release Dec_22_1999 |
112 | * Part of Release Dec_22_1999 |
113 | * |
113 | * |
114 | * Revision 1.6 99/06/25 14:35:51 14:35:51 mjames (Mike James) |
114 | * Revision 1.6 99/06/25 14:35:51 14:35:51 mjames (Mike James) |
115 | * Added in reference to expression.h, but no changes made |
115 | * Added in reference to expression.h, but no changes made |
116 | * to the function of acfread yet. |
116 | * to the function of acfread yet. |
117 | * |
117 | * |
118 | * Revision 1.5 99/05/04 09:52:52 09:52:52 mjames (Mike James) |
118 | * Revision 1.5 99/05/04 09:52:52 09:52:52 mjames (Mike James) |
119 | * General checkin |
119 | * General checkin |
120 | * |
120 | * |
121 | * Revision 1.4 98/02/11 11:27:19 11:27:19 mjames (Mike James) |
121 | * Revision 1.4 98/02/11 11:27:19 11:27:19 mjames (Mike James) |
122 | * Checked in for version 6.2a |
122 | * Checked in for version 6.2a |
123 | * |
123 | * |
124 | * Revision 1.3 97/04/23 08:43:25 08:43:25 mjames (Mike James) |
124 | * Revision 1.3 97/04/23 08:43:25 08:43:25 mjames (Mike James) |
125 | * CHecked in for release rel23041997 |
125 | * CHecked in for release rel23041997 |
126 | * |
126 | * |
127 | * Revision 1.2 96/12/23 15:17:00 15:17:00 mjames (Mike James) |
127 | * Revision 1.2 96/12/23 15:17:00 15:17:00 mjames (Mike James) |
128 | * Altered because find_socket takes a reference |
128 | * Altered because find_socket takes a reference |
129 | * to the head-of-list-pointer noth the pointer itself. |
129 | * to the head-of-list-pointer noth the pointer itself. |
130 | * |
130 | * |
131 | * Revision 1.1 96/12/23 10:26:21 10:26:21 mjames (Mike James) |
131 | * Revision 1.1 96/12/23 10:26:21 10:26:21 mjames (Mike James) |
132 | * Initial revision * */ |
132 | * Initial revision * */ |
133 | 133 | ||
134 | #include <ctype.h> |
- | |
135 | #include <regex.h> |
- | |
136 | #include <stdio.h> |
134 | #include <stdio.h> |
137 | #include <stdlib.h> |
- | |
138 | #include <string.h> |
135 | #include <string.h> |
- | 136 | #include <stdlib.h> |
|
- | 137 | #include <ctype.h> |
|
- | 138 | ||
139 | #include <sys/types.h> |
139 | #include <sys/types.h> |
- | 140 | #include <regex.h> |
|
140 | 141 | ||
141 | /* TCL/Tk declarations */ |
142 | /* TCL/Tk declarations */ |
142 | #include "cmdlog.h" |
- | |
143 | #include "cmdparse.h" |
- | |
144 | #include "database.h" |
143 | #include "vertcl_main.h" |
145 | #include "expression.h" |
144 | #include "expression.h" |
146 | #include "generic.h" |
145 | #include "generic.h" |
- | 146 | #include "database.h" |
|
147 | #include "routing.h" |
147 | #include "routing.h" |
- | 148 | #include "cmdparse.h" |
|
- | 149 | #include "cmdlog.h" |
|
148 | #include "sorting.h" |
150 | #include "sorting.h" |
149 | #include "vertcl_main.h" |
- | |
150 | 151 | ||
151 | #ident \ |
- | |
- | 152 | ||
152 | "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/sorting.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $"; |
153 | #ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/sorting.c,v 1.1.1.1 2003/11/04 23:34:57 mjames Exp $"; |
- | 154 | ||
153 | 155 | ||
154 | /* the comparison function : requires upgrade for checking : |
156 | /* the comparison function : requires upgrade for checking : |
155 | A1...A10 then B1..B10 or is it 1a..10a then 1b..10b */ |
157 | A1...A10 then B1..B10 or is it 1a..10a then 1b..10b */ |
156 | #if defined SORT_ORIGINAL |
158 | #if defined SORT_ORIGINAL |
157 | static int sort_nodes_compar (const void *p, const void *q) |
159 | static int sort_nodes_compar(const void * p,const void * q) |
158 | { |
- | |
159 | char *s1 = (*(node_t **) p)->identifier; |
160 | { char * s1 = (*(node_t **)p)->identifier; |
160 | char *s2 = (*(node_t **) q)->identifier; |
161 | char * s2 = (*(node_t **)q)->identifier; |
161 | 162 | ||
162 | int l1 = strlen (s1); |
163 | int l1 = strlen(s1); |
163 | int l2 = strlen (s2); |
164 | int l2 = strlen(s2); |
164 | if (l1 == l2) /* only call strcmp() for same length strings |
165 | if(l1==l2) /* only call strcmp() for same length strings |
165 | This makes '2' smaller than '19' */ |
166 | This makes '2' smaller than '19' */ |
166 | return strcmp (s1, s2); |
167 | return strcmp(s1,s2); |
167 | else |
168 | else |
168 | return l1 - l2; /* if different lengths, use the shorter name */ |
169 | return l1-l2; /* if different lengths, use the shorter name */ |
169 | } |
170 | } |
170 | #else |
171 | #else |
171 | 172 | ||
- | 173 | ||
172 | /* this sort works for alpha - numeric strings : A1 A2 |
174 | /* this sort works for alpha - numeric strings : A1 A2 |
173 | use SWAP command to swap identifiers */ |
175 | use SWAP command to swap identifiers */ |
174 | static int sort_nodes_compar (const void *p, const void *q) |
176 | static int sort_nodes_compar(const void * p,const void * q) |
175 | { |
177 | { |
176 | char *s1 = (*(node_t **) p)->id_alpha_chars; |
178 | char * s1 = (*(node_t **)p)->id_alpha_chars; |
177 | char *s2 = (*(node_t **) q)->id_alpha_chars; |
179 | char * s2 = (*(node_t **)q)->id_alpha_chars; |
178 | 180 | ||
179 | int l1 = (*(node_t **) p)->id_alpha_cnt; |
181 | int l1 = (*(node_t **)p)->id_alpha_cnt; |
180 | int l2 = (*(node_t **) q)->id_alpha_cnt; |
182 | int l2 = (*(node_t **)q)->id_alpha_cnt; |
181 | int diff = 0; |
183 | int diff = 0; |
182 | /* |
184 | /* |
183 | printf("cmp p: a %3s[%2d] n %3s[%2d]\n", |
185 | printf("cmp p: a %3s[%2d] n %3s[%2d]\n", |
184 | (*(node_t **)p)->id_alpha_chars, |
186 | (*(node_t **)p)->id_alpha_chars, |
185 | (*(node_t **)p)->id_alpha_cnt, |
187 | (*(node_t **)p)->id_alpha_cnt, |
186 | (*(node_t **)p)->id_numeric_chars, |
188 | (*(node_t **)p)->id_numeric_chars, |
187 | (*(node_t **)p)->id_numeric_cnt); |
189 | (*(node_t **)p)->id_numeric_cnt); |
188 | printf("cmp q: a %3s[%2d] n %3s[%2d]\n", |
190 | printf("cmp q: a %3s[%2d] n %3s[%2d]\n", |
189 | (*(node_t **)q)->id_alpha_chars, |
191 | (*(node_t **)q)->id_alpha_chars, |
190 | (*(node_t **)q)->id_alpha_cnt, |
192 | (*(node_t **)q)->id_alpha_cnt, |
191 | (*(node_t **)q)->id_numeric_chars, |
193 | (*(node_t **)q)->id_numeric_chars, |
192 | (*(node_t **)q)->id_numeric_cnt); |
194 | (*(node_t **)q)->id_numeric_cnt); |
193 | */ |
195 | */ |
194 | 196 | ||
195 | if (l1 == l2) |
197 | if(l1==l2) |
196 | { |
198 | { |
197 | /* only call strcmp() for same length strings */ |
199 | /* only call strcmp() for same length strings */ |
198 | diff = strncmp (s1, s2, l1); |
200 | diff = strncmp(s1,s2,l1); |
199 | /* |
201 | /* |
200 | printf("alpha cmp (%s,%s,%d) different %d\n",s1,s2,l1,diff); |
202 | printf("alpha cmp (%s,%s,%d) different %d\n",s1,s2,l1,diff); |
201 | */ |
203 | */ |
202 | if (diff == 0) /* alpha same */ |
204 | if (diff==0) /* alpha same */ |
203 | { |
205 | { |
204 | /* otherwise check the numeric parts of the strings */ |
206 | /* otherwise check the numeric parts of the strings */ |
205 | /* these have been decoded already */ |
207 | /* these have been decoded already */ |
206 | l1 = (*(node_t **) p)->pin_row; |
208 | l1 = (*(node_t **)p)->pin_row; |
207 | l2 = (*(node_t **) q)->pin_row; |
209 | l2 = (*(node_t **)q)->pin_row; |
208 | diff = l1 - l2; |
210 | diff = l1-l2; |
209 | /* |
211 | /* |
210 | printf("num different %d\n",diff); |
212 | printf("num different %d\n",diff); |
211 | */ |
213 | */ |
212 | } |
214 | } |
213 | } |
215 | } |
214 | else |
216 | else |
215 | { |
217 | { |
216 | diff = l1 - l2; /* if different alpha lengths, use the shorter name */ |
218 | diff = l1-l2; /* if different alpha lengths, use the shorter name */ |
217 | /* |
- | |
- | 219 | /* |
|
218 | printf("alpha len different %d\n",diff); |
220 | printf("alpha len different %d\n",diff); |
219 | */ |
- | |
- | 221 | */ |
|
220 | } |
222 | } |
221 | /* |
223 | /* |
222 | printf("diff: %d string %7s row %2d and %7s row%2d\n",diff, |
224 | printf("diff: %d string %7s row %2d and %7s row%2d\n",diff, |
223 | (*(node_t **)p)->identifier, |
225 | (*(node_t **)p)->identifier, |
224 | (*(node_t **)p)->pin_row, |
226 | (*(node_t **)p)->pin_row, |
225 | (*(node_t **)q)->identifier, |
227 | (*(node_t **)q)->identifier, |
226 | (*(node_t **)q)->pin_row); |
228 | (*(node_t **)q)->pin_row); |
227 | */ |
229 | */ |
228 | return diff; |
230 | return diff; |
229 | } |
231 | } |
230 | 232 | ||
231 | #endif |
233 | #endif |
232 | 234 | ||
- | 235 | ||
- | 236 | ||
- | 237 | ||
- | 238 | ||
233 | /* this function sorts all of the pin references on a chip |
239 | /* this function sorts all of the pin references on a chip |
234 | into alphanumeric order, and also generates a unique pin index for each pin |
240 | into alphanumeric order, and also generates a unique pin index for each pin |
235 | in the case of alphanumeric pin identifiers : pin A1 or 1A will become index 1 */ |
241 | in the case of alphanumeric pin identifiers : pin A1 or 1A will become index 1 */ |
236 | #define BIG 1000000 |
242 | #define BIG 1000000 |
237 | 243 | ||
238 | /* mapping table has no letter 'I' or 'O' in it */ |
244 | /* mapping table has no letter 'I' or 'O' in it */ |
239 | static unsigned char illegal_chars[] = PIN_MAP_ILLEGAL_CHARS; |
245 | static unsigned char illegal_chars[] = PIN_MAP_ILLEGAL_CHARS; |
240 | 246 | ||
241 | void sort_nodes (socket_t *chip, extract_xy_t mode) |
247 | void sort_nodes(socket_t * chip,extract_xy_t mode) { |
242 | { |
248 | node_t * nodes = chip-> nodes; |
243 | node_t *nodes = chip->nodes; |
249 | node_t ** sort_list; |
244 | node_t **sort_list; |
250 | |
245 | 251 | int alpha_seen = 0; |
|
246 | int alpha_seen = 0; |
252 | int numeric_seen = 0; |
247 | int numeric_seen = 0; |
253 | /* Use generics to find out if the user has defined pin row/column |
248 | /* Use generics to find out if the user has defined pin row/column |
254 | limits (in the case where top or bottom connector rows are not |
249 | limits (in the case where top or bottom connector rows are not |
255 | connected at all */ |
250 | connected at all */ |
256 | |
251 | 257 | generic_info_t gen[1]; |
|
252 | generic_info_t gen[1]; |
258 | |
253 | 259 | ||
254 | /* |
260 | /* |
255 | printf("chip %s\n",chip->identifier); |
261 | printf("chip %s\n",chip->identifier); |
256 | */ |
262 | */ |
257 | int nodecnt = 0; |
263 | int nodecnt = 0; |
258 | 264 | ||
259 | int max_row = -BIG; |
265 | int max_row = -BIG; |
260 | int min_row = BIG; |
266 | int min_row = BIG; |
261 | int max_col = -BIG; |
267 | int max_col = -BIG; |
262 | int min_col = BIG; |
268 | int min_col = BIG; |
263 | 269 | ||
264 | while (nodes) |
270 | while(nodes) { |
265 | { |
271 | /* to do need to identify the pattern of node identifiers */ |
266 | /* to do need to identify the pattern of node identifiers */ |
272 | /* numeric only ? */ |
267 | /* numeric only ? */ |
273 | /* alpha only ? */ |
268 | /* alpha only ? */ |
274 | /* alpha number */ |
269 | /* alpha number */ |
275 | /* number alpha */ |
270 | /* number alpha */ |
276 | /* highest pin number ? */ |
271 | /* highest pin number ? */ |
277 | /* number of different alphas */ |
272 | /* number of different alphas */ |
278 | /* assign an ordinal automatically to each node element */ |
273 | /* assign an ordinal automatically to each node element */ |
279 | |
274 | 280 | /* sorting data structure */ |
|
275 | /* sorting data structure */ |
281 | /* the form is 23A */ |
276 | /* the form is 23A */ |
282 | if (nodes->identifier) |
277 | if (nodes->identifier) |
283 | { |
278 | { |
284 | if (isdigit(nodes->identifier[0])) |
279 | if (isdigit (nodes->identifier[0])) |
285 | { |
280 | { |
286 | nodes->id_numeric_chars = nodes->identifier; |
281 | nodes->id_numeric_chars = nodes->identifier; |
287 | nodes->id_numeric_cnt = 0; /* the numeric part of the identifier */ |
282 | nodes->id_numeric_cnt = |
288 | while(isdigit(nodes->identifier[nodes->id_numeric_cnt])) |
283 | 0; /* the numeric part of the identifier */ |
289 | nodes->id_numeric_cnt++; /* the number of numeric chars in this part of the identifier */ |
284 | while (isdigit (nodes->identifier[nodes->id_numeric_cnt])) |
290 | nodes->id_alpha_chars = nodes->identifier+nodes->id_numeric_cnt; |
285 | nodes->id_numeric_cnt++; /* the number of numeric chars |
291 | nodes->id_alpha_cnt = strlen(nodes->identifier)-nodes->id_numeric_cnt; |
286 | in this part of the |
292 | } |
287 | identifier */ |
293 | else |
288 | nodes->id_alpha_chars = |
294 | { |
289 | nodes->identifier + nodes->id_numeric_cnt; |
295 | nodes->id_alpha_chars = nodes->identifier; |
290 | nodes->id_alpha_cnt = |
296 | nodes->id_alpha_cnt = 0; /* the numeric part of the identifier */ |
291 | strlen (nodes->identifier) - nodes->id_numeric_cnt; |
297 | while(isalpha (nodes->identifier[nodes->id_alpha_cnt])) |
292 | } |
298 | nodes->id_alpha_cnt++; /* the number of numeric chars in this part of the identifier */ |
293 | else |
299 | nodes->id_numeric_chars = nodes->identifier+nodes->id_alpha_cnt; |
294 | { |
300 | nodes->id_numeric_cnt = strlen(nodes->identifier)-nodes->id_alpha_cnt; |
295 | nodes->id_alpha_chars = nodes->identifier; |
301 | } |
296 | nodes->id_alpha_cnt = |
302 | |
297 | 0; /* the numeric part of the identifier */ |
303 | /* |
298 | while (isalpha (nodes->identifier[nodes->id_alpha_cnt])) |
304 | printf("node : %s : alpha=%d num=%d\n",nodes->identifier,nodes->id_alpha_cnt,nodes->id_numeric_cnt); |
299 | nodes->id_alpha_cnt++; /* the number of numeric chars |
305 | */ |
300 | in this part of the |
306 | } |
301 | identifier */ |
307 | else |
302 | nodes->id_numeric_chars = |
308 | { |
303 | nodes->identifier + nodes->id_alpha_cnt; |
309 | nodes->id_alpha_chars = NULL; /* the numeric part of the identifier */ |
304 | nodes->id_numeric_cnt = |
310 | nodes->id_alpha_cnt = 0; /* the number of numeric chars in this part of the identifier */ |
305 | strlen (nodes->identifier) - nodes->id_alpha_cnt; |
311 | nodes->id_numeric_chars= NULL; |
306 | } |
312 | nodes->id_numeric_cnt = 0; |
307 | 313 | } |
|
308 | /* |
314 | |
309 | printf("node : %s : alpha=%d |
315 | /* dont touch the row/col indices unless asked to */ |
310 | num=%d\n",nodes->identifier,nodes->id_alpha_cnt,nodes->id_numeric_cnt); |
316 | if(mode == EXTRACT_XY) |
311 | */ |
317 | { |
312 | } |
318 | /* if digits seen these are assigned as row 1..n */ |
313 | else |
319 | if(nodes->id_numeric_cnt) |
314 | { |
320 | { |
315 | nodes->id_alpha_chars = NULL; /* the numeric part of the identifier */ |
321 | int index = atoi(nodes->id_numeric_chars); |
316 | nodes->id_alpha_cnt = |
322 | numeric_seen = 1; |
317 | 0; /* the number of numeric chars in this part of the identifier */ |
323 | nodes->pin_row = index; |
318 | nodes->id_numeric_chars = NULL; |
324 | if(index > max_row) |
319 | nodes->id_numeric_cnt = 0; |
325 | { |
320 | } |
326 | max_row=index; |
321 | 327 | } |
|
322 | /* dont touch the row/col indices unless asked to */ |
328 | else if(index < min_row) |
323 | if (mode == EXTRACT_XY) |
329 | { |
324 | { |
330 | min_row=index; |
325 | /* if digits seen these are assigned as row 1..n */ |
331 | } |
326 | if (nodes->id_numeric_cnt) |
332 | } |
327 | { |
333 | else |
328 | int index = atoi (nodes->id_numeric_chars); |
334 | { |
329 | numeric_seen = 1; |
335 | /* default is on row 1 */ |
330 | nodes->pin_row = index; |
336 | nodes->pin_row = 1; |
331 | if (index > max_row) |
337 | } |
332 | { |
338 | if(nodes->id_alpha_cnt > 0) |
333 | max_row = index; |
339 | { |
334 | } |
340 | alpha_seen = 1; |
335 | else if (index < min_row) |
341 | } |
336 | { |
342 | |
337 | min_row = index; |
343 | /* between 1 and a few letters can be processed */ |
338 | } |
344 | if(nodes->id_alpha_cnt > 0 && nodes->id_alpha_cnt <= MAX_ID_ALPHA_SORT ) |
339 | } |
345 | { |
340 | else |
346 | int index; |
341 | { |
347 | int charcnt; |
342 | /* default is on row 1 */ |
348 | index = 0; |
343 | nodes->pin_row = 1; |
349 | for (charcnt=0;charcnt<nodes->id_alpha_cnt;charcnt++) |
344 | } |
350 | { |
345 | if (nodes->id_alpha_cnt > 0) |
351 | int i; |
346 | { |
352 | char c,d; |
347 | alpha_seen = 1; |
353 | d = 0; |
348 | } |
354 | c = toupper(nodes->id_alpha_chars[charcnt]); |
349 | 355 | /* work out how many illegal chars are before this one */ |
|
350 | /* between 1 and a few letters can be processed */ |
356 | /* this mapping actually collapses I onto J and O onto P */ |
351 | if (nodes->id_alpha_cnt > 0 && |
357 | /* I am assuming those two chars dont exist in the pin ID .... */ |
352 | nodes->id_alpha_cnt <= MAX_ID_ALPHA_SORT) |
358 | /* flag an error and continue for the present */ |
353 | { |
359 | /* characters are actually coded as 1..n so that IDs like 'AA' look */ |
354 | int index; |
360 | /* different to 'A', which they wont be if the leading 'A' is coded as 0 */ |
355 | int charcnt; |
361 | for (i=0;i< PIN_MAP_ILLEGAL_CHAR_COUNT; i++) |
356 | index = 0; |
362 | { |
357 | for (charcnt = 0; charcnt < nodes->id_alpha_cnt; charcnt++) |
363 | if(c==illegal_chars[i]) |
358 | { |
364 | { |
359 | int i; |
365 | Log(LOG_GENERAL,"-- Warning : illegal pin ident character in %s(%d)\n", |
360 | char c, d; |
366 | chip->identifier,nodes->identifier); |
361 | d = 0; |
367 | } |
362 | c = toupper (nodes->id_alpha_chars[charcnt]); |
368 | if(c>=illegal_chars[i]) |
363 | /* work out how many illegal chars are before this one |
369 | { |
364 | */ |
370 | d++; |
365 | /* this mapping actually collapses I onto J and O onto |
371 | } |
366 | * P */ |
372 | } |
367 | /* I am assuming those two chars dont exist in the pin |
373 | index *= (PIN_MAP_LEGAL_CHAR_COUNT+1); |
368 | * ID .... */ |
374 | index += (c-d-'A'+1); |
369 | /* flag an error and continue for the present */ |
375 | |
370 | /* characters are actually coded as 1..n so that IDs |
376 | } |
371 | * like 'AA' look */ |
377 | /* |
372 | /* different to 'A', which they wont be if the leading |
378 | printf("'\n"); |
373 | * 'A' is coded as 0 */ |
379 | */ nodes->pin_col = index; |
374 | for (i = 0; i < PIN_MAP_ILLEGAL_CHAR_COUNT; i++) |
380 | if(index > max_col) |
375 | { |
381 | { |
376 | if (c == illegal_chars[i]) |
382 | max_col=index; |
377 | { |
383 | } |
378 | Log ( |
384 | else if(index < min_col) |
379 | LOG_GENERAL, |
385 | { |
380 | "-- Warning : illegal pin ident " |
386 | min_col=index; |
381 | "character in %s(%d)\n", |
387 | } |
382 | chip->identifier, |
388 | } |
383 | nodes->identifier); |
389 | else |
384 | } |
390 | { |
385 | if (c >= illegal_chars[i]) |
391 | /* default is column zero */ |
386 | { |
392 | nodes->pin_col = 0; |
387 | d++; |
393 | } |
388 | } |
394 | } |
389 | } |
395 | nodecnt++; |
390 | index *= (PIN_MAP_LEGAL_CHAR_COUNT + 1); |
396 | nodes=nodes->sktnext; |
391 | index += (c - d - 'A' + 1); |
397 | } |
392 | } |
398 | |
393 | /* |
399 | |
394 | printf("'\n"); |
400 | chip-> max_pin_col = max_col== -BIG ? 0 : max_col; |
395 | */ |
401 | chip-> min_pin_col = min_col== BIG ? 0 : min_col; |
396 | nodes->pin_col = index; |
402 | chip-> max_pin_row = max_row== -BIG ? 0 : max_row; |
397 | if (index > max_col) |
403 | chip-> min_pin_row = min_row== BIG ? 0 : min_row; |
398 | { |
404 | /* |
399 | max_col = index; |
405 | printf("chip %10s col %3d to %3d , row %3d to %3d\n",chip->identifier,max_col,min_col,max_row,min_row); |
400 | } |
406 | */ |
401 | else if (index < min_col) |
407 | /* know the number of nodes now allocate storage for the pointers |
402 | { |
408 | to be used by qsort() */ |
403 | min_col = index; |
409 | |
404 | } |
410 | sort_list = calloc(nodecnt,sizeof(node_t *)); |
405 | } |
411 | |
406 | else |
412 | |
407 | { |
413 | /* grab hold of all of the pointers */ |
408 | /* default is column zero */ |
414 | nodes = chip-> nodes; |
409 | nodes->pin_col = 0; |
415 | nodecnt = 0; |
410 | } |
416 | while(nodes) { |
411 | } |
417 | sort_list[nodecnt++]=nodes; |
412 | nodecnt++; |
418 | nodes=nodes->sktnext; |
413 | nodes = nodes->sktnext; |
419 | } |
414 | } |
420 | |
415 | 421 | /* sort them */ |
|
416 | chip->max_pin_col = max_col == -BIG ? 0 : max_col; |
422 | |
417 | chip->min_pin_col = min_col == BIG ? 0 : min_col; |
423 | if(nodecnt) { |
418 | chip->max_pin_row = max_row == -BIG ? 0 : max_row; |
424 | int i; |
419 | chip->min_pin_row = min_row == BIG ? 0 : min_row; |
425 | |
420 | /* |
426 | qsort((void *)sort_list, |
421 | printf("chip %10s col %3d to %3d , row %3d to |
427 | nodecnt,sizeof(node_t *),&sort_nodes_compar); |
422 | %3d\n",chip->identifier,max_col,min_col,max_row,min_row); |
428 | |
423 | */ |
429 | /* and now rebuild the list based on the sorted list */ |
424 | /* know the number of nodes now allocate storage for the pointers |
430 | chip->nodes = sort_list[0]; |
425 | to be used by qsort() */ |
431 | chip->lastnode = sort_list[nodecnt-1]; |
426 | 432 | ||
427 | sort_list = calloc (nodecnt, sizeof (node_t *)); |
433 | /* relink the list */ |
428 | 434 | for(i=0;i<(nodecnt-1);i++) { |
|
429 | /* grab hold of all of the pointers */ |
435 | sort_list[i]->sktnext = sort_list[i+1]; |
430 | nodes = chip->nodes; |
436 | } |
431 | nodecnt = 0; |
437 | sort_list[nodecnt-1]->sktnext = NULL; |
432 | while (nodes) |
438 | |
433 | { |
439 | } |
434 | sort_list[nodecnt++] = nodes; |
440 | |
435 | nodes = nodes->sktnext; |
441 | free(sort_list); |
436 | } |
442 | |
437 | 443 | /* check for overrides in case there are missing rows/cols */ |
|
438 | /* sort them */ |
444 | |
439 | 445 | if (get_generic_value(&chip->generics, "min_pin_row",gen) == IS_ATTRIBUTE) |
|
440 | if (nodecnt) |
446 | { |
441 | { |
447 | chip->min_pin_row = eval_expression(gen->expr, &chip->generics); |
442 | int i; |
448 | } |
443 | 449 | if (get_generic_value(&chip->generics, "max_pin_row",gen) == IS_ATTRIBUTE) |
|
444 | qsort ((void *) sort_list, nodecnt, sizeof (node_t *), &sort_nodes_compar); |
450 | { |
445 | 451 | chip->max_pin_row = eval_expression(gen->expr, &chip->generics ); |
|
446 | /* and now rebuild the list based on the sorted list */ |
452 | } |
447 | chip->nodes = sort_list[0]; |
453 | if (get_generic_value(&chip->generics, "min_pin_col",gen) == IS_ATTRIBUTE) |
448 | chip->lastnode = sort_list[nodecnt - 1]; |
454 | { |
449 | 455 | chip->min_pin_col = eval_expression(gen->expr, &chip->generics ); |
|
450 | /* relink the list */ |
456 | } |
451 | for (i = 0; i < (nodecnt - 1); i++) |
457 | if (get_generic_value(&chip->generics, "max_pin_col",gen) == IS_ATTRIBUTE) |
452 | { |
458 | { |
453 | sort_list[i]->sktnext = sort_list[i + 1]; |
459 | chip->max_pin_col = eval_expression(gen->expr, &chip->generics ); |
454 | } |
460 | } |
455 | sort_list[nodecnt - 1]->sktnext = NULL; |
- | |
456 | } |
- | |
457 | - | ||
458 | free (sort_list); |
- | |
459 | - | ||
460 | /* check for overrides in case there are missing rows/cols */ |
- | |
461 | - | ||
462 | if (get_generic_value (&chip->generics, "min_pin_row", gen) == IS_ATTRIBUTE) |
- | |
463 | { |
- | |
464 | chip->min_pin_row = eval_expression (gen->expr, &chip->generics); |
- | |
465 | } |
- | |
466 | if (get_generic_value (&chip->generics, "max_pin_row", gen) == IS_ATTRIBUTE) |
- | |
467 | { |
- | |
468 | chip->max_pin_row = eval_expression (gen->expr, &chip->generics); |
- | |
469 | } |
- | |
470 | if (get_generic_value (&chip->generics, "min_pin_col", gen) == IS_ATTRIBUTE) |
- | |
471 | { |
- | |
472 | chip->min_pin_col = eval_expression (gen->expr, &chip->generics); |
- | |
473 | } |
- | |
474 | if (get_generic_value (&chip->generics, "max_pin_col", gen) == IS_ATTRIBUTE) |
- | |
475 | { |
- | |
476 | chip->max_pin_col = eval_expression (gen->expr, &chip->generics); |
- | |
477 | } |
- | |
478 | } |
461 | } |
479 | 462 | ||
480 | /* we have a pair of pointers to array elements */ |
463 | /* we have a pair of pointers to array elements */ |
481 | 464 | ||
482 | static int sort_socket_compar (const void *p, const void *q) |
465 | static int sort_socket_compar(const void * p,const void * q) |
483 | { |
466 | { |
484 | return strcmp ((*(socket_t **) p)->identifier, (*(socket_t **) q)->identifier); |
467 | return strcmp((*(socket_t **)p)->identifier,(*(socket_t **)q)->identifier); |
485 | } |
468 | } |
486 | 469 | ||
487 | /* this function sorts all of sockets into alphanumeric order */ |
- | |
488 | - | ||
489 | socket_t *sort_sockets (socket_t **head) |
- | |
490 | { |
- | |
491 | socket_t **sort_list, *chip = *head; |
- | |
492 | int sktcnt = 0; |
- | |
493 | 470 | ||
494 | while (chip) |
- | |
495 | { |
- | |
496 | sktcnt++; |
- | |
497 | chip = chip->next; |
- | |
498 | } |
- | |
499 | /* know the number of nodes now allocate storage for the pointers |
- | |
500 | to be used by qsort() */ |
- | |
501 | sort_list = calloc (sktcnt, sizeof (socket_t *)); |
471 | /* this function sorts all of sockets into alphanumeric order */ |
502 | - | ||
503 | /* grab hold of all of the pointers */ |
- | |
504 | chip = *head; |
- | |
505 | sktcnt = 0; |
- | |
506 | while (chip) |
- | |
507 | { |
- | |
508 | sort_list[sktcnt++] = chip; |
- | |
509 | chip = chip->next; |
- | |
510 | } |
- | |
511 | - | ||
512 | /* sort them */ |
- | |
513 | 472 | ||
- | 473 | socket_t * sort_sockets(socket_t ** head) { |
|
- | 474 | socket_t ** sort_list,* chip= *head; |
|
- | 475 | int sktcnt = 0; |
|
- | 476 | ||
- | 477 | while(chip) { |
|
- | 478 | sktcnt++; |
|
- | 479 | chip=chip->next; |
|
- | 480 | } |
|
- | 481 | /* know the number of nodes now allocate storage for the pointers |
|
- | 482 | to be used by qsort() */ |
|
- | 483 | sort_list = calloc(sktcnt,sizeof(socket_t *)); |
|
- | 484 | ||
- | 485 | /* grab hold of all of the pointers */ |
|
- | 486 | chip = *head; |
|
- | 487 | sktcnt = 0; |
|
- | 488 | while(chip) { |
|
- | 489 | sort_list[sktcnt++]=chip; |
|
- | 490 | chip=chip->next; |
|
- | 491 | } |
|
- | 492 | ||
- | 493 | /* sort them */ |
|
- | 494 | ||
514 | if (sktcnt) |
495 | if(sktcnt) { |
515 | { |
496 | int i; |
- | 497 | qsort((char *)sort_list, |
|
516 | int i; |
498 | sktcnt, |
- | 499 | sizeof(socket_t *), |
|
- | 500 | &sort_socket_compar); |
|
- | 501 | ||
517 | qsort ((char *) sort_list, sktcnt, sizeof (socket_t *), &sort_socket_compar); |
502 | /* and now rebuild the list based on the sorted list */ |
- | 503 | *head = sort_list[0]; |
|
- | 504 | ||
- | 505 | /* relink the list */ |
|
- | 506 | for(i=0;i<(sktcnt-1);i++) { |
|
- | 507 | sort_list[i]->next = sort_list[i+1]; |
|
- | 508 | } |
|
- | 509 | sort_list[sktcnt-1]->next = NULL; |
|
- | 510 | ||
- | 511 | } |
|
- | 512 | free(sort_list); |
|
- | 513 | return * head; |
|
- | 514 | } |
|
518 | 515 | ||
519 | /* and now rebuild the list based on the sorted list */ |
- | |
520 | *head = sort_list[0]; |
- | |
521 | 516 | ||
522 | /* relink the list */ |
- | |
523 | for (i = 0; i < (sktcnt - 1); i++) |
- | |
524 | { |
- | |
525 | sort_list[i]->next = sort_list[i + 1]; |
- | |
526 | } |
- | |
527 | sort_list[sktcnt - 1]->next = NULL; |
- | |
528 | } |
- | |
529 | free (sort_list); |
- | |
530 | return *head; |
- | |
531 | } |
- | |
532 | 517 | ||
533 | /* compile regular expression according |
518 | /* compile regular expression according |
534 | to Vertical expectations */ |
519 | to Vertical expectations */ |
535 | /* What is required is a whole string match. In order to |
520 | /* What is required is a whole string match. In order to |
536 | achieve this, the regular expression is bracketed with |
521 | achieve this, the regular expression is bracketed with |
537 | ^ and $ which mean in this context 'match start of string' |
522 | ^ and $ which mean in this context 'match start of string' |
538 | and 'match end of string' */ |
523 | and 'match end of string' */ |
539 | 524 | ||
540 | int vert_regcomp (vert_regex_t **vert_preg, char *expr) |
- | |
541 | { |
- | |
542 | int rc; |
- | |
543 | vert_regex_t *preg; |
- | |
544 | /* allocate structure members */ |
- | |
545 | preg = calloc (1, sizeof (vert_regex_t)); |
- | |
546 | *vert_preg = preg; |
- | |
547 | rc = check_wildcard (expr); |
- | |
548 | if (rc != TCL_OK) |
- | |
549 | { |
- | |
550 | preg->buff = malloc (3); |
- | |
551 | strcpy (preg->buff, "^$"); |
- | |
552 | } |
- | |
553 | else |
- | |
554 | { |
- | |
555 | preg->buff = malloc (strlen (expr) + 3); |
- | |
556 | sprintf (preg->buff, "^%s$", expr); |
- | |
557 | } |
- | |
558 | /* printf("-- compare '%s'\n",preg->buff); */ |
- | |
559 | rc = regcomp (preg->preg, preg->buff, REG_EXTENDED | REG_ICASE); |
- | |
560 | return rc; |
- | |
561 | } |
- | |
562 | 525 | ||
- | 526 | int vert_regcomp(vert_regex_t ** vert_preg,char * expr) |
|
- | 527 | { |
|
- | 528 | int rc; |
|
- | 529 | vert_regex_t * preg; |
|
- | 530 | /* allocate structure members */ |
|
- | 531 | preg = calloc(1,sizeof(vert_regex_t)); |
|
- | 532 | *vert_preg = preg; |
|
- | 533 | rc = check_wildcard(expr); |
|
- | 534 | if (rc!=TCL_OK) |
|
- | 535 | { |
|
- | 536 | preg->buff = malloc(3); |
|
- | 537 | strcpy(preg->buff,"^$"); |
|
- | 538 | } |
|
- | 539 | else |
|
- | 540 | { |
|
- | 541 | preg->buff = malloc(strlen(expr)+3); |
|
- | 542 | sprintf(preg->buff,"^%s$",expr); |
|
- | 543 | } |
|
- | 544 | /* printf("-- compare '%s'\n",preg->buff); */ |
|
- | 545 | rc = regcomp(preg->preg,preg->buff,REG_EXTENDED | REG_ICASE); |
|
- | 546 | return rc; |
|
- | 547 | } |
|
- | 548 | ||
563 | /* tidy up */ |
549 | /* tidy up */ |
564 | int vert_regfree (vert_regex_t **vert_preg) |
550 | int vert_regfree(vert_regex_t ** vert_preg) |
565 | { |
551 | { |
566 | regfree ((*vert_preg)->preg); |
552 | regfree((*vert_preg)->preg); |
567 | free ((*vert_preg)->buff); |
553 | free((*vert_preg)->buff); |
568 | free (*vert_preg); |
554 | free(*vert_preg); |
569 | *vert_preg = NULL; |
555 | *vert_preg = NULL; |
570 | return 0; |
556 | return 0; |
571 | } |
557 | } |