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