Index: trunk/src/netlist.c =================================================================== --- trunk/src/netlist.c (revision 19823) +++ trunk/src/netlist.c (revision 19824) @@ -323,3 +323,29 @@ memset(Net, 0, sizeof(pcb_net_t)); } } + +pcb_lib_menu_t *pcb_netlist_lookup(int patch, const char *netname, pcb_bool alloc) +{ + pcb_lib_t *netlist = patch ? &PCB->NetlistLib[PCB_NETLIST_EDITED] : &PCB->NetlistLib[PCB_NETLIST_INPUT]; + long ni; + + if ((netname == NULL) || (*netname == '\0')) + return NULL; + + for (ni = 0; ni < netlist->MenuN; ni++) + if (strcmp(netlist->Menu[ni].Name + 2, netname) == 0) + return &(netlist->Menu[ni]); + + if (!alloc) + return NULL; + + if (!patch) { + pcb_lib_menu_t *net = pcb_lib_menu_new(netlist, NULL); + net->Name = pcb_strdup_printf(" %s", netname); + net->flag = 1; + PCB->netlist_needs_update=1; + return net; + } + + return pcb_lib_net_new(netlist, (char *)netname, NULL); +} Index: trunk/src/netlist.h =================================================================== --- trunk/src/netlist.h (revision 19823) +++ trunk/src/netlist.h (revision 19824) @@ -57,6 +57,12 @@ void pcb_netlist_changed(int force_unfreeze); + + +/* Look up a net by name; if not found and alloc is true, create it, else + return NULL */ +pcb_lib_menu_t *pcb_netlist_lookup(int patch, const char *netname, pcb_bool alloc); + pcb_lib_menu_t *pcb_netnode_to_netname(const char *nodename); pcb_lib_menu_t *pcb_netname_to_netname(const char *netname); Index: trunk/src/netlist_act.c =================================================================== --- trunk/src/netlist_act.c (revision 19823) +++ trunk/src/netlist_act.c (revision 19824) @@ -112,13 +112,11 @@ return ret; } - /* The primary purpose of this action is to rebuild a netlist from a script, in conjunction with the clear action above. */ static int pcb_netlist_add(int patch, const char *netname, const char *pinname) { - int ni, pi; - pcb_lib_t *netlist = patch ? &PCB->NetlistLib[PCB_NETLIST_EDITED] : &PCB->NetlistLib[PCB_NETLIST_INPUT]; + int pi; pcb_lib_menu_t *net = NULL; pcb_lib_entry_t *pin = NULL; @@ -128,25 +126,8 @@ if ((*netname == '\0') || (*pinname == '\0')) return -1; - for (ni = 0; ni < netlist->MenuN; ni++) { - if (strcmp(netlist->Menu[ni].Name + 2, netname) == 0) { - net = &(netlist->Menu[ni]); - break; - } - } + net = pcb_netlist_lookup(patch, netname, pcb_true); - - if (net == NULL) { - if (!patch) { - net = pcb_lib_menu_new(netlist, NULL); - net->Name = pcb_strdup_printf(" %s", netname); - net->flag = 1; - PCB->netlist_needs_update=1; - } - else - net = pcb_lib_net_new(netlist, (char *) netname, NULL); - } - for (pi = 0; pi < net->EntryN; pi++) { if (strcmp(net->Entry[pi].ListEntry, pinname) == 0) { pin = &(net->Entry[pi]);