Fix o_net_consolidate_segments() to consolidate with all joined lines
[geda-gaf/pcjc2.git] / gnetlist / src / s_cpinlist.c
blob734d8ce294df21ced34a56c8dbec1281719a88bd
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>
27 #endif
28 #ifdef HAVE_ASSERT_H
29 #include <assert.h>
30 #endif
31 #ifdef HAVE_STRING_H
32 #include <string.h>
33 #endif
35 #include <libgeda/libgeda.h>
37 #include "../include/globals.h"
38 #include "../include/prototype.h"
40 #ifdef HAVE_LIBDMALLOC
41 #include <dmalloc.h>
42 #endif
44 /* hack rename this to be s_return_tail */
45 /* update object_tail or any list of that matter */
46 CPINLIST *s_cpinlist_return_tail(CPINLIST * head)
48 CPINLIST *pl_current = NULL;
49 CPINLIST *ret_struct = NULL;
51 pl_current = head;
52 while (pl_current != NULL) { /* goto end of list */
53 ret_struct = pl_current;
54 pl_current = pl_current->next;
57 return (ret_struct);
60 /* hack rename this to be s_return_head */
61 /* update object_tail or any list of that matter */
62 CPINLIST *s_cpinlist_return_head(CPINLIST * tail)
64 CPINLIST *pl_current = NULL;
65 CPINLIST *ret_struct = NULL;
67 pl_current = tail;
68 while (pl_current != NULL) { /* goto end of list */
69 ret_struct = pl_current;
70 pl_current = pl_current->prev;
73 return (ret_struct);
77 /* returns new node */
78 CPINLIST *s_cpinlist_add(CPINLIST * ptr)
80 CPINLIST *new_node;
82 new_node = (CPINLIST *) g_malloc(sizeof(CPINLIST));
84 /* setup node information */
85 new_node->plid = 0;
86 new_node->type = PIN_TYPE_NET;
87 new_node->pin_number = NULL;
88 new_node->pin_label = NULL;
89 new_node->net_name = NULL;
90 new_node->nets = NULL;
92 /* Setup link list stuff */
93 new_node->next = NULL;
95 if (ptr == NULL) {
96 new_node->prev = NULL; /* setup previous link */
97 return (new_node);
98 } else {
99 new_node->prev = ptr; /* setup previous link */
100 ptr->next = new_node;
101 return (ptr->next);
105 void s_cpinlist_print(CPINLIST * ptr)
107 CPINLIST *pl_current = NULL;
109 pl_current = ptr;
111 if (pl_current == NULL) {
112 return;
115 while (pl_current != NULL) {
117 if (pl_current->plid != -1) {
118 if (pl_current->pin_number) {
119 printf(" pin %s", pl_current->pin_number);
120 } else {
121 printf(" pin ?");
124 if (pl_current->pin_label) {
125 printf(" (%s)", pl_current->pin_label);
126 } else {
127 printf(" ()");
130 if (pl_current->net_name) {
131 printf(" %s", pl_current->net_name);
132 } else {
133 printf(" Null net name");
137 printf("\n");
140 if (pl_current->nets) {
141 s_net_print(pl_current->nets);
145 pl_current = pl_current->next;
149 CPINLIST *s_cpinlist_search_pin(CPINLIST * ptr, char *pin_number)
151 CPINLIST *pl_current = NULL;
153 pl_current = ptr;
155 if (pl_current == NULL) {
156 return (NULL);
159 while (pl_current != NULL) {
161 if (pl_current->plid != -1 && (pl_current->pin_number != NULL)) {
163 if (strcmp(pl_current->pin_number, pin_number) == 0) {
165 #if DEBUG
166 printf("equal: %s %s\n",
167 pl_current->pin_number, pin_number);
168 #endif
170 return (pl_current);
174 pl_current = pl_current->next;
177 return (NULL);