Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* |
2 | * $Id: rename.c,v 1.2 2003/11/06 04:36:03 mjames Exp $ |
||
3 | * |
||
4 | * $Log: rename.c,v $ |
||
5 | * Revision 1.2 2003/11/06 04:36:03 mjames |
||
6 | * Checkin : builds but has problems with object renaming |
||
7 | * |
||
8 | * Revision 1.1.1.1 2003/11/04 23:34:57 mjames |
||
9 | * Imported into local repositrory |
||
10 | * |
||
11 | * Revision 1.24 2003/01/02 21:37:17 mjames |
||
12 | * Experiment on creating NOT_ROUTABLE_H and NOT_ROUTABLE_L |
||
13 | * properties on the nets so that pin jumpers can be made without a problem. |
||
14 | * |
||
15 | * Still need to sort out pin assignments made to these not_routable nets |
||
16 | * which will become legal in some cases so that pullups and pulldown |
||
17 | * pins can be used on the FPGA. |
||
18 | * |
||
19 | * Revision 1.23 2002/10/02 18:41:24 MJAMES |
||
20 | * Dont print '&a' if the pin_column is expression is less than or equal to zero |
||
21 | * |
||
22 | * Revision 1.22 2002/09/18 08:50:10 mjames |
||
23 | * Removed further sidefects of redefining pin 'a' as 1 in place of '0' |
||
24 | * |
||
25 | * Revision 1.21 2002/09/16 14:41:43 mjames |
||
26 | * Merge back pin indexing bug that meant |
||
27 | * pin AZ12 was indistinguishable from pin Z12 in |
||
28 | * rename ident/name commands |
||
29 | * |
||
30 | * Revision 1.19 2002/08/23 14:17:29 mjames |
||
31 | * Regular expressions extended to |
||
32 | * &a, &n &d , &i as special replacement patterns |
||
33 | * |
||
34 | * Revision 1.18 2002/01/21 09:33:30 mjames |
||
35 | * Appended a null character when copying regular expression |
||
36 | * matched pattern. |
||
37 | * |
||
38 | * Revision 1.17 2001/12/24 20:07:18 mjames |
||
39 | * Added &D for device identifier in the replacement string in edit_pin as well |
||
40 | * as &0 .. &9 |
||
41 | * |
||
42 | * Revision 1.16 2001/12/11 20:30:26 mjames |
||
43 | * Implemented regular expression pin name editing |
||
44 | * |
||
45 | * Revision 1.15 2001/11/19 10:21:04 mjames |
||
46 | * Fixed errors |
||
47 | * |
||
48 | * Revision 1.14 2001/11/19 10:02:23 mjames |
||
49 | * Merge back |
||
50 | * |
||
51 | * Revision 1.13.2.1 2001/11/15 22:03:52 mjames |
||
52 | * Altered the 'alter' command to use two arguments rather than one |
||
53 | * after TH suggestion. |
||
54 | * |
||
55 | * Revision 1.13 2001/10/31 22:28:27 mjames |
||
56 | * Problems with regular expression argument lists. |
||
57 | * |
||
58 | * Revision 1.12 2001/10/31 22:20:14 mjames |
||
59 | * Tidying up problematical comments caused by CVS |
||
60 | * 'intelligent' comment guessing |
||
61 | * |
||
62 | * Revision 1.11 2001/10/31 16:18:05 mjames |
||
63 | * Added a datastructure to hide regular expression information from programs. |
||
64 | * Changed call to regexec to indicate 0 subexpressions to be matched |
||
65 | * rather than a number dependent on strlen(string) which was wrong. |
||
66 | * |
||
67 | * Revision 1.10 2001/10/18 21:36:17 mjames |
||
68 | * Added modify pins command : nets inherit identifier from selected socket and pin on that |
||
69 | * socket to ease cross referencing. |
||
70 | * |
||
71 | * Revision 1.9 2001/10/11 16:10:16 mjames |
||
72 | * Corrections to the SWAP command, and printout so that |
||
73 | * WRITE net now outputs all chips in the design so that their generics |
||
74 | * can be passed forward to the next phase. |
||
75 | * |
||
76 | * Revision 1.8 2001/10/10 20:18:21 mjames |
||
77 | * Added a vert_regcomp function to compile regular expressions |
||
78 | * with '^' (match start string) and '$' (match end string) bracketing |
||
79 | * this => wildcard must match entire string not just a part of it. |
||
80 | * |
||
81 | * Revision 1.7 2001/10/07 20:50:52 mjames |
||
82 | * Added wildcard checking (warn user about |
||
83 | * using wildcard '*' on the end of a string in stead of wildcard '.*') |
||
84 | * |
||
85 | * Revision 1.6 2001/09/25 23:15:23 mjames |
||
86 | * Converted wildcards to use proper regexp pattern match library |
||
87 | * |
||
88 | * Revision 1.5 2001/08/31 09:37:42 mjames |
||
89 | * modified rename rules so that un-named objects do not get |
||
90 | * name suffixes appended. |
||
91 | * |
||
92 | * Revision 1.4 2001/07/20 14:49:42 mjames |
||
93 | * Corrected reading names in on multiple boards : if present in a database file |
||
94 | * when reading in a suffixed design |
||
95 | * e.g. CHIP fred |
||
96 | * Will also get its name suffixed. |
||
97 | * |
||
98 | * Revision 1.3 2001/06/06 12:10:18 mjames |
||
99 | * Move from HPUX |
||
100 | * |
||
101 | * Revision 1.2 2001/01/26 21:50:10 mjames |
||
102 | * Managed to get vertical non TCL to compile again |
||
103 | * |
||
104 | * Conversion to argv, argc[] mode of operation continues |
||
105 | * |
||
106 | * Revision 1.1.1.1 2000/10/19 21:58:39 mjames |
||
107 | * Mike put it here |
||
108 | * |
||
109 | * |
||
110 | * Revision 1.26 2000/08/25 09:57:15 09:57:15 mjames (Mike James) |
||
111 | * Modified for Vertical2 : support COMPONENTS and SIGNALS |
||
112 | * |
||
113 | * Revision 1.26 2000/08/25 09:57:15 09:57:15 mjames (Mike James) |
||
114 | * Part of Release Aug25_alpha |
||
115 | * |
||
116 | * Revision 1.25 2000/08/16 08:57:31 08:57:31 mjames (Mike James) |
||
117 | * Part of Release CD01_Aug2000 |
||
118 | * |
||
119 | * Revision 1.24 2000/08/14 14:45:12 14:45:12 mjames (Mike James) |
||
120 | * Part of Release Aug_14_2000 |
||
121 | * |
||
122 | * Revision 1.23 2000/08/11 08:30:33 08:30:33 mjames (Mike James) |
||
123 | * Part of Release Aug_11_2000 |
||
124 | * |
||
125 | * Revision 1.22 2000/08/09 10:31:48 10:31:48 mjames (Mike James) |
||
126 | * Part of Release Aug__9_2000 |
||
127 | * |
||
128 | * Revision 1.21 2000/05/31 11:42:58 11:42:58 mjames (Mike James) |
||
129 | * Part of Release May_31_2000 |
||
130 | * |
||
131 | * Revision 1.20 2000/05/08 17:01:38 17:01:38 mjames (Mike James) |
||
132 | * Part of Release May__8_2000 |
||
133 | * |
||
134 | * Revision 1.19 2000/05/08 16:59:31 16:59:31 mjames (Mike James) |
||
135 | * Part of Release May__8_2000 |
||
136 | * |
||
137 | * Revision 1.18 2000/05/08 16:57:08 16:57:08 mjames (Mike James) |
||
138 | * Part of Release May__8_2000 |
||
139 | * |
||
140 | * Revision 1.17 2000/03/08 16:19:26 16:19:26 mjames (Mike James) |
||
141 | * New version including PC |
||
142 | * |
||
143 | * Revision 1.14 2000/01/20 15:58:48 15:58:48 mjames (Mike James) |
||
144 | * Part of Release R22 |
||
145 | * |
||
146 | * Revision 1.13 99/12/22 11:15:29 11:15:29 mjames (Mike James) |
||
147 | * Part of Release Dec_22_1999 |
||
148 | * |
||
149 | * Revision 1.12 99/06/25 14:35:49 14:35:49 mjames (Mike James) |
||
150 | * Added in reference to expression.h, but no changes made |
||
151 | * to the function of acfread yet. |
||
152 | * |
||
153 | * Revision 1.11 99/05/04 09:52:43 09:52:43 mjames (Mike James) |
||
154 | * General checkin |
||
155 | * |
||
156 | * Revision 1.10 98/08/12 14:22:18 14:22:18 mjames (Mike James) |
||
157 | * Corrected include file list |
||
158 | * |
||
159 | * Revision 1.9 98/04/24 14:07:51 14:07:51 mjames (Mike James) |
||
160 | * Added pin name swapping code |
||
161 | * |
||
162 | * Revision 1.8 98/03/16 11:38:24 11:38:24 mjames (Mike James) |
||
163 | * Removed an old bug - suffixing of PCB names has been broken for about |
||
164 | * a year. If a pcb were read in non-suffixed and then another with a suffix, |
||
165 | * the suffix would be applied over all of the sockets and nets, not just the new ones. |
||
166 | * |
||
167 | * Revision 1.7 98/02/11 11:27:06 11:27:06 mjames (Mike James) |
||
168 | * Checked in for version 6.2a |
||
169 | * |
||
170 | * Revision 1.6 97/04/23 08:43:22 08:43:22 mjames (Mike James) |
||
171 | * CHecked in for release rel23041997 |
||
172 | * |
||
173 | * Revision 1.5 96/07/19 14:38:51 14:38:51 mjames (Mike James) |
||
174 | * Update to give to PRL |
||
175 | * |
||
176 | * Revision 1.4 1996/07/12 15:52:12 mjames |
||
177 | * Sorted out things like Alias and Jumpers |
||
178 | * Work Correctly |
||
179 | * Print COrrectly |
||
180 | * |
||
181 | * Revision 1.4 1996/07/12 15:52:12 mjames |
||
182 | * Sorted out things like Alias and Jumpers |
||
183 | * Work Correctly |
||
184 | * Print COrrectly |
||
185 | * |
||
186 | * Revision 1.3 96/06/04 11:53:28 11:53:28 mjames (Mike James) |
||
187 | * Corrected the operation of the renaming function |
||
188 | * |
||
189 | * Revision 1.2 96/05/29 11:00:10 11:00:10 mjames (Mike James) |
||
190 | * Added explanatory comments |
||
191 | * |
||
192 | * Revision 1.1 96/05/29 10:53:13 10:53:13 mjames (Mike James) |
||
193 | * Initial revision |
||
194 | * */ |
||
195 | |||
196 | #include "rename.h" |
||
197 | |||
198 | #include "chck_names.h" |
||
199 | #include "cmdlog.h" |
||
200 | #include "cmdparse.h" |
||
201 | #include "database.h" |
||
202 | #include "expression.h" |
||
203 | #include "generic.h" |
||
204 | #include "lx_support.h" |
||
205 | #include "sorting.h" |
||
206 | #include "vertcl_main.h" |
||
207 | |||
208 | #include <ctype.h> |
||
209 | #include <regex.h> |
||
210 | #include <stdio.h> |
||
211 | #include <stdlib.h> |
||
212 | #include <string.h> |
||
213 | #include <sys/types.h> |
||
214 | |||
215 | #ident \ |
||
216 | "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/vertlib/rename.c,v 1.2 2003/11/06 04:36:03 mjames Exp $" |
||
217 | |||
218 | /* added on to suffix all signal names */ |
||
219 | /* all new objects will appear after the 'mark'. Only |
||
220 | these new objects need to be renamed by adding a suffix. |
||
221 | Older objects have already been renamed. */ |
||
222 | |||
223 | static net_t *mark_nets = NULL; |
||
224 | static socket_t *mark_skts = NULL; |
||
225 | |||
226 | /* record the last known net and socket before |
||
227 | reading in new nets and sockets */ |
||
228 | |||
229 | void mark_board_objects (void) |
||
230 | { |
||
231 | net_t *net = routed_list; |
||
232 | socket_t *skt = socket_head; |
||
233 | while (net && net->next) |
||
234 | { |
||
235 | net = net->next; |
||
236 | } |
||
237 | mark_nets = net; |
||
238 | while (skt && skt->next) |
||
239 | { |
||
240 | skt = skt->next; |
||
241 | } |
||
242 | mark_skts = skt; |
||
243 | /* |
||
244 | printf("Mark at net=%p and skt=%p\n",mark_nets,mark_skts); |
||
245 | */ |
||
246 | } |
||
247 | |||
248 | /* only name nets that are not null names */ |
||
249 | static char *alter_id (char *id, char *suffix) |
||
250 | { |
||
251 | if (!ISNULLSTR (id) && !ISNULLSTR (suffix)) |
||
252 | { |
||
253 | id = realloc (id, strlen (id) + strlen (suffix) + 1); |
||
254 | strcat (id, suffix); |
||
255 | return (id); |
||
256 | } |
||
257 | return NULL; |
||
258 | } |
||
259 | |||
260 | /* suffixes all net and component identifiers |
||
261 | since the last 'mark_board_objects' call with the string s */ |
||
262 | |||
263 | void set_board_suffix (char *s) |
||
264 | { |
||
265 | net_t *net = mark_nets; |
||
266 | socket_t *skt = mark_skts; |
||
267 | |||
268 | /* |
||
269 | printf("Mark at net=%p and skt=%p\n",mark_nets,mark_skts); |
||
270 | */ |
||
271 | /* flag the nets and sockets as having been renamed */ |
||
272 | mark_nets = NULL; |
||
273 | mark_skts = NULL; |
||
274 | |||
275 | if (net) |
||
276 | net = net->next; /* move to next one (new one) */ |
||
277 | else |
||
278 | net = routed_list; |
||
279 | if (skt) |
||
280 | skt = skt->next; /* ditto */ |
||
281 | else |
||
282 | skt = socket_head; |
||
283 | |||
284 | /* rename all of the net identifiers */ |
||
285 | while (net) |
||
286 | { |
||
287 | struct net *sub_n = net->subnets; |
||
288 | |||
289 | /* jumpered nets have their subnets renamed */ |
||
290 | if (sub_n && net->how_joined == Jumpered) |
||
291 | while (sub_n) |
||
292 | { |
||
293 | sub_n->identifier = alter_id (sub_n->identifier, s); |
||
294 | sub_n = sub_n->subnets; |
||
295 | } |
||
296 | else |
||
297 | net->identifier = alter_id (net->identifier, s); |
||
298 | net = net->next; |
||
299 | } |
||
300 | /* rename all of the socket identifiers */ |
||
301 | while (skt) |
||
302 | { |
||
303 | skt->identifier = alter_id (skt->identifier, s); |
||
304 | if (skt->name) /* mod MDJ July 2001 */ |
||
305 | skt->name = alter_id (skt->name, s); |
||
306 | skt = skt->next; |
||
307 | } |
||
308 | } |
||
309 | |||
310 | /*********************************************************************/ |
||
311 | /* Pin_swapping : reverse A23 to 23a */ |
||
312 | /* allow up to lead_chars before digits to permit pin swap */ |
||
313 | /* lead_chars = 2 -> aa23 maps to 23aa but pin23 remains unswapped */ |
||
314 | /*********************************************************************/ |
||
315 | /* modified from the original, now allows swapping 1a to a1 if |
||
316 | * AlphaSwap_t == Want_A1 |
||
317 | * or allows swapping a1 to 1a if |
||
318 | * AlphaSwap_t == Want_1A |
||
319 | * probably better using the renaming command below. |
||
320 | */ |
||
321 | void pin_id_swap (char *template, int lead_chars, AlphaSwap_t lead_alpha) |
||
322 | { |
||
323 | enum |
||
324 | { |
||
325 | First_Char, |
||
326 | Leading_Chars, |
||
327 | Trailing_Digits, |
||
328 | Leading_Digits, |
||
329 | Trailing_Chars, |
||
330 | No_Swap |
||
331 | } SwapState; |
||
332 | int rc; |
||
333 | socket_t *chip; |
||
334 | node_t *nodes; |
||
335 | /* compile regular expression */ |
||
336 | vert_regex_t *preg; |
||
337 | |||
338 | if (ISNULLSTR (template)) |
||
339 | { |
||
340 | template = ".*"; |
||
341 | } |
||
342 | rc = vert_regcomp (&preg, template); |
||
343 | if (rc != 0) |
||
344 | { |
||
345 | char errbuff[100]; |
||
346 | regerror (rc, preg->preg, errbuff, 100); |
||
347 | Log ( |
||
348 | LOG_ERROR, |
||
349 | "-- Problem (rc=%d) %s with '%s' as regular expression\n", |
||
350 | rc, |
||
351 | errbuff, |
||
352 | template); |
||
353 | |||
354 | /* return TCL_ERROR; |
||
355 | */ |
||
356 | return; |
||
357 | } |
||
358 | else |
||
359 | { |
||
360 | Log (LOG_GENERAL, "-- Using '%s' as match pattern\n", template); |
||
361 | } |
||
362 | |||
363 | if (lead_alpha == Want_A1) |
||
364 | { |
||
365 | Log ( |
||
366 | LOG_GENERAL, |
||
367 | "-- Swapping pin identifiers with up to %d leading letters\n", |
||
368 | lead_chars); |
||
369 | } |
||
370 | else |
||
371 | { |
||
372 | Log ( |
||
373 | LOG_GENERAL, |
||
374 | "-- Swapping pin identifiers with up to %d trailing letters\n", |
||
375 | lead_chars); |
||
376 | } |
||
377 | Log ( |
||
378 | LOG_GENERAL, |
||
379 | "-- for sockets matching template '%s' --\n", |
||
380 | template ? template : "[ALL Sockets]"); |
||
381 | |||
382 | chip = socket_head; |
||
383 | while (chip) |
||
384 | { |
||
385 | int found; |
||
386 | |||
387 | found = regexec (preg->preg, chip->identifier, 0, preg->regpatt, 0); |
||
388 | |||
389 | if (!found) |
||
390 | { |
||
391 | Log (LOG_GENERAL, "-- Processing socket '%s' --\n", chip->identifier); |
||
392 | |||
393 | nodes = chip->nodes; |
||
394 | while (nodes) |
||
395 | { |
||
396 | int lead_count = 0; |
||
397 | int done = 0; |
||
398 | char new_id[MAXIDLEN]; |
||
399 | char *pos = nodes->identifier; |
||
400 | SwapState = First_Char; |
||
401 | while (pos && *pos && !done) |
||
402 | { |
||
403 | /* |
||
404 | printf("%s (%c) State |
||
405 | %d\n",nodes->identifier,*pos,SwapState); |
||
406 | */ |
||
407 | switch (SwapState) |
||
408 | { |
||
409 | case First_Char: |
||
410 | |||
411 | if (lead_alpha == Want_A1 && isdigit (*pos) && |
||
412 | lead_chars > 0) |
||
413 | { |
||
414 | SwapState = Leading_Digits; |
||
415 | lead_count = 1; |
||
416 | break; |
||
417 | } |
||
418 | if (lead_alpha == Want_1A && isalpha (*pos) && |
||
419 | lead_chars > 0) |
||
420 | { |
||
421 | SwapState = Leading_Chars; |
||
422 | lead_count = 1; |
||
423 | break; |
||
424 | } |
||
425 | /* no action needed, so continue */ |
||
426 | SwapState = No_Swap; |
||
427 | done = 1; |
||
428 | break; |
||
429 | |||
430 | case Leading_Chars: |
||
431 | |||
432 | if (isdigit (*pos)) |
||
433 | { |
||
434 | if (lead_count <= lead_chars) |
||
435 | { /* encountered a digit after a |
||
436 | character success so far */ |
||
437 | SwapState = Trailing_Digits; |
||
438 | break; |
||
439 | } |
||
440 | else |
||
441 | { |
||
442 | SwapState = No_Swap; |
||
443 | done = 1; |
||
444 | break; |
||
445 | } |
||
446 | } |
||
447 | if (isalpha (*pos)) |
||
448 | { |
||
449 | lead_count++; |
||
450 | break; |
||
451 | } |
||
452 | SwapState = No_Swap; |
||
453 | done = 1; |
||
454 | break; |
||
455 | |||
456 | case Leading_Digits: |
||
457 | |||
458 | if (isalpha (*pos)) |
||
459 | { |
||
460 | if (lead_count <= lead_chars) |
||
461 | { /* encountered a character after a |
||
462 | number success so far */ |
||
463 | SwapState = Trailing_Chars; |
||
464 | break; |
||
465 | } |
||
466 | else |
||
467 | { |
||
468 | SwapState = No_Swap; |
||
469 | done = 1; |
||
470 | break; |
||
471 | } |
||
472 | } |
||
473 | if (isdigit (*pos)) |
||
474 | { /* continue ok */ |
||
475 | lead_count++; |
||
476 | break; |
||
477 | } |
||
478 | SwapState = No_Swap; |
||
479 | done = 1; |
||
480 | break; |
||
481 | |||
482 | case Trailing_Digits: |
||
483 | |||
484 | if (!isdigit (*pos)) |
||
485 | { |
||
486 | SwapState = No_Swap; |
||
487 | done = 1; |
||
488 | } |
||
489 | break; |
||
490 | case Trailing_Chars: |
||
491 | |||
492 | if (!isalpha (*pos)) |
||
493 | { |
||
494 | SwapState = No_Swap; |
||
495 | done = 1; |
||
496 | } |
||
497 | break; |
||
498 | default: |
||
499 | break; |
||
500 | } |
||
501 | pos++; |
||
502 | } |
||
503 | /* on arrival here in either state we can swap the two parts of |
||
504 | * the ident */ |
||
505 | if (SwapState == Trailing_Digits || |
||
506 | SwapState == Trailing_Chars) |
||
507 | { |
||
508 | int i, l; |
||
509 | strcpy (new_id, (nodes->identifier) + lead_count); |
||
510 | strncat (new_id, nodes->identifier, lead_count); |
||
511 | l = strlen (new_id); |
||
512 | for (i = 0; i < l; i++) |
||
513 | new_id[i] = tolower (new_id[i]); |
||
514 | Log ( |
||
515 | LOG_GENERAL, |
||
516 | "# Renaming %s(%s) to %s(%s)\n", |
||
517 | chip->identifier, |
||
518 | nodes->identifier, |
||
519 | chip->identifier, |
||
520 | new_id); |
||
521 | strcpy (nodes->identifier, new_id); |
||
522 | } |
||
523 | nodes = nodes->sktnext; |
||
524 | } |
||
525 | } |
||
526 | chip = chip->next; |
||
527 | } |
||
528 | vert_regfree (&preg); |
||
529 | } |
||
530 | |||
531 | /***************************************************************************************/ |
||
532 | /* Name nets after node name on device instead of pcb CAD name */ |
||
533 | /* Initially lookup all matching sockets */ |
||
534 | |||
535 | void alter_net_to_socket_name (char *chip_id_template, char *prefix_opt) |
||
536 | { |
||
537 | node_t *chip_node; |
||
538 | int found, rc, count = 0; |
||
539 | socket_t *socket; |
||
540 | vert_regex_t *preg; |
||
541 | |||
542 | socket = socket_head; |
||
543 | |||
544 | /* create_unrouted_list(); */ |
||
545 | /* compile regular expression */ |
||
546 | |||
547 | if (!chip_id_template) |
||
548 | { |
||
549 | chip_id_template = ".*"; |
||
550 | } |
||
551 | |||
552 | rc = vert_regcomp (&preg, chip_id_template); |
||
553 | if (rc != 0) |
||
554 | { |
||
555 | char errbuff[100]; |
||
556 | regerror (rc, preg->preg, errbuff, 100); |
||
557 | Log ( |
||
558 | LOG_ERROR, |
||
559 | "-- Problem (rc=%d) %s with '%s' as regular expression\n", |
||
560 | rc, |
||
561 | errbuff, |
||
562 | chip_id_template); |
||
563 | |||
564 | /* return TCL_ERROR; |
||
565 | */ |
||
566 | return; |
||
567 | } |
||
568 | else |
||
569 | { |
||
570 | Log (LOG_GENERAL, "-- Using '%s' as match pattern\n", chip_id_template); |
||
571 | } |
||
572 | while (socket) |
||
573 | { |
||
574 | found = regexec (preg->preg, socket->identifier, 0, preg->regpatt, 0); |
||
575 | |||
576 | if (!found) |
||
577 | { |
||
578 | /* |
||
579 | Log(LOG_GENERAL,"found %s\n",skt->identifier); |
||
580 | */ |
||
581 | count++; |
||
582 | chip_node = socket->nodes; |
||
583 | while (chip_node) |
||
584 | { |
||
585 | char name_buff[MAXIDLEN]; |
||
586 | int count; |
||
587 | net_t *net = chip_node->net; |
||
588 | if (net && IS_ROUTABLE (net->how_routed)) |
||
589 | { |
||
590 | if (prefix_opt) /* TH requests this change. Not a |
||
591 | problem */ |
||
592 | { |
||
593 | count = sprintf ( |
||
594 | name_buff, |
||
595 | "%s%s", |
||
596 | prefix_opt, |
||
597 | chip_node->identifier); |
||
598 | } |
||
599 | else |
||
600 | { |
||
601 | count = sprintf ( |
||
602 | name_buff, |
||
603 | "%s_%s", |
||
604 | socket->identifier, |
||
605 | chip_node->identifier); |
||
606 | } |
||
607 | net->identifier = realloc (net->identifier, count + 1); |
||
608 | strcpy (net->identifier, name_buff); |
||
609 | /* printf("-- id = %s\n",name_buff); */ |
||
610 | } |
||
611 | chip_node = chip_node->sktnext; |
||
612 | } |
||
613 | } |
||
614 | socket = socket->next; |
||
615 | } |
||
616 | Log (LOG_GENERAL, "-- processed %d sockets\n", count); |
||
617 | vert_regfree (&preg); |
||
618 | } |
||
619 | |||
620 | static char pin_map_chars[] = PIN_MAP_LEGAL_CHARS; |
||
621 | |||
622 | static int row_index, col_index; /* Made static so I can check them later .*/ |
||
623 | |||
624 | /***************************************************************************************/ |
||
625 | /* Name nets after node name on device instead of pcb CAD name */ |
||
626 | /* Initially lookup all matching sockets */ |
||
627 | /* change device template pin identifiers */ |
||
628 | |||
629 | void edit_socket_pin_name ( |
||
630 | char *chip_id_template, char *pin_patt, char *pin_repl, property_t search_space) |
||
631 | { |
||
632 | node_t *chip_node; |
||
633 | int found, rc, count = 0; |
||
634 | int subexpressions; |
||
635 | socket_t *socket; |
||
636 | vert_regex_t *preg; |
||
637 | vert_regex_t *ppin_reg; |
||
638 | int loop; |
||
639 | |||
640 | if (ISNULLSTR (pin_patt)) |
||
641 | { |
||
642 | return; |
||
643 | } |
||
644 | |||
645 | socket = template_head; |
||
646 | |||
647 | /* create_unrouted_list(); */ |
||
648 | /* compile regular expression for chip type */ |
||
649 | |||
650 | if (!chip_id_template) |
||
651 | { |
||
652 | chip_id_template = ".*"; |
||
653 | } |
||
654 | |||
655 | rc = vert_regcomp (&preg, chip_id_template); |
||
656 | if (rc != 0) |
||
657 | { |
||
658 | char errbuff[100]; |
||
659 | regerror (rc, preg->preg, errbuff, 100); |
||
660 | Log ( |
||
661 | LOG_ERROR, |
||
662 | "-- Problem (rc=%d) %s with '%s' as regular expression\n", |
||
663 | rc, |
||
664 | errbuff, |
||
665 | chip_id_template); |
||
666 | |||
667 | /* return TCL_ERROR; |
||
668 | */ |
||
669 | return; |
||
670 | } |
||
671 | else |
||
672 | { |
||
673 | Log ( |
||
674 | LOG_GENERAL, |
||
675 | "-- Using '%s' as match pattern for chip %s\n", |
||
676 | chip_id_template, |
||
677 | search_space == Type ? "type" : "ident"); |
||
678 | } |
||
679 | |||
680 | /* now compile pin regexp match pattern */ |
||
681 | rc = vert_regcomp (&ppin_reg, pin_patt); |
||
682 | if (rc != 0) |
||
683 | { |
||
684 | char errbuff[100]; |
||
685 | regerror (rc, ppin_reg->preg, errbuff, 100); |
||
686 | Log ( |
||
687 | LOG_ERROR, |
||
688 | "-- Problem (rc=%d) %s with '%s' as regular expression\n", |
||
689 | rc, |
||
690 | errbuff, |
||
691 | pin_patt); |
||
692 | |||
693 | /* return TCL_ERROR; |
||
694 | */ |
||
695 | return; |
||
696 | } |
||
697 | else |
||
698 | { |
||
699 | subexpressions = ppin_reg->preg->re_nsub + 1; /* count up subexpressions */ |
||
700 | Log ( |
||
701 | LOG_GENERAL, |
||
702 | "-- Using '%s' as chip pin ID matching pattern (%d subexpressions)\n", |
||
703 | pin_patt, |
||
704 | subexpressions); |
||
705 | } |
||
706 | |||
707 | if (subexpressions > MAX_REGEXP_SUBEXPR) |
||
708 | { |
||
709 | Log (LOG_ERROR, "-- Too many (>%d) subexpressions\n", MAX_REGEXP_SUBEXPR); |
||
710 | return; |
||
711 | } |
||
712 | /* decode the command type */ |
||
713 | |||
714 | switch (search_space) |
||
715 | { |
||
716 | case Ident: |
||
717 | loop = 1; |
||
718 | break; |
||
719 | case Type: |
||
720 | loop = 2; |
||
721 | break; |
||
722 | default: |
||
723 | loop = 0; |
||
724 | break; |
||
725 | } |
||
726 | |||
727 | /* loop 2,1, 0 or 1,0 dependent on whether search is type or ident based */ |
||
728 | while (loop) |
||
729 | { |
||
730 | switch (loop) |
||
731 | { |
||
732 | case 1: |
||
733 | socket = socket_head; |
||
734 | break; |
||
735 | case 2: |
||
736 | socket = template_head; |
||
737 | break; |
||
738 | default: |
||
739 | break; |
||
740 | } |
||
741 | loop--; |
||
742 | while (socket) |
||
743 | { |
||
744 | if (search_space == Type) |
||
745 | { |
||
746 | found = |
||
747 | regexec (preg->preg, socket->type, 0, preg->regpatt, 0); |
||
748 | } |
||
749 | else |
||
750 | { |
||
751 | found = regexec ( |
||
752 | preg->preg, socket->identifier, 0, preg->regpatt, 0); |
||
753 | } |
||
754 | if (!found) |
||
755 | { |
||
756 | /* |
||
757 | Log(LOG_GENERAL,"found %s\n",skt->identifier); |
||
758 | */ |
||
759 | |||
760 | int rows, columns; |
||
761 | /* int row_index,col_index; Made static so I can check |
||
762 | * them later .*/ |
||
763 | |||
764 | generic_info_t info, *row_expr, *col_expr; |
||
765 | |||
766 | /* Setup the row and column variables for this device */ |
||
767 | /* these are input names that can be used in an expression */ |
||
768 | info.g_type = IS_ATTRIBUTE; |
||
769 | info.g_class = DEFINED; |
||
770 | |||
771 | /* info is copied, simply change the variable parts and call |
||
772 | the compile and set functions */ |
||
773 | info.name = "pin_row"; |
||
774 | info.expr = compile_variable_reference (&row_index, "pin_row"); |
||
775 | set_generic_value (&socket->generics, &info); |
||
776 | |||
777 | info.name = "pin_col"; |
||
778 | info.expr = compile_variable_reference (&row_index, "pin_col"); |
||
779 | set_generic_value (&socket->generics, &info); |
||
780 | |||
781 | /* this expression will be evaluated when &n is seen in the |
||
782 | input file */ |
||
783 | row_expr = get_generic_ref (&socket->generics, "row_expr"); |
||
784 | |||
785 | /* |
||
786 | if(row_expr && row_expr->expr) |
||
787 | { |
||
788 | printf("row = "); |
||
789 | print_expression(stdout,row_expr->expr,NO_RECURSE); |
||
790 | printf("\n"); |
||
791 | } |
||
792 | */ |
||
793 | |||
794 | /* this expression will be evaluated when &a is seen in the |
||
795 | input file */ |
||
796 | col_expr = get_generic_ref (&socket->generics, "col_expr"); |
||
797 | /* |
||
798 | if(col_expr && col_expr->expr) |
||
799 | { |
||
800 | printf("col = "); |
||
801 | print_expression(stdout,col_expr->expr,NO_RECURSE); |
||
802 | printf("\n"); |
||
803 | } |
||
804 | */ |
||
805 | count++; |
||
806 | sort_nodes (socket, EXTRACT_XY); /* sort pins , determine pin |
||
807 | row and column*/ |
||
808 | |||
809 | rows = socket->max_pin_row - socket->min_pin_row + 1; |
||
810 | columns = socket->max_pin_col - socket->min_pin_col + 1; |
||
811 | |||
812 | chip_node = socket->nodes; |
||
813 | while (chip_node) |
||
814 | { |
||
815 | char *str; |
||
816 | str = chip_node->identifier; |
||
817 | /* allow one bracketed subexpression in pin names */ |
||
818 | found = regexec ( |
||
819 | ppin_reg->preg, |
||
820 | str, |
||
821 | subexpressions, |
||
822 | ppin_reg->regpatt, |
||
823 | 0); |
||
824 | if (!found) |
||
825 | { |
||
826 | char name_buff[MAXIDLEN]; |
||
827 | int count, fail; |
||
828 | int editp, copyp; |
||
829 | name_buff[0] = 0; |
||
830 | /* get length of replacement string */ |
||
831 | editp = 0; |
||
832 | count = 0; |
||
833 | fail = 0; |
||
834 | /* printf("Processing |
||
835 | * '%s'\n",pin_repl); */ |
||
836 | while (pin_repl[editp] && !fail) |
||
837 | { |
||
838 | /* escape anything */ |
||
839 | if (pin_repl[editp] == '\\') |
||
840 | { |
||
841 | editp++; |
||
842 | name_buff[count++] = |
||
843 | pin_repl[editp]; |
||
844 | if (pin_repl[editp]) |
||
845 | { |
||
846 | editp++; |
||
847 | } |
||
848 | } |
||
849 | /* replace matched patterns */ |
||
850 | else if (pin_repl[editp] == '&') |
||
851 | { |
||
852 | int index, len; |
||
853 | char c; |
||
854 | char temp[30]; |
||
855 | int digits; |
||
856 | /* change values to those seen |
||
857 | * on this pin */ |
||
858 | col_index = chip_node->pin_col; |
||
859 | row_index = chip_node->pin_row; |
||
860 | |||
861 | editp++; |
||
862 | c = pin_repl[editp]; |
||
863 | if (c) |
||
864 | { |
||
865 | /* printf("c='%c' |
||
866 | * row = %d col |
||
867 | * =%d\n",c,chip_node->pin_row |
||
868 | * ,chip_node->pin_col); |
||
869 | */ |
||
870 | editp++; |
||
871 | switch (c) |
||
872 | { |
||
873 | case 'c': |
||
874 | case 'C': |
||
875 | if (chip_node |
||
876 | ->net && |
||
877 | chip_node |
||
878 | ->net |
||
879 | ->name) |
||
880 | { |
||
881 | len = strlen ( |
||
882 | chip_node |
||
883 | ->net |
||
884 | ->name); |
||
885 | strncpy ( |
||
886 | name_buff + |
||
887 | count, |
||
888 | chip_node |
||
889 | ->net |
||
890 | ->name, |
||
891 | len); |
||
892 | count += |
||
893 | len; |
||
894 | } |
||
895 | else |
||
896 | { |
||
897 | fail = |
||
898 | 1; |
||
899 | } |
||
900 | break; |
||
901 | |||
902 | /* &d or &D is |
||
903 | * the device |
||
904 | * identifier |
||
905 | */ |
||
906 | case 'd': |
||
907 | case 'D': |
||
908 | len = strlen ( |
||
909 | socket |
||
910 | ->identifier); |
||
911 | strncpy ( |
||
912 | name_buff + |
||
913 | count, |
||
914 | socket |
||
915 | ->identifier, |
||
916 | len); |
||
917 | count += len; |
||
918 | break; |
||
919 | /* &p or &P is |
||
920 | * the pin |
||
921 | * identifier |
||
922 | */ |
||
923 | case 'p': |
||
924 | case 'P': |
||
925 | len = strlen ( |
||
926 | chip_node |
||
927 | ->identifier); |
||
928 | strncpy ( |
||
929 | name_buff + |
||
930 | count, |
||
931 | chip_node |
||
932 | ->identifier, |
||
933 | len); |
||
934 | count += len; |
||
935 | break; |
||
936 | /* &a is the |
||
937 | * alpha |
||
938 | * component of |
||
939 | * the |
||
940 | * identifier |
||
941 | */ |
||
942 | case 'a': |
||
943 | case 'A': |
||
944 | /* always |
||
945 | * synthesise |
||
946 | * pin column |
||
947 | * from the |
||
948 | * info left by |
||
949 | * sort_nodes |
||
950 | */ |
||
951 | if (col_expr && |
||
952 | col_expr |
||
953 | ->expr) |
||
954 | { |
||
955 | index = eval_expression ( |
||
956 | col_expr |
||
957 | ->expr, |
||
958 | &socket |
||
959 | ->generics); |
||
960 | } |
||
961 | else |
||
962 | { |
||
963 | index = |
||
964 | chip_node |
||
965 | ->pin_col; |
||
966 | } |
||
967 | /* printf("Alpha |
||
968 | * %d : |
||
969 | * ",index); */ |
||
970 | digits = 0; |
||
971 | /* always at |
||
972 | * least a |
||
973 | * single char |
||
974 | */ |
||
975 | if (index > |
||
976 | 0) /* index |
||
977 | = 0 |
||
978 | means |
||
979 | no |
||
980 | chars |
||
981 | at |
||
982 | all ! |
||
983 | */ |
||
984 | { |
||
985 | do |
||
986 | { |
||
987 | if (c == |
||
988 | 'a') /* lower case idents if lower case 'a' is used */ |
||
989 | { |
||
990 | temp[digits++] = tolower ( |
||
991 | pin_map_chars |
||
992 | [index % |
||
993 | (PIN_MAP_LEGAL_CHAR_COUNT + |
||
994 | 1) - |
||
995 | 1]); |
||
996 | } |
||
997 | else |
||
998 | { |
||
999 | temp[digits++] = pin_map_chars |
||
1000 | [index % |
||
1001 | (PIN_MAP_LEGAL_CHAR_COUNT + |
||
1002 | 1) - |
||
1003 | 1]; |
||
1004 | } |
||
1005 | |||
1006 | index /= |
||
1007 | (PIN_MAP_LEGAL_CHAR_COUNT + |
||
1008 | 1); |
||
1009 | } while ( |
||
1010 | index); |
||
1011 | temp[digits] = |
||
1012 | 0; |
||
1013 | /* printf("conversion |
||
1014 | * '%s'\n",temp); |
||
1015 | */ |
||
1016 | /* reverse |
||
1017 | * copy |
||
1018 | * string, |
||
1019 | * at |
||
1020 | * least |
||
1021 | * one |
||
1022 | * char |
||
1023 | */ |
||
1024 | for ( |
||
1025 | ; |
||
1026 | digits > |
||
1027 | 0; |
||
1028 | name_buff |
||
1029 | [count++] = temp |
||
1030 | [--digits]) |
||
1031 | ; |
||
1032 | } |
||
1033 | else |
||
1034 | { |
||
1035 | /* error |
||
1036 | * in |
||
1037 | * the |
||
1038 | * expansion |
||
1039 | * as |
||
1040 | * the |
||
1041 | * index |
||
1042 | * < 0 |
||
1043 | */ |
||
1044 | /* Leave |
||
1045 | it |
||
1046 | blank |
||
1047 | as |
||
1048 | there |
||
1049 | is a |
||
1050 | danger |
||
1051 | elsewhere |
||
1052 | name_buff[count++] = '&'; |
||
1053 | name_buff[count++] = c; |
||
1054 | */ |
||
1055 | } |
||
1056 | break; |
||
1057 | /* &n is the |
||
1058 | * alpha |
||
1059 | * component of |
||
1060 | * the |
||
1061 | * identifier |
||
1062 | */ |
||
1063 | case 'n': |
||
1064 | case 'N': |
||
1065 | if (row_expr && |
||
1066 | row_expr |
||
1067 | ->expr) |
||
1068 | { |
||
1069 | index = eval_expression ( |
||
1070 | row_expr |
||
1071 | ->expr, |
||
1072 | &socket |
||
1073 | ->generics); |
||
1074 | } |
||
1075 | else |
||
1076 | { |
||
1077 | index = |
||
1078 | chip_node |
||
1079 | ->pin_row; |
||
1080 | } |
||
1081 | /* printf("Numeric |
||
1082 | * %d\n",index); |
||
1083 | */ |
||
1084 | if (index > |
||
1085 | 0) /* index |
||
1086 | = 0 |
||
1087 | means |
||
1088 | no |
||
1089 | chars |
||
1090 | at |
||
1091 | all ! |
||
1092 | */ |
||
1093 | { |
||
1094 | sprintf ( |
||
1095 | temp, |
||
1096 | "%" |
||
1097 | "d", |
||
1098 | index); |
||
1099 | len = strlen ( |
||
1100 | temp); |
||
1101 | strncpy ( |
||
1102 | name_buff + |
||
1103 | count, |
||
1104 | temp, |
||
1105 | len); |
||
1106 | /* printf("result: |
||
1107 | * '%s' |
||
1108 | * %d\n",name_buff,strlen(name_buff)); |
||
1109 | */ |
||
1110 | count += |
||
1111 | len; |
||
1112 | } |
||
1113 | else |
||
1114 | { |
||
1115 | /* error |
||
1116 | * in |
||
1117 | * the |
||
1118 | * expansion |
||
1119 | * as |
||
1120 | * the |
||
1121 | * index |
||
1122 | * < 0 |
||
1123 | */ |
||
1124 | name_buff |
||
1125 | [count++] = |
||
1126 | '&'; |
||
1127 | name_buff |
||
1128 | [count++] = |
||
1129 | c; |
||
1130 | } |
||
1131 | |||
1132 | break; |
||
1133 | case 'i': |
||
1134 | case 'I': |
||
1135 | sprintf ( |
||
1136 | temp, |
||
1137 | "%d", |
||
1138 | chip_node |
||
1139 | ->pin_row - |
||
1140 | socket |
||
1141 | ->min_pin_row + |
||
1142 | (chip_node |
||
1143 | ->pin_col - |
||
1144 | socket |
||
1145 | ->min_pin_col) * |
||
1146 | rows + |
||
1147 | 1); |
||
1148 | |||
1149 | len = strlen ( |
||
1150 | temp); |
||
1151 | strncpy ( |
||
1152 | name_buff + |
||
1153 | count, |
||
1154 | temp, |
||
1155 | len); |
||
1156 | count += len; |
||
1157 | break; |
||
1158 | /* &0 to &9 or |
||
1159 | whatever is |
||
1160 | the regular |
||
1161 | expression |
||
1162 | bracketed |
||
1163 | section */ |
||
1164 | default: |
||
1165 | index = |
||
1166 | c - '0'; |
||
1167 | if (index < |
||
1168 | |||
1169 | index > |
||
1170 | subexpressions) |
||
1171 | { |
||
1172 | fail = |
||
1173 | 1; |
||
1174 | } |
||
1175 | else |
||
1176 | { |
||
1177 | /* copy |
||
1178 | * subexpression |
||
1179 | * over |
||
1180 | */ |
||
1181 | copyp = |
||
1182 | ppin_reg |
||
1183 | ->regpatt |
||
1184 | [index] |
||
1185 | .rm_so; |
||
1186 | if (copyp >= |
||
1187 | 0) |
||
1188 | { |
||
1189 | while ( |
||
1190 | copyp < |
||
1191 | ppin_reg |
||
1192 | ->regpatt |
||
1193 | [index] |
||
1194 | .rm_eo) |
||
1195 | { |
||
1196 | name_buff |
||
1197 | [count++] = str |
||
1198 | [copyp++]; |
||
1199 | } |
||
1200 | } |
||
1201 | else |
||
1202 | { |
||
1203 | name_buff |
||
1204 | [count++] = |
||
1205 | '@'; |
||
1206 | } |
||
1207 | } |
||
1208 | } |
||
1209 | } |
||
1210 | } |
||
1211 | |||
1212 | else |
||
1213 | { |
||
1214 | name_buff[count++] = |
||
1215 | pin_repl[editp++]; |
||
1216 | } |
||
1217 | } |
||
1218 | if (!fail) |
||
1219 | { |
||
1220 | name_buff[count] = 0; |
||
1221 | /* |
||
1222 | printf("replacing '%s' with |
||
1223 | '%s'\n",chip_node->identifier,name_buff); |
||
1224 | */ |
||
1225 | chip_node->identifier = realloc ( |
||
1226 | chip_node->identifier, count + 1); |
||
1227 | strcpy ( |
||
1228 | chip_node->identifier, name_buff); |
||
1229 | } |
||
1230 | } |
||
1231 | chip_node = chip_node->sktnext; |
||
1232 | } |
||
1233 | } |
||
1234 | sort_nodes (socket, NO_EXTRACT_XY); |
||
1235 | socket = socket->next; |
||
1236 | } |
||
1237 | } |
||
1238 | Log (LOG_GENERAL, "-- processed %d sockets\n", count); |
||
1239 | vert_regfree (&preg); |
||
1240 | vert_regfree (&ppin_reg); |
||
1241 | } |
||
1242 | |||
1243 | /***************************************************************************************/ |
||
1244 | /* allows for net renaming : currently in the routed list only */ |
||
1245 | void edit_net_names (char *pin_patt, char *pin_repl, property_t search_space) |
||
1246 | { |
||
1247 | net_t *curr_net; |
||
1248 | int found, rc = 0; |
||
1249 | int subexpressions; |
||
1250 | int net_count; |
||
1251 | vert_regex_t *ppin_reg; |
||
1252 | int loop; |
||
1253 | net_count = 0; |
||
1254 | |||
1255 | if (ISNULLSTR (pin_patt)) |
||
1256 | { |
||
1257 | return; |
||
1258 | } |
||
1259 | |||
1260 | curr_net = routed_list; |
||
1261 | |||
1262 | /* now compile pin regexp match pattern */ |
||
1263 | rc = vert_regcomp (&ppin_reg, pin_patt); |
||
1264 | if (rc != 0) |
||
1265 | { |
||
1266 | char errbuff[100]; |
||
1267 | regerror (rc, ppin_reg->preg, errbuff, 100); |
||
1268 | Log ( |
||
1269 | LOG_ERROR, |
||
1270 | "-- Problem (rc=%d) %s with '%s' as regular expression\n", |
||
1271 | rc, |
||
1272 | errbuff, |
||
1273 | pin_patt); |
||
1274 | |||
1275 | /* return TCL_ERROR; |
||
1276 | */ |
||
1277 | return; |
||
1278 | } |
||
1279 | else |
||
1280 | { |
||
1281 | subexpressions = ppin_reg->preg->re_nsub + 1; /* count up subexpressions */ |
||
1282 | Log ( |
||
1283 | LOG_GENERAL, |
||
1284 | "-- Using '%s' as net matching pattern (%d subexpressions)\n", |
||
1285 | pin_patt, |
||
1286 | subexpressions); |
||
1287 | } |
||
1288 | |||
1289 | if (subexpressions > MAX_REGEXP_SUBEXPR) |
||
1290 | { |
||
1291 | Log (LOG_ERROR, "-- Too many (>%d) subexpressions\n", MAX_REGEXP_SUBEXPR); |
||
1292 | return; |
||
1293 | } |
||
1294 | /* decode the command type */ |
||
1295 | /* |
||
1296 | switch (search_space) |
||
1297 | { |
||
1298 | case Ident: loop = 1; break; |
||
1299 | case Type : loop = 2; break; |
||
1300 | default : loop = 0; break; |
||
1301 | } |
||
1302 | */ |
||
1303 | |||
1304 | loop = 3; |
||
1305 | /* loop 2,1, 0 or 1,0 dependent on whether search is type or ident based */ |
||
1306 | while (loop) |
||
1307 | { |
||
1308 | char *str; |
||
1309 | printf ("In loop %d\n", loop); |
||
1310 | switch (loop) |
||
1311 | { |
||
1312 | case 1: |
||
1313 | curr_net = routed_list; |
||
1314 | break; |
||
1315 | case 2: |
||
1316 | curr_net = unrouted_list; |
||
1317 | break; |
||
1318 | case 3: |
||
1319 | curr_net = named_list; |
||
1320 | break; |
||
1321 | default: |
||
1322 | curr_net = NULL; |
||
1323 | break; |
||
1324 | } |
||
1325 | loop--; |
||
1326 | while (curr_net) |
||
1327 | { |
||
1328 | found = 1; |
||
1329 | str = "nothing"; |
||
1330 | if (search_space == Name && !ISNULLSTR (curr_net->name)) |
||
1331 | { |
||
1332 | found = regexec ( |
||
1333 | ppin_reg->preg, curr_net->name, 0, ppin_reg->regpatt, 0); |
||
1334 | str = curr_net->name; |
||
1335 | } |
||
1336 | |||
1337 | if (search_space == Ident && !ISNULLSTR (curr_net->identifier)) |
||
1338 | { |
||
1339 | found = regexec ( |
||
1340 | ppin_reg->preg, |
||
1341 | curr_net->identifier, |
||
1342 | 0, |
||
1343 | ppin_reg->regpatt, |
||
1344 | 0); |
||
1345 | str = curr_net->identifier; |
||
1346 | } |
||
1347 | /* printf("Checking '%s'\n",str); */ |
||
1348 | |||
1349 | /* found will not be set if neither Name or Ident is used */ |
||
1350 | if (!found) |
||
1351 | { |
||
1352 | char name_buff[MAXIDLEN]; |
||
1353 | int fail, count; |
||
1354 | int editp, copyp; |
||
1355 | name_buff[0] = 0; |
||
1356 | /* get length of replacement string */ |
||
1357 | editp = 0; |
||
1358 | fail = 0; |
||
1359 | count = 0; |
||
1360 | net_count++; |
||
1361 | printf ("Processing '%s'\n", str); |
||
1362 | while (pin_repl[editp] && !fail) |
||
1363 | { |
||
1364 | /* escape anything */ |
||
1365 | if (pin_repl[editp] == '\\') |
||
1366 | { |
||
1367 | editp++; |
||
1368 | name_buff[count++] = pin_repl[editp]; |
||
1369 | if (pin_repl[editp]) |
||
1370 | { |
||
1371 | editp++; |
||
1372 | } |
||
1373 | } |
||
1374 | /* replace matched patterns */ |
||
1375 | else if (pin_repl[editp] == '&') |
||
1376 | { |
||
1377 | int index, len; |
||
1378 | char c; |
||
1379 | editp++; |
||
1380 | c = pin_repl[editp]; |
||
1381 | if (c) |
||
1382 | { |
||
1383 | editp++; |
||
1384 | switch (c) |
||
1385 | { |
||
1386 | /* replace with name part of |
||
1387 | * net */ |
||
1388 | case 'n': |
||
1389 | case 'N': |
||
1390 | if (!ISNULLSTR ( |
||
1391 | curr_net->name)) |
||
1392 | { |
||
1393 | len = strlen ( |
||
1394 | curr_net->name); |
||
1395 | strncpy ( |
||
1396 | name_buff + count, |
||
1397 | curr_net->name, |
||
1398 | len); |
||
1399 | count += len; |
||
1400 | } |
||
1401 | else |
||
1402 | { |
||
1403 | fail = 1; |
||
1404 | } |
||
1405 | break; |
||
1406 | |||
1407 | case 'i': |
||
1408 | case 'I': |
||
1409 | if (!ISNULLSTR ( |
||
1410 | curr_net->identifier)) |
||
1411 | { |
||
1412 | len = strlen ( |
||
1413 | curr_net |
||
1414 | ->identifier); |
||
1415 | strncpy ( |
||
1416 | name_buff + count, |
||
1417 | curr_net |
||
1418 | ->identifier, |
||
1419 | len); |
||
1420 | count += len; |
||
1421 | } |
||
1422 | else |
||
1423 | { |
||
1424 | fail = 1; |
||
1425 | } |
||
1426 | break; |
||
1427 | |||
1428 | /* &0 to &9 or whatever is the |
||
1429 | regular expression bracketed |
||
1430 | section */ |
||
1431 | default: |
||
1432 | index = c - '0'; |
||
1433 | if (index < 0 || |
||
1434 | index > subexpressions) |
||
1435 | { |
||
1436 | fail = 1; |
||
1437 | } |
||
1438 | else |
||
1439 | { |
||
1440 | /* copy subexpression |
||
1441 | * over */ |
||
1442 | copyp = ppin_reg |
||
1443 | ->regpatt |
||
1444 | [index] |
||
1445 | .rm_so; |
||
1446 | if (copyp >= 0) |
||
1447 | { |
||
1448 | while ( |
||
1449 | copyp < |
||
1450 | ppin_reg |
||
1451 | ->regpatt |
||
1452 | [index] |
||
1453 | .rm_eo) |
||
1454 | { |
||
1455 | name_buff |
||
1456 | [count++] = str |
||
1457 | [copyp++]; |
||
1458 | } |
||
1459 | } |
||
1460 | else |
||
1461 | { |
||
1462 | name_buff |
||
1463 | [count++] = |
||
1464 | '@'; |
||
1465 | } |
||
1466 | } |
||
1467 | } /* cae */ |
||
1468 | } |
||
1469 | } |
||
1470 | |||
1471 | else |
||
1472 | { |
||
1473 | name_buff[count++] = pin_repl[editp++]; |
||
1474 | } |
||
1475 | } |
||
1476 | if (!fail) |
||
1477 | { |
||
1478 | name_buff[count] = 0; |
||
1479 | /* |
||
1480 | printf("replacing '%s' with |
||
1481 | '%s'\n",chip_node->identifier,name_buff); |
||
1482 | */ |
||
1483 | if (search_space == Ident) |
||
1484 | { |
||
1485 | curr_net->identifier = |
||
1486 | realloc (curr_net->identifier, count + 1); |
||
1487 | |||
1488 | printf ( |
||
1489 | "replacing '%s' with '%s'\n", |
||
1490 | curr_net->identifier, |
||
1491 | name_buff); |
||
1492 | strcpy (curr_net->identifier, name_buff); |
||
1493 | } |
||
1494 | if (search_space == Name) |
||
1495 | { |
||
1496 | curr_net->name = |
||
1497 | realloc (curr_net->name, count + 1); |
||
1498 | printf ( |
||
1499 | "replacing '%s' with '%s'\n", |
||
1500 | curr_net->name, |
||
1501 | name_buff); |
||
1502 | strcpy (curr_net->name, name_buff); |
||
1503 | } |
||
1504 | } |
||
1505 | } |
||
1506 | curr_net = curr_net->next; |
||
1507 | } |
||
1508 | } |
||
1509 | Log (LOG_GENERAL, "-- processed %d nets\n", net_count); |
||
1510 | vert_regfree (&ppin_reg); |
||
1511 | } |