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