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