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