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