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

Last change on this file since 502 was 502, checked in by bcornec, 18 years ago

Internationalization: gettextize is an unfriendly tool that you can't invoke non-interactively.
So we now copy it, hack it to make it non-interactive, and run it, then delete it.
Everything in bootstrap.
Should end the Internationalization patch integration

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