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