On Sun, Apr 10, 2011 at 11:22:54PM +0200, Markus Traidl wrote: > Actually I would like to use only the net attribute. There I could > assign net=3V3 instead of net=3V3:1. > > I know that the ":1" is that the gnetlist tool knows that the 3V3 is > connected to pin 1. > > But in case of a "One-Pin-Symbol" the gnetlist tool could assume that > the only net should be assigned to the only pin.
This has been asked for several times and I don't see a reason why this should not be allowed for single pin symbols and only for pin number 1. The patches are attached - please test and report any potential breakage. -- Krzysztof Kościuszkiewicz "Simplicity is the ultimate sophistication" -- Leonardo da Vinci
>From 336dbb62f859a19c5078504828c8298a11d47210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ko=C5=9Bciuszkiewicz?= <k.kosciuszkiew...@gmail.com> Date: Mon, 11 Apr 2011 23:03:12 +0200 Subject: [PATCH 1/3] gnetlist: refactor s_netattrib_net_search Replace two loops with one by using o_attrib_search_object_attribs_by_name. Factor out inside of the loop to a separate function, netname_if_matching_wanted_pin. --- gnetlist/src/s_netattrib.c | 94 ++++++++++++++++---------------------------- 1 files changed, 34 insertions(+), 60 deletions(-) diff --git a/gnetlist/src/s_netattrib.c b/gnetlist/src/s_netattrib.c index 957735c..c8052f9 100644 --- a/gnetlist/src/s_netattrib.c +++ b/gnetlist/src/s_netattrib.c @@ -213,84 +213,58 @@ s_netattrib_handle (TOPLEVEL * pr_current, OBJECT * o_current, } } +static char* netname_if_matching_wanted_pin (OBJECT *o_current, + char *net_attr, + const char *wanted_pin) +{ + char *char_ptr = strchr (net_attr, ':'); + + if (char_ptr != NULL) { + /* found a colon separating netname and list of pins */ + char *net_name = s_netattrib_extract_netname (net_attr); + char *start_of_pinlist = char_ptr + 1; + char *current_pin = strtok (start_of_pinlist, DELIMITERS); + + while (current_pin) { + if (strcmp (current_pin, wanted_pin) == 0) + return net_name; + current_pin = strtok (NULL, DELIMITERS); + } + + g_free (net_name); + return NULL; + } else { + fprintf (stderr, "Got an invalid net= attrib [net=%s]\n" + "Missing : in net= attrib\n", net_attr); + return NULL; + } +} + char *s_netattrib_net_search (OBJECT * o_current, char *wanted_pin) { char *value = NULL; - char *char_ptr = NULL; char *net_name = NULL; - char *current_pin = NULL; - char *start_of_pinlist = NULL; - char *return_value = NULL; int counter; if (o_current == NULL || o_current->complex == NULL) return NULL; - /* for now just look inside the component */ - for (counter = 0; ;) { - value = o_attrib_search_inherited_attribs_by_name (o_current, - "net", counter); + for (counter = 0; ; ++counter) { + value = o_attrib_search_object_attribs_by_name (o_current, + "net", counter); if (value == NULL) break; - counter++; - - char_ptr = strchr (value, ':'); - if (char_ptr == NULL) { - fprintf (stderr, "Got an invalid net= attrib [net=%s]\n" - "Missing : in net= attrib\n", value); - g_free (value); - return NULL; - } - - net_name = s_netattrib_extract_netname (value); - - start_of_pinlist = char_ptr + 1; - current_pin = strtok (start_of_pinlist, DELIMITERS); - while (current_pin && !return_value) { - if (strcmp (current_pin, wanted_pin) == 0) { - return_value = net_name; - } - current_pin = strtok (NULL, DELIMITERS); - } + net_name = netname_if_matching_wanted_pin (o_current, value, wanted_pin); g_free (value); - } - - /* now look outside the component */ - for (counter = 0; ;) { - value = o_attrib_search_attached_attribs_by_name (o_current, - "net", counter); - if (value == NULL) - break; - - counter++; - char_ptr = strchr (value, ':'); - if (char_ptr == NULL) { - fprintf (stderr, "Got an invalid net= attrib [net=%s]\n" - "Missing : in net= attrib\n", value); - g_free (value); - return NULL; - } - - net_name = s_netattrib_extract_netname (value); - - start_of_pinlist = char_ptr + 1; - current_pin = strtok (start_of_pinlist, DELIMITERS); - while (current_pin) { - if (strcmp (current_pin, wanted_pin) == 0) { - g_free (return_value); - return net_name; - } - current_pin = strtok (NULL, DELIMITERS); - } - - g_free (value); + if (net_name != NULL) + return net_name; } - return return_value; + return NULL; } char *s_netattrib_return_netname(TOPLEVEL * pr_current, OBJECT * o_current, -- 1.7.4.1
>From 68eeaa6103d851371b1264f24eab10a126fa97ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ko=C5=9Bciuszkiewicz?= <k.kosciuszkiew...@gmail.com> Date: Mon, 11 Apr 2011 23:05:12 +0200 Subject: [PATCH 2/3] gnetlist: make pin number optional in net attribute The colon and pin number can be omitted only if: * The symbol has exactly one pin * The pin number is 1 This change allows the user to omit ":1" from single pin symbols, such as power connectors with editable net name. --- gnetlist/src/s_netattrib.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/gnetlist/src/s_netattrib.c b/gnetlist/src/s_netattrib.c index c8052f9..4c44de5 100644 --- a/gnetlist/src/s_netattrib.c +++ b/gnetlist/src/s_netattrib.c @@ -213,6 +213,24 @@ s_netattrib_handle (TOPLEVEL * pr_current, OBJECT * o_current, } } +static int count_object_pins (OBJECT *o_current) +{ + GList *l; + int count = 0; + + g_return_val_if_fail (o_current, 0); + g_return_val_if_fail (o_current->type == OBJ_COMPLEX, 0); + g_return_val_if_fail (o_current->complex, 0); + + for (l = o_current->complex->prim_objs; l; l = g_list_next (l)) { + OBJECT *o = (OBJECT*) l->data; + if (o && o->type == OBJ_PIN) + count += 1; + } + + return count; +} + static char* netname_if_matching_wanted_pin (OBJECT *o_current, char *net_attr, const char *wanted_pin) @@ -233,6 +251,11 @@ static char* netname_if_matching_wanted_pin (OBJECT *o_current, g_free (net_name); return NULL; + } else if (strcmp (wanted_pin, "1") == 0 + && count_object_pins (o_current) == 1) { + /* no colon, but looking for pin #1 in symbol with only one pin */ + /* this matches the case for single net power symbols */ + return g_strdup (net_attr); } else { fprintf (stderr, "Got an invalid net= attrib [net=%s]\n" "Missing : in net= attrib\n", net_attr); -- 1.7.4.1
>From de28cf1a6e414c94ac7a90bd9635fef88cc1a08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ko=C5=9Bciuszkiewicz?= <k.kosciuszkiew...@gmail.com> Date: Mon, 11 Apr 2011 23:42:05 +0200 Subject: [PATCH 3/3] gnetlist: netattrib testcase covers optional pin number --- gnetlist/tests/netattrib.geda | 2 +- gnetlist/tests/netattrib.sch | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/gnetlist/tests/netattrib.geda b/gnetlist/tests/netattrib.geda index 5910ebd..229a970 100644 --- a/gnetlist/tests/netattrib.geda +++ b/gnetlist/tests/netattrib.geda @@ -22,7 +22,7 @@ END renamed-nets START nets -unnamed_net1 : U300 2 +power : U300 2 netattrib : U200 2, U100 5 GND : U300 7, U200 7, U100 7 Vcc : U300 14, U200 14, U100 14 diff --git a/gnetlist/tests/netattrib.sch b/gnetlist/tests/netattrib.sch index 2c56e7b..658c256 100644 --- a/gnetlist/tests/netattrib.sch +++ b/gnetlist/tests/netattrib.sch @@ -1,46 +1,51 @@ -v 20030901 +v 20110116 2 C 38100 60100 1 0 0 7400-1.sym { -T 38400 61000 5 10 1 1 0 0 +T 38400 61000 5 10 1 1 0 0 1 refdes=U100 -T 39000 60200 5 10 1 1 0 0 +T 39000 60200 5 10 1 1 0 0 1 net=netattrib:5 } C 41000 58800 1 0 0 7404-1.sym { -T 41300 59700 5 10 1 1 0 0 +T 41300 59700 5 10 1 1 0 0 1 refdes=U200 } N 40000 59300 41000 59300 4 { -T 40100 59400 5 10 1 1 0 0 +T 40100 59400 5 10 1 1 0 0 1 netname=two } N 40000 59300 40000 61300 4 N 40000 61300 41200 61300 4 { -T 40200 61400 5 10 1 1 0 0 +T 40200 61400 5 10 1 1 0 0 1 netname=one } C 41200 60800 1 0 0 7404-1.sym { -T 41500 61700 5 10 1 1 0 0 +T 41500 61700 5 10 1 1 0 0 1 refdes=U300 } N 39400 60600 40000 60600 4 N 42100 59300 43300 59300 4 { -T 42500 59400 5 10 1 1 0 0 +T 42500 59400 5 10 1 1 0 0 1 netname=netattrib } N 42300 61300 43000 61300 4 N 38400 58600 39100 58600 4 { -T 38500 58700 5 10 1 1 0 0 +T 38500 58700 5 10 1 1 0 0 1 netname=two } C 39100 58600 1 0 0 fuse-1.sym { -T 39300 58800 5 10 1 1 0 0 +T 39300 58800 5 10 1 1 0 0 1 refdes=F1 } +C 42800 61300 1 0 0 generic-power.sym +{ +T 43000 61550 5 10 1 1 0 3 1 +net=power +} -- 1.7.4.1
_______________________________________________ geda-user mailing list geda-user@moria.seul.org http://www.seul.org/cgi-bin/mailman/listinfo/geda-user