1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
22 * 2005/05/02 Almost totally reimplemented to support dynamic allocation.
24 * Changes are Copyright (C) 2005 Carlos A. R. Azevedo
41 #include <libgeda/libgeda.h>
43 #include "../include/globals.h"
44 #include "../include/prototype.h"
46 #ifdef HAVE_LIBDMALLOC
58 RENAME
* first_rename
;
62 static SET
* first_set
= NULL
;
63 static SET
* last_set
= NULL
;
65 void s_rename_init(void)
69 fprintf(stderr
,"ERROR: Overwriting a valid rename list.\n");
74 void s_rename_destroy_all(void)
81 for (temp
= first_set
->first_rename
; temp
;)
90 first_set
= first_set
->next_set
;
96 void s_rename_next_set(void)
100 new_set
= g_malloc(sizeof(SET
));
101 memset(new_set
,0,sizeof(SET
));
104 last_set
->next_set
= new_set
;
109 first_set
= last_set
= new_set
;
113 void s_rename_print(void)
116 RENAME
* temp_rename
;
119 for (i
= 0, temp_set
= first_set
; temp_set
; temp_set
= temp_set
->next_set
, i
++)
121 for (temp_rename
= temp_set
->first_rename
; temp_rename
; temp_rename
= temp_rename
->next
)
123 printf("%d) Source: _%s_", i
, temp_rename
->src
);
124 printf(" -> Dest: _%s_\n", temp_rename
->dest
);
129 /* if the src is found, return true */
130 /* if the dest is found, also return true, but warn user */
131 /* If quiet_flag is true than don't print anything */
132 int s_rename_search(char *src
, char *dest
, int quiet_flag
)
138 for (temp
= last_set
->first_rename
; temp
; temp
= temp
->next
)
140 if (strcmp(src
, temp
->src
) == 0)
145 if (strcmp(dest
, temp
->src
) == 0)
149 fprintf(stderr
,"WARNING: Trying to rename something twice:\n\t%s and %s\nare both a src and dest name\n", dest
, temp
->src
);
150 fprintf(stderr
,"This warning is okay if you have multiple levels of hierarchy!\n");
159 void s_rename_add(char *src
, char *dest
)
167 if (src
== NULL
|| dest
== NULL
)
172 flag
= s_rename_search(src
, dest
, FALSE
);
176 /* If found follow the original behaviour, limiting the operation to the current end-of-list */
177 last
= last_set
->last_rename
;
178 for (temp
= last_set
->first_rename
; ; temp
= temp
->next
)
180 if (strcmp(dest
, temp
->src
) == 0)
183 printf("Found dest [%s] in src [%s] and that had a dest as: [%s]\nSo you want rename [%s] to [%s]\n",
184 dest
, temp
->src
, temp
->dest
, src
, temp
->dest
);
186 new_rename
= g_malloc(sizeof(RENAME
));
187 new_rename
->next
= NULL
;
188 new_rename
->src
= g_strdup(src
);
189 new_rename
->dest
= g_strdup(temp
->dest
);
190 /* If the rename pair was found then a set already exists, so there's no need the check it */
191 if (last_set
->first_rename
== NULL
)
193 last_set
->first_rename
= last_set
->last_rename
= new_rename
;
197 last_set
->last_rename
->next
= new_rename
;
198 last_set
->last_rename
= new_rename
;
209 /* Check for a valid set */
210 if (first_set
== NULL
)
212 new_set
= g_malloc(sizeof(SET
));
213 memset(new_set
,0,sizeof(SET
));
214 first_set
= last_set
= new_set
;
216 new_rename
= g_malloc(sizeof(RENAME
));
217 new_rename
->next
= NULL
;
218 new_rename
->src
= g_strdup(src
);
219 new_rename
->dest
= g_strdup(dest
);
220 if (last_set
->first_rename
== NULL
)
222 last_set
->first_rename
= last_set
->last_rename
= new_rename
;
226 last_set
->last_rename
->next
= new_rename
;
227 last_set
->last_rename
= new_rename
;
232 void s_rename_all_lowlevel(NETLIST
* netlist_head
, char *src
, char *dest
)
234 NETLIST
*nl_current
= NULL
;
235 CPINLIST
*pl_current
;
237 nl_current
= netlist_head
;
239 while (nl_current
!= NULL
)
241 if (nl_current
->cpins
)
243 pl_current
= nl_current
->cpins
;
244 while (pl_current
!= NULL
)
246 if (pl_current
->net_name
!= NULL
)
248 if (strcmp(pl_current
->net_name
, src
) == 0)
250 pl_current
->net_name
= g_strdup(dest
);
253 pl_current
= pl_current
->next
;
256 nl_current
= nl_current
->next
;
260 void s_rename_all(TOPLEVEL
* pr_current
, NETLIST
* netlist_head
)
270 for (temp
= last_set
->first_rename
; temp
; temp
= temp
->next
)
273 s_rename_all_lowlevel(netlist_head
, temp
->src
, temp
->dest
);
279 SCM
g_get_renamed_nets(SCM scm_level
)
281 SCM pairlist
= SCM_EOL
;
282 SCM outerlist
= SCM_EOL
;
284 RENAME
* temp_rename
;
287 level
= SCM_STRING_CHARS (scm_level
);
289 for (temp_set
= first_set
; temp_set
; temp_set
= temp_set
->next_set
)
291 for (temp_rename
= temp_set
->first_rename
; temp_rename
; temp_rename
= temp_rename
->next
)
293 pairlist
= scm_list_n (scm_makfrom0str (temp_rename
->src
), scm_makfrom0str (temp_rename
->dest
), SCM_UNDEFINED
);
294 outerlist
= scm_cons (pairlist
, outerlist
);