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
36 #include <libgeda/libgeda.h>
38 #include "../include/globals.h"
39 #include "../include/prototype.h"
41 #ifdef HAVE_LIBDMALLOC
45 static int unnamed_net_counter
= 1;
46 static int unnamed_bus_counter
= 1;
47 static int unnamed_pin_counter
= 1;
49 #define MAX_UNNAMED_NETS 99999999
50 #define MAX_UNNAMED_PINS 99999999
52 /* hack rename this to be s_return_tail */
53 /* update object_tail or any list of that matter */
54 NET
*s_net_return_tail(NET
* head
)
56 NET
*n_current
= NULL
;
57 NET
*ret_struct
= NULL
;
60 while (n_current
!= NULL
) { /* goto end of list */
61 ret_struct
= n_current
;
62 n_current
= n_current
->next
;
68 /* hack rename this to be s_return_head */
69 /* update object_tail or any list of that matter */
70 NET
*s_net_return_head(NET
* tail
)
72 NET
*n_current
= NULL
;
73 NET
*ret_struct
= NULL
;
76 while (n_current
!= NULL
) { /* goto end of list */
77 ret_struct
= n_current
;
78 n_current
= n_current
->prev
;
85 NET
*s_net_add(NET
* ptr
)
89 new_node
= (NET
*) g_malloc(sizeof(NET
));
91 /* setup node information */
92 new_node
->net_name
= NULL
;
93 new_node
->pin_label
= NULL
;
94 new_node
->net_name_has_priority
= FALSE
;
96 new_node
->connected_to
= NULL
;
98 /* Setup link list stuff */
99 new_node
->next
= NULL
;
102 new_node
->prev
= NULL
; /* setup previous link */
105 new_node
->prev
= ptr
; /* setup previous link */
106 ptr
->next
= new_node
;
111 void s_net_print(NET
* ptr
)
113 NET
*n_current
= NULL
;
117 if (n_current
== NULL
) {
121 while (n_current
!= NULL
) {
123 if (n_current
->nid
!= -1) {
126 if (n_current
->net_name
) {
127 printf(" %s [%d]\n", n_current
->net_name
, n_current
->nid
);
131 if (n_current
->connected_to
) {
132 printf(" %s [%d]\n", n_current
->connected_to
, n_current
->nid
);
136 n_current
= n_current
->next
;
141 /* object being a pin */
142 char *s_net_return_connected_string(TOPLEVEL
* pr_current
, OBJECT
* object
,
149 char *temp_uref
= NULL
;
155 pinnum
= o_attrib_search_object_attribs_by_name (o_current
, "pinnumber", 0);
158 printf("found pinnum: %s\n", pinnum
);
161 scm_uref
= g_scm_c_get_uref(pr_current
, o_current
->parent
);
163 if (scm_is_string( scm_uref
)) {
164 temp_uref
= scm_to_utf8_string (scm_uref
);
167 /* apply the hierarchy name to the uref */
168 uref
= s_hierarchy_create_uref(pr_current
, temp_uref
, hierarchy_tag
);
170 if (uref
&& pinnum
) {
171 string
= g_strdup_printf("%s %s", uref
, pinnum
);
174 string
= g_strdup_printf("POWER %s", pinnum
);
178 s_hierarchy_create_uref(pr_current
, "U?",
180 string
= g_strdup_printf("%s ?", misc
);
183 string
= g_strdup("U? ?");
186 fprintf(stderr
, "Missing Attributes (refdes and pin number)\n");
199 int s_net_find(NET
* net_head
, NET
* node
)
203 n_current
= net_head
;
204 while (n_current
!= NULL
) {
205 if (n_current
->nid
== node
->nid
) {
209 n_current
= n_current
->next
;
214 char *s_net_name_search(TOPLEVEL
* pr_current
, NET
* net_head
)
219 n_current
= net_head
;
222 while (n_current
!= NULL
) {
224 if (n_current
->net_name
) {
228 name
= n_current
->net_name
;
230 } else if (strcmp(name
, n_current
->net_name
) != 0) {
234 fprintf(stderr
, "Found a net with two names!\n");
235 fprintf(stderr
, "Net called: [%s] and [%s]\n",
236 name
, n_current
->net_name
);
240 /* only rename if this net name has priority */
241 /* AND, you are using net= attributes as the */
242 /* netnames which have priority */
243 if (pr_current
->net_naming_priority
== NETATTRIB_ATTRIBUTE
) {
246 printf("\nNETATTRIB_ATTRIBUTE\n");
248 if (n_current
->net_name_has_priority
) {
251 fprintf(stderr
, "Net is now called: [%s]\n",
252 n_current
->net_name
);
254 /* this show how to rename nets */
255 printf("\nRENAME all nets: %s -> %s\n", name
,
256 n_current
->net_name
);
258 s_rename_add(name
, n_current
->net_name
);
260 name
= n_current
->net_name
;
266 ("\nFound a net name called [%s], but it doesn't have priority\n",
267 n_current
->net_name
);
270 /* do the rename anyways, this might cause problems */
271 /* this will rename net which have the same label= */
273 (name
, n_current
->net_name
, TRUE
)) {
275 "Found duplicate net name, renaming [%s] to [%s]\n",
276 name
, n_current
->net_name
);
277 s_rename_add(name
, n_current
->net_name
);
278 name
= n_current
->net_name
;
282 } else { /* NETNAME_ATTRIBUTE */
285 printf("\nNETNAME_ATTRIBUTE\n");
288 /* here we want to rename the net */
289 /* that has priority to the label */
291 if (n_current
->net_name_has_priority
) {
293 #if DEBUG /* this shows how to rename nets */
294 printf("\nRENAME all nets: %s -> %s (priority)\n",
295 n_current
->net_name
, name
);
298 s_rename_add(n_current
->net_name
, name
);
302 #if DEBUG /* this shows how to rename nets */
304 ("\nRENAME all nets: %s -> %s (not priority)\n",
305 name
, n_current
->net_name
);
307 /* do the rename anyways, this might cause problems */
308 /* this will rename net which have the same label= */
310 (name
, n_current
->net_name
, TRUE
)) {
312 "Found duplicate net name, renaming [%s] to [%s]\n",
313 name
, n_current
->net_name
);
315 s_rename_add(name
, n_current
->net_name
);
316 name
= n_current
->net_name
;
321 fprintf(stderr
, "Net is now called: [%s]\n", name
);
328 n_current
= n_current
->next
;
338 char *s_net_name (TOPLEVEL
* pr_current
, NETLIST
* netlist_head
,
339 NET
* net_head
, char *hierarchy_tag
, int type
)
344 CPINLIST
*pl_current
;
345 char *net_name
= NULL
;
348 int *unnamed_counter
;
349 char *unnamed_string
;
351 net_name
= s_net_name_search(pr_current
, net_head
);
358 printf("didn't find named net\n");
361 /* didn't find a name */
362 /* go looking for another net which might have already been named */
363 /* ie you don't want to create a new unnamed net if the net has */
364 /* already been named */
365 nl_current
= netlist_head
;
366 while (nl_current
!= NULL
) {
367 if (nl_current
->cpins
) {
368 pl_current
= nl_current
->cpins
;
369 while (pl_current
!= NULL
) {
370 if (pl_current
->nets
) {
371 n_start
= pl_current
->nets
;
372 if (n_start
->next
&& net_head
->next
) {
373 found
= s_net_find(n_start
->next
, net_head
->next
);
377 s_net_name_search(pr_current
, n_start
);
386 pl_current
= pl_current
->next
;
389 nl_current
= nl_current
->next
;
394 printf("didn't find previously named\n");
397 /* AND we don't want to assign a dangling pin */
398 /* which is signified by having only a head node */
399 /* which is just a place holder */
400 /* and the head node shows up here */
402 if (net_head
->nid
== -1 && net_head
->prev
== NULL
403 && net_head
->next
== NULL
) {
404 string
= g_strdup_printf("unconnected_pin-%d",
405 unnamed_pin_counter
++);
413 unnamed_counter
= &unnamed_net_counter
;
414 unnamed_string
= pr_current
->unnamed_netname
;
417 unnamed_counter
= &unnamed_bus_counter
;
418 unnamed_string
= pr_current
->unnamed_busname
;
421 g_critical ("Incorrect connectivity type %i in s_name_nets()\n", type
);
425 /* have we exceeded the number of unnamed nets? */
426 if (*unnamed_counter
< MAX_UNNAMED_NETS
) {
428 if (netlist_mode
== SPICE
) {
429 string
= g_strdup_printf("%d", (*unnamed_counter
)++);
431 temp
= g_strdup_printf ("%s%d", unnamed_string
, (*unnamed_counter
)++);
433 string
= s_hierarchy_create_netname (pr_current
, temp
, hierarchy_tag
);
441 fprintf(stderr
, "Increase number of unnamed nets (s_net.c)\n");