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
31 #include "libgeda_priv.h"
33 /*! \todo Finish function documentation!!!
35 * \par Function Description
38 UNDO
*s_undo_return_tail(UNDO
*head
)
41 UNDO
*ret_struct
=NULL
;
44 while ( u_current
!= NULL
) { /* goto end of list */
45 ret_struct
= u_current
;
46 u_current
= u_current
->next
;
52 /*! \todo Finish function documentation!!!
54 * \par Function Description
57 UNDO
*s_undo_return_head(UNDO
*tail
)
60 UNDO
*ret_struct
=NULL
;
63 while ( u_current
!= NULL
) { /* goto end of list */
64 ret_struct
= u_current
;
65 u_current
= u_current
->prev
;
71 /*! \todo Finish function documentation!!!
73 * \par Function Description
76 UNDO
*s_undo_new_head(void)
80 u_new
= (UNDO
*) g_malloc(sizeof(UNDO
));
82 u_new
->filename
= NULL
;
83 u_new
->object_list
= NULL
;
84 u_new
->x
= u_new
->y
= 0;
87 u_new
->page_control
= 0;
101 /*! \todo Finish function documentation!!!
103 * \par Function Description
106 void s_undo_destroy_head(UNDO
*u_head
)
111 /*! \todo Finish function documentation!!!
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
)
123 u_new
= (UNDO
*) g_malloc(sizeof(UNDO
));
125 u_new
->filename
= g_strdup (filename
);
127 u_new
->object_list
= object_list
;
133 u_new
->scale
= scale
;
135 u_new
->page_control
= page_control
;
137 u_new
->CHANGED
= CHANGED
;
144 u_new
->prev
= NULL
; /* setup previous link */
148 tail
= s_undo_return_tail(head
);
149 u_new
->prev
= tail
; /* setup previous link */
156 /*! \todo Finish function documentation!!!
158 * \par Function Description
161 void s_undo_print_all( UNDO
*head
)
167 printf("START printing undo ********************\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
;
181 printf("Number of levels: %d\n", s_undo_levels(head
));
182 printf("DONE printing undo ********************\n");
187 /*! \todo Finish function documentation!!!
189 * \par Function Description
192 void s_undo_destroy_all(TOPLEVEL
*toplevel
, UNDO
*head
)
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
;
213 /*! \todo Finish function documentation!!!
215 * \par Function Description
218 void s_undo_remove(TOPLEVEL
*toplevel
, UNDO
*head
, UNDO
*u_tos
)
223 fprintf(stderr
, "Got NULL for u_tos in s_undo_remove\n");
229 while (u_current
!= NULL
) {
230 if (u_current
== u_tos
) {
232 u_current
->next
->prev
= u_current
->prev
;
234 u_current
->next
= NULL
;
237 u_current
->prev
->next
= u_current
->next
;
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
;
251 u_current
= u_current
->next
;
255 /*! \todo Finish function documentation!!!
257 * \par Function Description
260 void s_undo_remove_rest(TOPLEVEL
*toplevel
, UNDO
*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
;
285 /*! \todo Finish function documentation!!!
287 * \par Function Description
290 int s_undo_levels(UNDO
*head
)
296 while (u_current
!= NULL
) {
297 if (u_current
->filename
|| u_current
->object_list
) {
301 u_current
= u_current
->next
;
307 /*! \todo Finish function documentation!!!
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!!!
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
;