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