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
44 #include "../include/prototype.h"
46 #ifdef HAVE_LIBDMALLOC
50 /*! \todo Finish function documentation!!!
52 * \par Function Description
55 UNDO
*s_undo_return_tail(UNDO
*head
)
58 UNDO
*ret_struct
=NULL
;
61 while ( u_current
!= NULL
) { /* goto end of list */
62 ret_struct
= u_current
;
63 u_current
= u_current
->next
;
69 /*! \todo Finish function documentation!!!
71 * \par Function Description
74 UNDO
*s_undo_return_head(UNDO
*tail
)
77 UNDO
*ret_struct
=NULL
;
80 while ( u_current
!= NULL
) { /* goto end of list */
81 ret_struct
= u_current
;
82 u_current
= u_current
->prev
;
88 /*! \todo Finish function documentation!!!
90 * \par Function Description
93 UNDO
*s_undo_new_head(void)
97 u_new
= (UNDO
*) g_malloc(sizeof(UNDO
));
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;
112 /*! \todo Finish function documentation!!!
114 * \par Function Description
117 void s_undo_destroy_head(UNDO
*u_head
)
122 /*! \todo Finish function documentation!!!
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
,
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
;
141 u_new
->object_head
= NULL
;
148 u_new
->right
= right
;
149 u_new
->bottom
= bottom
;
151 u_new
->page_control
= page_control
;
155 u_new
->prev
= NULL
; /* setup previous link */
159 tail
= s_undo_return_tail(head
);
160 u_new
->prev
= tail
; /* setup previous link */
167 /*! \todo Finish function documentation!!!
169 * \par Function Description
172 void s_undo_print_all( UNDO
*head
)
178 printf("START printing undo ********************\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
;
194 printf("Number of levels: %d\n", s_undo_levels(head
));
195 printf("DONE printing undo ********************\n");
200 /*! \todo Finish function documentation!!!
202 * \par Function Description
205 void s_undo_destroy_all(TOPLEVEL
*w_current
, UNDO
*head
)
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
;
229 /*! \todo Finish function documentation!!!
231 * \par Function Description
234 void s_undo_remove(TOPLEVEL
*w_current
, UNDO
*head
, UNDO
*u_tos
)
239 fprintf(stderr
, "Got NULL for u_tos in s_undo_remove\n");
245 while (u_current
!= NULL
) {
246 if (u_current
== u_tos
) {
248 u_current
->next
->prev
= u_current
->prev
;
250 u_current
->next
= NULL
;
253 u_current
->prev
->next
= u_current
->next
;
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
;
272 u_current
= u_current
->next
;
276 /*! \todo Finish function documentation!!!
278 * \par Function Description
281 void s_undo_remove_rest(TOPLEVEL
*w_current
, UNDO
*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
;
309 /*! \todo Finish function documentation!!!
311 * \par Function Description
314 int s_undo_levels(UNDO
*head
)
320 while (u_current
!= NULL
) {
321 if (u_current
->filename
|| u_current
->object_head
) {
325 u_current
= u_current
->next
;
331 /*! \todo Finish function documentation!!!
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!!!
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
;