gschem: Fix `may be used uninitialized' warning
[geda-gaf.git] / gnetlist-legacy / src / s_cpinlist.c
bloba143f8647a69aa4cff14b31a001136738edbcdee
1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2019 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 /* hack rename this to be s_return_tail */
41 /* update object_tail or any list of that matter */
42 CPINLIST *s_cpinlist_return_tail(CPINLIST * head)
44 CPINLIST *pl_current = NULL;
45 CPINLIST *ret_struct = NULL;
47 pl_current = head;
48 while (pl_current != NULL) { /* goto end of list */
49 ret_struct = pl_current;
50 pl_current = pl_current->next;
53 return (ret_struct);
56 /* hack rename this to be s_return_head */
57 /* update object_tail or any list of that matter */
58 CPINLIST *s_cpinlist_return_head(CPINLIST * tail)
60 CPINLIST *pl_current = NULL;
61 CPINLIST *ret_struct = NULL;
63 pl_current = tail;
64 while (pl_current != NULL) { /* goto end of list */
65 ret_struct = pl_current;
66 pl_current = pl_current->prev;
69 return (ret_struct);
73 /* returns new node */
74 CPINLIST *s_cpinlist_add(CPINLIST * ptr)
76 CPINLIST *new_node;
78 new_node = (CPINLIST *) g_malloc(sizeof(CPINLIST));
80 /* setup node information */
81 new_node->plid = 0;
82 new_node->type = PIN_TYPE_NET;
83 new_node->pin_number = NULL;
84 new_node->pin_label = NULL;
85 new_node->net_name = NULL;
86 new_node->nets = NULL;
88 /* Setup link list stuff */
89 new_node->next = NULL;
91 if (ptr == NULL) {
92 new_node->prev = NULL; /* setup previous link */
93 return (new_node);
94 } else {
95 new_node->prev = ptr; /* setup previous link */
96 ptr->next = new_node;
97 return (ptr->next);
101 void s_cpinlist_print(CPINLIST * ptr)
103 CPINLIST *pl_current = NULL;
105 pl_current = ptr;
107 if (pl_current == NULL) {
108 return;
111 while (pl_current != NULL) {
113 if (pl_current->plid != -1) {
114 if (pl_current->pin_number) {
115 printf(" pin %s", pl_current->pin_number);
116 } else {
117 printf(" pin ?");
120 if (pl_current->pin_label) {
121 printf(" (%s)", pl_current->pin_label);
122 } else {
123 printf(" ()");
126 if (pl_current->net_name) {
127 printf(" %s", pl_current->net_name);
128 } else {
129 printf(" Null net name");
133 printf("\n");
136 if (pl_current->nets) {
137 s_net_print(pl_current->nets);
141 pl_current = pl_current->next;
145 CPINLIST *s_cpinlist_search_pin(CPINLIST * ptr, char *pin_number)
147 CPINLIST *pl_current = NULL;
149 pl_current = ptr;
151 if (pl_current == NULL) {
152 return (NULL);
155 while (pl_current != NULL) {
157 if (pl_current->plid != -1 && (pl_current->pin_number != NULL)) {
159 if (strcmp(pl_current->pin_number, pin_number) == 0) {
161 #if DEBUG
162 printf("equal: %s %s\n",
163 pl_current->pin_number, pin_number);
164 #endif
166 return (pl_current);
170 pl_current = pl_current->next;
173 return (NULL);