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