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