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