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