Print the desired object's description.
[geda-gaf/berndj.git] / libgeda / src / s_stretch.c
blobc69e822f18b55bbff371de8b88529231bd4fc4b0
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #if HAVE_STDLIB_H
25 #include <stdlib.h>
26 #endif
28 #include "libgeda_priv.h"
30 #ifdef HAVE_LIBDMALLOC
31 #include <dmalloc.h>
32 #endif
34 /*! \todo Finish function documentation!!!
35 * \brief
36 * \par Function Description
39 STRETCH *s_stretch_return_tail(STRETCH *head)
41 STRETCH *s_current=NULL;
42 STRETCH *ret_struct=NULL;
44 s_current = head;
45 while ( s_current != NULL ) { /* goto end of list */
46 ret_struct = s_current;
47 s_current = s_current->next;
50 return(ret_struct);
53 /*! \todo Finish function documentation!!!
54 * \brief
55 * \par Function Description
58 STRETCH *s_stretch_new_head(void)
60 STRETCH *s_new;
62 s_new = (STRETCH *) g_malloc(sizeof(STRETCH));
64 s_new->object = NULL;
65 s_new->connection = NULL;
66 s_new->whichone = -1;
68 s_new->prev = NULL;
69 s_new->next = NULL;
71 return(s_new);
74 /*! \todo Finish function documentation!!!
75 * \brief
76 * \par Function Description
79 /*! \todo also does the needed work to make the object visually selected */
80 STRETCH *s_stretch_add(STRETCH *head, OBJECT *object,
81 CONN *connection, int whichone)
83 STRETCH *tail;
84 STRETCH *s_new;
85 STRETCH *s_current;
87 s_current = head;
88 while (s_current != NULL) {
89 if (s_current->object) {
90 /*printf("%d %d\n", s_current->object->sid, object->sid);*/
91 if (s_current->object->sid == object->sid) {
92 /* printf("already inside\n");*/
93 return(s_stretch_return_tail(head));
97 s_current = s_current->next;
99 /*printf("Adding: %s\n", object->name);*/
101 s_new = (STRETCH *) g_malloc(sizeof(STRETCH));
102 s_new->object = object;
103 s_new->connection = connection;
104 s_new->whichone = whichone;
106 if (head == NULL) {
107 s_new->prev = NULL; /* setup previous link */
108 s_new->next = NULL;
109 return(s_new);
110 } else {
111 tail = s_stretch_return_tail(head);
112 s_new->prev = tail; /* setup previous link */
113 s_new->next = NULL;
114 tail->next = s_new;
115 return(tail->next);
119 /*! \todo Finish function documentation!!!
120 * \brief
121 * \par Function Description
124 /*! \note
125 * it's okay to call this with an o_selected which is not necessarily
126 * selected
128 void s_stretch_remove(STRETCH *head, OBJECT *object)
130 STRETCH *s_current;
132 if (object == NULL) {
133 fprintf(stderr, "Got NULL for s_stretch in s_stretch_remove\n");
134 return;
137 s_current = head;
139 while (s_current != NULL) {
140 if (s_current->object == object) {
141 if (s_current->next)
142 s_current->next->prev = s_current->prev;
143 else
144 s_current->next = NULL;
146 if (s_current->prev)
147 s_current->prev->next = s_current->next;
148 else
149 s_current->prev = NULL;
151 s_current->object = NULL;
152 s_current->connection = NULL;
153 s_current->whichone = -1;
155 g_free(s_current);
156 return;
158 s_current = s_current->next;
162 /*! \todo Finish function documentation!!!
163 * \brief
164 * \par Function Description
167 /*! \note removes all but the head node */
168 void s_stretch_remove_most(STRETCH *head)
170 STRETCH *s_current;
171 STRETCH *s_prev;
173 s_current = s_stretch_return_tail(head);
175 while (s_current != NULL) {
176 if (s_current->object != NULL) {
177 s_prev = s_current->prev;
179 s_current->object = NULL;
180 s_current->connection = NULL;
181 s_current->whichone = -1;
183 g_free(s_current);
184 s_current = s_prev;
185 } else {
186 break;
190 /* clear out any dangling pointers */
191 head->next=NULL;
194 /*! \todo Finish function documentation!!!
195 * \brief
196 * \par Function Description
199 void s_stretch_print_all(STRETCH const *head)
201 STRETCH const *s_current;
203 s_current = head;
205 printf("START printing stretch ********************\n");
206 while(s_current != NULL) {
207 if (s_current->object) {
208 printf("Object: %s\n", s_current->object->name);
209 } else {
210 printf("Object is NULL\n");
213 if (s_current->object) {
214 printf("Connection type: %d\n", s_current->connection->type);
215 } else {
216 printf("Connection is NULL\n");
219 printf("which one: %d\n", s_current->whichone);
221 s_current = s_current->next;
223 printf("DONE printing stretch ********************\n");
224 printf("\n");
228 /*! \todo Finish function documentation!!!
229 * \brief
230 * \par Function Description
233 void s_stretch_destroy_all(STRETCH *head)
235 STRETCH *s_current;
236 STRETCH *s_prev;
238 s_current = s_stretch_return_tail(head);
240 while (s_current != NULL) {
241 s_prev = s_current->prev;
243 s_current->object = NULL;
244 s_current->connection = NULL;
245 s_current->whichone = -1;
247 g_free(s_current);
248 s_current = s_prev;