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