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