1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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 #ifdef HAVE_LIBDMALLOC
37 /*! \todo Finish function documentation!!!
39 * \par Function Description
42 UNDO
*s_undo_return_tail(UNDO
*head
)
45 UNDO
*ret_struct
=NULL
;
48 while ( u_current
!= NULL
) { /* goto end of list */
49 ret_struct
= u_current
;
50 u_current
= u_current
->next
;
56 /*! \todo Finish function documentation!!!
58 * \par Function Description
61 UNDO
*s_undo_return_head(UNDO
*tail
)
64 UNDO
*ret_struct
=NULL
;
67 while ( u_current
!= NULL
) { /* goto end of list */
68 ret_struct
= u_current
;
69 u_current
= u_current
->prev
;
75 /*! \todo Finish function documentation!!!
77 * \par Function Description
80 UNDO
*s_undo_new_head(void)
84 u_new
= (UNDO
*) g_malloc(sizeof(UNDO
));
86 u_new
->filename
= NULL
;
87 u_new
->object_list
= NULL
;
88 u_new
->left
= u_new
->right
= u_new
->top
= u_new
->bottom
= -1;
90 u_new
->page_control
= 0;
99 /*! \todo Finish function documentation!!!
101 * \par Function Description
104 void s_undo_destroy_head(UNDO
*u_head
)
109 /*! \todo Finish function documentation!!!
111 * \par Function Description
114 UNDO
*s_undo_add (UNDO
*head
, int type
, char *filename
, GList
*object_list
,
115 int left
, int top
, int right
, int bottom
, int page_control
,
121 u_new
= (UNDO
*) g_malloc(sizeof(UNDO
));
123 u_new
->filename
= g_strdup (filename
);
125 u_new
->object_list
= object_list
;
131 u_new
->right
= right
;
132 u_new
->bottom
= bottom
;
134 u_new
->page_control
= page_control
;
138 u_new
->prev
= NULL
; /* setup previous link */
142 tail
= s_undo_return_tail(head
);
143 u_new
->prev
= tail
; /* setup previous link */
150 /*! \todo Finish function documentation!!!
152 * \par Function Description
155 void s_undo_print_all( UNDO
*head
)
161 printf("START printing undo ********************\n");
163 while(u_current
!= NULL
) {
165 if (u_current
->filename
) printf("%s\n", u_current
->filename
);
167 if (u_current
->object_list
) {
168 print_struct_forw (u_current
->object_list
);
171 printf("\t%d %d %d %d\n", u_current
->left
, u_current
->top
,
172 u_current
->right
, u_current
->bottom
);
173 u_current
= u_current
->next
;
176 printf("Number of levels: %d\n", s_undo_levels(head
));
177 printf("DONE printing undo ********************\n");
182 /*! \todo Finish function documentation!!!
184 * \par Function Description
187 void s_undo_destroy_all(TOPLEVEL
*toplevel
, UNDO
*head
)
192 u_current
= s_undo_return_tail(head
);
194 while (u_current
!= NULL
) {
195 u_prev
= u_current
->prev
;
196 g_free(u_current
->filename
);
198 if (u_current
->object_list
) {
199 s_delete_object_glist (toplevel
, u_current
->object_list
);
200 u_current
->object_list
= NULL
;
208 /*! \todo Finish function documentation!!!
210 * \par Function Description
213 void s_undo_remove(TOPLEVEL
*toplevel
, UNDO
*head
, UNDO
*u_tos
)
218 fprintf(stderr
, "Got NULL for u_tos in s_undo_remove\n");
224 while (u_current
!= NULL
) {
225 if (u_current
== u_tos
) {
227 u_current
->next
->prev
= u_current
->prev
;
229 u_current
->next
= NULL
;
232 u_current
->prev
->next
= u_current
->next
;
234 u_current
->prev
= NULL
;
236 g_free(u_current
->filename
);
238 if (u_current
->object_list
) {
239 s_delete_object_glist (toplevel
, u_current
->object_list
);
240 u_current
->object_list
= NULL
;
246 u_current
= u_current
->next
;
250 /*! \todo Finish function documentation!!!
252 * \par Function Description
255 void s_undo_remove_rest(TOPLEVEL
*toplevel
, UNDO
*head
)
262 while (u_current
!= NULL
) {
263 u_next
= u_current
->next
;
265 if (u_current
->filename
) {
266 unlink(u_current
->filename
);
267 g_free(u_current
->filename
);
270 if (u_current
->object_list
) {
271 s_delete_object_glist (toplevel
, u_current
->object_list
);
272 u_current
->object_list
= NULL
;
280 /*! \todo Finish function documentation!!!
282 * \par Function Description
285 int s_undo_levels(UNDO
*head
)
291 while (u_current
!= NULL
) {
292 if (u_current
->filename
|| u_current
->object_list
) {
296 u_current
= u_current
->next
;
302 /*! \todo Finish function documentation!!!
304 * \par Function Description
307 void s_undo_init(PAGE
*p_current
)
309 p_current
->undo_tos
= p_current
->undo_bottom
= NULL
;
310 p_current
->undo_current
= NULL
;
313 /*! \todo Finish function documentation!!!
315 * \par Function Description
318 void s_undo_free_all(TOPLEVEL
*toplevel
, PAGE
*p_current
)
320 s_undo_destroy_all(toplevel
, p_current
->undo_bottom
);
321 p_current
->undo_bottom
= NULL
;
322 p_current
->undo_tos
= NULL
;
323 p_current
->undo_current
= NULL
;