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