missing NULL terminator in set_config_x
[geda-gaf.git] / gnetlist-legacy / src / s_netlist.c
blobb7549ab11acbd406d419b06ba46e83032860acd7
1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 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 /* used by the extract functions below */
38 #define DELIMITERS ",; "
40 /* hack rename this to be s_return_tail */
41 /* update object_tail or any list of that matter */
42 NETLIST *s_netlist_return_tail(NETLIST * head)
44 NETLIST *nl_current = NULL;
45 NETLIST *ret_struct = NULL;
47 nl_current = head;
48 while (nl_current != NULL) { /* goto end of list */
49 ret_struct = nl_current;
50 nl_current = nl_current->next;
53 return (ret_struct);
56 /* hack rename this to be s_return_head */
57 /* update object_tail or any list of that matter */
58 NETLIST *s_netlist_return_head(NETLIST * tail)
60 NETLIST *nl_current = NULL;
61 NETLIST *ret_struct = NULL;
63 nl_current = tail;
64 while (nl_current != NULL) { /* goto end of list */
65 ret_struct = nl_current;
66 nl_current = nl_current->prev;
69 return (ret_struct);
73 /* returns new node */
74 NETLIST *s_netlist_add(NETLIST * ptr)
76 NETLIST *new_node;
78 new_node = (NETLIST *) g_malloc(sizeof(NETLIST));
80 /* setup node information */
81 new_node->nlid = 0;
82 new_node->cpins = NULL;
83 new_node->component_uref = NULL;
84 new_node->object_ptr = NULL;
85 new_node->hierarchy_tag = NULL;
86 new_node->composite_component = FALSE;
88 /* Setup link list stuff */
89 new_node->next = NULL;
91 if (ptr == NULL) {
92 new_node->prev = NULL; /* setup previous link */
93 return (new_node);
94 } else {
95 new_node->prev = ptr; /* setup previous link */
96 ptr->next = new_node;
97 return (ptr->next);
101 void s_netlist_print(NETLIST * ptr)
103 NETLIST *nl_current = NULL;
105 nl_current = ptr;
107 if (nl_current == NULL) {
108 return;
111 while (nl_current != NULL) {
113 if (nl_current->nlid != -1) {
115 if (nl_current->component_uref) {
116 printf("component %s \n", nl_current->component_uref);
117 } else {
118 printf("component SPECIAL \n");
121 if (nl_current->hierarchy_tag) {
122 printf("Hierarchy tag: %s\n", nl_current->hierarchy_tag);
125 if (nl_current->cpins) {
126 s_cpinlist_print(nl_current->cpins);
129 printf("\n");
132 nl_current = nl_current->next;
134 printf("\n");
137 void s_netlist_post_process(TOPLEVEL * pr_current, NETLIST * head)
139 NETLIST *nl_current;
140 CPINLIST *pl_current;
142 if (verbose_mode) {
143 printf("\n- Staring post processing\n");
144 printf("- Naming nets:\n");
147 /* this pass gives all nets a name, whether specified or creates a */
148 /* name */
149 nl_current = head;
150 while (nl_current != NULL) {
151 if (nl_current->cpins) {
152 pl_current = nl_current->cpins;
153 while (pl_current != NULL) {
155 if (pl_current->plid != -1) {
156 verbose_print("p");
159 if (pl_current->plid != -1 && pl_current->nets) {
161 g_free(pl_current->net_name);
163 verbose_print("n");
165 /* only name nets of components which */
166 /* have a uref */
167 if (nl_current->component_uref) {
168 pl_current->net_name =
169 s_net_name(pr_current,
170 head,
171 pl_current->nets,
172 nl_current->hierarchy_tag,
173 pl_current->type);
175 /* put this name also in the first
176 node of the nets linked list */
177 if (pl_current->net_name && pl_current->nets) {
178 if (pl_current->nets->next) {
179 pl_current->nets->next->net_name =
180 g_strdup (pl_current->net_name);
186 pl_current = pl_current->next;
189 nl_current = nl_current->next;
192 verbose_done();
193 if (verbose_mode) {
194 printf("- Renaming nets:\n");
197 s_rename_all(pr_current, head);
199 verbose_done();
200 if (verbose_mode) {
201 printf("- Resolving hierarchy:\n");
203 s_hierarchy_post_process(pr_current, head);
205 verbose_done();
206 if (pr_current->hierarchy_uref_mangle == FALSE) {
207 if (verbose_mode) {
208 printf("- Removing refdes mangling:\n");
210 s_hierarchy_remove_uref_mangling(pr_current, head);
213 verbose_done();
216 void s_netlist_name_named_nets (TOPLEVEL *pr_current,
217 NETLIST *named_netlist,
218 NETLIST *unnamed_netlist) {
220 NETLIST *nl_current;
221 CPINLIST *pl_current;
222 NET *n_current;
223 char *net_name;
225 if (verbose_mode) {
226 printf("\n- Staring post processing\n");
227 printf("- Naming nets of graphical objects:\n");
230 /* this pass gives all nets a name, whether specified or creates a */
231 /* name */
232 nl_current = unnamed_netlist;
233 while (nl_current != NULL) {
234 if (nl_current->cpins) {
235 pl_current = nl_current->cpins;
236 while (pl_current != NULL) {
238 if (pl_current->plid != -1) {
239 verbose_print("p");
242 if (pl_current->plid != -1 && pl_current->nets) {
243 verbose_print("n");
244 net_name = NULL;
245 n_current = pl_current->nets;
246 while (n_current != NULL) {
247 g_free (n_current->net_name);
248 n_current->net_name = s_netlist_netname_of_netid(pr_current,
249 named_netlist,
250 n_current->nid);
252 if (n_current->net_name != NULL) {
253 net_name = n_current->net_name;
255 n_current = n_current->next;
257 if (net_name != NULL) {
258 pl_current->net_name = g_strdup(net_name);
261 pl_current = pl_current->next;
264 nl_current = nl_current->next;
267 verbose_done();
271 char *s_netlist_netname_of_netid (TOPLEVEL *pr_current,
272 NETLIST *netlist_head,
273 int net_id) {
275 NETLIST *nl_current;
276 CPINLIST *pl_current;
277 NET *n_current;
279 nl_current = netlist_head;
281 /* walk through the list of components, and through the list
282 * of individual pins on each, looking for the net identifier
284 while (nl_current != NULL) {
285 pl_current = nl_current->cpins;
286 while (pl_current != NULL) {
287 if (pl_current->net_name) {
288 n_current = pl_current->nets;
289 while (n_current != NULL) {
290 if (n_current->nid == net_id) {
291 return (g_strdup(n_current->net_name));
293 n_current = n_current->next;
296 pl_current = pl_current->next;
298 nl_current = nl_current->next;
300 return NULL;