Bump gEDA version
[geda-gaf.git] / libgeda / src / s_undo.c
blob9deca327a243788cc7c2343cfffab93c2d3a1c86
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 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
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_UNISTD_H
28 #include <unistd.h>
29 #endif
31 #include "libgeda_priv.h"
33 /*! \todo Finish function documentation!!!
34 * \brief
35 * \par Function Description
38 UNDO *s_undo_return_tail(UNDO *head)
40 UNDO *u_current=NULL;
41 UNDO *ret_struct=NULL;
43 u_current = head;
44 while ( u_current != NULL ) { /* goto end of list */
45 ret_struct = u_current;
46 u_current = u_current->next;
49 return(ret_struct);
52 /*! \todo Finish function documentation!!!
53 * \brief
54 * \par Function Description
57 UNDO *s_undo_return_head(UNDO *tail)
59 UNDO *u_current=NULL;
60 UNDO *ret_struct=NULL;
62 u_current = tail;
63 while ( u_current != NULL ) { /* goto end of list */
64 ret_struct = u_current;
65 u_current = u_current->prev;
68 return(ret_struct);
71 /*! \todo Finish function documentation!!!
72 * \brief
73 * \par Function Description
76 UNDO *s_undo_new_head(void)
78 UNDO *u_new;
80 u_new = (UNDO *) g_malloc(sizeof(UNDO));
81 u_new->type = -1;
82 u_new->filename = NULL;
83 u_new->object_list = NULL;
84 u_new->x = u_new->y = 0;
85 u_new->scale = 0;
87 u_new->page_control = 0;
88 u_new->up = -2;
89 u_new->CHANGED = 0;
91 u_new->desc = NULL;
92 u_new->tx = 0;
93 u_new->ty = 0;
95 u_new->prev = NULL;
96 u_new->next = NULL;
98 return(u_new);
101 /*! \todo Finish function documentation!!!
102 * \brief
103 * \par Function Description
106 void s_undo_destroy_head(UNDO *u_head)
108 g_free(u_head);
111 /*! \todo Finish function documentation!!!
112 * \brief
113 * \par Function Description
116 UNDO *s_undo_add (UNDO *head, int type, char *filename, GList *object_list,
117 int x, int y, double scale, int page_control, int up,
118 int CHANGED, const char *desc)
120 UNDO *tail;
121 UNDO *u_new;
123 u_new = (UNDO *) g_malloc(sizeof(UNDO));
125 u_new->filename = g_strdup (filename);
127 u_new->object_list = object_list;
129 u_new->type = type;
131 u_new->x = x;
132 u_new->y = y;
133 u_new->scale = scale;
135 u_new->page_control = page_control;
136 u_new->up = up;
137 u_new->CHANGED = CHANGED;
139 u_new->desc = desc;
140 u_new->tx = 0;
141 u_new->ty = 0;
143 if (head == NULL) {
144 u_new->prev = NULL; /* setup previous link */
145 u_new->next = NULL;
146 return(u_new);
147 } else {
148 tail = s_undo_return_tail(head);
149 u_new->prev = tail; /* setup previous link */
150 u_new->next = NULL;
151 tail->next = u_new;
152 return(tail->next);
156 /*! \todo Finish function documentation!!!
157 * \brief
158 * \par Function Description
161 void s_undo_print_all( UNDO *head )
163 UNDO *u_current;
165 u_current = head;
167 printf("START printing undo ********************\n");
168 printf("BOTTOM\n");
169 while(u_current != NULL) {
171 if (u_current->filename) printf("%s\n", u_current->filename);
173 if (u_current->object_list) {
174 print_struct_forw (u_current->object_list);
177 printf("\t%d %d %f\n", u_current->x, u_current->y, u_current->scale);
178 u_current = u_current->next;
180 printf("TOS\n");
181 printf("Number of levels: %d\n", s_undo_levels(head));
182 printf("DONE printing undo ********************\n");
183 printf("\n");
187 /*! \todo Finish function documentation!!!
188 * \brief
189 * \par Function Description
192 void s_undo_destroy_all(TOPLEVEL *toplevel, UNDO *head)
194 UNDO *u_current;
195 UNDO *u_prev;
197 u_current = s_undo_return_tail(head);
199 while (u_current != NULL) {
200 u_prev = u_current->prev;
201 g_free(u_current->filename);
203 if (u_current->object_list) {
204 s_delete_object_glist (toplevel, u_current->object_list);
205 u_current->object_list = NULL;
208 g_free(u_current);
209 u_current = u_prev;
213 /*! \todo Finish function documentation!!!
214 * \brief
215 * \par Function Description
218 void s_undo_remove(TOPLEVEL *toplevel, UNDO *head, UNDO *u_tos)
220 UNDO *u_current;
222 if (u_tos == NULL) {
223 fprintf(stderr, "Got NULL for u_tos in s_undo_remove\n");
224 return;
227 u_current = head;
229 while (u_current != NULL) {
230 if (u_current == u_tos) {
231 if (u_current->next)
232 u_current->next->prev = u_current->prev;
233 else
234 u_current->next = NULL;
236 if (u_current->prev)
237 u_current->prev->next = u_current->next;
238 else
239 u_current->prev = NULL;
241 g_free(u_current->filename);
243 if (u_current->object_list) {
244 s_delete_object_glist (toplevel, u_current->object_list);
245 u_current->object_list = NULL;
248 g_free(u_current);
249 return;
251 u_current = u_current->next;
255 /*! \todo Finish function documentation!!!
256 * \brief
257 * \par Function Description
260 void s_undo_remove_rest(TOPLEVEL *toplevel, UNDO *head)
262 UNDO *u_current;
263 UNDO *u_next;
265 u_current = head;
267 while (u_current != NULL) {
268 u_next = u_current->next;
270 if (u_current->filename) {
271 unlink(u_current->filename);
272 g_free(u_current->filename);
275 if (u_current->object_list) {
276 s_delete_object_glist (toplevel, u_current->object_list);
277 u_current->object_list = NULL;
280 g_free(u_current);
281 u_current = u_next;
285 /*! \todo Finish function documentation!!!
286 * \brief
287 * \par Function Description
290 int s_undo_levels(UNDO *head)
292 UNDO *u_current;
293 int count = 0;
295 u_current = head;
296 while (u_current != NULL) {
297 if (u_current->filename || u_current->object_list) {
298 count++;
301 u_current = u_current->next;
304 return(count);
307 /*! \todo Finish function documentation!!!
308 * \brief
309 * \par Function Description
312 void s_undo_init(PAGE *p_current)
314 p_current->undo_tos = p_current->undo_bottom = NULL;
315 p_current->undo_current = NULL;
318 /*! \todo Finish function documentation!!!
319 * \brief
320 * \par Function Description
323 void s_undo_free_all(TOPLEVEL *toplevel, PAGE *p_current)
325 s_undo_destroy_all(toplevel, p_current->undo_bottom);
326 p_current->undo_bottom = NULL;
327 p_current->undo_tos = NULL;
328 p_current->undo_current = NULL;