gnetlist

g_netlist.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gnetlist - gEDA Netlist
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include <config.h>
00022 #include <missing.h>
00023 
00024 #include <stdio.h> 
00025 #ifdef HAVE_STRING_H
00026 #include <string.h> 
00027 #endif
00028 #include <math.h>
00029 
00030 #include <libgeda/libgeda.h>
00031 #include <libgeda/libgedaguile.h>
00032 
00033 #include "../include/globals.h"
00034 #include "../include/prototype.h"
00035 
00036 #ifdef HAVE_LIBDMALLOC
00037 #include <dmalloc.h>
00038 #endif
00039 
00040 
00041 SCM g_scm_c_get_uref (TOPLEVEL *toplevel, OBJECT *object)
00042 {
00043   SCM func = scm_variable_ref (scm_c_lookup ("get-uref"));
00044   SCM object_smob = edascm_from_object (object);
00045   SCM exp = scm_list_2 (func, object_smob);
00046 
00047   return g_scm_eval_protected (exp, SCM_UNDEFINED);
00048 }
00049 
00050 
00051 /* this function will only return a unique list of packages */
00052 SCM g_get_packages(SCM level)
00053 {
00054     SCM list = SCM_EOL;
00055     GHashTable *ht;
00056 
00057     NETLIST *nl_current = NULL;
00058 
00059     SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");
00060 
00061     /* build a hash table */
00062     ht = g_hash_table_new (g_str_hash, g_str_equal);
00063     for (nl_current = netlist_head; nl_current != NULL;
00064          nl_current = nl_current->next) {
00065       if (nl_current->component_uref != NULL) {
00066         /* add component_uref in the hash table */
00067         /* uniqueness of component_uref is guaranteed by the hashtable */
00068 
00069         if (g_hash_table_lookup (ht, nl_current->component_uref) == NULL) {
00070           g_hash_table_insert (ht, nl_current->component_uref,
00071                                    nl_current->component_uref);
00072           list = scm_cons (scm_from_utf8_string (nl_current->component_uref),
00073                            list);
00074         }
00075       }
00076     }
00077     g_hash_table_destroy (ht);
00078 
00079     return list;
00080 }
00081 
00082 /* this function will only return a non unique list of packages */
00083 SCM g_get_non_unique_packages(SCM level)
00084 {
00085     SCM list = SCM_EOL;
00086 
00087     NETLIST *nl_current = NULL;
00088 
00089     SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");
00090 
00091     for (nl_current = netlist_head; nl_current != NULL;
00092          nl_current = nl_current->next) {
00093       if (nl_current->component_uref != NULL) {
00094         list = scm_cons (scm_from_utf8_string (nl_current->component_uref),
00095                          list);
00096       }
00097     }
00098     
00099     return list;
00100 }
00101 
00102 
00103 SCM g_get_pins(SCM scm_uref)
00104 {
00105     char *uref;
00106     SCM list = SCM_EOL;
00107     NETLIST *nl_current;
00108     CPINLIST *pl_current;
00109 
00110     SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1, "gnetlist:get-pins");
00111 
00112     uref = scm_to_utf8_string (scm_uref);
00113 
00114     /* here is where you make it multi page aware */
00115     nl_current = netlist_head;
00116 
00117     /* search for the first instance */
00118     /* through the entire list */
00119     while (nl_current != NULL) {
00120 
00121     if (nl_current->component_uref) {
00122         if (strcmp(nl_current->component_uref, uref) == 0) {
00123 
00124         pl_current = nl_current->cpins;
00125         while (pl_current != NULL) {
00126             if (pl_current->pin_number) {
00127               list = scm_cons (scm_from_utf8_string (pl_current->pin_number),
00128                                list);
00129             }
00130             pl_current = pl_current->next;
00131         }
00132         }
00133     }
00134     nl_current = nl_current->next;
00135     }
00136 
00137     free (uref);
00138 
00139     return (list);
00140 }
00141 
00142 SCM g_get_all_nets(SCM scm_level)
00143 {
00144 
00145     SCM list = SCM_EOL;
00146     NETLIST *nl_current;
00147     CPINLIST *pl_current;
00148     char *net_name;
00149 
00150     SCM_ASSERT(scm_is_string (scm_level), scm_level, SCM_ARG1, 
00151            "gnetlist:get-all-nets");
00152 
00153     nl_current = netlist_head;
00154 
00155     /* walk through the list of components, and through the list
00156      * of individual pins on each, adding net names to the list
00157      * being careful to ignore duplicates, and unconnected pins 
00158      */
00159     while (nl_current != NULL) {
00160     pl_current = nl_current->cpins;
00161     while (pl_current != NULL) {
00162         if (pl_current->net_name) {
00163 
00164         net_name = pl_current->net_name;
00165         /* filter off unconnected pins */
00166         if (strncmp(net_name, "unconnected_pin", 15) != 0) {
00167             /*printf("Got net: `%s'\n",net_name); */
00168             /* add the net name to the list */
00169 #if DEBUG
00170             printf("Got net: `%s'\n", net_name);
00171             printf("pin %s\n", pl_current->pin_number);
00172 #endif
00173             list = scm_cons (scm_from_utf8_string (net_name),
00174                                      list);
00175         }
00176         }
00177         pl_current = pl_current->next;
00178     }
00179     nl_current = nl_current->next;
00180     }
00181 
00182     return list;
00183 }
00184 
00185 SCM g_get_all_unique_nets(SCM scm_level)
00186 {
00187 
00188     SCM list = SCM_EOL;
00189     SCM x = SCM_EOL;
00190     NETLIST *nl_current;
00191     CPINLIST *pl_current;
00192     char *net_name;
00193 
00194     SCM_ASSERT(scm_is_string (scm_level), scm_level, SCM_ARG1, 
00195            "gnetlist:get-all-unique-nets");
00196 
00197     nl_current = netlist_head;
00198 
00199     /* walk through the list of components, and through the list
00200      * of individual pins on each, adding net names to the list
00201      * being careful to ignore duplicates, and unconnected pins 
00202      */
00203     while (nl_current != NULL) {
00204     pl_current = nl_current->cpins;
00205     while (pl_current != NULL) {
00206         if (pl_current->net_name) {
00207 
00208         net_name = pl_current->net_name;
00209         /* filter off unconnected pins */
00210         if (strncmp(net_name, "unconnected_pin", 15) != 0) {
00211             /* add the net name to the list */
00212             /*printf("Got net: `%s'\n",net_name); */
00213 
00214             x = scm_from_utf8_string (net_name);
00215             if (scm_is_false (scm_member (x, list))) {
00216               list = scm_cons (x, list);
00217             }
00218         }
00219         }
00220         pl_current = pl_current->next;
00221     }
00222     nl_current = nl_current->next;
00223     }
00224 
00225     return list;
00226 }
00227 
00228 /* given a net name, return all connections */
00229 SCM g_get_all_connections(SCM scm_netname)
00230 {
00231 
00232     SCM list = SCM_EOL;
00233     SCM x = SCM_EOL;
00234     SCM is_member = SCM_EOL;
00235     SCM connlist = SCM_EOL;
00236     SCM pairlist = SCM_EOL;
00237     NETLIST *nl_current;
00238     CPINLIST *pl_current;
00239     NET *n_current;
00240     char *wanted_net_name;
00241     char *net_name;
00242     char *pin;
00243     char *uref;
00244 
00245     SCM_ASSERT(scm_is_string(scm_netname), scm_netname, SCM_ARG1, 
00246            "gnetlist:get-all-connections");
00247 
00248     wanted_net_name = scm_to_utf8_string (scm_netname);
00249 
00250     if (wanted_net_name == NULL) {
00251     return list;
00252     }
00253 
00254 
00255     nl_current = netlist_head;
00256 
00257     /* walk through the list of components, and through the list
00258      * of individual pins on each, adding net names to the list
00259      * being careful to ignore duplicates, and unconnected pins 
00260      */
00261     while (nl_current != NULL) {
00262     pl_current = nl_current->cpins;
00263     while (pl_current != NULL) {
00264         if (pl_current->net_name) {
00265 
00266         net_name = pl_current->net_name;
00267         /* filter off unconnected pins */
00268         if (strcmp(net_name, wanted_net_name) == 0) {
00269             /* add the net name to the list */
00270 
00271 #if DEBUG
00272             printf("found net: `%s'\n", net_name);
00273 #endif
00274 
00275             n_current = pl_current->nets;
00276             while (n_current != NULL) {
00277 
00278             if (n_current->connected_to) {
00279 
00280                 pairlist = SCM_EOL;
00281                 pin = (char *) g_malloc(sizeof(char) *
00282                           strlen(n_current->
00283                              connected_to));
00284                 uref =
00285                 (char *) g_malloc(sizeof(char) *
00286                         strlen(n_current->
00287                                connected_to));
00288 
00289                 sscanf(n_current->connected_to,
00290                    "%s %s", uref, pin);
00291 
00292                 pairlist = scm_list_n (scm_from_utf8_string (uref),
00293                                        scm_from_utf8_string (pin),
00294                                        SCM_UNDEFINED);
00295 
00296                 x = pairlist;
00297                 is_member = scm_member(x, connlist);
00298 
00299                 if (scm_is_false (is_member)) {
00300                 connlist = scm_cons (pairlist, connlist);
00301                 }
00302 
00303                 g_free(uref);
00304                 g_free(pin);
00305             }
00306             n_current = n_current->next;
00307             }
00308         }
00309         }
00310         pl_current = pl_current->next;
00311     }
00312     nl_current = nl_current->next;
00313     }
00314 
00315     free (wanted_net_name);
00316     return connlist;
00317 }
00318 
00319 /* Given a uref and a pin number return a list of: */
00320 /*  (netname (uref pin) (uref pin) ... ) */
00321 SCM g_get_nets(SCM scm_uref, SCM scm_pin)
00322 {
00323   SCM outerlist = SCM_EOL;
00324   SCM pinslist = SCM_EOL;
00325   SCM pairlist = SCM_EOL;
00326   NETLIST *nl_current = NULL;
00327   CPINLIST *pl_current = NULL;
00328   NET *n_current;
00329   char *wanted_uref = NULL;
00330   char *wanted_pin = NULL;
00331   char *net_name = NULL;
00332 
00333   char *pin;
00334   char *uref;
00335 
00336   SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1, 
00337              "gnetlist:get-nets");
00338 
00339   SCM_ASSERT(scm_is_string (scm_pin), scm_pin, SCM_ARG2, 
00340              "gnetlist:get-nets");
00341 
00342   scm_dynwind_begin (0);
00343 
00344   wanted_uref = scm_to_utf8_string (scm_uref);
00345   scm_dynwind_free (wanted_uref);
00346 
00347   wanted_pin = scm_to_utf8_string (scm_pin);
00348   scm_dynwind_free (wanted_pin);
00349 
00350   nl_current = netlist_head;
00351 
00352   /* search for the first instance */
00353   /* through the entire list */
00354   for (nl_current = netlist_head;
00355        nl_current != NULL;
00356        nl_current = nl_current->next) {
00357 
00358     if (!nl_current->component_uref) continue;
00359     if (strcmp (nl_current->component_uref, wanted_uref) != 0) continue;
00360 
00361     for (pl_current = nl_current->cpins;
00362          pl_current != NULL;
00363          pl_current = pl_current->next) {
00364 
00365       if (!pl_current->pin_number) continue;
00366       if (strcmp(pl_current->pin_number, wanted_pin) != 0) continue;
00367 
00368       if (pl_current->net_name) {
00369         net_name = pl_current->net_name;
00370       }
00371 
00372       for (n_current = pl_current->nets;
00373            n_current != NULL;
00374            n_current = n_current->next) {
00375 
00376         if (!n_current->connected_to) continue;
00377 
00378         pairlist = SCM_EOL;
00379         pin = (char *) g_malloc(sizeof(char) *
00380                                 strlen
00381                                 (n_current->
00382                                  connected_to));
00383         uref =
00384           (char *) g_malloc(sizeof(char) *
00385                             strlen(n_current->
00386                                    connected_to));
00387 
00388         sscanf(n_current->connected_to,
00389                "%s %s", uref, pin);
00390 
00391         pairlist = scm_list_n (scm_from_utf8_string (uref),
00392                                scm_from_utf8_string (pin),
00393                                SCM_UNDEFINED);
00394 
00395         pinslist = scm_cons (pairlist, pinslist);
00396 
00397         g_free(uref);
00398         g_free(pin);
00399       }
00400     }
00401   }
00402 
00403   if (net_name != NULL) {
00404     outerlist = scm_cons (scm_from_utf8_string (net_name), pinslist);
00405   } else {
00406     outerlist = scm_cons (scm_from_utf8_string ("ERROR_INVALID_PIN"),
00407                           outerlist);
00408     fprintf(stderr, "Invalid refdes ('%s') and pin ('%s') passed to get-nets\n",
00409             wanted_uref, wanted_pin);
00410   }
00411 
00412   scm_dynwind_end ();
00413 
00414   return (outerlist);
00415 }
00416 
00417 
00418 /* Given a uref, Return a list of pairs, each pair contains the name
00419  * of the pin, and the name of the net connected to that pin.  
00420  */
00421 SCM g_get_pins_nets(SCM scm_uref)
00422 {
00423     SCM pinslist = SCM_EOL;
00424     SCM pairlist = SCM_EOL;
00425     NETLIST *nl_current = NULL;
00426     CPINLIST *pl_current = NULL;
00427 
00428     char *wanted_uref = NULL;
00429     char *net_name = NULL;
00430     char *pin = NULL;
00431 
00432     SCM_ASSERT(scm_is_string (scm_uref),
00433            scm_uref, SCM_ARG1, "gnetlist:get-pins-nets");
00434 
00435     wanted_uref = scm_to_utf8_string (scm_uref);
00436 
00437     /* search for the any instances */
00438     /* through the entire list */
00439     for (nl_current = netlist_head; nl_current != NULL;
00440      nl_current = nl_current->next) {
00441 
00442     /* is there a uref? */
00443     if (nl_current->component_uref) {
00444         /* is it the one we want ? */
00445         if (strcmp(nl_current->component_uref, wanted_uref) == 0) {
00446 
00447         for (pl_current = nl_current->cpins; pl_current != NULL;
00448              pl_current = pl_current->next) {
00449             /* is there a valid pin number and a valid name ? */
00450             if (pl_current->pin_number) {
00451             if (pl_current->net_name) {
00452                 /* yes, add it to the list */
00453                 pin = pl_current->pin_number;
00454                 net_name = pl_current->net_name;
00455 
00456                 pairlist = scm_cons (scm_from_utf8_string (pin),
00457                                                  scm_from_utf8_string (net_name));
00458                 pinslist = scm_cons (pairlist, pinslist);
00459             }
00460 
00461             }
00462         }
00463         }
00464     }
00465     }
00466 
00467     free (wanted_uref);
00468 
00469     pinslist = scm_reverse (pinslist);  /* pins are in reverse order on the way 
00470                      * out 
00471                      */
00472     return (pinslist);
00473 }
00474 
00475 
00492 SCM g_get_all_package_attributes(SCM scm_uref, SCM scm_wanted_attrib)
00493 {
00494     SCM ret = SCM_EOL;
00495     NETLIST *nl_current;
00496     char *uref;
00497     char *wanted_attrib;
00498 
00499     SCM_ASSERT(scm_is_string (scm_uref),
00500            scm_uref, SCM_ARG1, "gnetlist:get-all-package-attributes");
00501 
00502     SCM_ASSERT(scm_is_string (scm_wanted_attrib),
00503            scm_wanted_attrib, SCM_ARG2, "gnetlist:get-all-package-attributes");
00504 
00505     uref          = scm_to_utf8_string (scm_uref);
00506     wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
00507 
00508     /* here is where you make it multi page aware */
00509     nl_current = netlist_head;
00510 
00511     /* search for uref instances and through the entire list */
00512     while (nl_current != NULL) {
00513 
00514     if (nl_current->component_uref) {
00515         if (strcmp(nl_current->component_uref, uref) == 0) {
00516         char *value =
00517             o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
00518                                                     wanted_attrib, 0);
00519 
00520         ret = scm_cons (value ? scm_from_utf8_string (value) : SCM_BOOL_F, ret);
00521 
00522         g_free (value);
00523         }
00524     }
00525     nl_current = nl_current->next;
00526     }
00527 
00528     free (uref);
00529     free (wanted_attrib);
00530 
00531     return scm_reverse_x (ret, SCM_EOL);
00532 }
00533 
00534 /* takes a uref and pinseq number and returns wanted_attribute associated */
00535 /* with that pinseq pin and component */
00536 SCM g_get_attribute_by_pinseq(SCM scm_uref, SCM scm_pinseq,
00537                               SCM scm_wanted_attrib)
00538 {
00539   SCM scm_return_value;
00540   NETLIST *nl_current;
00541   char *uref;
00542   char *pinseq;
00543   char *wanted_attrib;
00544   char *return_value = NULL;
00545   OBJECT *o_pin_object;
00546 
00547   SCM_ASSERT(scm_is_string (scm_uref),
00548          scm_uref, SCM_ARG1, "gnetlist:get-pin-number-seq");
00549 
00550   SCM_ASSERT(scm_is_string (scm_pinseq),
00551              scm_pinseq, SCM_ARG2, "gnetlist:get-pin-number-seq");
00552 
00553 
00554   SCM_ASSERT(scm_is_string (scm_wanted_attrib),
00555              scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute-seq");
00556 
00557   scm_dynwind_begin (0);
00558 
00559   uref = scm_to_utf8_string (scm_uref);
00560   scm_dynwind_free (uref);
00561 
00562   pinseq = scm_to_utf8_string (scm_pinseq);
00563   scm_dynwind_free (pinseq);
00564 
00565   wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
00566   scm_dynwind_free (wanted_attrib);
00567 
00568 #if DEBUG
00569   printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- \n");
00570   printf("  wanted uref = %s\n", uref);
00571   printf("  wanted_pin_seq = %s\n", pinseq);
00572   printf("  wanted_attrib = %s\n", wanted_attrib);
00573 #endif
00574 
00575   /* here is where you make it multi page aware */
00576   nl_current = netlist_head;
00577 
00578   /* search for the first instance */
00579   /* through the entire list */
00580   while (nl_current != NULL) {
00581 
00582     if (nl_current->component_uref) {
00583       if (strcmp(nl_current->component_uref, uref) == 0) {
00584 
00585         o_pin_object = o_complex_find_pin_by_attribute (nl_current->object_ptr,
00586                                                         "pinseq", pinseq);
00587 
00588         if (o_pin_object) {
00589           return_value =
00590             o_attrib_search_object_attribs_by_name (o_pin_object,
00591                                                     wanted_attrib, 0);
00592           if (return_value) {
00593             break;
00594           }
00595         }
00596 
00597         /* Don't break until we search the whole netlist to handle slotted */
00598         /* parts.   4.28.2007 -- SDB. */
00599       }
00600     }
00601     nl_current = nl_current->next;
00602   }
00603 
00604   scm_dynwind_end ();
00605 
00606   if (return_value) {
00607     scm_return_value = scm_from_utf8_string (return_value);
00608   } else {
00609     scm_return_value = scm_from_utf8_string ("unknown");
00610   }
00611 
00612 #if DEBUG
00613   printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- ");
00614   printf("return_value: %s\n", return_value);
00615 #endif
00616 
00617   return (scm_return_value);
00618 }
00619 
00620 /* this takes a pin number and returns the appropriate attribute on that pin*/
00621 /* scm_pin is the value associated with the pinnumber= attribute and uref */
00622 SCM g_get_attribute_by_pinnumber(SCM scm_uref, SCM scm_pin, SCM
00623                                scm_wanted_attrib)
00624 {
00625     SCM scm_return_value;
00626     NETLIST *nl_current;
00627     OBJECT *pin_object;
00628     char *uref;
00629     char *pin;
00630     char *wanted_attrib;
00631     char *return_value = NULL;
00632     int done = FALSE;
00633 
00634     SCM_ASSERT(scm_is_string (scm_uref),
00635            scm_uref, SCM_ARG1, "gnetlist:get-pin-attribute");
00636 
00637     SCM_ASSERT(scm_is_string (scm_pin),
00638            scm_pin, SCM_ARG2, "gnetlist:get-pin-attribute");
00639 
00640     SCM_ASSERT(scm_is_string (scm_wanted_attrib),
00641            scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute");
00642 
00643     scm_dynwind_begin (0);
00644 
00645     uref = scm_to_utf8_string (scm_uref);
00646     scm_dynwind_free (uref);
00647 
00648     pin = scm_to_utf8_string (scm_pin);
00649     scm_dynwind_free (pin);
00650 
00651     wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
00652     scm_dynwind_free (wanted_attrib);
00653 
00654     /* here is where you make it multi page aware */
00655     nl_current = netlist_head;
00656 
00657     /* search for the first instance */
00658     /* through the entire list */
00659     while (nl_current != NULL && !done) {
00660     if (nl_current->component_uref) {
00661         if (strcmp(nl_current->component_uref, uref) == 0) {
00662 
00663         pin_object =
00664             o_complex_find_pin_by_attribute (nl_current->object_ptr,
00665                                              "pinnumber", pin);
00666 
00667         if (pin_object) {
00668 
00669             /* only look for the first occurance of wanted_attrib */
00670             return_value =
00671               o_attrib_search_object_attribs_by_name (pin_object,
00672                                                       wanted_attrib, 0);
00673 #if DEBUG
00674             if (return_value) {
00675             printf("GOT IT: %s\n", return_value);
00676             }
00677 #endif
00678         } else if (strcmp("pintype",
00679                   wanted_attrib) == 0) {
00680           if (nl_current->cpins) {
00681             CPINLIST *pinobject =
00682               s_cpinlist_search_pin(nl_current->cpins, pin);
00683             if (pinobject) {
00684               return_value="pwr";
00685 #if DEBUG
00686               
00687               printf("Supplied pintype 'pwr' for artificial pin '%s' of '%s'\n",
00688                  pin, uref);
00689 #endif
00690             }
00691           }     
00692         }
00693         }
00694     }
00695     nl_current = nl_current->next;
00696     }
00697 
00698     scm_dynwind_end ();
00699 
00700     if (return_value) {
00701       scm_return_value = scm_from_utf8_string (return_value);
00702     } else {
00703       scm_return_value = scm_from_utf8_string ("unknown");
00704     }
00705 
00706     return (scm_return_value);
00707 }
00708 
00709 
00710 /* returns value of attribute otherwise string "none" */
00711 /* still highly temp and doesn't work right */
00712 SCM g_get_toplevel_attribute(SCM scm_wanted_attrib)
00713 {
00714   const GList *p_iter;
00715   PAGE *p_current;
00716   char *wanted_attrib;
00717   char *attrib_value = NULL;
00718   SCM scm_return_value;
00719   TOPLEVEL *toplevel = edascm_c_current_toplevel ();
00720 
00721   SCM_ASSERT(scm_is_string (scm_wanted_attrib),
00722              scm_wanted_attrib, SCM_ARG1, "gnetlist:get-toplevel-attribute");
00723 
00724   wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
00725 
00726   for (p_iter = geda_list_get_glist (toplevel->pages); p_iter != NULL;
00727        p_iter = g_list_next (p_iter)) {
00728     p_current = p_iter->data;
00729 
00730     /* only look for first occurrance of the attribute on each page */
00731     attrib_value =
00732       o_attrib_search_floating_attribs_by_name (s_page_objects (p_current),
00733                                                 wanted_attrib, 0);
00734 
00735     /* Stop when we find the first one */
00736     if (attrib_value != NULL)
00737       break;
00738   }
00739 
00740   free (wanted_attrib);
00741 
00742   if (attrib_value != NULL) {
00743     scm_return_value = scm_from_utf8_string (attrib_value);
00744     g_free (attrib_value);
00745   } else {
00746     scm_return_value = scm_from_utf8_string ("not found");
00747   }
00748 
00749   return (scm_return_value);
00750 }
00751 
00752 
00758 SCM
00759 g_get_backend_arguments()
00760 {
00761   SCM result = SCM_EOL;
00762   GSList *iter;
00763 
00764   for (iter = backend_params; iter != NULL; iter = g_slist_next (iter)) {
00765     result = scm_cons (scm_from_locale_string ((char *) iter->data),
00766                        result);
00767   }
00768 
00769   return scm_reverse_x (result, SCM_UNDEFINED);
00770 }
00771 
00772 
00779 SCM g_get_input_files()
00780 {
00781     SCM list = SCM_EOL;
00782     GSList *current = input_files;
00783 
00784     while (current != NULL) {
00785         list = scm_cons (scm_from_locale_string (current->data), list);
00786         current = g_slist_next(current);
00787     }
00788 
00789     return scm_reverse_x (list, SCM_EOL);
00790 }
00791 
00792 
00793 /* given a net name, an attribute, and a wanted attribute, return all 
00794    the given attribute of all the graphical objects connected to that 
00795    net name */
00796 SCM g_graphical_objs_in_net_with_attrib_get_attrib (SCM scm_netname, SCM scm_has_attribute, SCM scm_wanted_attribute)
00797 {
00798 
00799     SCM list = SCM_EOL;
00800     NETLIST *nl_current;
00801     CPINLIST *pl_current;
00802     char *wanted_net_name;
00803     char *wanted_attrib;
00804     char *has_attrib;
00805     char *net_name;
00806     char *attrib_value=NULL;
00807     char *has_attrib_value = NULL;
00808     char *has_attrib_name = NULL;
00809 
00810     SCM_ASSERT(scm_is_string (scm_netname), scm_netname, SCM_ARG1, 
00811            "gnetlist:get-attr-of-conn-graph-objs-with-attr");
00812 
00813     SCM_ASSERT(scm_is_string (scm_wanted_attribute),
00814            scm_wanted_attribute, SCM_ARG3, 
00815            "gnetlist:get-attr-of-conn-graph-objs-with-attr");
00816 
00817     SCM_ASSERT(scm_is_string (scm_has_attribute),
00818            scm_has_attribute, SCM_ARG2, 
00819            "gnetlist:get-attr-of-conn-graph-objs-with-attr");
00820 
00821     scm_dynwind_begin (0);
00822 
00823     wanted_net_name = scm_to_utf8_string (scm_netname);
00824     if (wanted_net_name == NULL) {
00825     return list;
00826     }
00827 
00828     scm_dynwind_free (wanted_net_name);
00829 
00830     wanted_attrib = scm_to_utf8_string (scm_wanted_attribute);
00831     scm_dynwind_free (wanted_attrib);
00832 
00833     has_attrib = scm_to_utf8_string (scm_has_attribute);
00834     scm_dynwind_free (has_attrib);
00835 
00836     nl_current = graphical_netlist_head;
00837     
00838     /* walk through the list of components, and through the list
00839      * of individual pins on each, adding net names to the list
00840      * being careful to ignore duplicates, and unconnected pins 
00841      */
00842     while (nl_current != NULL) {
00843     pl_current = nl_current->cpins;
00844     while (pl_current != NULL) {
00845         if (pl_current->net_name) {
00846         net_name = pl_current->net_name;
00847         if (strcmp(net_name, wanted_net_name) == 0) {
00848 
00849           if (o_attrib_string_get_name_value (has_attrib, &has_attrib_name,
00850                            &has_attrib_value) != 0) {
00851             attrib_value = 
00852               o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
00853                                                       has_attrib_name, 0);
00854             
00855             if ( ((has_attrib_value == NULL) && (attrib_value == NULL)) ||
00856              ((has_attrib_value != NULL) && (attrib_value != NULL) &&
00857               (strcmp(attrib_value, has_attrib_value) == 0)) ) {
00858               g_free (attrib_value);
00859               attrib_value =
00860                 o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
00861                                                         wanted_attrib, 0);
00862               if (attrib_value) {
00863             list = scm_cons (scm_from_utf8_string (attrib_value), list);
00864               }
00865               g_free (attrib_value);
00866             }
00867             g_free (has_attrib_name);
00868             g_free (has_attrib_value);
00869           }
00870         }
00871         }
00872         pl_current = pl_current->next;
00873     }
00874     nl_current = nl_current->next;
00875     }
00876 
00877     scm_dynwind_end ();
00878     return list;
00879 }
00880 
00881 
00882 
00883 
00884 
00885 /* 
00886  * This function is in s_rename.c:  SCM g_get_renamed_nets(SCM scm_level)
00887  */
 All Data Structures Files Functions Variables Defines