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