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 /* used by the extract functions below */
45 #define DELIMITERS ",; "
47 /* things to do here : */
48 /* write the net alias function */
50 /* be sure to g_free returned string */
51 char *s_netattrib_extract_netname(char *value
)
53 char *return_value
= NULL
;
56 /* a bit larger than needed ... */
57 return_value
= g_strdup (value
);
59 while (value
[i
] != ':' && value
[i
] != '\0') {
60 return_value
[i
] = value
[i
];
64 if (value
[i
] != ':') {
65 fprintf(stderr
, "Found malformed net attribute\n");
66 return (g_strdup ("unknown"));
69 return_value
[i
] = '\0';
71 return (return_value
);
75 /* if this function creates a cpinlist list, it will not have a head node */
77 s_netattrib_create_pins(TOPLEVEL
* pr_current
, OBJECT
* o_current
,
78 NETLIST
* netlist
, char *value
,
79 char const *hierarchy_tag
)
81 NETLIST
*netlist_tail
= NULL
;
82 CPINLIST
*cpinlist_tail
= NULL
;
83 CPINLIST
*new_cpin
= NULL
;
84 CPINLIST
*old_cpin
= NULL
;
85 char *connected_to
= NULL
;
86 char *net_name
= NULL
;
87 char *start_of_pinlist
= NULL
;
88 char *char_ptr
= NULL
;
89 char *current_pin
= NULL
;
91 char_ptr
= strchr(value
, ':');
93 if (char_ptr
== NULL
) {
97 net_name
= s_netattrib_extract_netname(value
);
99 /* skip over first : */
100 start_of_pinlist
= char_ptr
+ 1;
101 current_pin
= strtok(start_of_pinlist
, DELIMITERS
);
102 while (current_pin
) {
103 netlist_tail
= s_netlist_return_tail(netlist
);
104 cpinlist_tail
= s_cpinlist_return_tail(netlist_tail
->cpins
);
106 if (netlist
->component_uref
) {
108 s_cpinlist_search_pin(netlist_tail
->cpins
, current_pin
);
111 if (!old_cpin
->nets
) {
113 "Ack! internal error! (s_netattrib_create_pins)\n");
116 if (old_cpin
->nets
->net_name
) {
118 "Found a cpinlist head with a netname! [%s]\n",
119 old_cpin
->nets
->net_name
);
120 g_free(old_cpin
->nets
->net_name
);
124 old_cpin
->nets
->net_name
=
125 s_hierarchy_create_netattrib(pr_current
, net_name
,
127 old_cpin
->nets
->net_name_has_priority
= TRUE
;
128 connected_to
= g_strdup_printf("%s %s",
129 netlist
->component_uref
,
131 old_cpin
->nets
->connected_to
= g_strdup(connected_to
);
132 old_cpin
->nets
->nid
= o_current
->sid
;
133 g_free(connected_to
);
135 new_cpin
= s_cpinlist_add(cpinlist_tail
);
137 new_cpin
->pin_number
= g_strdup (current_pin
);
138 new_cpin
->net_name
= NULL
;
140 new_cpin
->plid
= o_current
->sid
;
142 new_cpin
->nets
= s_net_add(NULL
);
143 new_cpin
->nets
->net_name_has_priority
= TRUE
;
144 new_cpin
->nets
->net_name
=
145 s_hierarchy_create_netattrib(pr_current
, net_name
,
148 connected_to
= g_strdup_printf("%s %s",
149 netlist
->component_uref
,
151 new_cpin
->nets
->connected_to
= g_strdup(connected_to
);
152 new_cpin
->nets
->nid
= o_current
->sid
;
155 printf("Finished creating: %s\n", connected_to
);
156 printf("netname: %s %s\n", new_cpin
->nets
->net_name
,
160 g_free(connected_to
);
163 } else { /* no uref, means this is a special component */
166 current_pin
= strtok(NULL
, DELIMITERS
);
174 s_netattrib_handle(TOPLEVEL
* pr_current
, OBJECT
* o_current
,
175 NETLIST
* netlist
, char const *hierarchy_tag
)
180 /* for now just look inside the component */
181 value
= o_attrib_search_name(o_current
->complex->prim_objs
,
185 printf("found net= %s\n", value
);
188 while (value
!= NULL
) {
190 s_netattrib_create_pins(pr_current
, o_current
, netlist
, value
,
195 value
= o_attrib_search_name(o_current
->complex->prim_objs
,
198 printf("found net= %s\n", value
);
206 /* for now just look inside the component */
208 value
= o_attrib_search_name_single_count(o_current
, "net", counter
);
209 while (value
!= NULL
) {
211 s_netattrib_create_pins(pr_current
, o_current
, netlist
, value
,
217 o_attrib_search_name_single_count(o_current
, "net", counter
);
223 char *s_netattrib_net_search(OBJECT
* o_current
, char *wanted_pin
)
226 char *char_ptr
= NULL
;
227 char *net_name
= NULL
;
228 char *current_pin
= NULL
;
229 char *start_of_pinlist
= NULL
;
230 char *return_value
= NULL
;
233 if (o_current
== NULL
) {
237 if (o_current
->complex == NULL
) {
241 /* for now just look inside the component */
242 value
= o_attrib_search_name(o_current
->complex->prim_objs
,
244 while (value
!= NULL
) {
246 char_ptr
= strchr(value
, ':');
247 if (char_ptr
== NULL
) {
248 fprintf(stderr
, "Got an invalid net= attrib [net=%s]\nMissing : in net= attrib\n",
253 net_name
= s_netattrib_extract_netname(value
);
255 start_of_pinlist
= char_ptr
+ 1;
256 current_pin
= strtok(start_of_pinlist
, DELIMITERS
);
257 while (current_pin
&& !return_value
) {
259 printf("looking at: %s\n", current_pin
);
261 if (strcmp(current_pin
, wanted_pin
) == 0) {
263 printf("found net_name: _%s_\n", net_name
);
265 return_value
= net_name
;
267 current_pin
= strtok(NULL
, DELIMITERS
);
273 value
= o_attrib_search_name(o_current
->complex->prim_objs
,
281 /* now look outside the component */
283 value
= o_attrib_search_name_single_count(o_current
, "net", counter
);
284 while (value
!= NULL
) {
286 char_ptr
= strchr(value
, ':');
287 if (char_ptr
== NULL
) {
288 fprintf(stderr
, "Got an invalid net= attrib [net=%s]\nMissing : in net= attrib\n",
293 net_name
= s_netattrib_extract_netname(value
);
295 start_of_pinlist
= char_ptr
+ 1;
296 current_pin
= strtok(start_of_pinlist
, DELIMITERS
);
297 while (current_pin
) {
300 printf("looking at: %s\n", current_pin
);
302 if (strcmp(current_pin
, wanted_pin
) == 0) {
304 printf("found net_name: _%s_\n", net_name
);
307 g_free(return_value
);
313 current_pin
= strtok(NULL
, DELIMITERS
);
320 o_attrib_search_name_single_count(o_current
, "net", counter
);
326 return (return_value
);
332 char *s_netattrib_return_netname(TOPLEVEL
* pr_current
, OBJECT
* o_current
,
333 char *pinnumber
, char const *hierarchy_tag
)
340 printf("extract return netname here\n");
343 /* skip over POWER tag */
344 current_pin
= strtok(pinnumber
, " ");
346 current_pin
= strtok(NULL
, " ");
347 if (current_pin
== NULL
) {
351 printf("inside return_netname: %s\n", current_pin
);
354 /* use hierarchy tag here to make this net uniq */
355 temp_netname
= s_netattrib_net_search(o_current
->complex_parent
,
359 s_hierarchy_create_netattrib(pr_current
, temp_netname
,
363 printf("netname: %s\n", netname
);