Move o_redraw_single() from libgeda to gschem
[geda-gaf/peter-b.git] / libgeda / src / s_stretch.c
blob2e781acbf44fcadf21db31abf615460825c85776
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
27 #if HAVE_ASSERT_H
28 #include <assert.h>
29 #endif
30 #ifndef HAVE_VSNPRINTF
31 #include <stdarg.h>
32 #endif
34 #include <gtk/gtk.h>
35 #include <libguile.h>
37 #include "defines.h"
38 #include "struct.h"
39 #include "defines.h"
40 #include "globals.h"
41 #include "o_types.h"
42 #include "colors.h"
44 #include "../include/prototype.h"
46 #ifdef HAVE_LIBDMALLOC
47 #include <dmalloc.h>
48 #endif
50 /*! \todo Finish function documentation!!!
51 * \brief
52 * \par Function Description
55 STRETCH *s_stretch_return_tail(STRETCH *head)
57 STRETCH *s_current=NULL;
58 STRETCH *ret_struct=NULL;
60 s_current = head;
61 while ( s_current != NULL ) { /* goto end of list */
62 ret_struct = s_current;
63 s_current = s_current->next;
66 return(ret_struct);
69 /*! \todo Finish function documentation!!!
70 * \brief
71 * \par Function Description
74 STRETCH *s_stretch_return_head(STRETCH *tail)
76 STRETCH *s_current=NULL;
77 STRETCH *ret_struct=NULL;
79 s_current = tail;
80 while ( s_current != NULL ) { /* goto end of list */
81 ret_struct = s_current;
82 s_current = s_current->prev;
85 return(ret_struct);
88 /*! \todo Finish function documentation!!!
89 * \brief
90 * \par Function Description
93 STRETCH *s_stretch_new_head(void)
95 STRETCH *s_new;
97 s_new = (STRETCH *) g_malloc(sizeof(STRETCH));
99 s_new->object = NULL;
100 s_new->connection = NULL;
101 s_new->whichone = -1;
103 s_new->prev = NULL;
104 s_new->next = NULL;
106 return(s_new);
109 /*! \todo Finish function documentation!!!
110 * \brief
111 * \par Function Description
114 void s_stretch_destroy_head(STRETCH *s_head)
116 g_free(s_head);
119 /*! \todo Finish function documentation!!!
120 * \brief
121 * \par Function Description
124 /*! \todo also does the needed work to make the object visually selected */
125 STRETCH *s_stretch_add(STRETCH *head, OBJECT *object,
126 CONN *connection, int whichone)
128 STRETCH *tail;
129 STRETCH *s_new;
130 STRETCH *s_current;
132 s_current = head;
133 while (s_current != NULL) {
134 if (s_current->object) {
135 /*printf("%d %d\n", s_current->object->sid, object->sid);*/
136 if (s_current->object->sid == object->sid) {
137 /* printf("already inside\n");*/
138 return(s_stretch_return_tail(head));
142 s_current = s_current->next;
144 /*printf("Adding: %s\n", object->name);*/
146 s_new = (STRETCH *) g_malloc(sizeof(STRETCH));
147 s_new->object = object;
148 s_new->connection = connection;
149 s_new->whichone = whichone;
151 if (head == NULL) {
152 s_new->prev = NULL; /* setup previous link */
153 s_new->next = NULL;
154 return(s_new);
155 } else {
156 tail = s_stretch_return_tail(head);
157 s_new->prev = tail; /* setup previous link */
158 s_new->next = NULL;
159 tail->next = s_new;
160 return(tail->next);
164 /*! \todo Finish function documentation!!!
165 * \brief
166 * \par Function Description
169 /*! \note
170 * it's okay to call this with an o_selected which is not necessarily
171 * selected
173 void s_stretch_remove(STRETCH *head, OBJECT *object)
175 STRETCH *s_current;
177 if (object == NULL) {
178 fprintf(stderr, "Got NULL for s_stretch in s_stretch_remove\n");
179 return;
182 s_current = head;
184 while (s_current != NULL) {
185 if (s_current->object == object) {
186 if (s_current->next)
187 s_current->next->prev = s_current->prev;
188 else
189 s_current->next = NULL;
191 if (s_current->prev)
192 s_current->prev->next = s_current->next;
193 else
194 s_current->prev = NULL;
196 s_current->object = NULL;
197 s_current->connection = NULL;
198 s_current->whichone = -1;
200 g_free(s_current);
201 return;
203 s_current = s_current->next;
207 /*! \todo Finish function documentation!!!
208 * \brief
209 * \par Function Description
212 /*! \note removes all but the head node */
213 void s_stretch_remove_most(TOPLEVEL *toplevel, STRETCH *head)
215 STRETCH *s_current;
216 STRETCH *s_prev;
218 s_current = s_stretch_return_tail(head);
220 while (s_current != NULL) {
221 if (s_current->object != NULL) {
222 s_prev = s_current->prev;
224 s_current->object = NULL;
225 s_current->connection = NULL;
226 s_current->whichone = -1;
228 g_free(s_current);
229 s_current = s_prev;
230 } else {
231 break;
235 /* clear out any dangling pointers */
236 head->next=NULL;
239 /*! \todo Finish function documentation!!!
240 * \brief
241 * \par Function Description
244 void s_stretch_print_all( STRETCH *head )
246 STRETCH *s_current;
248 s_current = head;
250 printf("START printing stretch ********************\n");
251 while(s_current != NULL) {
252 if (s_current->object) {
253 printf("Object: %s\n", s_current->object->name);
254 } else {
255 printf("Object is NULL\n");
258 if (s_current->object) {
259 printf("Connection type: %d\n", s_current->connection->type);
260 } else {
261 printf("Connection is NULL\n");
264 printf("which one: %d\n", s_current->whichone);
266 s_current = s_current->next;
268 printf("DONE printing stretch ********************\n");
269 printf("\n");
273 /*! \todo Finish function documentation!!!
274 * \brief
275 * \par Function Description
278 void s_stretch_destroy_all(STRETCH *head)
280 STRETCH *s_current;
281 STRETCH *s_prev;
283 s_current = s_stretch_return_tail(head);
285 while (s_current != NULL) {
286 s_prev = s_current->prev;
288 s_current->object = NULL;
289 s_current->connection = NULL;
290 s_current->whichone = -1;
292 g_free(s_current);
293 s_current = s_prev;