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
35 #include <libgeda/libgeda.h>
37 #include "../include/globals.h"
38 #include "../include/prototype.h"
40 #ifdef HAVE_LIBDMALLOC
44 static int unnamed_net_counter
= 1;
45 static int unnamed_pin_counter
= 1;
47 #define MAX_UNNAMED_NETS 99999999
48 #define MAX_UNNAMED_PINS 99999999
50 NET
*s_net_add(NET
* ptr
)
54 new_node
= (NET
*) g_malloc(sizeof(NET
));
56 /* setup node information */
57 new_node
->net_name
= NULL
;
58 new_node
->pin_label
= NULL
;
59 new_node
->net_name_has_priority
= FALSE
;
61 new_node
->connected_to
= NULL
;
63 /* Setup link list stuff */
64 new_node
->next
= NULL
;
67 new_node
->prev
= NULL
; /* setup previous link */
70 new_node
->prev
= ptr
; /* setup previous link */
76 void s_net_print(NET
* ptr
)
78 NET
*n_current
= NULL
;
82 if (n_current
== NULL
) {
86 while (n_current
!= NULL
) {
87 if (n_current
->nid
!= -1) {
89 if (n_current
->net_name
) {
90 printf(" %s [%d]\n", n_current
->net_name
, n_current
->nid
);
94 if (n_current
->connected_to
) {
95 printf(" %s [%d]\n", n_current
->connected_to
, n_current
->nid
);
99 n_current
= n_current
->next
;
104 /* object being a pin */
105 char *s_net_return_connected_string(TOPLEVEL
* pr_current
, OBJECT
* object
,
106 char const *hierarchy_tag
)
109 OBJECT
*o_pinnum_object
;
113 char *temp_uref
= NULL
;
119 /* this function only searches the single o_current */
120 pinnum
= o_attrib_search_name_single(o_current
, "pinnumber",
124 printf("found pinnum: %s\n", pinnum
);
127 scm_uref
= g_scm_c_get_uref(pr_current
, o_current
->complex_parent
);
129 if (scm_is_string( scm_uref
)) {
130 temp_uref
= scm_to_locale_string( scm_uref
);
133 /* apply the hierarchy name to the uref */
134 uref
= s_hierarchy_create_uref(pr_current
, temp_uref
, hierarchy_tag
);
136 if (uref
&& pinnum
) {
137 string
= g_strdup_printf("%s %s", uref
, pinnum
);
140 string
= g_strdup_printf("POWER %s", pinnum
);
144 s_hierarchy_create_uref(pr_current
, "U?",
146 string
= g_strdup_printf("%s ?", misc
);
149 string
= g_strdup("U? ?");
152 fprintf(stderr
, "Missing Attributes (refdes and pin number)\n");
165 int s_net_find(NET
* net_head
, NET
* node
)
169 n_current
= net_head
;
170 while (n_current
!= NULL
) {
171 if (n_current
->nid
== node
->nid
) {
175 n_current
= n_current
->next
;
180 char *s_net_name_search(TOPLEVEL
* pr_current
, NET
* net_head
)
185 n_current
= net_head
;
187 while (n_current
!= NULL
) {
188 if (n_current
->net_name
) {
190 name
= n_current
->net_name
;
191 } else if (strcmp(name
, n_current
->net_name
) != 0) {
193 fprintf(stderr
, "Found a net with two names!\n");
194 fprintf(stderr
, "Net called: [%s] and [%s]\n",
195 name
, n_current
->net_name
);
198 /* only rename if this net name has priority */
199 /* AND, you are using net= attributes as the */
200 /* netnames which have priority */
201 if (pr_current
->net_naming_priority
== NETATTRIB_ATTRIBUTE
) {
203 printf("\nNETATTRIB_ATTRIBUTE\n");
205 if (n_current
->net_name_has_priority
) {
207 fprintf(stderr
, "Net is now called: [%s]\n",
208 n_current
->net_name
);
210 /* this show how to rename nets */
211 printf("\nRENAME all nets: %s -> %s\n", name
,
212 n_current
->net_name
);
214 s_rename_add(name
, n_current
->net_name
);
216 name
= n_current
->net_name
;
220 ("\nFound a net name called [%s], but it doesn't have priority\n",
221 n_current
->net_name
);
224 /* do the rename anyways, this might cause problems */
225 /* this will rename net which have the same label= */
227 (name
, n_current
->net_name
, TRUE
)) {
229 "Found duplicate net name, renaming [%s] to [%s]\n",
230 name
, n_current
->net_name
);
231 s_rename_add(name
, n_current
->net_name
);
232 name
= n_current
->net_name
;
235 } else { /* NETNAME_ATTRIBUTE */
237 printf("\nNETNAME_ATTRIBUTE\n");
240 /* here we want to rename the net */
241 /* that has priority to the label */
243 if (n_current
->net_name_has_priority
) {
245 /* this shows how to rename nets */
246 printf("\nRENAME all nets: %s -> %s (priority)\n",
247 n_current
->net_name
, name
);
250 s_rename_add(n_current
->net_name
, name
);
253 /* this shows how to rename nets */
255 ("\nRENAME all nets: %s -> %s (not priority)\n",
256 name
, n_current
->net_name
);
258 /* do the rename anyways, this might cause problems */
259 /* this will rename net which have the same label= */
261 (name
, n_current
->net_name
, TRUE
)) {
263 "Found duplicate net name, renaming [%s] to [%s]\n",
264 name
, n_current
->net_name
);
266 s_rename_add(name
, n_current
->net_name
);
267 name
= n_current
->net_name
;
272 fprintf(stderr
, "Net is now called: [%s]\n", name
);
278 n_current
= n_current
->next
;
288 char *s_net_name(TOPLEVEL
*pr_current
, NETLIST
*netlist
,
289 NET
* net_head
, char const *hierarchy_tag
)
294 CPINLIST
*pl_current
;
295 char *net_name
= NULL
;
300 net_name
= s_net_name_search(pr_current
, net_head
);
307 printf("didn't find named net\n");
310 /* didn't find a name */
311 /* go looking for another net which might have already been named */
312 /* ie you don't want to create a new unnamed net if the net has */
313 /* already been named */
314 nl_current
= netlist
;
315 while (nl_current
!= NULL
) {
316 if (nl_current
->cpins
) {
317 pl_current
= nl_current
->cpins
;
318 while (pl_current
!= NULL
) {
319 if (pl_current
->nets
) {
320 n_start
= pl_current
->nets
;
321 if (n_start
->next
&& net_head
->next
) {
322 found
= s_net_find(n_start
->next
, net_head
->next
);
326 s_net_name_search(pr_current
, n_start
);
335 pl_current
= pl_current
->next
;
338 nl_current
= nl_current
->next
;
342 printf("didn't find previously named\n");
345 /* AND we don't want to assign a dangling pin */
346 /* which is signified by having only a head node */
347 /* which is just a place holder */
348 /* and the head node shows up here */
350 if (net_head
->nid
== -1 && net_head
->prev
== NULL
351 && net_head
->next
== NULL
) {
352 string
= g_strdup_printf("unconnected_pin-%d",
353 unnamed_pin_counter
++);
359 /* have we exceeded the number of unnamed nets? */
360 if (unnamed_net_counter
< MAX_UNNAMED_NETS
) {
362 if (netlist_mode
== SPICE
) {
364 g_strdup_printf("%d", unnamed_net_counter
++);
369 temp
= g_strdup_printf("%s%d", pr_current
->unnamed_netname
,
370 unnamed_net_counter
++);
373 s_hierarchy_create_netname(pr_current
, temp
,
375 string
= g_strdup(misc
);
378 string
= g_strdup_printf("%s%d", pr_current
->unnamed_netname
,
379 unnamed_net_counter
++);
386 fprintf(stderr
, "Increase number of unnamed nets (s_net.c)\n");