gnetlist: Fix some "set but not used" warnings.
[geda-gaf/peter-b.git] / gnetlist / src / s_netlist.c
blobc4bf1d9b337c7a4ec44786959c0c7f04f0279af8
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>
27 #endif
28 #ifdef HAVE_ASSERT_H
29 #include <assert.h>
30 #endif
32 #include <libgeda/libgeda.h>
34 #include "../include/globals.h"
35 #include "../include/prototype.h"
37 #ifdef HAVE_LIBDMALLOC
38 #include <dmalloc.h>
39 #endif
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;
51 nl_current = head;
52 while (nl_current != NULL) { /* goto end of list */
53 ret_struct = nl_current;
54 nl_current = nl_current->next;
57 return (ret_struct);
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;
67 nl_current = tail;
68 while (nl_current != NULL) { /* goto end of list */
69 ret_struct = nl_current;
70 nl_current = nl_current->prev;
73 return (ret_struct);
77 /* returns new node */
78 NETLIST *s_netlist_add(NETLIST * ptr)
80 NETLIST *new_node;
82 new_node = (NETLIST *) g_malloc(sizeof(NETLIST));
84 /* setup node information */
85 new_node->nlid = 0;
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;
95 if (ptr == NULL) {
96 new_node->prev = NULL; /* setup previous link */
97 return (new_node);
98 } else {
99 new_node->prev = ptr; /* setup previous link */
100 ptr->next = new_node;
101 return (ptr->next);
105 void s_netlist_print(NETLIST * ptr)
107 NETLIST *nl_current = NULL;
109 nl_current = ptr;
111 if (nl_current == NULL) {
112 return;
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);
121 } else {
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);
133 printf("\n");
136 nl_current = nl_current->next;
138 printf("\n");
141 void s_netlist_post_process(TOPLEVEL * pr_current, NETLIST * head)
143 NETLIST *nl_current;
144 CPINLIST *pl_current;
146 nl_current = head;
148 if (verbose_mode) {
149 printf("\n- Staring post processing\n");
150 printf("- Naming nets:\n");
153 /* this pass gives all nets a name, whether specified or creates a */
154 /* name */
155 nl_current = head;
156 while (nl_current != NULL) {
157 if (nl_current->cpins) {
158 pl_current = nl_current->cpins;
159 while (pl_current != NULL) {
161 if (pl_current->plid != -1) {
162 verbose_print("p");
165 if (pl_current->plid != -1 && pl_current->nets) {
167 g_free(pl_current->net_name);
169 verbose_print("n");
171 /* only name nets of components which */
172 /* have a uref */
173 if (nl_current->component_uref) {
174 pl_current->net_name =
175 s_net_name(pr_current,
176 head,
177 pl_current->nets,
178 nl_current->hierarchy_tag,
179 pl_current->type);
181 /* put this name also in the first
182 node of the nets linked list */
183 if (pl_current->net_name && pl_current->nets) {
184 if (pl_current->nets->next) {
185 pl_current->nets->next->net_name =
186 g_strdup (pl_current->net_name);
192 pl_current = pl_current->next;
195 nl_current = nl_current->next;
198 verbose_done();
199 if (verbose_mode) {
200 printf("- Renaming nets:\n");
203 s_rename_all(pr_current, head);
205 verbose_done();
206 if (verbose_mode) {
207 printf("- Resolving hierarchy:\n");
209 s_hierarchy_post_process(pr_current, head);
211 verbose_done();
212 if (pr_current->hierarchy_uref_mangle == FALSE) {
213 if (verbose_mode) {
214 printf("- Removing refdes mangling:\n");
216 s_hierarchy_remove_uref_mangling(pr_current, head);
219 verbose_done();
222 void s_netlist_name_named_nets (TOPLEVEL *pr_current,
223 NETLIST *named_netlist,
224 NETLIST *unnamed_netlist) {
226 NETLIST *nl_current;
227 CPINLIST *pl_current;
228 NET *n_current;
229 char *net_name;
231 if (verbose_mode) {
232 printf("\n- Staring post processing\n");
233 printf("- Naming nets of graphical objects:\n");
236 /* this pass gives all nets a name, whether specified or creates a */
237 /* name */
238 nl_current = unnamed_netlist;
239 while (nl_current != NULL) {
240 if (nl_current->cpins) {
241 pl_current = nl_current->cpins;
242 while (pl_current != NULL) {
244 if (pl_current->plid != -1) {
245 verbose_print("p");
248 if (pl_current->plid != -1 && pl_current->nets) {
249 verbose_print("n");
250 net_name = NULL;
251 n_current = pl_current->nets;
252 while (n_current != NULL) {
253 g_free (n_current->net_name);
254 n_current->net_name = s_netlist_netname_of_netid(pr_current,
255 named_netlist,
256 n_current->nid);
258 if (n_current->net_name != NULL) {
259 net_name = n_current->net_name;
261 n_current = n_current->next;
263 if (net_name != NULL) {
264 pl_current->net_name = g_strdup(net_name);
267 pl_current = pl_current->next;
270 nl_current = nl_current->next;
273 verbose_done();
277 char *s_netlist_netname_of_netid (TOPLEVEL *pr_current,
278 NETLIST *netlist_head,
279 int net_id) {
281 NETLIST *nl_current;
282 CPINLIST *pl_current;
283 NET *n_current;
285 nl_current = netlist_head;
287 /* walk through the list of components, and through the list
288 * of individual pins on each, looking for the net identifier
290 while (nl_current != NULL) {
291 pl_current = nl_current->cpins;
292 while (pl_current != NULL) {
293 if (pl_current->net_name) {
294 n_current = pl_current->nets;
295 while (n_current != NULL) {
296 if (n_current->nid == net_id) {
297 return (g_strdup(n_current->net_name));
299 n_current = n_current->next;
302 pl_current = pl_current->next;
304 nl_current = nl_current->next;
306 return NULL;