Changeset 3192 in MondoRescue for branches/3.0/mondo/src/common/newt-specific.c
- Timestamp:
- Sep 25, 2013, 9:03:25 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/newt-specific.c
r3188 r3192 97 97 extern int g_current_media_number; 98 98 pid_t g_main_pid = 0; ///< The PID of the main Mondo process. 99 long g_maximum_progress = 999 L; ///< The maximum amount of progress (100%) for the currently opened progress form.99 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form. 100 100 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form. 101 long g_start_time = 0 L; ///< The time (in seconds since the epoch) that the progress form was opened.101 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened. 102 102 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 103 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo. 104 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo. 105 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo. 103 106 char *g_selfmounted_isodir; ///< Holds the NETFS mountpoint if mounted via mondoarchive. 104 107 105 108 /* @} - end of globalGroup */ 109 110 //int g_fd_in=-1, g_fd_out=-1; 106 111 107 112 void popup_and_OK(char *); … … 120 125 121 126 /*@ buffers ********************************************************** */ 122 int i = 0;123 char * tmp = NULL;127 int i; 128 char *p; 124 129 125 130 assert_string_is_neither_NULL_nor_zerolength(prompt); … … 131 136 } 132 137 if (g_text_mode) { 138 139 char *tmp; 140 tmp = malloc(MAX_NEWT_COMMENT_LEN); 141 133 142 while (1) { 134 sync(); 135 printf("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", prompt); 136 mr_getline(tmp, stdin); 143 paranoid_system("sync"); 144 printf 145 ("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", 146 prompt); 147 p= fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 148 if (!p) { 149 //FIXME 150 } 137 151 if (tmp[strlen(tmp) - 1] == '\n') 138 152 tmp[strlen(tmp) - 1] = '\0'; … … 143 157 } 144 158 if (strstr("yesYES", tmp)) { 145 mr_free(tmp);159 paranoid_free(tmp); 146 160 return (TRUE); 147 161 } else if (strstr("NOno", tmp)) { 148 mr_free(tmp);162 paranoid_free(tmp); 149 163 return (FALSE); 150 164 } else { 151 sync(); 152 printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 165 paranoid_system("sync"); 166 printf 167 ("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 153 168 } 154 169 } … … 168 183 169 184 /*@ buffer *********************************************************** */ 170 char *tmp = NULL; 185 char *tmp; 186 char *p; 171 187 int i; 172 188 … … 177 193 finish(1); 178 194 } 179 195 tmp = malloc(MAX_NEWT_COMMENT_LEN); 180 196 if (g_text_mode) { 181 sync(); 182 printf("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", prompt); 183 mr_getline(tmp, stdin); 197 paranoid_system("sync"); 198 printf 199 ("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", 200 prompt); 201 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 202 if (!p) { 203 // FIXME 204 } 184 205 if (tmp[strlen(tmp) - 1] == '\n') 185 206 tmp[strlen(tmp) - 1] = '\0'; … … 190 211 } 191 212 if (strstr("okOKOkYESyes", tmp)) { 192 mr_free(tmp);213 paranoid_free(tmp); 193 214 return (TRUE); 194 215 } else { 195 mr_free(tmp);216 paranoid_free(tmp); 196 217 return (FALSE); 197 218 } 198 219 } else { 220 paranoid_free(tmp); 199 221 return (popup_with_buttons(prompt, " Okay ", "Cancel")); 200 222 } … … 242 264 } 243 265 if (g_current_progress == -999) { 244 log_msg(2, "Trying to close the progress form when it ain't open!"); 266 log_msg(2, 267 "Trying to close the progress form when it ain't open!"); 245 268 return; 246 269 } … … 278 301 mr_asprintf(tmp1,"kill `%s`", tmp); 279 302 run_program_and_log_output(tmp1, TRUE); 280 mr_free(tmp1);281 } 282 mr_free(tmp);303 paranoid_free(tmp1); 304 } 305 paranoid_free(tmp); 283 306 } 284 307 … … 289 312 * @note This function never returns. 290 313 */ 291 void fatal_error(char *error_string) { 292 314 void 315 fatal_error(char *error_string) { 293 316 /*@ buffers ***************************************************** */ 294 char *command = NULL; 317 char fatalstr[MAX_NEWT_COMMENT_LEN] = 318 "-------FATAL ERROR---------"; 319 char *tmp; 320 char *command; 295 321 static bool already_exiting = FALSE; 296 322 297 323 /*@ end vars **************************************************** */ 298 324 325 malloc_string(command); 326 tmp = malloc(MAX_NEWT_COMMENT_LEN); 299 327 set_signals(FALSE); // link to external func 300 328 g_exiting = TRUE; … … 304 332 log_msg(2, "mastermind %d is exiting", (int) getpid()); 305 333 kill(g_main_pid, SIGTERM); 334 paranoid_free(tmp); 306 335 finish(1); 307 336 } … … 311 340 log_msg(2, "non-m/m %d is exiting", (int) getpid()); 312 341 kill(g_main_pid, SIGTERM); 342 paranoid_free(tmp); 313 343 finish(1); 314 344 } … … 318 348 if (already_exiting) { 319 349 log_msg(3, "...I'm already exiting. Give me time, Julian!"); 350 paranoid_free(tmp); 320 351 finish(1); 321 352 } … … 328 359 kill_anything_like_this("ntfsclone"); 329 360 sync(); 361 /* 362 sprintf(tmp, "umount %s", g_tmpfs_mountpt); 363 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) { 364 log_msg(2, "Waiting for child processes to terminate"); 365 sleep(1); 366 run_program_and_log_output(tmp, 5); 367 } 368 */ 330 369 331 370 if (chdir("/")) { … … 333 372 } 334 373 if (g_selfmounted_isodir) { 335 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir);374 sprintf(command, "umount -d %s", g_selfmounted_isodir); 336 375 run_program_and_log_output(command, 5); 337 mr_free(command); 338 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 376 sprintf(command, "rmdir %s", g_selfmounted_isodir); 339 377 run_program_and_log_output(command, 5); 340 mr_free(command);341 378 } 342 379 343 380 if (!g_text_mode) { 344 log_msg(0, "-------FATAL ERROR---------");381 log_msg(0, fatalstr); 345 382 log_msg(0, error_string); 383 // popup_and_OK (error_string); 384 newtFinished(); 346 385 } 347 386 348 387 printf("---FATALERROR--- %s\n", error_string); 349 printf("If you require technical support, please contact the mailing list.\n"); 388 printf 389 ("If you require technical support, please contact the mailing list.\n"); 350 390 printf("See http://www.mondorescue.org for details.\n"); 351 printf("The list's members can help you, if you attach that file to your e-mail.\n"); 391 printf 392 ("The list's members can help you, if you attach that file to your e-mail.\n"); 352 393 printf("Log file: %s\n", MONDO_LOGFILE); 353 394 printf("Mondo has aborted.\n"); … … 355 396 log_msg(3, "FYI - g_main_pid is blank"); 356 397 } 398 paranoid_free(tmp); 399 paranoid_free(command); 357 400 finish(254); 358 401 } … … 377 420 * @note This function never returns. 378 421 */ 379 void finish(int signal) { 380 422 void 423 finish(int signal) { 381 424 char *command = NULL; 425 426 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */ 427 428 /* newtPopHelpLine(); */ 382 429 383 430 /* Before removing dir, make sure we're out of them */ … … 389 436 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir); 390 437 run_program_and_log_output(command, 1); 391 mr_free(command); 392 438 paranoid_free(command); 393 439 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 394 440 run_program_and_log_output(command, 1); 395 mr_free(command); 396 } 441 paranoid_free(command); 442 } 443 if (!g_text_mode) { 444 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 445 log_msg(1, "Calling newtFinished()"); 446 newtFinished(); 447 } else { 448 log_msg(1, "Calling newtSuspend()"); 449 newtSuspend(); 450 } 451 } 452 printf("Execution run ended; result=%d\n", signal); 453 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 397 454 if (bkpinfo->tmpdir) { 398 455 log_msg(8,"tempdir is %s",bkpinfo->tmpdir); … … 419 476 mr_free(bkpinfo->exclude_paths); 420 477 mr_free(bkpinfo->subdir); 478 421 479 /* Then free the structure */ 422 480 paranoid_free(bkpinfo); 423 424 481 free_libmondo_global_strings(); 425 482 free_newt_stuff(); 426 if (!g_text_mode) {427 if (does_file_exist("/THIS-IS-A-RAMDISK")) {428 log_msg(1, "Calling newtFinished()");429 newtFinished();430 } else {431 log_msg(1, "Calling newtSuspend()");432 newtSuspend();433 }434 }435 printf("Execution run ended; result=%d\n", signal);436 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);437 483 exit(signal); 438 484 } 485 486 487 439 488 440 489 … … 445 494 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression. 446 495 */ 447 void log_file_end_to_screen(char *filename, char *grep_for_me) { 496 void 497 log_file_end_to_screen(char *filename, char *grep_for_me) { 448 498 449 499 /*@ buffers ********************************************************** */ … … 465 515 } 466 516 if (grep_for_me[0] != '\0') { 467 mr_asprintf(command, "grep '%s' %s | tail -n%d", grep_for_me, filename, g_noof_log_lines); 468 } else { 469 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, filename); 517 mr_asprintf(command, "grep '%s' %s | tail -n%d", 518 grep_for_me, filename, g_noof_log_lines); 519 } else { 520 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, 521 filename); 470 522 } 471 523 fin = popen(command, "r"); … … 505 557 * @note The message is also written to the logfile. 506 558 */ 507 void log_to_screen(const char *fmt, ...) { 559 void 560 log_to_screen(const char *fmt, ...) { 508 561 509 562 /*@ int ************************************************************** */ … … 561 614 * @param output The string to write. 562 615 */ 563 void mvaddstr_and_log_it(int y, int x, char *output) { 564 616 void 617 mvaddstr_and_log_it(int y, int x, char *output) { 565 618 assert_string_is_neither_NULL_nor_zerolength(output); 566 619 log_msg(0, output); … … 580 633 * @param ttl The title to use for the evalcall form. 581 634 */ 582 void open_evalcall_form(char *ttl) { 635 void 636 open_evalcall_form(char *ttl) { 583 637 584 638 /*@ buffers ********************************************************* */ 585 char *tmp = NULL; 639 char *title; 640 char *tmp; 586 641 587 642 /*@ initialize ****************************************************** */ 588 643 g_isoform_old_progress = -1; 589 644 g_mysterious_dot_counter = 0; 645 malloc_string(title); 646 malloc_string(tmp); 590 647 591 648 assert(ttl != NULL); 592 malloc_string(tmp); 593 strcpy(g_isoform_header_str, ttl); 649 strcpy(title, ttl); 650 strcpy(g_isoform_header_str, title); 651 // center_string (title, 80); 594 652 if (g_text_mode) { 595 log_msg(0, t tl);596 } else { 597 strcpy(tmp, t tl);653 log_msg(0, title); 654 } else { 655 strcpy(tmp, title); 598 656 center_string(tmp, 80); 599 657 newtPushHelpLine(tmp); … … 606 664 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 607 665 g_isoform_scale = newtScale(3, 3, 34, 100); 608 newtCenteredWindow(40, 7, ttl); 666 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 667 newtCenteredWindow(40, 7, title); 609 668 g_isoform_main = newtForm(NULL, NULL, 0); 610 669 g_isoform_timeline = newtLabel(1, 5, " "); … … 618 677 update_evalcall_form(0); 619 678 paranoid_free(tmp); 679 paranoid_free(title); 620 680 } 621 681 … … 631 691 * @param max_val The maximum amount of progress (number of filesets, etc.) 632 692 */ 633 void open_progress_form(char *title, char *b1, char *b2, char *b3, long max_val) { 693 void 694 open_progress_form(char *title, char *b1, char *b2, char *b3, 695 long max_val) { 634 696 635 697 /*@ buffers ********************************************************* */ 636 698 char *b1c; 637 char *blurb1 = NULL;638 char *blurb2 = NULL;639 char *blurb3 = NULL;699 char *blurb1; 700 char *blurb2; 701 char *blurb3; 640 702 641 703 /*@ initialize ****************************************************** */ … … 643 705 644 706 malloc_string(b1c); 707 malloc_string(blurb1); 708 malloc_string(blurb2); 709 malloc_string(blurb3); 645 710 646 711 assert(title != NULL); … … 649 714 assert(b3 != NULL); 650 715 651 mr_asprintf(blurb1, "%s", b1); 652 mr_asprintf(blurb2, "%s", b2); 653 mr_asprintf(blurb3, "%s", b3); 654 716 strcpy(blurb1, b1); 717 strcpy(blurb2, b2); 718 strcpy(blurb3, b3); 655 719 strcpy(b1c, b1); 656 720 center_string(b1c, 80); … … 673 737 g_blurb2 = newtLabel(2, 2, blurb3); 674 738 g_blurb3 = newtLabel(2, 4, blurb2); 739 // newtOpenWindow (10, 4, 60, 11, title); 675 740 newtCenteredWindow(60, 11, title); 676 g_scale = newtScale(3, 6, 54, (long long)g_maximum_progress);741 g_scale = newtScale(3, 6, 54, g_maximum_progress); 677 742 g_progressForm = newtForm(NULL, NULL, 0); 678 743 g_percentline = newtLabel(10, 9, " "); 679 744 g_timeline = newtLabel(10, 8, " "); 680 newtFormAddComponents(g_progressForm, g_percentline, g_timeline, g_scale, g_blurb1, g_blurb3, g_blurb2, NULL); 745 newtFormAddComponents(g_progressForm, g_percentline, 746 g_timeline, g_scale, g_blurb1, g_blurb3, 747 g_blurb2, NULL); 681 748 newtPushHelpLine(b1c); 682 749 newtDrawForm(g_progressForm); … … 685 752 update_progress_form_full(blurb1, blurb2, blurb3); 686 753 paranoid_free(b1c); 687 mr_free(blurb1);688 mr_free(blurb2);689 mr_free(blurb3);754 paranoid_free(blurb1); 755 paranoid_free(blurb2); 756 paranoid_free(blurb3); 690 757 } 691 758 … … 694 761 * @param prompt The message. 695 762 */ 696 void popup_and_OK(char *prompt) { 697 763 void 764 popup_and_OK(char *prompt) { 698 765 char ch; 699 766 … … 702 769 log_msg(0, prompt); 703 770 if (g_text_mode) { 704 printf("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", prompt); 771 printf 772 ("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", 773 prompt); 705 774 while (((ch = getchar()) != '\n') && (ch != EOF)); 706 775 } else { … … 717 786 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 718 787 */ 719 bool popup_and_get_string(char *title, char *b, char *output, int maxsize) { 788 bool popup_and_get_string(char *title, char *b, char *output, 789 int maxsize) { 720 790 721 791 /*@ newt ************************************************************ */ … … 731 801 732 802 /*@ buffers ********************************************************** */ 733 char *blurb = NULL;803 char *blurb; 734 804 char *p; 735 char *original_contents = NULL; 736 805 char *original_contents; 806 807 blurb = malloc(MAX_NEWT_COMMENT_LEN); 808 original_contents = malloc(MAX_NEWT_COMMENT_LEN); 737 809 assert_string_is_neither_NULL_nor_zerolength(title); 738 810 assert(b != NULL); … … 740 812 741 813 if (g_text_mode) { 742 printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", title, b); 814 printf 815 ("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", 816 title, b); 743 817 p = fgets(output, maxsize, stdin); 744 818 if (!p) { … … 747 821 if (output[strlen(output) - 1] == '\n') 748 822 output[strlen(output) - 1] = '\0'; 823 paranoid_free(blurb); 824 paranoid_free(original_contents); 749 825 return (TRUE); 750 826 } 751 752 blurb = malloc(MAX_NEWT_COMMENT_LEN);753 827 strcpy(blurb, b); 754 828 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 755 mr_asprintf(original_contents, "%s", output);829 strcpy(original_contents, output); 756 830 output[0] = '\0'; 757 type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, original_contents, 50, 831 type_here = 832 newtEntry(2, newtTextboxGetNumLines(text) + 2, 833 original_contents, 50, 758 834 #ifdef __cplusplus 759 835 0, NEWT_FLAG_RETURNEXIT … … 764 840 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, " OK "); 765 841 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel"); 842 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title); 766 843 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 767 844 myForm = newtForm(NULL, NULL, 0); … … 774 851 newtFormDestroy(myForm); 775 852 newtPopWindow(); 776 paranoid_free(blurb);777 778 853 if (b_res == b_2) { 779 854 strcpy(output, original_contents); 780 mr_free(original_contents); 855 paranoid_free(blurb); 856 paranoid_free(original_contents); 781 857 return (FALSE); 782 858 } else { 783 mr_free(original_contents); 859 paranoid_free(blurb); 860 paranoid_free(original_contents); 784 861 return (TRUE); 785 862 } … … 794 871 * @return TRUE if @p button1 was pushed, FALSE otherwise. 795 872 */ 796 bool popup_with_buttons(char *p, char *button1, char *button2) {873 bool popup_with_buttons(char *p, char *button1, char *button2) { 797 874 798 875 /*@ buffers *********************************************************** */ 799 char *prompt = NULL; 876 char *prompt; 877 char *q; 800 878 801 879 /*@ newt ************************************************************** */ … … 809 887 assert(button1 != NULL); 810 888 assert(button2 != NULL); 889 prompt = malloc(MAX_NEWT_COMMENT_LEN); 811 890 if (g_text_mode) { 812 891 if (strlen(button2) == 0) { … … 815 894 printf("%s (%s or %s) --> ", p, button1, button2); 816 895 } 817 mr_getline(prompt, stdin); 818 while (strcmp(prompt, button1) && (strlen(button2) == 0 || strcmp(prompt, button2))) { 896 for (prompt[0] = '\0'; 897 strcmp(prompt, button1) && (strlen(button2) == 0 898 || strcmp(prompt, button2));) { 819 899 printf("--> "); 820 mr_free(prompt); 821 mr_getline(prompt, stdin); 900 q = fgets(prompt, MAX_NEWT_COMMENT_LEN, stdin); 901 if (!q) { 902 // FIXME 903 } 822 904 } 823 905 if (!strcmp(prompt, button1)) { 824 mr_free(prompt);906 paranoid_free(prompt); 825 907 return (TRUE); 826 908 } else { 827 mr_free(prompt);909 paranoid_free(prompt); 828 910 return (FALSE); 829 911 } 830 912 } 831 913 832 prompt = malloc(MAX_NEWT_COMMENT_LEN);833 914 strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1); 834 915 prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0'; 835 916 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 836 b_1 = newtButton(20 - ((button2[0] != '\0') ? strlen(button1) + 2 : strlen(button1) / 2), newtTextboxGetNumLines(text) + 3, button1); 917 b_1 = 918 newtButton(20 - 919 ((button2[0] != 920 '\0') ? strlen(button1) + 921 2 : strlen(button1) / 2), 922 newtTextboxGetNumLines(text) + 3, button1); 837 923 if (button2[0] != '\0') { 838 b_2 = newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 924 b_2 = 925 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 839 926 } else { 840 927 b_2 = NULL; 841 928 } 929 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 842 930 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert"); 843 931 myForm = newtForm(NULL, NULL, 0); … … 865 953 * on the screen. 866 954 */ 867 void refresh_log_screen() { 955 void 956 refresh_log_screen() { 868 957 869 958 /*@ int *********************************************************** */ … … 892 981 * only allocate some memory. 893 982 */ 894 void setup_newt_stuff() { 983 void 984 setup_newt_stuff() { 895 985 896 986 /*@ int *********************************************************** */ … … 901 991 newtInit(); 902 992 newtCls(); 903 newtPushHelpLine("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 993 newtPushHelpLine 994 ("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 995 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 904 996 newtDrawRootText(18, 0, WELCOME_STRING); 905 997 newtRefresh(); … … 908 1000 } 909 1001 910 err_log_lines = (char **) mr_malloc(sizeof(char *) * g_noof_log_lines); 1002 err_log_lines = 1003 (char **) malloc(sizeof(char *) * g_noof_log_lines); 1004 if (!err_log_lines) { 1005 fatal_error("Out of memory"); 1006 } 911 1007 912 1008 for (i = 0; i < g_noof_log_lines; i++) { 913 err_log_lines[i] = (char *) mr_malloc(MAX_NEWT_COMMENT_LEN); 1009 err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN); 1010 if (!err_log_lines[i]) { 1011 fatal_error("Out of memory"); 1012 } 914 1013 } 915 1014 … … 925 1024 * @param denom The denomenator of the ratio. 926 1025 */ 927 void update_evalcall_form_ratio(int num, int denom) { 1026 void 1027 update_evalcall_form_ratio(int num, int denom) { 928 1028 929 1029 /*@ long ************************************************************ */ 930 long current_time = 0 L;931 long time_taken = 0 L;932 long time_total_est = 0 L;933 long time_remaining = 0 L;1030 long current_time = 0; 1031 long time_taken = 0; 1032 long time_total_est = 0; 1033 long time_remaining = 0; 934 1034 935 1035 /*@ buffers ********************************************************** */ 936 char *timeline_str = NULL;1036 char *timeline_str; 937 1037 char *pcline_str = NULL; 938 1038 char *taskprogress = NULL; … … 943 1043 int j = 0; 944 1044 1045 malloc_string(timeline_str); 1046 timeline_str[0] = '\0'; 1047 // log_it("update_eval_call_form called"); 945 1048 if (num * 100 < denom) { 946 1049 percentage = 1; … … 955 1058 time_remaining = time_total_est - time_taken; 956 1059 } else { 957 time_remaining = 0 L;1060 time_remaining = 0; 958 1061 } 959 1062 if (!g_text_mode) { … … 966 1069 || percentage > g_isoform_old_progress) { 967 1070 g_isoform_old_progress = percentage; 968 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60); 1071 sprintf(timeline_str, 1072 "%2ld:%02ld taken %2ld:%02ld remaining", 1073 (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, 1074 (long) time_remaining % 60); 969 1075 if (percentage < 3) { 970 1076 mr_asprintf(pcline_str, " Working"); … … 977 1083 mr_strcat(pcline_str, " %c", special_dot_char(g_mysterious_dot_counter)); 978 1084 } else { 979 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); 1085 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", 1086 percentage, 100 - percentage); 980 1087 } 981 1088 if (g_text_mode) { … … 988 1095 } 989 1096 if (percentage >= 3) { 990 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 991 printf("---evalcall---1--- %s\n", g_isoform_header_str); 1097 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1098 (long) time_remaining / 60, (long) time_remaining % 60); 1099 printf("---evalcall---1--- %s\n", 1100 g_isoform_header_str); 992 1101 printf("---evalcall---2--- %s\n", taskprogress); 993 1102 printf("---evalcall---E---\n"); 994 1103 } 995 mr_free(taskprogress);1104 paranoid_free(taskprogress); 996 1105 } else { 997 newtScaleSet(g_isoform_scale, (unsigned long long) percentage); 1106 newtScaleSet(g_isoform_scale, 1107 (unsigned long long) percentage); 998 1108 if (g_isoform_pcline) { 999 1109 newtLabelSetText(g_isoform_pcline, pcline_str); … … 1003 1113 } 1004 1114 } 1005 mr_free(pcline_str); 1006 mr_free(timeline_str); 1115 paranoid_free(pcline_str); 1007 1116 } 1008 1117 if (!g_text_mode) { 1118 // log_it("refreshing"); 1009 1119 newtDrawForm(g_isoform_main); 1010 1120 newtRefresh(); 1011 1121 } 1122 paranoid_free(timeline_str); 1012 1123 } 1013 1124 … … 1018 1129 * @param curr The current amount of progress (percentage) in the evalcall form. 1019 1130 */ 1020 void update_evalcall_form(int curr) { 1021 1131 void 1132 update_evalcall_form(int curr) { 1022 1133 update_evalcall_form_ratio(curr, 100); 1023 }1134 } 1024 1135 1025 1136 … … 1030 1141 * @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. 1031 1142 */ 1032 void update_progress_form(char *blurb3) { 1033 1143 void 1144 update_progress_form(char *blurb3) { 1145 /* log_it("update_progress_form --- called"); */ 1034 1146 if (g_current_progress == -999) { 1147 /* 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."); */ 1035 1148 return; 1036 1149 } 1037 1150 strcpy(g_blurb_str_2, blurb3); 1038 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, g_blurb_str_3); 1039 } 1151 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1152 g_blurb_str_3); 1153 } 1040 1154 1041 1155 … … 1046 1160 * @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. 1047 1161 */ 1048 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1049 1162 void 1163 update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1050 1164 /*@ long ***************************************************** */ 1051 1165 long current_time = 0L; … … 1059 1173 1060 1174 /*@ buffers *************************************************** */ 1061 char *percentline_str = NULL;1062 char *timeline_str = NULL;1175 char *percentline_str; 1176 char *timeline_str; 1063 1177 char *taskprogress = NULL; 1064 1178 char *tmp; 1179 1180 // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1181 percentline_str = malloc(MAX_NEWT_COMMENT_LEN); 1182 timeline_str = malloc(MAX_NEWT_COMMENT_LEN); 1183 malloc_string(tmp); 1065 1184 if (!g_text_mode) { 1066 1185 assert(blurb1 != NULL); … … 1070 1189 } 1071 1190 1191 percentline_str[0] = '\0'; 1192 1072 1193 current_time = get_time(); 1073 1194 time_taken = current_time - g_start_time; … … 1076 1197 } else { 1077 1198 if (g_current_progress > g_maximum_progress) { 1078 log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress); 1199 sprintf(tmp, 1200 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1201 blurb1, blurb2, blurb3, g_current_progress, 1202 g_maximum_progress); 1203 log_msg(0, tmp); 1079 1204 g_current_progress = g_maximum_progress; 1080 1205 } 1081 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); 1206 percentage = 1207 (int) ((g_current_progress * 100L) / g_maximum_progress); 1082 1208 } 1083 1209 if (percentage < 1) { … … 1088 1214 } 1089 1215 if (g_current_progress) { 1090 time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress; 1216 time_total_est = 1217 time_taken * (long) g_maximum_progress / 1218 (long) (g_current_progress); 1091 1219 time_remaining = time_total_est - time_taken; 1092 1220 } else { … … 1094 1222 } 1095 1223 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1224 sprintf(timeline_str, 1225 "%2ld:%02ld taken %2ld:%02ld remaining ", 1226 (long) time_taken / 60, time_taken % 60, time_remaining / 60, 1227 time_remaining % 60); 1228 sprintf(percentline_str, " %3d%% done %3d%% to go", 1229 percentage, 100 - percentage); 1230 1096 1231 if (g_text_mode) { 1097 1232 printf("---progress-form---1--- %s\n", blurb1); … … 1109 1244 log_msg(2, "percentage = %d", percentage); 1110 1245 } 1111 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 1246 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1247 (long) time_remaining / 60, (long) time_remaining % 60); 1112 1248 printf("---progress-form---4--- %s\n", taskprogress); 1113 1249 paranoid_free(taskprogress); 1114 1250 } else { 1115 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60);1116 mr_asprintf(percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage);1117 1118 1251 center_string(blurb1, 54); 1119 1252 center_string(blurb2, 54); … … 1132 1265 newtLabelSetText(g_timeline, timeline_str); 1133 1266 } 1134 mr_free(timeline_str);1135 1136 1267 if (g_percentline) { 1137 1268 newtLabelSetText(g_percentline, percentline_str); 1138 1269 } 1139 mr_free(percentline_str);1140 1141 1270 newtDrawForm(g_progressForm); 1142 1271 newtRefresh(); 1143 1272 } 1144 } 1273 paranoid_free(percentline_str); 1274 paranoid_free(timeline_str); 1275 paranoid_free(tmp); 1276 } 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1145 1289 1146 1290 … … 1153 1297 * @return The backup type chosen, or @c none if the user chose "Exit to shell". 1154 1298 */ 1155 t_bkptype which_backup_media_type(bool restoring) {1299 t_bkptype which_backup_media_type(bool restoring) { 1156 1300 1157 1301 /*@ char ************************************************************ */ … … 1160 1304 1161 1305 /*@ newt ************************************************************ */ 1162 char *title_sz = NULL; 1163 char *minimsg_sz = NULL; 1164 static t_bkptype possible_bkptypes[] = { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1165 static char *possible_responses[] = { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "netfs", "iso", NULL }; 1166 char *outstr = NULL; 1306 char *title_sz; 1307 char *minimsg_sz; 1308 static t_bkptype possible_bkptypes[] = 1309 { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1310 static char *possible_responses[] = 1311 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1312 "netfs", "iso", NULL }; 1313 char *outstr; 1314 char *p; 1167 1315 t_bkptype backup_type; 1168 1316 int i; … … 1179 1327 newtComponent myForm; 1180 1328 1329 title_sz = malloc(MAX_NEWT_COMMENT_LEN); 1330 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN); 1331 outstr = malloc(MAX_NEWT_COMMENT_LEN); 1181 1332 if (g_text_mode) { 1182 1333 for (backup_type = none; backup_type == none;) { … … 1187 1338 } 1188 1339 printf(")\n--> "); 1189 mr_getline(outstr, stdin); 1190 mr_strip_spaces(outstr); 1340 p = fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin); 1341 if (!p) { 1342 // FIXME 1343 } 1344 strip_spaces(outstr); 1191 1345 for (i = 0; possible_responses[i]; i++) { 1192 1346 if (!strcmp(possible_responses[i], outstr)) { … … 1194 1348 } 1195 1349 } 1196 mr_free(outstr); 1197 } 1350 } 1351 paranoid_free(title_sz); 1352 paranoid_free(minimsg_sz); 1353 paranoid_free(outstr); 1198 1354 return (backup_type); 1199 1355 } 1200 1356 newtDrawRootText(18, 0, WELCOME_STRING); 1201 1357 if (restoring) { 1202 mr_asprintf(title_sz, "Please choose the backup media from which you want to read data."); 1203 mr_asprintf(minimsg_sz, "Read from:"); 1204 } else { 1205 mr_asprintf(title_sz, "Please choose the backup media to which you want to archive data."); 1206 mr_asprintf(minimsg_sz, "Backup to:"); 1358 strcpy(title_sz, 1359 "Please choose the backup media from which you want to read data."); 1360 strcpy(minimsg_sz, "Read from:"); 1361 } else { 1362 strcpy(title_sz, 1363 "Please choose the backup media to which you want to archive data."); 1364 strcpy(minimsg_sz, "Backup to:"); 1207 1365 } 1208 1366 newtPushHelpLine(title_sz); 1367 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); 1209 1368 newtCenteredWindow(34, 17, minimsg_sz); 1210 1369 b1 = newtButton(1, 1, "CD-R disks "); … … 1240 1399 } 1241 1400 newtPopHelpLine(); 1242 mr_free(title_sz); 1243 mr_free(minimsg_sz); 1401 paranoid_free(title_sz); 1402 paranoid_free(minimsg_sz); 1403 paranoid_free(outstr); 1244 1404 return (output); 1245 1405 } … … 1263 1423 newtComponent b2; 1264 1424 newtComponent b3; 1265 newtComponent b4;1425 //newtComponent b4; 1266 1426 newtComponent b5; 1267 1427 newtComponent b_res; … … 1275 1435 b2 = newtButton(18, 1, "gzip"); 1276 1436 b3 = newtButton(4, 5, "lzo"); 1277 b4 = newtButton(18, 5, "lzma");1437 //b4 = newtButton(18, 5, "lzma"); 1278 1438 b5 = newtButton(4, 9, " Exit "); 1279 1439 myForm = newtForm(NULL, NULL, 0); … … 1288 1448 } else if (b_res == b3) { 1289 1449 mr_asprintf(output, "%s", "lzo"); 1290 } else if (b_res == b4) {1291 mr_asprintf(output, "%s", "lzma");1450 //} else if (b_res == b4) { 1451 //mr_asprintf(output, "%s", "lzma"); 1292 1452 } 1293 1453 newtPopHelpLine(); … … 1301 1461 * @return The compression level (0-9) chosen, or -1 for "Exit". 1302 1462 */ 1303 int which_compression_level() { 1463 int 1464 which_compression_level() { 1304 1465 1305 1466 /*@ char ************************************************************ */ … … 1318 1479 1319 1480 newtDrawRootText(18, 0, WELCOME_STRING); 1320 newtPushHelpLine(" Please specify the level of compression that you want."); 1481 newtPushHelpLine 1482 (" Please specify the level of compression that you want."); 1483 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1321 1484 newtCenteredWindow(34, 13, "How much compression?"); 1322 1485 b1 = newtButton(4, 1, "Maximum (9)"); … … 1355 1518 * @param source_file The file containing a list of filenames to load into @p filelist. 1356 1519 */ 1357 int load_filelist_into_array(struct s_filelist *filelist, char *source_file) { 1358 1520 int load_filelist_into_array(struct s_filelist *filelist, 1521 char *source_file) { 1359 1522 int i; 1360 1523 int j = 0; 1361 1524 bool done; 1362 char *tmp = NULL; 1525 char *tmp; 1526 char *p; 1363 1527 char *tmp1 = NULL; 1364 1528 FILE *fin, *fout; … … 1379 1543 if (!(fout = fopen(tmp1, "a"))) { 1380 1544 log_msg(2, "Can't write to %s", tmp1); 1381 mr_free(tmp1);1382 1545 return(1); 1383 1546 } 1384 1547 1548 malloc_string(tmp); 1385 1549 log_msg(2, "Loading %s", source_file); 1386 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; ) { 1387 mr_free(tmp); 1550 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1551 filelist->entries++) { 1552 god_i_hate_gotos: 1388 1553 if (feof(fin)) { 1389 1554 break; 1390 1555 } 1391 mr_getline(tmp, fin); 1556 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, fin); 1557 if (!p) { 1558 // FIXME 1559 } 1392 1560 i = (int) strlen(tmp); 1393 1561 if (i < 2) { 1394 continue;1562 goto god_i_hate_gotos; 1395 1563 } 1396 1564 if (tmp[i - 1] < 32) { … … 1398 1566 } 1399 1567 if (i < 2) { 1400 continue;1568 goto god_i_hate_gotos; 1401 1569 } 1402 1570 if (!does_file_exist(tmp) && !feof(fin)) { 1403 1571 j++; 1404 1572 fprintf(fout, "%s\n", tmp); 1405 continue; 1406 } 1407 filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL); 1573 1574 goto god_i_hate_gotos; 1575 } 1576 filelist->el[filelist->entries].severity = 1577 severity_of_difference(tmp, NULL); 1408 1578 strcpy(filelist->el[filelist->entries].filename, tmp); 1409 1579 if (feof(fin)) { 1410 1580 break; 1411 1581 } 1412 filelist->entries++; 1413 } 1414 mr_free(tmp); 1582 } 1415 1583 paranoid_fclose(fin); 1416 1584 paranoid_fclose(fout); … … 1418 1586 log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1); 1419 1587 } 1420 mr_free(tmp1);1588 paranoid_free(tmp1); 1421 1589 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1422 1590 log_to_screen("Arbitrary limits suck, man!"); 1591 paranoid_free(tmp); 1423 1592 return (1); 1424 1593 } … … 1448 1617 } 1449 1618 } 1619 paranoid_free(tmp); 1450 1620 log_it("leaving"); 1451 1621 return (0); 1452 1622 } 1623 1453 1624 1454 1625 … … 1459 1630 * @note The returned value points to static storage that will be overwritten with each call. 1460 1631 */ 1461 char *filelist_entry_to_string(struct s_filelist_entry *flentry) {1632 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1462 1633 static char comment[100]; 1463 1634 char *tmp = NULL; 1464 1635 1465 log_ msg(8,"entering");1636 log_it("entering"); 1466 1637 assert(flentry != NULL); 1467 1638 if (flentry->severity == 0) { … … 1477 1648 mr_strcat(tmp, flentry->filename); 1478 1649 strncpy(comment, tmp, 99); 1479 mr_free(tmp);1650 paranoid_free(tmp); 1480 1651 1481 1652 log_it("leaving"); 1482 1653 return (comment); 1483 1654 } 1655 1656 1657 1484 1658 1485 1659 … … 1489 1663 * @param source_file The file containing a list of changed files. 1490 1664 */ 1491 void popup_changelist_from_file(char *source_file) { 1492 1493 char *reason = NULL; 1665 void popup_changelist_from_file(char *source_file) { 1666 char *reason; 1494 1667 newtComponent myForm; 1495 1668 newtComponent bClose; … … 1512 1685 1513 1686 /*@ buffers ********************************************************* */ 1514 char *tmp = NULL;1515 char *differ_sz = NULL;1687 char *tmp; 1688 char *differ_sz; 1516 1689 1517 1690 struct s_filelist *filelist; 1691 malloc_string(reason); 1692 tmp = malloc(5000); 1693 malloc_string(differ_sz); 1518 1694 assert_string_is_neither_NULL_nor_zerolength(source_file); 1519 1695 if (g_text_mode) { 1520 1696 log_msg(2, "Text mode. Therefore, no popup list."); 1521 return;1697 goto free_to_go; 1522 1698 } 1523 1699 log_msg(2, "Examining file %s", source_file); … … 1526 1702 if (lng < 1) { 1527 1703 log_msg(2, "No lines in file. Therefore, no popup list."); 1528 return; 1704 paranoid_free(reason); 1705 goto free_to_go; 1529 1706 } else if (lng >= ARBITRARY_MAXIMUM) { 1530 1707 log_msg(2, "Too many files differ for me to list."); 1531 return;1708 goto free_to_go; 1532 1709 } 1533 1710 … … 1538 1715 1539 1716 if (load_filelist_into_array(filelist, source_file)) { 1540 log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); 1717 log_msg(2, "Can't open %s; therefore, cannot popup list", 1718 source_file); 1719 paranoid_free(reason); 1541 1720 return; 1542 1721 } 1543 log_msg(2, "%d files loaded into filelist array", filelist->entries); 1722 log_msg(2, "%d files loaded into filelist array", 1723 filelist->entries); 1544 1724 for (i = 0; i < filelist->entries; i++) { 1545 1725 keylist[i] = (void *) i; … … 1550 1730 keylist[i]); 1551 1731 } 1552 mr_asprintf(differ_sz, " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i); 1732 sprintf(differ_sz, 1733 " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", 1734 i); 1553 1735 newtPushHelpLine(differ_sz); 1554 mr_free(differ_sz);1555 1556 1736 bClose = newtCompactButton(10, 15, " Close "); 1557 1737 bSelect = newtCompactButton(30, 15, " Select "); 1558 mr_asprintf(tmp, "%-10s %-20s", "Priority", "Filename");1738 sprintf(tmp, "%-10s %-20s", "Priority", "Filename"); 1559 1739 headerMsg = newtLabel(2, 1, tmp); 1560 mr_free(tmp);1561 1562 1740 newtOpenWindow(5, 4, 70, 16, "Non-matching files"); 1563 1741 myForm = newtForm(NULL, NULL, 0); 1564 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, bSelect, NULL);1565 1742 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, 1743 bSelect, NULL); 1566 1744 while (!finished) { 1567 1745 b_res = newtRunForm(myForm); … … 1578 1756 currline = i; 1579 1757 if (filelist->entries > 0) { 1580 malloc_string(reason);1581 severity_of_difference(filelist->el[currline]. filename, &reason);1582 mr_asprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason);1583 1758 severity_of_difference(filelist->el[currline]. 1759 filename, reason); 1760 sprintf(tmp, "%s --- %s", 1761 filelist->el[currline].filename, reason); 1584 1762 popup_and_OK(tmp); 1585 mr_free(tmp);1586 paranoid_free(reason);1587 1763 } 1588 1764 } … … 1592 1768 newtPopWindow(); 1593 1769 newtPopHelpLine(); 1770 free_to_go: 1771 paranoid_free(reason); 1772 paranoid_free(tmp); 1773 paranoid_free(differ_sz); 1594 1774 return; 1595 1775 }
Note:
See TracChangeset
for help on using the changeset viewer.