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