Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gnetlist / src / g_netlist.c
blobb3af8fa2a246ce3b6e1cd2a63d0c43447e5c7133
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., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 #include <config.h>
23 #include <stdio.h>
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 #include <math.h>
29 #include <libgeda/libgeda.h>
31 #include "../include/globals.h"
32 #include "../include/prototype.h"
34 #ifdef HAVE_LIBDMALLOC
35 #include <dmalloc.h>
36 #endif
39 /* current project */
40 static TOPLEVEL *project_current;
42 void g_set_project_current(TOPLEVEL * pr_current)
44 project_current = pr_current;
48 SCM g_scm_c_get_uref (TOPLEVEL *toplevel, OBJECT *object)
50 SCM func = scm_variable_ref (scm_c_lookup ("get-uref"));
51 SCM object_smob = g_make_object_smob (toplevel, object);
52 SCM exp = scm_list_2 (func, object_smob);
54 return g_scm_eval_protected (exp, SCM_UNDEFINED);
58 /* this function will only return a unique list of packages */
59 SCM g_get_packages(SCM level)
61 SCM list = SCM_EOL;
62 GHashTable *ht;
64 NETLIST *nl_current = NULL;
66 SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");
68 /* build a hash table */
69 ht = g_hash_table_new (g_str_hash, g_str_equal);
70 for (nl_current = netlist_head; nl_current != NULL;
71 nl_current = nl_current->next) {
72 if (nl_current->component_uref != NULL) {
73 /* add component_uref in the hash table */
74 /* uniqueness of component_uref is guaranteed by the hashtable */
76 if (g_hash_table_lookup (ht, nl_current->component_uref) == NULL) {
77 g_hash_table_insert (ht, nl_current->component_uref,
78 nl_current->component_uref);
79 list = scm_cons (scm_makfrom0str (nl_current->component_uref), list);
83 g_hash_table_destroy (ht);
85 return list;
88 /* this function will only return a non unique list of packages */
89 SCM g_get_non_unique_packages(SCM level)
91 SCM list = SCM_EOL;
93 NETLIST *nl_current = NULL;
95 SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");
97 for (nl_current = netlist_head; nl_current != NULL;
98 nl_current = nl_current->next) {
99 if (nl_current->component_uref != NULL) {
100 list = scm_cons (scm_makfrom0str (nl_current->component_uref),
101 list);
105 return list;
109 SCM g_get_pins(SCM uref)
111 SCM list = SCM_EOL;
112 NETLIST *nl_current;
113 CPINLIST *pl_current;
115 SCM_ASSERT(scm_is_string (uref), uref, SCM_ARG1, "gnetlist:get-pins");
117 /* here is where you make it multi page aware */
118 nl_current = netlist_head;
120 /* search for the first instance */
121 /* through the entire list */
122 while (nl_current != NULL) {
124 if (nl_current->component_uref) {
125 if (strcmp(nl_current->component_uref, SCM_STRING_CHARS (uref)) == 0) {
127 pl_current = nl_current->cpins;
128 while (pl_current != NULL) {
129 if (pl_current->pin_number) {
130 list = scm_cons (scm_makfrom0str (pl_current->pin_number),
131 list);
133 pl_current = pl_current->next;
137 nl_current = nl_current->next;
140 return (list);
143 SCM g_get_all_nets(SCM scm_level)
146 SCM list = SCM_EOL;
147 NETLIST *nl_current;
148 CPINLIST *pl_current;
149 char *net_name;
151 SCM_ASSERT(scm_is_string (scm_level), scm_level, SCM_ARG1,
152 "gnetlist:get-all-nets");
154 nl_current = netlist_head;
156 /* walk through the list of components, and through the list
157 * of individual pins on each, adding net names to the list
158 * being careful to ignore duplicates, and unconnected pins
160 while (nl_current != NULL) {
161 pl_current = nl_current->cpins;
162 while (pl_current != NULL) {
163 if (pl_current->net_name) {
165 net_name = pl_current->net_name;
166 /* filter off unconnected pins */
167 if (strncmp(net_name, "unconnected_pin", 15) != 0) {
168 /*printf("Got net: `%s'\n",net_name); */
169 /* add the net name to the list */
170 #if DEBUG
171 printf("Got net: `%s'\n", net_name);
172 printf("pin %s\n", pl_current->pin_number);
173 #endif
174 list = scm_cons (scm_makfrom0str (net_name),
175 list);
178 pl_current = pl_current->next;
180 nl_current = nl_current->next;
183 return list;
186 SCM g_get_all_unique_nets(SCM scm_level)
189 SCM list = SCM_EOL;
190 SCM x = SCM_EOL;
191 NETLIST *nl_current;
192 CPINLIST *pl_current;
193 char *net_name;
195 SCM_ASSERT(scm_is_string (scm_level), scm_level, SCM_ARG1,
196 "gnetlist:get-all-unique-nets");
198 nl_current = netlist_head;
200 /* walk through the list of components, and through the list
201 * of individual pins on each, adding net names to the list
202 * being careful to ignore duplicates, and unconnected pins
204 while (nl_current != NULL) {
205 pl_current = nl_current->cpins;
206 while (pl_current != NULL) {
207 if (pl_current->net_name) {
209 net_name = pl_current->net_name;
210 /* filter off unconnected pins */
211 if (strncmp(net_name, "unconnected_pin", 15) != 0) {
212 /* add the net name to the list */
213 /*printf("Got net: `%s'\n",net_name); */
215 x = scm_makfrom0str (net_name);
216 if (scm_member(x, list) == SCM_BOOL_F) {
217 list = scm_cons (x, list);
221 pl_current = pl_current->next;
223 nl_current = nl_current->next;
226 return list;
229 /* given a net name, return all connections */
230 SCM g_get_all_connections(SCM scm_netname)
233 SCM list = SCM_EOL;
234 SCM x = SCM_EOL;
235 SCM is_member = SCM_EOL;
236 SCM connlist = SCM_EOL;
237 SCM pairlist = SCM_EOL;
238 NETLIST *nl_current;
239 CPINLIST *pl_current;
240 NET *n_current;
241 char *wanted_net_name;
242 char *net_name;
243 char *pin;
244 char *uref;
246 SCM_ASSERT(scm_is_string(scm_netname), scm_netname, SCM_ARG1,
247 "gnetlist:get-all-connections");
249 wanted_net_name = SCM_STRING_CHARS (scm_netname);
251 if (wanted_net_name == NULL) {
252 return list;
256 nl_current = netlist_head;
258 /* walk through the list of components, and through the list
259 * of individual pins on each, adding net names to the list
260 * being careful to ignore duplicates, and unconnected pins
262 while (nl_current != NULL) {
263 pl_current = nl_current->cpins;
264 while (pl_current != NULL) {
265 if (pl_current->net_name) {
267 net_name = pl_current->net_name;
268 /* filter off unconnected pins */
269 if (strcmp(net_name, wanted_net_name) == 0) {
270 /* add the net name to the list */
272 #if DEBUG
273 printf("found net: `%s'\n", net_name);
274 #endif
276 n_current = pl_current->nets;
277 while (n_current != NULL) {
279 if (n_current->connected_to) {
281 pairlist = SCM_EOL;
282 pin = (char *) g_malloc(sizeof(char) *
283 strlen(n_current->
284 connected_to));
285 uref =
286 (char *) g_malloc(sizeof(char) *
287 strlen(n_current->
288 connected_to));
290 sscanf(n_current->connected_to,
291 "%s %s", uref, pin);
293 pairlist = scm_list_n (scm_makfrom0str (uref),
294 scm_makfrom0str (pin),
295 SCM_UNDEFINED);
297 x = pairlist;
298 is_member = scm_member(x, connlist);
300 if (is_member == SCM_BOOL_F) {
301 connlist = scm_cons (pairlist, connlist);
304 g_free(uref);
305 g_free(pin);
307 n_current = n_current->next;
311 pl_current = pl_current->next;
313 nl_current = nl_current->next;
316 return connlist;
319 /* Given a uref and a pin number return a list of: */
320 /* (netname (uref pin) (uref pin) ... ) */
321 SCM g_get_nets(SCM scm_uref, SCM scm_pin)
323 SCM outerlist = SCM_EOL;
324 SCM pinslist = SCM_EOL;
325 SCM pairlist = SCM_EOL;
326 NETLIST *nl_current = NULL;
327 CPINLIST *pl_current = NULL;
328 NET *n_current;
329 char *wanted_uref = NULL;
330 char *wanted_pin = NULL;
331 char *net_name = NULL;
333 char *pin;
334 char *uref;
336 SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1,
337 "gnetlist:get-nets");
339 SCM_ASSERT(scm_is_string (scm_pin), scm_pin, SCM_ARG2,
340 "gnetlist:get-nets");
343 wanted_uref = SCM_STRING_CHARS (scm_uref);
344 wanted_pin = SCM_STRING_CHARS (scm_pin);
346 nl_current = netlist_head;
348 /* search for the first instance */
349 /* through the entire list */
350 while (nl_current != NULL) {
352 if (nl_current->component_uref) {
354 if (strcmp(nl_current->component_uref, wanted_uref) == 0) {
356 pl_current = nl_current->cpins;
357 while (pl_current != NULL) {
359 if (pl_current->pin_number) {
360 if (strcmp(pl_current->pin_number, wanted_pin) ==
361 0) {
363 n_current = pl_current->nets;
365 if (pl_current->net_name) {
366 net_name = pl_current->net_name;
369 while (n_current != NULL) {
371 if (n_current->connected_to) {
373 pairlist = SCM_EOL;
374 pin = (char *) g_malloc(sizeof(char) *
375 strlen
376 (n_current->
377 connected_to));
378 uref =
379 (char *) g_malloc(sizeof(char) *
380 strlen(n_current->
381 connected_to));
383 sscanf(n_current->connected_to,
384 "%s %s", uref, pin);
386 pairlist = scm_list_n (scm_makfrom0str (uref),
387 scm_makfrom0str (pin),
388 SCM_UNDEFINED);
390 pinslist = scm_cons (pairlist, pinslist);
392 g_free(uref);
393 g_free(pin);
395 n_current = n_current->next;
399 pl_current = pl_current->next;
403 nl_current = nl_current->next;
406 if (net_name != NULL) {
407 outerlist = scm_cons (scm_makfrom0str (net_name), pinslist);
408 } else {
409 outerlist = scm_cons (scm_makfrom0str ("ERROR_INVALID_PIN"),
410 outerlist);
411 fprintf(stderr, "Invalid wanted_pin passed to get-nets [%s]\n",
412 wanted_pin);
415 return (outerlist);
419 /* Given a uref, Return a list of pairs, each pair contains the name
420 * of the pin, and the name of the net connected to that pin.
422 SCM g_get_pins_nets(SCM scm_uref)
424 SCM pinslist = SCM_EOL;
425 SCM pairlist = SCM_EOL;
426 NETLIST *nl_current = NULL;
427 CPINLIST *pl_current = NULL;
429 char *wanted_uref = NULL;
430 char *net_name = NULL;
431 char *pin = NULL;
433 SCM_ASSERT(scm_is_string (scm_uref),
434 scm_uref, SCM_ARG1, "gnetlist:get-pins-nets");
436 wanted_uref = SCM_STRING_CHARS (scm_uref);
438 /* search for the any instances */
439 /* through the entire list */
440 for (nl_current = netlist_head; nl_current != NULL;
441 nl_current = nl_current->next) {
443 /* is there a uref? */
444 if (nl_current->component_uref) {
445 /* is it the one we want ? */
446 if (strcmp(nl_current->component_uref, wanted_uref) == 0) {
448 for (pl_current = nl_current->cpins; pl_current != NULL;
449 pl_current = pl_current->next) {
450 /* is there a valid pin number and a valid name ? */
451 if (pl_current->pin_number) {
452 if (pl_current->net_name) {
453 /* yes, add it to the list */
454 pin = pl_current->pin_number;
455 net_name = pl_current->net_name;
457 pairlist = scm_cons (scm_makfrom0str (pin),
458 scm_makfrom0str (net_name));
459 pinslist = scm_cons (pairlist, pinslist);
468 pinslist = scm_reverse (pinslist); /* pins are in reverse order on the way
469 * out
471 return (pinslist);
475 SCM g_get_package_attribute(SCM scm_uref, SCM scm_wanted_attrib)
477 SCM scm_return_value;
478 NETLIST *nl_current;
479 char *uref;
480 char *wanted_attrib;
481 char *return_value = NULL;
483 SCM_ASSERT(scm_is_string (scm_uref),
484 scm_uref, SCM_ARG1, "gnetlist:get-package-attribute");
486 SCM_ASSERT(scm_is_string (scm_wanted_attrib),
487 scm_wanted_attrib, SCM_ARG2, "gnetlist:get-package-attribute");
489 uref = scm_to_locale_string (scm_uref);
490 wanted_attrib = scm_to_locale_string (scm_wanted_attrib);
492 /* here is where you make it multi page aware */
493 nl_current = netlist_head;
495 /* search for the first instance */
496 /* through the entire list */
497 while (nl_current != NULL) {
499 if (nl_current->component_uref) {
500 if (strcmp(nl_current->component_uref, uref) == 0) {
502 return_value =
503 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
504 wanted_attrib, 0);
505 break;
508 nl_current = nl_current->next;
511 if (return_value) {
512 scm_return_value = scm_makfrom0str (return_value);
513 } else {
514 scm_return_value = scm_makfrom0str ("unknown");
517 free (uref);
518 free (wanted_attrib);
520 return (scm_return_value);
523 /* takes a uref and pinseq number and returns wanted_attribute associated */
524 /* with that pinseq pin and component */
525 SCM g_get_attribute_by_pinseq(SCM scm_uref, SCM scm_pinseq,
526 SCM scm_wanted_attrib)
528 SCM scm_return_value;
529 NETLIST *nl_current;
530 char *uref;
531 char *pinseq;
532 char *wanted_attrib;
533 char *return_value = NULL;
534 OBJECT *o_pin_object;
536 SCM_ASSERT(scm_is_string (scm_uref),
537 scm_uref, SCM_ARG1, "gnetlist:get-pin-number-seq");
539 SCM_ASSERT(scm_is_string (scm_pinseq),
540 scm_pinseq, SCM_ARG2, "gnetlist:get-pin-number-seq");
543 SCM_ASSERT(scm_is_string (scm_wanted_attrib),
544 scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute-seq");
546 uref = SCM_STRING_CHARS (scm_uref);
547 pinseq = SCM_STRING_CHARS (scm_pinseq);
548 wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib);
550 #if DEBUG
551 printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- \n");
552 printf(" wanted uref = %s\n", uref);
553 printf(" wanted_pin_seq = %s\n", pinseq);
554 printf(" wanted_attrib = %s\n", wanted_attrib);
555 #endif
557 /* here is where you make it multi page aware */
558 nl_current = netlist_head;
560 /* search for the first instance */
561 /* through the entire list */
562 while (nl_current != NULL) {
564 if (nl_current->component_uref) {
565 if (strcmp(nl_current->component_uref, uref) == 0) {
567 o_pin_object = o_complex_find_pin_by_attribute (nl_current->object_ptr,
568 "pinseq", pinseq);
570 if (o_pin_object) {
571 return_value =
572 o_attrib_search_object_attribs_by_name (o_pin_object,
573 wanted_attrib, 0);
574 if (return_value) {
575 break;
579 /* Don't break until we search the whole netlist to handle slotted */
580 /* parts. 4.28.2007 -- SDB. */
583 nl_current = nl_current->next;
586 if (return_value) {
587 scm_return_value = scm_makfrom0str (return_value);
588 } else {
589 scm_return_value = scm_makfrom0str ("unknown");
592 #if DEBUG
593 printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- ");
594 printf("return_value: %s\n", return_value);
595 #endif
597 return (scm_return_value);
600 /* this takes a pin number and returns the appropriate attribute on that pin*/
601 /* scm_pin is the value associated with the pinnumber= attribute and uref */
602 SCM g_get_attribute_by_pinnumber(SCM scm_uref, SCM scm_pin, SCM
603 scm_wanted_attrib)
605 SCM scm_return_value;
606 NETLIST *nl_current;
607 OBJECT *pin_object;
608 char *uref;
609 char *pin;
610 char *wanted_attrib;
611 char *return_value = NULL;
612 int done = FALSE;
614 SCM_ASSERT(scm_is_string (scm_uref),
615 scm_uref, SCM_ARG1, "gnetlist:get-pin-attribute");
617 SCM_ASSERT(scm_is_string (scm_pin),
618 scm_pin, SCM_ARG2, "gnetlist:get-pin-attribute");
620 SCM_ASSERT(scm_is_string (scm_wanted_attrib),
621 scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute");
623 uref = SCM_STRING_CHARS (scm_uref);
624 pin = SCM_STRING_CHARS (scm_pin);
625 wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib);
627 /* here is where you make it multi page aware */
628 nl_current = netlist_head;
630 /* search for the first instance */
631 /* through the entire list */
632 while (nl_current != NULL && !done) {
633 if (nl_current->component_uref) {
634 if (strcmp(nl_current->component_uref, uref) == 0) {
636 pin_object =
637 o_complex_find_pin_by_attribute (nl_current->object_ptr,
638 "pinnumber", pin);
640 if (pin_object) {
642 /* only look for the first occurance of wanted_attrib */
643 return_value =
644 o_attrib_search_object_attribs_by_name (pin_object,
645 wanted_attrib, 0);
646 #if DEBUG
647 if (return_value) {
648 printf("GOT IT: %s\n", return_value);
650 #endif
651 } else if (strcmp("pintype",
652 wanted_attrib) == 0) {
653 if (nl_current->cpins) {
654 CPINLIST *pinobject =
655 s_cpinlist_search_pin(nl_current->cpins, pin);
656 if (pinobject) {
657 return_value="pwr";
658 #if DEBUG
660 printf("Supplied pintype 'pwr' for artificial pin '%s' of '%s'\n",
661 pin, uref);
662 #endif
668 nl_current = nl_current->next;
671 if (return_value) {
672 scm_return_value = scm_makfrom0str (return_value);
673 } else {
674 scm_return_value = scm_makfrom0str ("unknown");
677 return (scm_return_value);
681 /* returns value of attribute otherwise string "none" */
682 /* still highly temp and doesn't work right */
683 SCM g_get_toplevel_attribute(SCM scm_wanted_attrib)
685 const GList *p_iter;
686 PAGE *p_current;
687 char *wanted_attrib;
688 char *attrib_value = NULL;
689 SCM scm_return_value;
691 SCM_ASSERT(scm_is_string (scm_wanted_attrib),
692 scm_wanted_attrib, SCM_ARG1, "gnetlist:get-toplevel-attribute");
694 wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib);
696 for (p_iter = geda_list_get_glist (project_current->pages); p_iter != NULL;
697 p_iter = g_list_next (p_iter)) {
698 p_current = p_iter->data;
700 /* only look for first occurrance of the attribute on each page */
701 attrib_value =
702 o_attrib_search_floating_attribs_by_name (s_page_objects (p_current),
703 wanted_attrib, 0);
705 /* Stop when we find the first one */
706 if (attrib_value != NULL)
707 break;
710 if (attrib_value != NULL) {
711 scm_return_value = scm_makfrom0str (attrib_value);
712 g_free (attrib_value);
713 } else {
714 scm_return_value = scm_makfrom0str ("not found");
717 return (scm_return_value);
720 #if 0 /* No longer needed, but the netlist_mode variable is still used */
721 SCM g_set_netlist_mode(SCM mode)
723 char *string;
725 string = SCM_STRING_CHARS (mode);
727 if (strcmp(string, "gEDA") == 0) {
728 netlist_mode = gEDA;
729 } else if (strcmp(string, "SPICE") == 0) {
730 netlist_mode = SPICE;
731 } else if (strcmp(string, "TANGO") == 0) {
732 netlist_mode = TANGO;
734 #if DEBUG
735 printf("netlist_mode: %s %d\n", string, netlist_mode);
736 #endif
738 return (scm_from_int (0));
740 #endif
742 /* Given an uref, return a list of used slots in the schematic */
743 /* in the form: (1 2 3 4). Repeated slots are returned. */
744 SCM g_get_slots(SCM scm_uref)
746 NETLIST *nl_current;
747 char *uref;
748 gchar *slot = NULL;
749 char *slot_tmp = NULL;
750 SCM slots_list = SCM_EOL;
751 SCM slot_number;
754 SCM_ASSERT(scm_is_string (scm_uref),
755 scm_uref, SCM_ARG1, "gnetlist:get-slots-used-of-package");
757 uref = SCM_STRING_CHARS (scm_uref);
759 /* here is where you make it multi page aware */
760 nl_current = netlist_head;
762 /* search for the first instance */
763 /* through the entire list */
764 while (nl_current != NULL) {
766 if (nl_current->component_uref) {
767 if (strcmp(nl_current->component_uref, uref) == 0) {
769 /* first search outside the symbol */
770 slot_tmp =
771 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
772 "slot", 0);
774 /* When a package has no slot attribute, then assume it's slot number 1 */
775 if (!slot_tmp) {
776 slot_tmp=g_strdup("1");
778 slot = g_strconcat ("#d", slot_tmp, NULL);
779 slot_number = scm_string_to_number(scm_makfrom0str (slot),
780 scm_from_int(10));
781 g_free (slot);
782 if (slot_number != SCM_BOOL_F) {
783 slots_list = scm_cons (slot_number, slots_list);
785 else
786 fprintf(stderr, "Uref %s: Bad slot number: %s.\n", uref, slot_tmp);
787 g_free (slot_tmp);
790 nl_current = nl_current->next;
793 slots_list = scm_sort_list_x(slots_list,
794 SCM_VARIABLE_REF (scm_c_module_lookup (
795 scm_current_module (), "<")));
797 return (slots_list);
800 /* Given an uref, return a unique list of used slots in the schematic */
801 /* in the form: (1 2 3 4). Repeated slots are NOT returned */
802 SCM g_get_unique_slots(SCM scm_uref)
804 NETLIST *nl_current;
805 char *uref;
806 gchar *slot = NULL;
807 char *slot_tmp = NULL;
808 SCM slots_list = SCM_EOL;
809 SCM slot_number;
812 SCM_ASSERT(scm_is_string (scm_uref),
813 scm_uref, SCM_ARG1, "gnetlist:get-unique-slots-used-of-package");
815 uref = SCM_STRING_CHARS (scm_uref);
817 /* here is where you make it multi page aware */
818 nl_current = netlist_head;
820 /* search for the first instance */
821 /* through the entire list */
822 while (nl_current != NULL) {
824 if (nl_current->component_uref) {
825 if (strcmp(nl_current->component_uref, uref) == 0) {
827 /* first search outside the symbol */
828 slot_tmp =
829 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
830 "slot", 0);
832 /* When a package has no slot attribute, then assume it's slot number 1 */
833 if (!slot_tmp) {
834 slot_tmp=g_strdup("1");
836 slot = g_strconcat ("#d", slot_tmp, NULL);
837 slot_number = scm_string_to_number(scm_makfrom0str (slot),
838 scm_from_int(10));
839 g_free (slot);
840 if (slot_number != SCM_BOOL_F) {
841 if (scm_member(slot_number, slots_list) == SCM_BOOL_F) {
842 slots_list = scm_cons (slot_number, slots_list);
845 else
846 fprintf(stderr, "Uref %s: Bad slot number: %s.\n", uref, slot_tmp);
847 g_free (slot_tmp);
850 nl_current = nl_current->next;
853 slots_list = scm_sort_list_x(slots_list,
854 SCM_VARIABLE_REF (scm_c_module_lookup (
855 scm_current_module (), "<")));
856 return (slots_list);
861 This function returns certain calling flags to the calling guile prog.
862 The calling flags are returned to Guile as a list of option/value pairs [e.g.
863 ((verbose_mode #t) (interactive_mode #f) . . . ) ]
864 It is used primarily to enable refdes sorting during netlisting via
865 the -s flag. Note that this prog is not very flexible -- the allowed
866 calling flags are hard coded into the function. At some point this
867 should be fixed . . .
868 9.1.2003 -- SDB
870 8.2.2005 -- Carlos Nieves Onega
871 Different modes are now included in the backend_params list, as well as
872 the backend parameters given from the command line. Since the function
873 calling-flag? in scheme/gnetlist.scm returns false if the calling flag was
874 not found, it's only necessary to include the flags being true.
876 SCM g_get_calling_flags()
878 SCM arglist = SCM_EOL;
880 GSList *aux;
882 aux = backend_params;
883 while (aux != NULL) {
884 arglist = scm_cons (scm_list_n (scm_makfrom0str (aux->data),
885 SCM_BOOL (TRUE),
886 SCM_UNDEFINED),
887 arglist);
888 aux = aux->next;
891 return (arglist);
895 /* -------------------------------------------------------------------- *
896 * This fcn returns the command line with which gnetlist was invoked.
897 * It is used to write the first line of a SPICE file when netlisting
898 * to SPICE.
899 * SDB -- 8.22.2004.
900 * -------------------------------------------------------------------- */
901 SCM g_get_command_line()
903 SCM commandline;
905 commandline = scm_makfrom0str (command_line);
907 return (commandline);
911 /* given a net name, an attribute, and a wanted attribute, return all
912 the given attribute of all the graphical objects connected to that
913 net name */
914 SCM g_graphical_objs_in_net_with_attrib_get_attrib (SCM scm_netname, SCM scm_has_attribute, SCM scm_wanted_attribute)
917 SCM list = SCM_EOL;
918 NETLIST *nl_current;
919 CPINLIST *pl_current;
920 char *wanted_net_name;
921 char *wanted_attrib;
922 char *has_attrib;
923 char *net_name;
924 char *attrib_value=NULL;
925 char *has_attrib_value = NULL;
926 char *has_attrib_name = NULL;
928 SCM_ASSERT(scm_is_string (scm_netname), scm_netname, SCM_ARG1,
929 "gnetlist:get-attr-of-conn-graph-objs-with-attr");
931 SCM_ASSERT(scm_is_string (scm_wanted_attribute),
932 scm_wanted_attribute, SCM_ARG2,
933 "gnetlist:get-attr-of-conn-graph-objs-with-attr");
935 SCM_ASSERT(scm_is_string (scm_has_attribute),
936 scm_has_attribute, SCM_ARG3,
937 "gnetlist:get-attr-of-conn-graph-objs-with-attr");
939 wanted_net_name = SCM_STRING_CHARS (scm_netname);
940 wanted_attrib = SCM_STRING_CHARS (scm_wanted_attribute);
941 has_attrib = SCM_STRING_CHARS (scm_has_attribute);
943 if (wanted_net_name == NULL) {
944 return list;
948 nl_current = graphical_netlist_head;
950 /* walk through the list of components, and through the list
951 * of individual pins on each, adding net names to the list
952 * being careful to ignore duplicates, and unconnected pins
954 while (nl_current != NULL) {
955 pl_current = nl_current->cpins;
956 while (pl_current != NULL) {
957 if (pl_current->net_name) {
958 net_name = pl_current->net_name;
959 if (strcmp(net_name, wanted_net_name) == 0) {
961 if (o_attrib_string_get_name_value (has_attrib, &has_attrib_name,
962 &has_attrib_value) != 0) {
963 attrib_value =
964 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
965 has_attrib_name, 0);
967 if ( ((has_attrib_value == NULL) && (attrib_value == NULL)) ||
968 ((has_attrib_value != NULL) && (attrib_value != NULL) &&
969 (strcmp(attrib_value, has_attrib_value) == 0)) ) {
970 g_free (attrib_value);
971 attrib_value =
972 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
973 wanted_attrib, 0);
974 if (attrib_value) {
975 list = scm_cons (scm_makfrom0str (attrib_value), list);
977 g_free (attrib_value);
979 g_free (has_attrib_name);
980 g_free (has_attrib_value);
984 pl_current = pl_current->next;
986 nl_current = nl_current->next;
989 return list;
997 * This function is in s_rename.c: SCM g_get_renamed_nets(SCM scm_level)