1 | /* newt-specific.c
|
---|
2 | $Id: newt-specific.c 1747 2007-10-30 12:18:55Z bruno $
|
---|
3 |
|
---|
4 | subroutines which do display-type things
|
---|
5 | and use the newt library to do them
|
---|
6 | .
|
---|
7 |
|
---|
8 | 10/02
|
---|
9 | - tell user not to bother mailing list unless snapshot
|
---|
10 |
|
---|
11 | 07/09
|
---|
12 | - finish() calls g_erase_tmpdir_and_scratchdir to erase
|
---|
13 | tmpdir and scratchdir at end
|
---|
14 |
|
---|
15 | 06/25
|
---|
16 | - tried to fix newtFinished() segfault
|
---|
17 |
|
---|
18 | 04/13/2004
|
---|
19 | - lots of char[]'s are now *char's
|
---|
20 |
|
---|
21 | 10/09/2003
|
---|
22 | - allow DVD option for text-mode which_backup_type() too
|
---|
23 |
|
---|
24 | 09/28
|
---|
25 | - log_to_screen() now takes printf-like parameters
|
---|
26 |
|
---|
27 | 09/26
|
---|
28 | - b5 now means dvd (was udev)
|
---|
29 |
|
---|
30 | 09/16
|
---|
31 | - echo fatal error to screen before exiting
|
---|
32 | - working on fatal_error()
|
---|
33 | - swapped g_blurb2 and g_blurb3 in a few places to fix a GUI problem;
|
---|
34 | it shouldn't have worked! :) I think there's a mem-leak somewhere
|
---|
35 |
|
---|
36 | 09/13
|
---|
37 | - changed some '\n' occurrences to '\r\n'
|
---|
38 |
|
---|
39 | 09/09
|
---|
40 | - fixed silly bug in log_to_screen()
|
---|
41 |
|
---|
42 | 07/02
|
---|
43 | - modified popup_and_get_string()
|
---|
44 |
|
---|
45 | 05/03
|
---|
46 | - cleaned up fatal_error()
|
---|
47 |
|
---|
48 | 04/30
|
---|
49 | - fixed popup_changelist_*()
|
---|
50 |
|
---|
51 | 04/27
|
---|
52 | - replace newtFinished() and newtInit() with
|
---|
53 | newtSuspend() and newtResume()
|
---|
54 |
|
---|
55 | 04/25
|
---|
56 | - after comparing, popup the changelist for the user
|
---|
57 | - moved the relevant code from compare_to_cds() into
|
---|
58 | compare_mode(), so that tape users may benefit too
|
---|
59 |
|
---|
60 | 04/24
|
---|
61 | - added lots of assert()'s and log_OS_error()'s
|
---|
62 | - cleaned up a few uninitialized strings (valgrind)
|
---|
63 |
|
---|
64 | 04/22
|
---|
65 | - line 1181 - 'read from' (not 'restoring from')
|
---|
66 |
|
---|
67 | 03/15/2003
|
---|
68 | - fixed potentially infinite loop in log_to_screen (Tom Mortell)
|
---|
69 |
|
---|
70 | 12/04/2002
|
---|
71 | - changed "Pick file" to "Non-matching files"
|
---|
72 |
|
---|
73 | 11/28
|
---|
74 | - finish() now unregisters Mondo's pid
|
---|
75 |
|
---|
76 | 10/28
|
---|
77 | - unmount tmpfs if fatal_error
|
---|
78 |
|
---|
79 | 10/04
|
---|
80 | - more XMondo-related work
|
---|
81 | - added some =NULL's in a few places
|
---|
82 |
|
---|
83 | 09/01 - 09/30
|
---|
84 | - write log_to_screen()'s string to stdout if in text mode
|
---|
85 | - update_progress_form_FULL(), update_evalcall_form(),
|
---|
86 | popup_and_*(), ask_me_yes_or_no() now write
|
---|
87 | XMondo-friendly info to stdout if in text mode
|
---|
88 | - if fatal error then popup and say what the fatal error is
|
---|
89 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
90 | whether it will log its activities in the event of _success_
|
---|
91 | - added popup_changelist_from_file(char*source_file, char*topic, void*call_if_entry_selected(void*));
|
---|
92 |
|
---|
93 | 08/07
|
---|
94 | - added some functions to let user choose backup dev + format
|
---|
95 |
|
---|
96 | 07/27
|
---|
97 | - created
|
---|
98 | */
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * @file
|
---|
103 | * Functions for doing display-type things with the Newt library.
|
---|
104 | */
|
---|
105 |
|
---|
106 | #define MAX_NEWT_COMMENT_LEN 200
|
---|
107 |
|
---|
108 | #if __cplusplus
|
---|
109 | extern "C" {
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | #include "my-stuff.h"
|
---|
113 | #include "mondostructures.h"
|
---|
114 | #include "newt-specific.h"
|
---|
115 | #include "libmondo-string-EXT.h"
|
---|
116 | #include "libmondo-files-EXT.h"
|
---|
117 | #include "libmondo-devices-EXT.h"
|
---|
118 | #include "libmondo-tools-EXT.h"
|
---|
119 | #include "libmondo-fork-EXT.h"
|
---|
120 | #include "libmondo-gui-EXT.h"
|
---|
121 | #include "lib-common-externs.h"
|
---|
122 |
|
---|
123 | extern char *MONDO_LOGFILE;
|
---|
124 |
|
---|
125 | extern struct s_bkpinfo *bkpinfo;
|
---|
126 |
|
---|
127 | /*@unused@*/
|
---|
128 | //static char cvsid[] = "$Id: newt-specific.c 1747 2007-10-30 12:18:55Z bruno $";
|
---|
129 |
|
---|
130 | extern pid_t g_mastermind_pid;
|
---|
131 | extern char *g_tmpfs_mountpt;
|
---|
132 | extern char *g_boot_mountpt;
|
---|
133 | extern char *ps_options;
|
---|
134 | extern char *ps_proc_id;
|
---|
135 |
|
---|
136 | extern void set_signals(int);
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * @addtogroup globalGroup
|
---|
140 | * @{
|
---|
141 | */
|
---|
142 | /**
|
---|
143 | * Whether we are currently in a nested call of fatal_error().
|
---|
144 | */
|
---|
145 | bool g_exiting = FALSE;
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Padding below the Newt components, to overcome bugs in Newt.
|
---|
149 | */
|
---|
150 | char g_haharrrrr[500];
|
---|
151 |
|
---|
152 |
|
---|
153 | newtComponent g_timeline = NULL, ///< The line of the progress form that shows the time elapsed/remaining
|
---|
154 | g_percentline = NULL, ///< The line of the progress form that shows the percent completed/remaining
|
---|
155 | g_scale = NULL, ///< The progress bar component in the progress form
|
---|
156 | g_progressForm = NULL, ///< The progress form component itself
|
---|
157 | g_blurb1 = NULL, ///< The component for line 1 of the blurb in the progress form
|
---|
158 | g_blurb2 = NULL, ///< The component for line 2 of the blurb in the progress form
|
---|
159 | g_blurb3 = NULL, ///< The component for line 3 (updated continuously) of the blurb in the progress form
|
---|
160 | g_label = NULL; ///< ????? @bug ?????
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Padding above the Newt components, to overcome bugs in Newt.
|
---|
164 | */
|
---|
165 | char g_jim_lad_yarr[500];
|
---|
166 | char **err_log_lines = NULL, ///< The list of log lines to show on the screen.
|
---|
167 | g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 1 of the blurb in the progress form
|
---|
168 | g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 2 of the blurb in the progress form
|
---|
169 | g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = ""; ///< The string for line 3 (updated continuously) of the blurb in the progress form
|
---|
170 | newtComponent g_isoform_main = NULL, ///< The evalcall form component itself
|
---|
171 | g_isoform_header = NULL, ///< The component for the evalcall form title
|
---|
172 | g_isoform_scale = NULL, ///< The progress bar component in the evalcall form
|
---|
173 | g_isoform_timeline = NULL, ///< The line of the evalcall form that shows the time elapsed/remaining
|
---|
174 | g_isoform_pcline = NULL; ///< The line of the evalcall form that shows the percent completed/remaining
|
---|
175 | long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened.
|
---|
176 | int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent).
|
---|
177 | char g_isoform_header_str[MAX_STR_LEN] = " "; ///< The string for the evalcall form title.
|
---|
178 | int g_mysterious_dot_counter; ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
|
---|
179 | int g_noof_log_lines = 6; ///< The number of lines to show in the log at the bottom of the screen.
|
---|
180 | int g_noof_rows = 25; ///< The number of rows on the screen.
|
---|
181 |
|
---|
182 | int g_currentY = 3; ///< The row to write background progress messages to. Incremented each time a message is written.
|
---|
183 | extern int g_current_media_number;
|
---|
184 | pid_t g_main_pid = 0; ///< The PID of the main Mondo process.
|
---|
185 | long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form.
|
---|
186 | long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
|
---|
187 | long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened.
|
---|
188 | bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
|
---|
189 | char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo.
|
---|
190 | g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
|
---|
191 | bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo.
|
---|
192 | char *g_selfmounted_isodir; ///< Holds the NFS mountpoint if mounted via mondoarchive.
|
---|
193 |
|
---|
194 | /* @} - end of globalGroup */
|
---|
195 |
|
---|
196 | //int g_fd_in=-1, g_fd_out=-1;
|
---|
197 |
|
---|
198 | void popup_and_OK(char *);
|
---|
199 |
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * @addtogroup guiGroup
|
---|
203 | * @{
|
---|
204 | */
|
---|
205 | /**
|
---|
206 | * Ask the user a yes/no question.
|
---|
207 | * @param prompt The question to ask the user.
|
---|
208 | * @return TRUE for yes; FALSE for no.
|
---|
209 | */
|
---|
210 | bool ask_me_yes_or_no(char *prompt) {
|
---|
211 |
|
---|
212 | /*@ buffers ********************************************************** */
|
---|
213 | char *tmp;
|
---|
214 | int i;
|
---|
215 |
|
---|
216 | tmp = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
217 | assert_string_is_neither_NULL_nor_zerolength(prompt);
|
---|
218 |
|
---|
219 | if (g_text_mode) {
|
---|
220 | while (1) {
|
---|
221 | system("sync");
|
---|
222 | printf
|
---|
223 | ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ",
|
---|
224 | prompt);
|
---|
225 | (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
|
---|
226 | if (tmp[strlen(tmp) - 1] == '\n')
|
---|
227 | tmp[strlen(tmp) - 1] = '\0';
|
---|
228 |
|
---|
229 | i = (int) strlen(tmp);
|
---|
230 | if (i > 0 && tmp[i - 1] < 32) {
|
---|
231 | tmp[i - 1] = '\0';
|
---|
232 | }
|
---|
233 | if (strstr("yesYES", tmp)) {
|
---|
234 | paranoid_free(tmp);
|
---|
235 | return (TRUE);
|
---|
236 | } else if (strstr("NOno", tmp)) {
|
---|
237 | paranoid_free(tmp);
|
---|
238 | return (FALSE);
|
---|
239 | } else {
|
---|
240 | system("sync");
|
---|
241 | printf
|
---|
242 | ("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
|
---|
243 | }
|
---|
244 | }
|
---|
245 | } else {
|
---|
246 | paranoid_free(tmp);
|
---|
247 | return (popup_with_buttons(prompt, "Yes", "No"));
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Give the user the opportunity to continue the current operation (OK)
|
---|
254 | * or cancel it (Cancel).
|
---|
255 | * @param prompt The string to be displayed.
|
---|
256 | * @return TRUE for OK, FALSE for Cancel.
|
---|
257 | */
|
---|
258 | bool ask_me_OK_or_cancel(char *prompt) {
|
---|
259 |
|
---|
260 | /*@ buffer *********************************************************** */
|
---|
261 | char *tmp;
|
---|
262 | int i;
|
---|
263 |
|
---|
264 | tmp = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
265 | assert_string_is_neither_NULL_nor_zerolength(prompt);
|
---|
266 | if (g_text_mode) {
|
---|
267 | system("sync");
|
---|
268 | printf
|
---|
269 | ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ",
|
---|
270 | prompt);
|
---|
271 | (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
|
---|
272 | if (tmp[strlen(tmp) - 1] == '\n')
|
---|
273 | tmp[strlen(tmp) - 1] = '\0';
|
---|
274 |
|
---|
275 | i = (int) strlen(tmp);
|
---|
276 | if (i > 0 && tmp[i - 1] < 32) {
|
---|
277 | tmp[i - 1] = '\0';
|
---|
278 | }
|
---|
279 | if (strstr("okOKOkYESyes", tmp)) {
|
---|
280 | paranoid_free(tmp);
|
---|
281 | return (TRUE);
|
---|
282 | } else {
|
---|
283 | paranoid_free(tmp);
|
---|
284 | return (FALSE);
|
---|
285 | }
|
---|
286 | } else {
|
---|
287 | paranoid_free(tmp);
|
---|
288 | return (popup_with_buttons(prompt, " Okay ", "Cancel"));
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Close the currently opened evalcall form.
|
---|
296 | */
|
---|
297 | void
|
---|
298 | close_evalcall_form(void) {
|
---|
299 | if (g_text_mode) {
|
---|
300 | return;
|
---|
301 | }
|
---|
302 | if (g_isoform_main == NULL) {
|
---|
303 | return;
|
---|
304 | }
|
---|
305 | update_evalcall_form(100);
|
---|
306 | usleep(500000);
|
---|
307 | if (g_text_mode) {
|
---|
308 | log_msg(2, "Closing evalcall form");
|
---|
309 | return;
|
---|
310 | }
|
---|
311 | newtPopHelpLine();
|
---|
312 | newtFormDestroy(g_isoform_main);
|
---|
313 | newtPopWindow();
|
---|
314 | g_isoform_main = NULL;
|
---|
315 | g_isoform_old_progress = -1;
|
---|
316 | }
|
---|
317 |
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Close the currently opened progress form.
|
---|
321 | */
|
---|
322 | void
|
---|
323 | close_progress_form() {
|
---|
324 | if (g_text_mode) {
|
---|
325 | return;
|
---|
326 | }
|
---|
327 | if (g_current_progress == -999) {
|
---|
328 | log_msg(2,
|
---|
329 | "Trying to close the progress form when it ain't open!");
|
---|
330 | return;
|
---|
331 | }
|
---|
332 | g_current_progress = g_maximum_progress;
|
---|
333 | update_progress_form("Complete");
|
---|
334 | sleep(1);
|
---|
335 | if (g_text_mode) {
|
---|
336 | log_msg(2, "Closing progress form");
|
---|
337 | return;
|
---|
338 | }
|
---|
339 | newtPopHelpLine();
|
---|
340 | newtFormDestroy(g_progressForm);
|
---|
341 | newtPopWindow();
|
---|
342 | g_progressForm = NULL;
|
---|
343 | g_current_progress = -999;
|
---|
344 | }
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Kill any process containing the string @p str surrounded by spaces in its commandline.
|
---|
348 | */
|
---|
349 | void kill_anything_like_this(char *str) {
|
---|
350 |
|
---|
351 | char *tmp = NULL;
|
---|
352 |
|
---|
353 | asprintf(&tmp,"kill `ps %s | grep \" %s \" | awk '{print %s;}' | grep -v \"grep\"`", ps_options, str , ps_proc_id);
|
---|
354 | run_program_and_log_output(tmp, TRUE);
|
---|
355 | paranoid_free(tmp);
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * Exit Mondo with a fatal error.
|
---|
361 | * @param error_string The error message to present to the user before exiting.
|
---|
362 | * @note This function never returns.
|
---|
363 | */
|
---|
364 | void
|
---|
365 | fatal_error(char *error_string) {
|
---|
366 | /*@ buffers ***************************************************** */
|
---|
367 | char fatalstr[MAX_NEWT_COMMENT_LEN] =
|
---|
368 | "-------FATAL ERROR---------";
|
---|
369 | char *tmp;
|
---|
370 | char *command;
|
---|
371 | static bool already_exiting = FALSE;
|
---|
372 | int i;
|
---|
373 |
|
---|
374 | /*@ end vars **************************************************** */
|
---|
375 |
|
---|
376 | malloc_string(command);
|
---|
377 | tmp = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
378 | set_signals(FALSE); // link to external func
|
---|
379 | g_exiting = TRUE;
|
---|
380 | log_msg(1, "Fatal error received - '%s'", error_string);
|
---|
381 | printf("Fatal error... %s\n", error_string);
|
---|
382 | if (getpid() == g_mastermind_pid) {
|
---|
383 | log_msg(2, "mastermind %d is exiting", (int) getpid());
|
---|
384 | kill(g_main_pid, SIGTERM);
|
---|
385 | paranoid_free(tmp);
|
---|
386 | finish(1);
|
---|
387 | }
|
---|
388 |
|
---|
389 | if (getpid() != g_main_pid) {
|
---|
390 | if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) {
|
---|
391 | log_msg(2, "non-m/m %d is exiting", (int) getpid());
|
---|
392 | kill(g_main_pid, SIGTERM);
|
---|
393 | paranoid_free(tmp);
|
---|
394 | finish(1);
|
---|
395 | }
|
---|
396 | }
|
---|
397 |
|
---|
398 | log_msg(3, "OK, I think I'm the main PID.");
|
---|
399 | if (already_exiting) {
|
---|
400 | log_msg(3, "...I'm already exiting. Give me time, Julian!");
|
---|
401 | paranoid_free(tmp);
|
---|
402 | finish(1);
|
---|
403 | }
|
---|
404 |
|
---|
405 | already_exiting = TRUE;
|
---|
406 | log_msg(2, "I'm going to do some cleaning up now.");
|
---|
407 | paranoid_system("killall mindi 2> /dev/null");
|
---|
408 | kill_anything_like_this("/mondo/do-not");
|
---|
409 | kill_anything_like_this("tmp.mondo");
|
---|
410 | kill_anything_like_this("ntfsclone");
|
---|
411 | sync();
|
---|
412 | sprintf(tmp, "umount %s", g_tmpfs_mountpt);
|
---|
413 | chdir("/");
|
---|
414 | for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
|
---|
415 | log_msg(2, "Waiting for child processes to terminate");
|
---|
416 | sleep(1);
|
---|
417 | run_program_and_log_output(tmp, 5);
|
---|
418 | }
|
---|
419 |
|
---|
420 | if (g_selfmounted_isodir) {
|
---|
421 | sprintf(command, "umount %s", g_selfmounted_isodir);
|
---|
422 | run_program_and_log_output(command, 5);
|
---|
423 | sprintf(command, "rmdir %s", g_selfmounted_isodir);
|
---|
424 | run_program_and_log_output(command, 5);
|
---|
425 | }
|
---|
426 |
|
---|
427 | if (!g_text_mode) {
|
---|
428 | log_msg(0, fatalstr);
|
---|
429 | log_msg(0, error_string);
|
---|
430 | // popup_and_OK (error_string);
|
---|
431 | newtFinished();
|
---|
432 | }
|
---|
433 |
|
---|
434 | printf("---FATALERROR--- %s\n", error_string);
|
---|
435 | sprintf(command, "gzip -9c %s > %s/MA.log.gz 2> /dev/null", MONDO_LOGFILE, MONDO_CACHE);
|
---|
436 | system(command);
|
---|
437 | printf
|
---|
438 | ("If you require technical support, please contact the mailing list.\n");
|
---|
439 | printf("See http://www.mondorescue.org for details.\n");
|
---|
440 | printf
|
---|
441 | ("The list's members can help you, if you attach that file to your e-mail.\n");
|
---|
442 | printf("Log file: %s\n", MONDO_LOGFILE);
|
---|
443 | if (does_file_exist(MONDO_CACHE"/MA.log.gz")) {
|
---|
444 | printf("FYI, I have gzipped the log and saved it to "MONDO_CACHE"/MA.log.gz.\n");
|
---|
445 | }
|
---|
446 | printf("Mondo has aborted.\n");
|
---|
447 | register_pid(0, "mondo"); // finish() does this too, FYI
|
---|
448 | if (!g_main_pid) {
|
---|
449 | log_msg(3, "FYI - g_main_pid is blank");
|
---|
450 | }
|
---|
451 | paranoid_free(tmp);
|
---|
452 | paranoid_free(command);
|
---|
453 | finish(254);
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Exit Mondo normally.
|
---|
460 | * @param signal The exit code (0 indicates a successful backup; 1 for Mondo means the
|
---|
461 | * user aborted; 254 means a fatal error occured).
|
---|
462 | * @note This function never returns.
|
---|
463 | */
|
---|
464 | void
|
---|
465 | finish(int signal) {
|
---|
466 | char *command = NULL;
|
---|
467 |
|
---|
468 | /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
|
---|
469 |
|
---|
470 | /* newtPopHelpLine(); */
|
---|
471 |
|
---|
472 | register_pid(0, "mondo");
|
---|
473 | chdir("/");
|
---|
474 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
475 | if (g_selfmounted_isodir) {
|
---|
476 | asprintf(&command, "umount %s", g_selfmounted_isodir);
|
---|
477 | run_program_and_log_output(command, 1);
|
---|
478 | paranoid_free(command);
|
---|
479 | asprintf(&command, "rmdir %s", g_selfmounted_isodir);
|
---|
480 | run_program_and_log_output(command, 1);
|
---|
481 | paranoid_free(command);
|
---|
482 | }
|
---|
483 | if (!g_text_mode) {
|
---|
484 | if (does_file_exist("/THIS-IS-A-RAMDISK")) {
|
---|
485 | log_msg(1, "Calling newtFinished()");
|
---|
486 | newtFinished();
|
---|
487 | } else {
|
---|
488 | log_msg(1, "Calling newtSuspend()");
|
---|
489 | newtSuspend();
|
---|
490 | }
|
---|
491 | }
|
---|
492 | printf("Execution run ended; result=%d\n", signal);
|
---|
493 | printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
|
---|
494 | asprintf(&command, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
495 | system(command);
|
---|
496 | paranoid_free(command);
|
---|
497 | paranoid_free(bkpinfo);
|
---|
498 | free_libmondo_global_strings();
|
---|
499 | exit(signal);
|
---|
500 | }
|
---|
501 |
|
---|
502 |
|
---|
503 |
|
---|
504 |
|
---|
505 |
|
---|
506 | /**
|
---|
507 | * Log the last @p g_noof_log_lines lines of @p filename that match @p
|
---|
508 | * grep_for_me to the screen.
|
---|
509 | * @param filename The file to give the end of.
|
---|
510 | * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
|
---|
511 | */
|
---|
512 | void
|
---|
513 | log_file_end_to_screen(char *filename, char *grep_for_me) {
|
---|
514 |
|
---|
515 | /*@ buffers ********************************************************** */
|
---|
516 | char *command;
|
---|
517 | char *tmp;
|
---|
518 |
|
---|
519 | /*@ pointers ********************************************************* */
|
---|
520 | FILE *fin;
|
---|
521 |
|
---|
522 | /*@ int ************************************************************** */
|
---|
523 | int i = 0;
|
---|
524 |
|
---|
525 | malloc_string(command);
|
---|
526 | malloc_string(tmp);
|
---|
527 | assert_string_is_neither_NULL_nor_zerolength(filename);
|
---|
528 | assert(grep_for_me != NULL);
|
---|
529 |
|
---|
530 | if (!does_file_exist(filename)) {
|
---|
531 | paranoid_free(command);
|
---|
532 | paranoid_free(tmp);
|
---|
533 | return;
|
---|
534 | }
|
---|
535 | if (grep_for_me[0] != '\0') {
|
---|
536 | sprintf(command, "grep '%s' %s | tail -n%d",
|
---|
537 | grep_for_me, filename, g_noof_log_lines);
|
---|
538 | } else {
|
---|
539 | sprintf(command, "tail -n%d %s", g_noof_log_lines,
|
---|
540 | filename);
|
---|
541 | }
|
---|
542 | fin = popen(command, "r");
|
---|
543 | if (!fin) {
|
---|
544 | log_OS_error(command);
|
---|
545 | } else {
|
---|
546 | for (i = 0; i < g_noof_log_lines; i++) {
|
---|
547 | for (err_log_lines[i][0] = '\0';
|
---|
548 | strlen(err_log_lines[i]) < 2 && !feof(fin);) {
|
---|
549 | (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
|
---|
550 | fin);
|
---|
551 | /* Commented to make valgrind happy and avoid crash
|
---|
552 | strip_spaces(err_log_lines[i]);
|
---|
553 | */
|
---|
554 | if (!strncmp(err_log_lines[i], "root:", 5)) {
|
---|
555 | strcpy(tmp, err_log_lines[i] + 6);
|
---|
556 | strcpy(err_log_lines[i], tmp);
|
---|
557 | }
|
---|
558 | if (feof(fin)) {
|
---|
559 | break;
|
---|
560 | }
|
---|
561 | }
|
---|
562 | }
|
---|
563 | paranoid_pclose(fin);
|
---|
564 | }
|
---|
565 | refresh_log_screen();
|
---|
566 | paranoid_free(command);
|
---|
567 | paranoid_free(tmp);
|
---|
568 | }
|
---|
569 |
|
---|
570 |
|
---|
571 | /**
|
---|
572 | * Log a message to the screen.
|
---|
573 | * @param fmt A printf-style format string to write. The following parameters are its arguments.
|
---|
574 | * @note The message is also written to the logfile.
|
---|
575 | */
|
---|
576 | void
|
---|
577 | log_to_screen(const char *fmt, ...) {
|
---|
578 |
|
---|
579 | /*@ int ************************************************************** */
|
---|
580 | int i = 0;
|
---|
581 | int j = 0;
|
---|
582 | va_list args;
|
---|
583 |
|
---|
584 | /*@ buffers ********************************************************** */
|
---|
585 | char *output;
|
---|
586 |
|
---|
587 | malloc_string(output);
|
---|
588 |
|
---|
589 | va_start(args, fmt);
|
---|
590 | vsprintf(output, fmt, args);
|
---|
591 | log_msg(0, output);
|
---|
592 | output[80] = '\0';
|
---|
593 | va_end(args);
|
---|
594 | i = (int) strlen(output);
|
---|
595 | if (i > 0 && output[i - 1] < 32) {
|
---|
596 | output[i - 1] = '\0';
|
---|
597 | }
|
---|
598 |
|
---|
599 | if (err_log_lines) {
|
---|
600 | for (i = 1; i < g_noof_log_lines; i++) {
|
---|
601 | strcpy(err_log_lines[i - 1],
|
---|
602 | " ");
|
---|
603 | strcpy(err_log_lines[i - 1], err_log_lines[i]);
|
---|
604 | }
|
---|
605 | }
|
---|
606 | while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
|
---|
607 | output[strlen(output) - 1] = '\0';
|
---|
608 | }
|
---|
609 | for (j = 0; j < (int) strlen(output); j++) {
|
---|
610 | if (output[j] < 32) {
|
---|
611 | output[j] = ' ';
|
---|
612 | }
|
---|
613 | }
|
---|
614 | if (err_log_lines)
|
---|
615 | strcpy(err_log_lines[g_noof_log_lines - 1], output);
|
---|
616 | if (g_text_mode) {
|
---|
617 | printf("%s\n", output);
|
---|
618 | } else {
|
---|
619 | refresh_log_screen();
|
---|
620 | }
|
---|
621 | paranoid_free(output);
|
---|
622 | }
|
---|
623 |
|
---|
624 |
|
---|
625 |
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * Write a string to the root window at (@p x, @p y) and also to the logfile.
|
---|
629 | * @param y The row to write the string to.
|
---|
630 | * @param x The column to write the string to.
|
---|
631 | * @param output The string to write.
|
---|
632 | */
|
---|
633 | void
|
---|
634 | mvaddstr_and_log_it(int y, int x, char *output) {
|
---|
635 | assert_string_is_neither_NULL_nor_zerolength(output);
|
---|
636 | log_msg(0, output);
|
---|
637 | if (g_text_mode) {
|
---|
638 | printf("%s\n", output);
|
---|
639 | } else {
|
---|
640 | newtDrawRootText(x, y, output);
|
---|
641 | newtRefresh();
|
---|
642 | }
|
---|
643 | }
|
---|
644 |
|
---|
645 |
|
---|
646 |
|
---|
647 |
|
---|
648 | /**
|
---|
649 | * Open an evalcall form with title @p ttl.
|
---|
650 | * @param ttl The title to use for the evalcall form.
|
---|
651 | */
|
---|
652 | void
|
---|
653 | open_evalcall_form(char *ttl) {
|
---|
654 |
|
---|
655 | /*@ buffers ********************************************************* */
|
---|
656 | char *title;
|
---|
657 | char *tmp;
|
---|
658 |
|
---|
659 | /*@ initialize ****************************************************** */
|
---|
660 | g_isoform_old_progress = -1;
|
---|
661 | g_mysterious_dot_counter = 0;
|
---|
662 | malloc_string(title);
|
---|
663 | malloc_string(tmp);
|
---|
664 |
|
---|
665 | assert(ttl != NULL);
|
---|
666 | strcpy(title, ttl);
|
---|
667 | strcpy(g_isoform_header_str, title);
|
---|
668 | // center_string (title, 80);
|
---|
669 | if (g_text_mode) {
|
---|
670 | log_msg(0, title);
|
---|
671 | } else {
|
---|
672 | strcpy(tmp, title);
|
---|
673 | center_string(tmp, 80);
|
---|
674 | newtPushHelpLine(tmp);
|
---|
675 | }
|
---|
676 | center_string(g_isoform_header_str, 36);
|
---|
677 | g_isoform_starttime = get_time();
|
---|
678 | if (g_text_mode) {
|
---|
679 | log_msg(0, g_isoform_header_str);
|
---|
680 | } else {
|
---|
681 | g_isoform_header = newtLabel(1, 1, g_isoform_header_str);
|
---|
682 | g_isoform_scale = newtScale(3, 3, 34, 100);
|
---|
683 | // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait");
|
---|
684 | newtCenteredWindow(40, 7, title);
|
---|
685 | g_isoform_main = newtForm(NULL, NULL, 0);
|
---|
686 | g_isoform_timeline = newtLabel(1, 5, "This is the timeline");
|
---|
687 | g_isoform_pcline = newtLabel(1, 6, "This is the pcline");
|
---|
688 | newtFormAddComponents(g_isoform_main, g_isoform_timeline,
|
---|
689 | g_isoform_pcline, g_isoform_header,
|
---|
690 | g_isoform_scale, NULL);
|
---|
691 | newtRefresh();
|
---|
692 | }
|
---|
693 | update_evalcall_form(0);
|
---|
694 | paranoid_free(tmp);
|
---|
695 | paranoid_free(title);
|
---|
696 | }
|
---|
697 |
|
---|
698 |
|
---|
699 |
|
---|
700 | /**
|
---|
701 | * Open a progress form with title @p title.
|
---|
702 | * @param title The title to use for the progress form (will be put in the title bar on Newt).
|
---|
703 | * @param b1 The first line of the blurb; generally static.
|
---|
704 | * @param b2 The second line of the blurb; generally static.
|
---|
705 | * @param b3 The third line of the blurb; generally dynamic (it is passed
|
---|
706 | * to update_evalcall_form() every time).
|
---|
707 | * @param max_val The maximum amount of progress (number of filesets, etc.)
|
---|
708 | */
|
---|
709 | void
|
---|
710 | open_progress_form(char *title, char *b1, char *b2, char *b3,
|
---|
711 | long max_val) {
|
---|
712 |
|
---|
713 | /*@ buffers ********************************************************* */
|
---|
714 | char *b1c;
|
---|
715 | char *blurb1;
|
---|
716 | char *blurb2;
|
---|
717 | char *blurb3;
|
---|
718 |
|
---|
719 | /*@ initialize ****************************************************** */
|
---|
720 | g_mysterious_dot_counter = 0;
|
---|
721 |
|
---|
722 | malloc_string(b1c);
|
---|
723 | malloc_string(blurb1);
|
---|
724 | malloc_string(blurb2);
|
---|
725 | malloc_string(blurb3);
|
---|
726 |
|
---|
727 | assert(title != NULL);
|
---|
728 | assert(b1 != NULL);
|
---|
729 | assert(b2 != NULL);
|
---|
730 | assert(b3 != NULL);
|
---|
731 |
|
---|
732 | strcpy(blurb1, b1);
|
---|
733 | strcpy(blurb2, b2);
|
---|
734 | strcpy(blurb3, b3);
|
---|
735 | strcpy(b1c, b1);
|
---|
736 | center_string(b1c, 80);
|
---|
737 | if (max_val <= 0) {
|
---|
738 | max_val = 1;
|
---|
739 | }
|
---|
740 |
|
---|
741 | g_start_time = get_time();
|
---|
742 | g_maximum_progress = max_val;
|
---|
743 | g_current_progress = 0;
|
---|
744 | strcpy(g_blurb_str_1, blurb1);
|
---|
745 | strcpy(g_blurb_str_2, blurb3);
|
---|
746 | strcpy(g_blurb_str_3, blurb2);
|
---|
747 | if (g_text_mode) {
|
---|
748 | log_msg(0, blurb1);
|
---|
749 | log_msg(0, blurb2);
|
---|
750 | log_msg(0, blurb3);
|
---|
751 | } else {
|
---|
752 | g_blurb1 = newtLabel(2, 1, blurb1);
|
---|
753 | g_blurb2 = newtLabel(2, 2, blurb3);
|
---|
754 | g_blurb3 = newtLabel(2, 4, blurb2);
|
---|
755 | // newtOpenWindow (10, 4, 60, 11, title);
|
---|
756 | newtCenteredWindow(60, 11, title);
|
---|
757 | g_scale = newtScale(3, 6, 54, g_maximum_progress);
|
---|
758 | g_progressForm = newtForm(NULL, NULL, 0);
|
---|
759 | g_percentline = newtLabel(10, 9, "This is the percentline");
|
---|
760 | g_timeline = newtLabel(10, 8, "This is the timeline");
|
---|
761 | newtFormAddComponents(g_progressForm, g_percentline,
|
---|
762 | g_timeline, g_scale, g_blurb1, g_blurb3,
|
---|
763 | g_blurb2, NULL);
|
---|
764 | newtPushHelpLine(b1c);
|
---|
765 | newtRefresh();
|
---|
766 | }
|
---|
767 | update_progress_form_full(blurb1, blurb2, blurb3);
|
---|
768 | paranoid_free(b1c);
|
---|
769 | paranoid_free(blurb1);
|
---|
770 | paranoid_free(blurb2);
|
---|
771 | paranoid_free(blurb3);
|
---|
772 | }
|
---|
773 |
|
---|
774 | /**
|
---|
775 | * Give a message to the user in the form of a dialog box (under Newt).
|
---|
776 | * @param prompt The message.
|
---|
777 | */
|
---|
778 | void
|
---|
779 | popup_and_OK(char *prompt) {
|
---|
780 | char ch;
|
---|
781 |
|
---|
782 | assert_string_is_neither_NULL_nor_zerolength(prompt);
|
---|
783 |
|
---|
784 | log_msg(0, prompt);
|
---|
785 | if (g_text_mode) {
|
---|
786 | printf
|
---|
787 | ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ",
|
---|
788 | prompt);
|
---|
789 | while (((ch = getchar()) != '\n') && (ch != EOF));
|
---|
790 | } else {
|
---|
791 | (void) popup_with_buttons(prompt, " OK ", "");
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * Ask the user to enter a value.
|
---|
797 | * @param title The title of the dialog box.
|
---|
798 | * @param b The blurb (e.g. what you want the user to enter).
|
---|
799 | * @param output The string to put the user's answer in.
|
---|
800 | * @param maxsize The size in bytes allocated to @p output.
|
---|
801 | * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
|
---|
802 | */
|
---|
803 | bool popup_and_get_string(char *title, char *b, char *output,
|
---|
804 | int maxsize) {
|
---|
805 |
|
---|
806 | /*@ newt ************************************************************ */
|
---|
807 | newtComponent myForm;
|
---|
808 | newtComponent b_1;
|
---|
809 | newtComponent b_2;
|
---|
810 | newtComponent b_res;
|
---|
811 | newtComponent text;
|
---|
812 | newtComponent type_here;
|
---|
813 |
|
---|
814 | /*@ pointers ********************************************************* */
|
---|
815 | char *entry_value;
|
---|
816 |
|
---|
817 | /*@ buffers ********************************************************** */
|
---|
818 | char *blurb;
|
---|
819 | char *original_contents;
|
---|
820 |
|
---|
821 | blurb = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
822 | original_contents = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
823 | assert_string_is_neither_NULL_nor_zerolength(title);
|
---|
824 | assert(b != NULL);
|
---|
825 | assert(output != NULL);
|
---|
826 |
|
---|
827 | if (g_text_mode) {
|
---|
828 | printf
|
---|
829 | ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ",
|
---|
830 | title, b);
|
---|
831 | (void) fgets(output, maxsize, stdin);
|
---|
832 | if (output[strlen(output) - 1] == '\n')
|
---|
833 | output[strlen(output) - 1] = '\0';
|
---|
834 | paranoid_free(blurb);
|
---|
835 | paranoid_free(original_contents);
|
---|
836 | return (TRUE);
|
---|
837 | }
|
---|
838 | strcpy(blurb, b);
|
---|
839 | text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
|
---|
840 | strcpy(original_contents, output);
|
---|
841 | output[0] = '\0';
|
---|
842 | type_here =
|
---|
843 | newtEntry(2, newtTextboxGetNumLines(text) + 2,
|
---|
844 | original_contents, 50,
|
---|
845 | #ifdef __cplusplus
|
---|
846 | 0, NEWT_FLAG_RETURNEXIT
|
---|
847 | #else
|
---|
848 | (void *) &entry_value, NEWT_FLAG_RETURNEXIT
|
---|
849 | #endif
|
---|
850 | );
|
---|
851 | b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, " OK ");
|
---|
852 | b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
|
---|
853 | // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
|
---|
854 | newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
|
---|
855 | myForm = newtForm(NULL, NULL, 0);
|
---|
856 | newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
|
---|
857 | center_string(blurb, 80);
|
---|
858 | newtPushHelpLine(blurb);
|
---|
859 | b_res = newtRunForm(myForm);
|
---|
860 | strcpy(output, entry_value);
|
---|
861 | newtPopHelpLine();
|
---|
862 | newtFormDestroy(myForm);
|
---|
863 | newtPopWindow();
|
---|
864 | if (b_res == b_2) {
|
---|
865 | strcpy(output, original_contents);
|
---|
866 | paranoid_free(blurb);
|
---|
867 | paranoid_free(original_contents);
|
---|
868 | return (FALSE);
|
---|
869 | } else {
|
---|
870 | paranoid_free(blurb);
|
---|
871 | paranoid_free(original_contents);
|
---|
872 | return (TRUE);
|
---|
873 | }
|
---|
874 | }
|
---|
875 |
|
---|
876 |
|
---|
877 | /**
|
---|
878 | * Pop up a dialog box with user-defined buttons.
|
---|
879 | * @param p The text to put in the dialog box.
|
---|
880 | * @param button1 The label on the first button.
|
---|
881 | * @param button2 The label on the second button, or "" if you only want one button.
|
---|
882 | * @return TRUE if @p button1 was pushed, FALSE otherwise.
|
---|
883 | */
|
---|
884 | bool popup_with_buttons(char *p, char *button1, char *button2) {
|
---|
885 |
|
---|
886 | /*@ buffers *********************************************************** */
|
---|
887 | char *prompt, *tmp;
|
---|
888 |
|
---|
889 | /*@ newt ************************************************************** */
|
---|
890 | newtComponent myForm;
|
---|
891 | newtComponent b_1;
|
---|
892 | newtComponent b_2;
|
---|
893 | newtComponent b_res;
|
---|
894 | newtComponent text;
|
---|
895 |
|
---|
896 | prompt = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
897 | tmp = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
898 | assert_string_is_neither_NULL_nor_zerolength(p);
|
---|
899 | assert(button1 != NULL);
|
---|
900 | assert(button2 != NULL);
|
---|
901 | if (g_text_mode) {
|
---|
902 | if (strlen(button2) == 0) {
|
---|
903 | printf("%s (%s) --> ", p, button1);
|
---|
904 | } else {
|
---|
905 | printf("%s (%s or %s) --> ", p, button1, button2);
|
---|
906 | }
|
---|
907 | for (tmp[0] = '\0';
|
---|
908 | strcmp(tmp, button1) && (strlen(button2) == 0
|
---|
909 | || strcmp(tmp, button2));) {
|
---|
910 | printf("--> ");
|
---|
911 | (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
|
---|
912 | }
|
---|
913 | if (!strcmp(tmp, button1)) {
|
---|
914 | paranoid_free(tmp);
|
---|
915 | paranoid_free(prompt);
|
---|
916 | return (TRUE);
|
---|
917 | } else {
|
---|
918 | paranoid_free(tmp);
|
---|
919 | paranoid_free(prompt);
|
---|
920 | return (FALSE);
|
---|
921 | }
|
---|
922 | }
|
---|
923 |
|
---|
924 | strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1);
|
---|
925 | prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0';
|
---|
926 | text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
|
---|
927 | b_1 =
|
---|
928 | newtButton(20 -
|
---|
929 | ((button2[0] !=
|
---|
930 | '\0') ? strlen(button1) +
|
---|
931 | 2 : strlen(button1) / 2),
|
---|
932 | newtTextboxGetNumLines(text) + 3, button1);
|
---|
933 | if (button2[0] != '\0') {
|
---|
934 | b_2 =
|
---|
935 | newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
|
---|
936 | } else {
|
---|
937 | b_2 = NULL;
|
---|
938 | }
|
---|
939 | // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
|
---|
940 | newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert");
|
---|
941 | myForm = newtForm(NULL, NULL, 0);
|
---|
942 | newtFormAddComponents(myForm, text, b_1, b_2, NULL);
|
---|
943 | center_string(prompt, 80);
|
---|
944 | newtPushHelpLine(prompt);
|
---|
945 | b_res = newtRunForm(myForm);
|
---|
946 | newtPopHelpLine();
|
---|
947 | newtFormDestroy(myForm);
|
---|
948 | newtPopWindow();
|
---|
949 | if (b_res == b_1) {
|
---|
950 | paranoid_free(tmp);
|
---|
951 | paranoid_free(prompt);
|
---|
952 | return (TRUE);
|
---|
953 | } else {
|
---|
954 | paranoid_free(tmp);
|
---|
955 | paranoid_free(prompt);
|
---|
956 | return (FALSE);
|
---|
957 | }
|
---|
958 | }
|
---|
959 |
|
---|
960 |
|
---|
961 |
|
---|
962 |
|
---|
963 | /**
|
---|
964 | * Synchronize the log messages stored in @p err_log_lines with those shown
|
---|
965 | * on the screen.
|
---|
966 | */
|
---|
967 | void
|
---|
968 | refresh_log_screen() {
|
---|
969 |
|
---|
970 | /*@ int *********************************************************** */
|
---|
971 | int i = 0;
|
---|
972 |
|
---|
973 |
|
---|
974 | if (g_text_mode || !err_log_lines) {
|
---|
975 | return;
|
---|
976 | }
|
---|
977 | for (i = g_noof_log_lines - 1; i >= 0; i--) {
|
---|
978 | newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
|
---|
979 | " ");
|
---|
980 | }
|
---|
981 | newtRefresh();
|
---|
982 | for (i = g_noof_log_lines - 1; i >= 0; i--) {
|
---|
983 | err_log_lines[i][79] = '\0';
|
---|
984 | newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
|
---|
985 | err_log_lines[i]);
|
---|
986 | }
|
---|
987 | newtRefresh();
|
---|
988 | }
|
---|
989 |
|
---|
990 |
|
---|
991 | /**
|
---|
992 | * Set up the Newt graphical environment. If @p g_text_mode is TRUE, then
|
---|
993 | * only allocate some memory.
|
---|
994 | */
|
---|
995 | void
|
---|
996 | setup_newt_stuff() {
|
---|
997 |
|
---|
998 | /*@ int *********************************************************** */
|
---|
999 | int i = 0;
|
---|
1000 | int cols;
|
---|
1001 |
|
---|
1002 | if (!g_text_mode) {
|
---|
1003 | newtInit();
|
---|
1004 | newtCls();
|
---|
1005 | newtPushHelpLine
|
---|
1006 | ("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed.");
|
---|
1007 | /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
|
---|
1008 | newtDrawRootText(18, 0, WELCOME_STRING);
|
---|
1009 | newtRefresh();
|
---|
1010 | newtGetScreenSize(&cols, &g_noof_rows);
|
---|
1011 | g_noof_log_lines = (g_noof_rows / 5) + 1;
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | err_log_lines =
|
---|
1015 | (char **) malloc(sizeof(char *) * g_noof_log_lines);
|
---|
1016 | if (!err_log_lines) {
|
---|
1017 | fatal_error("Out of memory");
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | for (i = 0; i < g_noof_log_lines; i++) {
|
---|
1021 | err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1022 | if (!err_log_lines[i]) {
|
---|
1023 | fatal_error("Out of memory");
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | for (i = 0; i < g_noof_log_lines; i++) {
|
---|
1028 | err_log_lines[i][0] = '\0';
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 |
|
---|
1033 | /**
|
---|
1034 | * Update the evalcall form to show (<tt>num</tt>/<tt>denom</tt>)*100 %.
|
---|
1035 | * @param num The numerator of the ratio.
|
---|
1036 | * @param denom The denomenator of the ratio.
|
---|
1037 | */
|
---|
1038 | void
|
---|
1039 | update_evalcall_form_ratio(int num, int denom) {
|
---|
1040 |
|
---|
1041 | /*@ long ************************************************************ */
|
---|
1042 | long current_time = 0;
|
---|
1043 | long time_taken = 0;
|
---|
1044 | long time_total_est = 0;
|
---|
1045 | long time_remaining = 0;
|
---|
1046 |
|
---|
1047 | /*@ buffers ********************************************************** */
|
---|
1048 | char *timeline_str;
|
---|
1049 | char *pcline_str;
|
---|
1050 | char *taskprogress;
|
---|
1051 |
|
---|
1052 | /*@ int ************************************************************** */
|
---|
1053 | int percentage = 0;
|
---|
1054 | int i = 0;
|
---|
1055 | int j = 0;
|
---|
1056 |
|
---|
1057 | malloc_string(timeline_str);
|
---|
1058 | malloc_string(pcline_str);
|
---|
1059 | malloc_string(taskprogress);
|
---|
1060 | timeline_str[0] = '\0';
|
---|
1061 | // log_it("update_eval_call_form called");
|
---|
1062 | if (num * 100 < denom) {
|
---|
1063 | percentage = 1;
|
---|
1064 | } else {
|
---|
1065 | percentage = (num * 100 + denom / 2) / denom;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | current_time = get_time();
|
---|
1069 | time_taken = current_time - g_isoform_starttime;
|
---|
1070 | if (num) {
|
---|
1071 | time_total_est = time_taken * denom / num;
|
---|
1072 | time_remaining = time_total_est - time_taken;
|
---|
1073 | } else {
|
---|
1074 | time_remaining = 0;
|
---|
1075 | }
|
---|
1076 | if (!g_text_mode) {
|
---|
1077 | newtLabelSetText(g_isoform_header, g_isoform_header_str);
|
---|
1078 | }
|
---|
1079 | g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
|
---|
1080 | if ((percentage < 3 && g_isoform_old_progress < 3)
|
---|
1081 | || percentage > g_isoform_old_progress) {
|
---|
1082 | g_isoform_old_progress = percentage;
|
---|
1083 | sprintf(timeline_str,
|
---|
1084 | "%2ld:%02ld taken %2ld:%02ld remaining",
|
---|
1085 | time_taken / 60, time_taken % 60, time_remaining / 60,
|
---|
1086 | time_remaining % 60);
|
---|
1087 | if (percentage < 3) {
|
---|
1088 | sprintf(pcline_str, " Working");
|
---|
1089 | for (j = 0; j < g_mysterious_dot_counter; j++) {
|
---|
1090 | strcat(pcline_str, ".");
|
---|
1091 | }
|
---|
1092 | for (; j < 27; j++) {
|
---|
1093 | strcat(pcline_str, " ");
|
---|
1094 | }
|
---|
1095 | sprintf(pcline_str + strlen(pcline_str), " %c",
|
---|
1096 | special_dot_char(g_mysterious_dot_counter));
|
---|
1097 | } else {
|
---|
1098 | sprintf(pcline_str, " %3d%% done %3d%% to go",
|
---|
1099 | percentage, 100 - percentage);
|
---|
1100 | }
|
---|
1101 | if (g_text_mode) {
|
---|
1102 | sprintf(taskprogress, "TASK: [");
|
---|
1103 | for (i = 0; i < percentage; i += 5) {
|
---|
1104 | strcat(taskprogress, "*");
|
---|
1105 | }
|
---|
1106 | for (; i < 100; i += 5) {
|
---|
1107 | strcat(taskprogress, ".");
|
---|
1108 | }
|
---|
1109 | if (percentage >= 3) {
|
---|
1110 | sprintf(taskprogress + strlen(taskprogress),
|
---|
1111 | "] %3d%% done; %2ld:%02ld to go", percentage,
|
---|
1112 | time_remaining / 60, time_remaining % 60);
|
---|
1113 | printf("---evalcall---1--- %s\r\n",
|
---|
1114 | g_isoform_header_str);
|
---|
1115 | printf("---evalcall---2--- %s\r\n", taskprogress);
|
---|
1116 | printf("---evalcall---E---\r\n");
|
---|
1117 | }
|
---|
1118 | } else {
|
---|
1119 | newtScaleSet(g_isoform_scale,
|
---|
1120 | (unsigned long long) percentage);
|
---|
1121 | newtLabelSetText(g_isoform_pcline, pcline_str);
|
---|
1122 | if (percentage >= 3) {
|
---|
1123 | newtLabelSetText(g_isoform_timeline, timeline_str);
|
---|
1124 | }
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 | if (!g_text_mode) {
|
---|
1128 | // log_it("refreshing");
|
---|
1129 | newtRefresh();
|
---|
1130 | }
|
---|
1131 | paranoid_free(timeline_str);
|
---|
1132 | paranoid_free(pcline_str);
|
---|
1133 | paranoid_free(taskprogress);
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 |
|
---|
1137 |
|
---|
1138 | /**
|
---|
1139 | * Update the evalcall form to show @p curr %.
|
---|
1140 | * @param curr The current amount of progress (percentage) in the evalcall form.
|
---|
1141 | */
|
---|
1142 | void
|
---|
1143 | update_evalcall_form(int curr) {
|
---|
1144 | update_evalcall_form_ratio(curr, 100);
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 |
|
---|
1148 |
|
---|
1149 | /**
|
---|
1150 | * Update the progress form to show @p blurb3 and the current value of
|
---|
1151 | * @p g_maximum_progress.
|
---|
1152 | * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same.
|
---|
1153 | */
|
---|
1154 | void
|
---|
1155 | update_progress_form(char *blurb3) {
|
---|
1156 | /* log_it("update_progress_form --- called"); */
|
---|
1157 | if (g_current_progress == -999) {
|
---|
1158 | /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */
|
---|
1159 | return;
|
---|
1160 | }
|
---|
1161 | strcpy(g_blurb_str_2, blurb3);
|
---|
1162 | update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
|
---|
1163 | g_blurb_str_3);
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 |
|
---|
1167 | /**
|
---|
1168 | * Update the progress form's complete blurb and show @p g_current_progress.
|
---|
1169 | * @param blurb1 The first line of the blurb. Use @p g_blurb_str_1 to keep it unchanged.
|
---|
1170 | * @param blurb2 The second line of the blurb. Use @p g_blurb_str_3 (no, that's not a typo) to keep it the same.
|
---|
1171 | * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same.
|
---|
1172 | */
|
---|
1173 | void
|
---|
1174 | update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {
|
---|
1175 | /*@ long ***************************************************** */
|
---|
1176 | long current_time = 0;
|
---|
1177 | long time_taken = 0;
|
---|
1178 | long time_remaining = 0;
|
---|
1179 | long time_total_est = 0;
|
---|
1180 |
|
---|
1181 | /*@ int ******************************************************* */
|
---|
1182 | int percentage = 0;
|
---|
1183 | int i = 0;
|
---|
1184 |
|
---|
1185 | /*@ buffers *************************************************** */
|
---|
1186 | char *percentline_str;
|
---|
1187 | char *timeline_str;
|
---|
1188 | char *taskprogress;
|
---|
1189 | char *tmp;
|
---|
1190 |
|
---|
1191 | // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3);
|
---|
1192 | percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1193 | timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1194 | taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1195 | malloc_string(tmp);
|
---|
1196 | if (!g_text_mode) {
|
---|
1197 | assert(blurb1 != NULL);
|
---|
1198 | assert(blurb2 != NULL);
|
---|
1199 | assert(blurb3 != NULL);
|
---|
1200 | assert(g_timeline != NULL);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | percentline_str[0] = '\0';
|
---|
1204 |
|
---|
1205 | current_time = get_time();
|
---|
1206 | time_taken = current_time - g_start_time;
|
---|
1207 | if (g_maximum_progress == 0) {
|
---|
1208 | percentage = 0;
|
---|
1209 | } else {
|
---|
1210 | if (g_current_progress > g_maximum_progress) {
|
---|
1211 | sprintf(tmp,
|
---|
1212 | "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
|
---|
1213 | blurb1, blurb2, blurb3, g_current_progress,
|
---|
1214 | g_maximum_progress);
|
---|
1215 | log_msg(0, tmp);
|
---|
1216 | g_current_progress = g_maximum_progress;
|
---|
1217 | }
|
---|
1218 | percentage =
|
---|
1219 | (int) ((g_current_progress * 100L) / g_maximum_progress);
|
---|
1220 | }
|
---|
1221 | if (percentage < 1) {
|
---|
1222 | percentage = 1;
|
---|
1223 | }
|
---|
1224 | if (percentage > 100) {
|
---|
1225 | percentage = 100;
|
---|
1226 | }
|
---|
1227 | if (g_current_progress) {
|
---|
1228 | time_total_est =
|
---|
1229 | time_taken * (long) g_maximum_progress /
|
---|
1230 | (long) (g_current_progress);
|
---|
1231 | time_remaining = time_total_est - time_taken;
|
---|
1232 | } else {
|
---|
1233 | time_remaining = 0;
|
---|
1234 | }
|
---|
1235 | g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
|
---|
1236 | sprintf(timeline_str,
|
---|
1237 | "%2ld:%02ld taken %2ld:%02ld remaining ",
|
---|
1238 | time_taken / 60, time_taken % 60, time_remaining / 60,
|
---|
1239 | time_remaining % 60);
|
---|
1240 | sprintf(percentline_str, " %3d%% done %3d%% to go",
|
---|
1241 | percentage, 100 - percentage);
|
---|
1242 |
|
---|
1243 | if (g_text_mode) {
|
---|
1244 | printf("---progress-form---1--- %s\r\n", blurb1);
|
---|
1245 | printf("---progress-form---2--- %s\r\n", blurb2);
|
---|
1246 | printf("---progress-form---3--- %s\r\n", blurb3);
|
---|
1247 | printf("---progress-form---E---\n");
|
---|
1248 | sprintf(taskprogress, "TASK: [");
|
---|
1249 | for (i = 0; i < percentage; i += 5) {
|
---|
1250 | strcat(taskprogress, "*");
|
---|
1251 | }
|
---|
1252 | for (; i < 100; i += 5) {
|
---|
1253 | strcat(taskprogress, ".");
|
---|
1254 | }
|
---|
1255 | if (percentage > 100) {
|
---|
1256 | log_msg(2, "percentage = %d", percentage);
|
---|
1257 | }
|
---|
1258 | sprintf(taskprogress + strlen(taskprogress),
|
---|
1259 | "] %3d%c", percentage, '%');
|
---|
1260 | sprintf(taskprogress + strlen(taskprogress),
|
---|
1261 | " done; %2ld:%02ld to go",
|
---|
1262 | time_remaining / 60, time_remaining % 60);
|
---|
1263 | printf("---progress-form---4--- %s\r\n", taskprogress);
|
---|
1264 | } else {
|
---|
1265 | center_string(blurb1, 54);
|
---|
1266 | center_string(blurb2, 54);
|
---|
1267 | center_string(blurb3, 54);
|
---|
1268 | newtLabelSetText(g_blurb1, blurb1);
|
---|
1269 | newtLabelSetText(g_blurb2, blurb3);
|
---|
1270 | newtLabelSetText(g_blurb3, blurb2);
|
---|
1271 | newtScaleSet(g_scale, (unsigned long long) g_current_progress);
|
---|
1272 | if (percentage >= 2) {
|
---|
1273 | newtLabelSetText(g_timeline, timeline_str);
|
---|
1274 | }
|
---|
1275 | newtLabelSetText(g_percentline, percentline_str);
|
---|
1276 | newtRefresh();
|
---|
1277 | }
|
---|
1278 | paranoid_free(percentline_str);
|
---|
1279 | paranoid_free(timeline_str);
|
---|
1280 | paranoid_free(taskprogress);
|
---|
1281 | paranoid_free(tmp);
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 |
|
---|
1285 |
|
---|
1286 |
|
---|
1287 |
|
---|
1288 |
|
---|
1289 |
|
---|
1290 |
|
---|
1291 |
|
---|
1292 |
|
---|
1293 |
|
---|
1294 |
|
---|
1295 |
|
---|
1296 |
|
---|
1297 | /**
|
---|
1298 | * Ask the user which backup media type they would like to use.
|
---|
1299 | * The choices are @p none (exit to shell), @c cdr, @c cdrw, @c dvd,
|
---|
1300 | * @c tape, @c cdstream, @c udev (only when @p g_text_mode is TRUE), @c nfs,
|
---|
1301 | * and @c iso.
|
---|
1302 | * @param restoring TRUE if we're restoring, FALSE if we're backing up.
|
---|
1303 | * @return The backup type chosen, or @c none if the user chose "Exit to shell".
|
---|
1304 | */
|
---|
1305 | t_bkptype which_backup_media_type(bool restoring) {
|
---|
1306 |
|
---|
1307 | /*@ char ************************************************************ */
|
---|
1308 | t_bkptype output;
|
---|
1309 |
|
---|
1310 |
|
---|
1311 | /*@ newt ************************************************************ */
|
---|
1312 | char *title_sz;
|
---|
1313 | char *minimsg_sz;
|
---|
1314 | static t_bkptype possible_bkptypes[] =
|
---|
1315 | { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso };
|
---|
1316 | static char *possible_responses[] =
|
---|
1317 | { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
|
---|
1318 | "nfs", "iso", NULL };
|
---|
1319 | char *outstr;
|
---|
1320 | t_bkptype backup_type;
|
---|
1321 | int i;
|
---|
1322 |
|
---|
1323 | newtComponent b1;
|
---|
1324 | newtComponent b2;
|
---|
1325 | newtComponent b3;
|
---|
1326 | newtComponent b4;
|
---|
1327 | newtComponent b5;
|
---|
1328 | newtComponent b6;
|
---|
1329 | newtComponent b7;
|
---|
1330 | newtComponent b8;
|
---|
1331 | newtComponent b_res;
|
---|
1332 | newtComponent myForm;
|
---|
1333 |
|
---|
1334 | title_sz = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1335 | minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1336 | outstr = malloc(MAX_NEWT_COMMENT_LEN);
|
---|
1337 | if (g_text_mode) {
|
---|
1338 | for (backup_type = none; backup_type == none;) {
|
---|
1339 | printf("Backup type (");
|
---|
1340 | for (i = 0; possible_responses[i]; i++) {
|
---|
1341 | printf("%c%s", (i == 0) ? '\0' : ' ',
|
---|
1342 | possible_responses[i]);
|
---|
1343 | }
|
---|
1344 | printf(")\n--> ");
|
---|
1345 | (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
|
---|
1346 | strip_spaces(outstr);
|
---|
1347 | for (i = 0; possible_responses[i]; i++) {
|
---|
1348 | if (!strcmp(possible_responses[i], outstr)) {
|
---|
1349 | backup_type = possible_bkptypes[i];
|
---|
1350 | }
|
---|
1351 | }
|
---|
1352 | }
|
---|
1353 | paranoid_free(title_sz);
|
---|
1354 | paranoid_free(minimsg_sz);
|
---|
1355 | paranoid_free(outstr);
|
---|
1356 | return (backup_type);
|
---|
1357 | }
|
---|
1358 | newtDrawRootText(18, 0, WELCOME_STRING);
|
---|
1359 | if (restoring) {
|
---|
1360 | strcpy(title_sz,
|
---|
1361 | "Please choose the backup media from which you want to read data.");
|
---|
1362 | strcpy(minimsg_sz, "Read from:");
|
---|
1363 | } else {
|
---|
1364 | strcpy(title_sz,
|
---|
1365 | "Please choose the backup media to which you want to archive data.");
|
---|
1366 | strcpy(minimsg_sz, "Backup to:");
|
---|
1367 | }
|
---|
1368 | newtPushHelpLine(title_sz);
|
---|
1369 | // newtOpenWindow (23, 3, 34, 17, minimsg_sz);
|
---|
1370 | newtCenteredWindow(34, 17, minimsg_sz);
|
---|
1371 | b1 = newtButton(1, 1, "CD-R disks ");
|
---|
1372 | b2 = newtButton(17, 1, "CD-RW disks");
|
---|
1373 | b3 = newtButton(1, 9, "Tape drive ");
|
---|
1374 | b4 = newtButton(17, 5, "USB Key/Disk");
|
---|
1375 | b5 = newtButton(1, 5, " DVD disks ");
|
---|
1376 | b6 = newtButton(17, 9, " NFS mount ");
|
---|
1377 | b7 = newtButton(1, 13, " Hard disk ");
|
---|
1378 | b8 = newtButton(17, 13, " Exit ");
|
---|
1379 | myForm = newtForm(NULL, NULL, 0);
|
---|
1380 | newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8,
|
---|
1381 | NULL);
|
---|
1382 | b_res = newtRunForm(myForm);
|
---|
1383 | newtFormDestroy(myForm);
|
---|
1384 | newtPopWindow();
|
---|
1385 | if (b_res == b1) {
|
---|
1386 | output = cdr;
|
---|
1387 | } else if (b_res == b2) {
|
---|
1388 | output = cdrw;
|
---|
1389 | } else if (b_res == b3) {
|
---|
1390 | output = tape;
|
---|
1391 | } else if (b_res == b4) {
|
---|
1392 | output = usb;
|
---|
1393 | } else if (b_res == b5) {
|
---|
1394 | output = dvd;
|
---|
1395 | } else if (b_res == b6) {
|
---|
1396 | output = nfs;
|
---|
1397 | } else if (b_res == b7) {
|
---|
1398 | output = iso;
|
---|
1399 | } else {
|
---|
1400 | output = none;
|
---|
1401 | }
|
---|
1402 | newtPopHelpLine();
|
---|
1403 | paranoid_free(title_sz);
|
---|
1404 | paranoid_free(minimsg_sz);
|
---|
1405 | paranoid_free(outstr);
|
---|
1406 | return (output);
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 |
|
---|
1410 |
|
---|
1411 |
|
---|
1412 | /**
|
---|
1413 | * Ask the user how much compression they would like to use.
|
---|
1414 | * The choices are "None" (0), "Minimum" (1), "Average" (4), and "Maximum" (9).
|
---|
1415 | * @return The compression level (0-9) chosen, or -1 for "Exit".
|
---|
1416 | */
|
---|
1417 | int
|
---|
1418 | which_compression_level() {
|
---|
1419 |
|
---|
1420 | /*@ char ************************************************************ */
|
---|
1421 | int output = none;
|
---|
1422 |
|
---|
1423 |
|
---|
1424 | /*@ newt ************************************************************ */
|
---|
1425 |
|
---|
1426 | newtComponent b1;
|
---|
1427 | newtComponent b2;
|
---|
1428 | newtComponent b3;
|
---|
1429 | newtComponent b4;
|
---|
1430 | newtComponent b5;
|
---|
1431 | newtComponent b_res;
|
---|
1432 | newtComponent myForm;
|
---|
1433 |
|
---|
1434 | newtDrawRootText(18, 0, WELCOME_STRING);
|
---|
1435 | newtPushHelpLine
|
---|
1436 | (" Please specify the level of compression that you want.");
|
---|
1437 | // newtOpenWindow (23, 3, 34, 13, "How much compression?");
|
---|
1438 | newtCenteredWindow(34, 13, "How much compression?");
|
---|
1439 | b1 = newtButton(4, 1, "Maximum");
|
---|
1440 | b2 = newtButton(18, 1, "Average");
|
---|
1441 | b3 = newtButton(4, 5, "Minimum");
|
---|
1442 | b4 = newtButton(18, 5, " None ");
|
---|
1443 | b5 = newtButton(4, 9, " Exit ");
|
---|
1444 | myForm = newtForm(NULL, NULL, 0);
|
---|
1445 | newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL);
|
---|
1446 | b_res = newtRunForm(myForm);
|
---|
1447 | newtFormDestroy(myForm);
|
---|
1448 | newtPopWindow();
|
---|
1449 | if (b_res == b1) {
|
---|
1450 | output = 9;
|
---|
1451 | } else if (b_res == b2) {
|
---|
1452 | output = 4;
|
---|
1453 | } else if (b_res == b3) {
|
---|
1454 | output = 1;
|
---|
1455 | } else if (b_res == b4) {
|
---|
1456 | output = 0;
|
---|
1457 | } else if (b_res == b5) {
|
---|
1458 | output = -1;
|
---|
1459 | }
|
---|
1460 | newtPopHelpLine();
|
---|
1461 | return (output);
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 |
|
---|
1465 |
|
---|
1466 |
|
---|
1467 |
|
---|
1468 | /**
|
---|
1469 | * Load @p source_file (a list of files) into @p filelist. There can be no more than
|
---|
1470 | * @p ARBITRARY_MAXIMUM entries.
|
---|
1471 | * @param filelist The filelist structure to load @p source_file into.
|
---|
1472 | * @param source_file The file containing a list of filenames to load into @p filelist.
|
---|
1473 | */
|
---|
1474 | int load_filelist_into_array(struct s_filelist *filelist,
|
---|
1475 | char *source_file) {
|
---|
1476 | int i;
|
---|
1477 | int j = 0;
|
---|
1478 | bool done;
|
---|
1479 | char *tmp;
|
---|
1480 | char *tmp1 = NULL;
|
---|
1481 | FILE *fin, *fout;
|
---|
1482 | struct s_filelist_entry dummy_fle;
|
---|
1483 |
|
---|
1484 | assert(filelist != NULL);
|
---|
1485 | assert_string_is_neither_NULL_nor_zerolength(source_file);
|
---|
1486 |
|
---|
1487 | iamhere("entering");
|
---|
1488 | if (!(fin = fopen(source_file, "r"))) {
|
---|
1489 | log_OS_error(source_file);
|
---|
1490 | log_msg(2, "Can't open %s; therefore, cannot popup list",
|
---|
1491 | source_file);
|
---|
1492 | return (1);
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | asprintf(&tmp1,"%s/icantfindthesefiles.txt",bkpinfo->tmpdir);
|
---|
1496 | if (!(fout = fopen(tmp1, "a"))) {
|
---|
1497 | log_msg(2, "Can't write to %s", tmp1);
|
---|
1498 | return(1);
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | malloc_string(tmp);
|
---|
1502 | log_msg(2, "Loading %s", source_file);
|
---|
1503 | for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
|
---|
1504 | filelist->entries++) {
|
---|
1505 | god_i_hate_gotos:
|
---|
1506 | if (feof(fin)) {
|
---|
1507 | break;
|
---|
1508 | }
|
---|
1509 | (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
|
---|
1510 | i = (int) strlen(tmp);
|
---|
1511 | if (i < 2) {
|
---|
1512 | goto god_i_hate_gotos;
|
---|
1513 | }
|
---|
1514 | if (tmp[i - 1] < 32) {
|
---|
1515 | tmp[--i] = '\0';
|
---|
1516 | }
|
---|
1517 | if (i < 2) {
|
---|
1518 | goto god_i_hate_gotos;
|
---|
1519 | }
|
---|
1520 | if (!does_file_exist(tmp) && !feof(fin)) {
|
---|
1521 | j++;
|
---|
1522 | fprintf(fout, "%s\n", tmp);
|
---|
1523 |
|
---|
1524 | goto god_i_hate_gotos;
|
---|
1525 | }
|
---|
1526 | filelist->el[filelist->entries].severity =
|
---|
1527 | severity_of_difference(tmp, NULL);
|
---|
1528 | strcpy(filelist->el[filelist->entries].filename, tmp);
|
---|
1529 | if (feof(fin)) {
|
---|
1530 | break;
|
---|
1531 | }
|
---|
1532 | }
|
---|
1533 | paranoid_fclose(fin);
|
---|
1534 | paranoid_fclose(fout);
|
---|
1535 | if (j > 0) {
|
---|
1536 | log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1);
|
---|
1537 | }
|
---|
1538 | paranoid_free(tmp1);
|
---|
1539 | if (filelist->entries >= ARBITRARY_MAXIMUM) {
|
---|
1540 | log_to_screen("Arbitrary limits suck, man!");
|
---|
1541 | paranoid_free(tmp);
|
---|
1542 | return (1);
|
---|
1543 | }
|
---|
1544 | for (done = FALSE; !done;) {
|
---|
1545 | done = TRUE;
|
---|
1546 | for (i = 0; i < filelist->entries - 1; i++) {
|
---|
1547 | // if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0)
|
---|
1548 | if (filelist->el[i].severity < filelist->el[i + 1].severity
|
---|
1549 | || (filelist->el[i].severity ==
|
---|
1550 | filelist->el[i + 1].severity
|
---|
1551 | && strcmp(filelist->el[i].filename,
|
---|
1552 | filelist->el[i + 1].filename) > 0)) {
|
---|
1553 | memcpy((void *) &dummy_fle,
|
---|
1554 | (void *) &(filelist->el[i]),
|
---|
1555 | sizeof(struct s_filelist_entry));
|
---|
1556 | memcpy((void *) &(filelist->el[i]),
|
---|
1557 | (void *) &(filelist->el[i + 1]),
|
---|
1558 | sizeof(struct s_filelist_entry));
|
---|
1559 | memcpy((void *) &(filelist->el[i + 1]),
|
---|
1560 | (void *) &dummy_fle,
|
---|
1561 | sizeof(struct s_filelist_entry));
|
---|
1562 | log_msg(2, "Swapping %s and %s",
|
---|
1563 | filelist->el[i].filename,
|
---|
1564 | filelist->el[i + 1].filename);
|
---|
1565 | done = FALSE;
|
---|
1566 | }
|
---|
1567 | }
|
---|
1568 | }
|
---|
1569 | paranoid_free(tmp);
|
---|
1570 | iamhere("leaving");
|
---|
1571 | return (0);
|
---|
1572 | }
|
---|
1573 |
|
---|
1574 |
|
---|
1575 |
|
---|
1576 | /**
|
---|
1577 | * Generate a pretty string based on @p flentry.
|
---|
1578 | * @param flentry The filelist entry to stringify.
|
---|
1579 | * @return The string form of @p flentry.
|
---|
1580 | * @note The returned value points to static storage that will be overwritten with each call.
|
---|
1581 | */
|
---|
1582 | char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
|
---|
1583 | static char comment[100];
|
---|
1584 | char *tmp;
|
---|
1585 |
|
---|
1586 | iamhere("entering");
|
---|
1587 | malloc_string(tmp);
|
---|
1588 | assert(flentry != NULL);
|
---|
1589 | if (flentry->severity == 0) {
|
---|
1590 | strcpy(tmp, "0 ");
|
---|
1591 | } else if (flentry->severity == 1) {
|
---|
1592 | strcpy(tmp, "low ");
|
---|
1593 | } else if (flentry->severity == 2) {
|
---|
1594 | strcpy(tmp, "med ");
|
---|
1595 | } else {
|
---|
1596 | strcpy(tmp, "high");
|
---|
1597 | }
|
---|
1598 | strcat(tmp, " ");
|
---|
1599 | strncat(tmp, flentry->filename, 100);
|
---|
1600 | tmp[98] = '\0';
|
---|
1601 | strcpy(comment, tmp);
|
---|
1602 | paranoid_free(tmp);
|
---|
1603 | iamhere("leaving");
|
---|
1604 | return (comment);
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 |
|
---|
1608 |
|
---|
1609 |
|
---|
1610 |
|
---|
1611 | /**
|
---|
1612 | * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the
|
---|
1613 | * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file.
|
---|
1614 | * @param source_file The file containing a list of changed files.
|
---|
1615 | */
|
---|
1616 | void popup_changelist_from_file(char *source_file) {
|
---|
1617 | char *reason;
|
---|
1618 | newtComponent myForm;
|
---|
1619 | newtComponent bClose;
|
---|
1620 | newtComponent bSelect;
|
---|
1621 | newtComponent b_res;
|
---|
1622 | newtComponent fileListbox;
|
---|
1623 | newtComponent headerMsg;
|
---|
1624 |
|
---|
1625 | /*@ ???? ************************************************************ */
|
---|
1626 | void *curr_choice;
|
---|
1627 | void *keylist[ARBITRARY_MAXIMUM];
|
---|
1628 |
|
---|
1629 | /*@ int ************************************************************* */
|
---|
1630 | int currline = 0;
|
---|
1631 | int finished = FALSE;
|
---|
1632 |
|
---|
1633 | /*@ long ************************************************************ */
|
---|
1634 | long i = 0;
|
---|
1635 | long lng = 0;
|
---|
1636 |
|
---|
1637 | /*@ buffers ********************************************************* */
|
---|
1638 | char *tmp;
|
---|
1639 | char *differ_sz;
|
---|
1640 |
|
---|
1641 | struct s_filelist *filelist;
|
---|
1642 | malloc_string(reason);
|
---|
1643 | tmp = malloc(5000);
|
---|
1644 | malloc_string(differ_sz);
|
---|
1645 | assert_string_is_neither_NULL_nor_zerolength(source_file);
|
---|
1646 | if (g_text_mode) {
|
---|
1647 | log_msg(2, "Text mode. Therefore, no popup list.");
|
---|
1648 | goto free_to_go;
|
---|
1649 | }
|
---|
1650 | log_msg(2, "Examining file %s", source_file);
|
---|
1651 |
|
---|
1652 | lng = count_lines_in_file(source_file);
|
---|
1653 | if (lng < 1) {
|
---|
1654 | log_msg(2, "No lines in file. Therefore, no popup list.");
|
---|
1655 | paranoid_free(reason);
|
---|
1656 | goto free_to_go;
|
---|
1657 | } else if (lng >= ARBITRARY_MAXIMUM) {
|
---|
1658 | log_msg(2, "Too many files differ for me to list.");
|
---|
1659 | goto free_to_go;
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
|
---|
1663 | fileListbox =
|
---|
1664 | newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
|
---|
1665 | newtListboxClear(fileListbox);
|
---|
1666 |
|
---|
1667 | if (load_filelist_into_array(filelist, source_file)) {
|
---|
1668 | log_msg(2, "Can't open %s; therefore, cannot popup list",
|
---|
1669 | source_file);
|
---|
1670 | paranoid_free(reason);
|
---|
1671 | return;
|
---|
1672 | }
|
---|
1673 | log_msg(2, "%d files loaded into filelist array",
|
---|
1674 | filelist->entries);
|
---|
1675 | for (i = 0; i < filelist->entries; i++) {
|
---|
1676 | keylist[i] = (void *) i;
|
---|
1677 | newtListboxAppendEntry(fileListbox,
|
---|
1678 | filelist_entry_to_string(&
|
---|
1679 | (filelist->
|
---|
1680 | el[i])),
|
---|
1681 | keylist[i]);
|
---|
1682 | }
|
---|
1683 | sprintf(differ_sz,
|
---|
1684 | " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
|
---|
1685 | i);
|
---|
1686 | newtPushHelpLine(differ_sz);
|
---|
1687 | bClose = newtCompactButton(10, 15, " Close ");
|
---|
1688 | bSelect = newtCompactButton(30, 15, " Select ");
|
---|
1689 | sprintf(tmp, "%-10s %-20s", "Priority", "Filename");
|
---|
1690 | headerMsg = newtLabel(2, 1, tmp);
|
---|
1691 | newtOpenWindow(5, 4, 70, 16, "Non-matching files");
|
---|
1692 | myForm = newtForm(NULL, NULL, 0);
|
---|
1693 | newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
|
---|
1694 | bSelect, NULL);
|
---|
1695 | while (!finished) {
|
---|
1696 | b_res = newtRunForm(myForm);
|
---|
1697 | if (b_res == bClose) {
|
---|
1698 | finished = TRUE;
|
---|
1699 | } else {
|
---|
1700 | curr_choice = newtListboxGetCurrent(fileListbox);
|
---|
1701 | for (i = 0;
|
---|
1702 | i < filelist->entries && keylist[i] != curr_choice;
|
---|
1703 | i++);
|
---|
1704 | if (i == filelist->entries && filelist->entries > 0) {
|
---|
1705 | log_to_screen("I don't know what that button does!");
|
---|
1706 | } else {
|
---|
1707 | currline = i;
|
---|
1708 | if (filelist->entries > 0) {
|
---|
1709 | severity_of_difference(filelist->el[currline].
|
---|
1710 | filename, reason);
|
---|
1711 | sprintf(tmp, "%s --- %s",
|
---|
1712 | filelist->el[currline].filename, reason);
|
---|
1713 | popup_and_OK(tmp);
|
---|
1714 | }
|
---|
1715 | }
|
---|
1716 | }
|
---|
1717 | }
|
---|
1718 | newtFormDestroy(myForm);
|
---|
1719 | newtPopWindow();
|
---|
1720 | newtPopHelpLine();
|
---|
1721 | free_to_go:
|
---|
1722 | paranoid_free(reason);
|
---|
1723 | paranoid_free(tmp);
|
---|
1724 | paranoid_free(differ_sz);
|
---|
1725 | return;
|
---|
1726 | }
|
---|
1727 |
|
---|
1728 | /* @} - end of guiGroup */
|
---|
1729 |
|
---|
1730 |
|
---|
1731 | #if __cplusplus
|
---|
1732 | } /* extern "C" */
|
---|
1733 | #endif
|
---|
1734 |
|
---|
1735 |
|
---|
1736 | void wait_until_software_raids_are_prepped(char *mdstat_file,
|
---|
1737 | int wait_for_percentage);
|
---|