Updated po files using make update-po
[geda-gaf/peter-b.git] / libgeda / src / s_undo.c
blob0af0f5027f6b246353c1f89fc2da36be85b831c7
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 #ifdef HAVE_STDLIB_H
25 #include <stdlib.h>
26 #endif
27 #ifdef HAVE_ASSERT_H
28 #include <assert.h>
29 #endif
30 #ifdef HAVE_UNISTD_H
31 #include <unistd.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 "colors.h"
42 #include "o_types.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 UNDO *s_undo_return_tail(UNDO *head)
57 UNDO *u_current=NULL;
58 UNDO *ret_struct=NULL;
60 u_current = head;
61 while ( u_current != NULL ) { /* goto end of list */
62 ret_struct = u_current;
63 u_current = u_current->next;
66 return(ret_struct);
69 /*! \todo Finish function documentation!!!
70 * \brief
71 * \par Function Description
74 UNDO *s_undo_return_head(UNDO *tail)
76 UNDO *u_current=NULL;
77 UNDO *ret_struct=NULL;
79 u_current = tail;
80 while ( u_current != NULL ) { /* goto end of list */
81 ret_struct = u_current;
82 u_current = u_current->prev;
85 return(ret_struct);
88 /*! \todo Finish function documentation!!!
89 * \brief
90 * \par Function Description
93 UNDO *s_undo_new_head(void)
95 UNDO *u_new;
97 u_new = (UNDO *) g_malloc(sizeof(UNDO));
98 u_new->type = -1;
99 u_new->filename = NULL;
100 u_new->object_head = NULL;
101 u_new->left = u_new->right = u_new->top = u_new->bottom = -1;
103 u_new->page_control = 0;
104 u_new->up = -2;
106 u_new->prev = NULL;
107 u_new->next = NULL;
109 return(u_new);
112 /*! \todo Finish function documentation!!!
113 * \brief
114 * \par Function Description
117 void s_undo_destroy_head(UNDO *u_head)
119 g_free(u_head);
122 /*! \todo Finish function documentation!!!
123 * \brief
124 * \par Function Description
127 UNDO *s_undo_add(UNDO *head, int type, char *filename, OBJECT *object_head,
128 int left, int top, int right, int bottom, int page_control,
129 int up)
131 UNDO *tail;
132 UNDO *u_new;
134 u_new = (UNDO *) g_malloc(sizeof(UNDO));
136 u_new->filename = g_strdup (filename);
138 if (object_head != NULL) {
139 u_new->object_head = object_head;
140 } else {
141 u_new->object_head = NULL;
144 u_new->type = type;
146 u_new->left = left;
147 u_new->top = top;
148 u_new->right = right;
149 u_new->bottom = bottom;
151 u_new->page_control = page_control;
152 u_new->up = up;
154 if (head == NULL) {
155 u_new->prev = NULL; /* setup previous link */
156 u_new->next = NULL;
157 return(u_new);
158 } else {
159 tail = s_undo_return_tail(head);
160 u_new->prev = tail; /* setup previous link */
161 u_new->next = NULL;
162 tail->next = u_new;
163 return(tail->next);
167 /*! \todo Finish function documentation!!!
168 * \brief
169 * \par Function Description
172 void s_undo_print_all( UNDO *head )
174 UNDO *u_current;
176 u_current = head;
178 printf("START printing undo ********************\n");
179 printf("BOTTOM\n");
180 while(u_current != NULL) {
182 if (u_current->filename) printf("%s\n", u_current->filename);
184 if (u_current->object_head) {
185 printf("%s\n", u_current->object_head->name);
186 print_struct_forw(u_current->object_head);
189 printf("\t%d %d %d %d\n", u_current->left, u_current->top,
190 u_current->right, u_current->bottom);
191 u_current = u_current->next;
193 printf("TOS\n");
194 printf("Number of levels: %d\n", s_undo_levels(head));
195 printf("DONE printing undo ********************\n");
196 printf("\n");
200 /*! \todo Finish function documentation!!!
201 * \brief
202 * \par Function Description
205 void s_undo_destroy_all(TOPLEVEL *w_current, UNDO *head)
207 UNDO *u_current;
208 UNDO *u_prev;
210 u_current = s_undo_return_tail(head);
212 while (u_current != NULL) {
213 u_prev = u_current->prev;
214 if (u_current->filename) g_free(u_current->filename);
216 if (u_current->object_head) {
217 w_current->REMOVING_SEL = 1;
218 s_delete_list_fromstart(w_current,
219 u_current->object_head);
220 w_current->REMOVING_SEL = 0;
221 u_current->object_head = NULL;
224 g_free(u_current);
225 u_current = u_prev;
229 /*! \todo Finish function documentation!!!
230 * \brief
231 * \par Function Description
234 void s_undo_remove(TOPLEVEL *w_current, UNDO *head, UNDO *u_tos)
236 UNDO *u_current;
238 if (u_tos == NULL) {
239 fprintf(stderr, "Got NULL for u_tos in s_undo_remove\n");
240 return;
243 u_current = head;
245 while (u_current != NULL) {
246 if (u_current == u_tos) {
247 if (u_current->next)
248 u_current->next->prev = u_current->prev;
249 else
250 u_current->next = NULL;
252 if (u_current->prev)
253 u_current->prev->next = u_current->next;
254 else
255 u_current->prev = NULL;
257 if (u_current->filename) {
258 g_free(u_current->filename);
261 if (u_current->object_head) {
262 /*w_current->REMOVING_SEL = 1; */
263 s_delete_list_fromstart(w_current,
264 u_current->object_head);
265 /*w_current->REMOVING_SEL = 0;*/
266 u_current->object_head = NULL;
269 g_free(u_current);
270 return;
272 u_current = u_current->next;
276 /*! \todo Finish function documentation!!!
277 * \brief
278 * \par Function Description
281 void s_undo_remove_rest(TOPLEVEL *w_current, UNDO *head)
283 UNDO *u_current;
284 UNDO *u_next;
286 u_current = head;
288 while (u_current != NULL) {
289 u_next = u_current->next;
291 if (u_current->filename) {
292 unlink(u_current->filename);
293 g_free(u_current->filename);
296 if (u_current->object_head) {
297 w_current->REMOVING_SEL = 1;
298 s_delete_list_fromstart(w_current,
299 u_current->object_head);
300 w_current->REMOVING_SEL = 0;
301 u_current->object_head = NULL;
304 g_free(u_current);
305 u_current = u_next;
309 /*! \todo Finish function documentation!!!
310 * \brief
311 * \par Function Description
314 int s_undo_levels(UNDO *head)
316 UNDO *u_current;
317 int count = 0;
319 u_current = head;
320 while (u_current != NULL) {
321 if (u_current->filename || u_current->object_head) {
322 count++;
325 u_current = u_current->next;
328 return(count);
331 /*! \todo Finish function documentation!!!
332 * \brief
333 * \par Function Description
336 void s_undo_init(PAGE *p_current)
338 p_current->undo_tos = p_current->undo_bottom = NULL;
339 p_current->undo_current = NULL;
342 /*! \todo Finish function documentation!!!
343 * \brief
344 * \par Function Description
347 void s_undo_free_all(TOPLEVEL *w_current, PAGE *p_current)
349 s_undo_destroy_all(w_current, p_current->undo_bottom);
350 p_current->undo_bottom = NULL;
351 p_current->undo_tos = NULL;
352 p_current->undo_current = NULL;