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