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