source: MondoRescue/branches/stable/mondo/src/common/newt-specific.c@ 1670

Last change on this file since 1670 was 1670, checked in by Bruno Cornec, 17 years ago
  • Try to fix the issue with large exclude list (> 1000 chars) Some variables created after exclude_path (indirectly) were not sized big enough to handle them.
  • Remove useless .keep file
  • remove temporary.iso name remaining and suppress a warning in log trying to remove it in the tmpdir
  • missing extern bkpinfo in newt-specific.c
  • Attempt to fix #191 (allow edition of mountlist in compare mode)

(merge -r1662:1669 $SVN_M/branches/2.2.5)

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