1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 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
32 #include <libgeda/libgeda.h>
34 #include "../include/globals.h"
35 #include "../include/prototype.h"
37 #ifdef HAVE_LIBDMALLOC
41 /* used by the extract functions below */
42 #define DELIMITERS ",; "
44 /* hack rename this to be s_return_tail */
45 /* update object_tail or any list of that matter */
46 NETLIST
*s_netlist_return_tail(NETLIST
* head
)
48 NETLIST
*nl_current
= NULL
;
49 NETLIST
*ret_struct
= NULL
;
52 while (nl_current
!= NULL
) { /* goto end of list */
53 ret_struct
= nl_current
;
54 nl_current
= nl_current
->next
;
60 /* hack rename this to be s_return_head */
61 /* update object_tail or any list of that matter */
62 NETLIST
*s_netlist_return_head(NETLIST
* tail
)
64 NETLIST
*nl_current
= NULL
;
65 NETLIST
*ret_struct
= NULL
;
68 while (nl_current
!= NULL
) { /* goto end of list */
69 ret_struct
= nl_current
;
70 nl_current
= nl_current
->prev
;
77 /* returns new node */
78 NETLIST
*s_netlist_add(NETLIST
* ptr
)
82 new_node
= (NETLIST
*) g_malloc(sizeof(NETLIST
));
84 /* setup node information */
86 new_node
->cpins
= NULL
;
87 new_node
->component_uref
= NULL
;
88 new_node
->object_ptr
= NULL
;
89 new_node
->hierarchy_tag
= NULL
;
90 new_node
->composite_component
= FALSE
;
92 /* Setup link list stuff */
93 new_node
->next
= NULL
;
96 new_node
->prev
= NULL
; /* setup previous link */
99 new_node
->prev
= ptr
; /* setup previous link */
100 ptr
->next
= new_node
;
105 void s_netlist_print(NETLIST
* ptr
)
107 NETLIST
*nl_current
= NULL
;
111 if (nl_current
== NULL
) {
115 while (nl_current
!= NULL
) {
117 if (nl_current
->nlid
!= -1) {
119 if (nl_current
->component_uref
) {
120 printf("component %s \n", nl_current
->component_uref
);
122 printf("component SPECIAL \n");
125 if (nl_current
->hierarchy_tag
) {
126 printf("Hierarchy tag: %s\n", nl_current
->hierarchy_tag
);
129 if (nl_current
->cpins
) {
130 s_cpinlist_print(nl_current
->cpins
);
136 nl_current
= nl_current
->next
;
141 void s_netlist_post_process(TOPLEVEL
* pr_current
, NETLIST
* head
)
144 CPINLIST
*pl_current
;
150 printf("\n- Staring post processing\n");
151 printf("- Naming nets:\n");
155 /* this pass gives all nets a name, whether specified or creates a */
158 while (nl_current
!= NULL
) {
159 if (nl_current
->cpins
) {
160 pl_current
= nl_current
->cpins
;
161 while (pl_current
!= NULL
) {
163 if (pl_current
->plid
!= -1) {
167 if (pl_current
->plid
!= -1 && pl_current
->nets
) {
169 if (pl_current
->net_name
) {
170 g_free(pl_current
->net_name
);
175 /* only name nets of components which */
177 if (nl_current
->component_uref
) {
178 pl_current
->net_name
=
179 s_net_name(pr_current
,
182 nl_current
->hierarchy_tag
);
184 /* put this name also in the first
185 node of the nets linked list */
186 if (pl_current
->net_name
&& pl_current
->nets
) {
187 if (pl_current
->nets
->next
) {
188 pl_current
->nets
->next
->net_name
=
189 g_strdup (pl_current
->net_name
);
195 pl_current
= pl_current
->next
;
198 nl_current
= nl_current
->next
;
203 printf("- Renaming nets:\n");
206 s_rename_all(pr_current
, head
);
210 printf("- Resolving hierarchy:\n");
212 s_hierarchy_post_process(pr_current
, head
);
215 if (pr_current
->hierarchy_uref_mangle
== FALSE
) {
217 printf("- Removing refdes mangling:\n");
219 s_hierarchy_remove_uref_mangling(pr_current
, head
);
225 void s_netlist_name_named_nets (TOPLEVEL
*pr_current
,
226 NETLIST
*named_netlist
,
227 NETLIST
*unnamed_netlist
) {
230 CPINLIST
*pl_current
;
235 printf("\n- Staring post processing\n");
236 printf("- Naming nets of graphical objects:\n");
239 /* this pass gives all nets a name, whether specified or creates a */
241 nl_current
= unnamed_netlist
;
242 while (nl_current
!= NULL
) {
243 if (nl_current
->cpins
) {
244 pl_current
= nl_current
->cpins
;
245 while (pl_current
!= NULL
) {
247 if (pl_current
->plid
!= -1) {
251 if (pl_current
->plid
!= -1 && pl_current
->nets
) {
254 n_current
= pl_current
->nets
;
255 while (n_current
!= NULL
) {
256 if (n_current
->net_name
) {
257 g_free (n_current
->net_name
);
259 n_current
->net_name
= s_netlist_netname_of_netid(pr_current
,
263 if (n_current
->net_name
!= NULL
) {
264 net_name
= n_current
->net_name
;
266 n_current
= n_current
->next
;
268 if (net_name
!= NULL
) {
269 pl_current
->net_name
= g_strdup(net_name
);
272 pl_current
= pl_current
->next
;
275 nl_current
= nl_current
->next
;
282 char *s_netlist_netname_of_netid (TOPLEVEL
*pr_current
,
283 NETLIST
*netlist_head
,
287 CPINLIST
*pl_current
;
290 nl_current
= netlist_head
;
292 /* walk through the list of components, and through the list
293 * of individual pins on each, looking for the net identifier
295 while (nl_current
!= NULL
) {
296 pl_current
= nl_current
->cpins
;
297 while (pl_current
!= NULL
) {
298 if (pl_current
->net_name
) {
299 n_current
= pl_current
->nets
;
300 while (n_current
!= NULL
) {
301 if (n_current
->nid
== net_id
) {
302 return (g_strdup(n_current
->net_name
));
304 n_current
= n_current
->next
;
307 pl_current
= pl_current
->next
;
309 nl_current
= nl_current
->next
;