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