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