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