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