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