Changeset 87 in MondoRescue for trunk/mondo/mondo/common/newt-specific.c
- Timestamp:
- Oct 27, 2005, 10:03:00 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/newt-specific.c
r75 r87 49 49 bool g_exiting = FALSE; 50 50 51 /**52 * Padding below the Newt components, to overcome bugs in Newt.53 */54 char g_haharrrrr[500];55 56 57 51 newtComponent g_timeline = NULL, ///< The line of the progress form that shows the time elapsed/remaining 58 52 g_percentline = NULL, ///< The line of the progress form that shows the percent completed/remaining … … 67 61 * Padding above the Newt components, to overcome bugs in Newt. 68 62 */ 69 char g_jim_lad_yarr[500];70 63 char **err_log_lines = NULL, ///< The list of log lines to show on the screen. 71 g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 1 of the blurb in the progress form72 g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 2 of the blurb in the progress form73 g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = ""; ///< The string for line 3 (updated continuously) of the blurb in the progress form64 *g_blurb_str_1, ///< The string for line 1 of the blurb in the progress form 65 *g_blurb_str_2, ///< The string for line 2 of the blurb in the progress form 66 *g_blurb_str_3; ///< The string for line 3 (updated continuously) of the blurb in the progress form 74 67 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself 75 68 g_isoform_header = NULL, ///< The component for the evalcall form title … … 79 72 long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened. 80 73 int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent). 81 char g_isoform_header_str[MAX_STR_LEN] = " "; ///< The string for the evalcall form title.74 char *g_isoform_header_str; ///< The string for the evalcall form title. 82 75 int g_mysterious_dot_counter; ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3 83 76 int g_noof_log_lines = 6; ///< The number of lines to show in the log at the bottom of the screen. … … 91 84 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened. 92 85 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 93 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo.94 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.95 86 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo. 96 87 char *g_erase_tmpdir_and_scratchdir; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo. … … 255 246 fatal_error(char *error_string) { 256 247 /*@ buffers ***************************************************** */ 257 char fatalstr[MAX_NEWT_COMMENT_LEN] = 258 "-------FATAL ERROR---------"; 248 char *fatalstr; 259 249 char *tmp; 260 250 char *command; … … 264 254 /*@ end vars **************************************************** */ 265 255 266 malloc_string(command);256 asprintf(&fatalstr, "-------FATAL ERROR---------"); 267 257 set_signals(FALSE); // link to external func 268 258 g_exiting = TRUE; 269 log_msg(1, " Fatal error received - '%s'", error_string);270 printf(" Fatal error... %s\n", error_string);259 log_msg(1, "%s - '%s'", fatalstr, error_string); 260 printf("%s - %s\n", fatalstr, error_string); 271 261 if (getpid() == g_mastermind_pid) { 272 262 log_msg(2, "mastermind %d is exiting", (int) getpid()); … … 323 313 } 324 314 325 printf("---FATALERROR--- %s\n", error_string);326 315 system 327 316 ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null"); 328 317 if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) { 329 318 printf 330 ("Please try the snapshot (the version with 'cvs' and the date in its filename)");319 ("Please try the latest SVN version "); 331 320 printf 332 ("to see if that fixes the problem. 321 ("to see if that fixes the problem.\nPlease don't bother the mailing list with"); 333 322 printf 334 ("your problem UNTIL you've tried the snapshot. 323 ("your problem UNTIL you've tried the snapshot.\nThe snapshot contains bugfixes"); 335 324 printf 336 ("which might help you. Go to http://www.mondorescue.org/download/download.html");337 printf(" For more information.\n");325 ("which might help you.\nGo to http://mondorescue.berlios.de"); 326 printf(" for more information.\n"); 338 327 log_msg(0, 339 328 "Please DON'T contact the mailing list. Try the SNAPSHOTS."); … … 565 554 g_isoform_old_progress = -1; 566 555 g_mysterious_dot_counter = 0; 567 malloc_string(title);568 malloc_string(tmp);569 556 570 557 assert(ttl != NULL); 571 strcpy(title, ttl); 572 strcpy(g_isoform_header_str, title); 573 // center_string (title, 80); 558 asprintf(&title, ttl); 559 // BERLIOS: We need to unallocate it somewhere 560 asprintf(&g_isoform_header_str, title); 561 // center_string (title, 80); 574 562 if (g_text_mode) { 575 563 log_msg(0, title); 576 564 } else { 577 strcpy(tmp, title); 578 center_string(tmp, 80); 565 asprintf(&tmp, title); 566 /* BERLIOS: center_string is now broken replace it ! */ 567 //center_string(tmp, 80); 579 568 newtPushHelpLine(tmp); 580 } 581 center_string(g_isoform_header_str, 36); 569 paranoid_free(tmp); 570 } 571 /* BERLIOS: center_string is now broken replace it ! */ 572 //center_string(g_isoform_header_str, 36); 582 573 g_isoform_starttime = get_time(); 583 574 if (g_text_mode) { … … 597 588 } 598 589 update_evalcall_form(0); 599 paranoid_free(tmp);600 590 paranoid_free(title); 601 591 } … … 625 615 g_mysterious_dot_counter = 0; 626 616 627 malloc_string(b1c);628 malloc_string(blurb1);629 malloc_string(blurb2);630 malloc_string(blurb3);631 632 617 assert(title != NULL); 633 618 assert(b1 != NULL); … … 635 620 assert(b3 != NULL); 636 621 637 strcpy(blurb1, b1); 638 strcpy(blurb2, b2); 639 strcpy(blurb3, b3); 640 strcpy(b1c, b1); 641 center_string(b1c, 80); 622 asprintf(&blurb1, b1); 623 asprintf(&blurb2, b2); 624 asprintf(&blurb3, b3); 625 asprintf(&b1c, b1); 626 /* BERLIOS: center_string is now broken replace it ! */ 627 //center_string(b1c, 80); 642 628 if (max_val <= 0) { 643 629 max_val = 1; … … 647 633 g_maximum_progress = max_val; 648 634 g_current_progress = 0; 649 strcpy(g_blurb_str_1, blurb1); 650 strcpy(g_blurb_str_2, blurb3); 651 strcpy(g_blurb_str_3, blurb2); 635 // BERLIOS: We need to unallocate them 636 asprintf(&g_blurb_str_1, blurb1); 637 asprintf(&g_blurb_str_2, blurb3); 638 asprintf(&g_blurb_str_3, blurb2); 652 639 if (g_text_mode) { 653 640 log_msg(0, blurb1); … … 724 711 char *original_contents; 725 712 726 blurb = malloc(MAX_NEWT_COMMENT_LEN);727 original_contents = malloc(MAX_NEWT_COMMENT_LEN);728 713 assert_string_is_neither_NULL_nor_zerolength(title); 729 714 assert(b != NULL); … … 737 722 if (output[strlen(output) - 1] == '\n') 738 723 output[strlen(output) - 1] = '\0'; 739 paranoid_free(blurb);740 paranoid_free(original_contents);741 724 return (TRUE); 742 725 } 743 strcpy(blurb, b);726 asprintf(&blurb, b); 744 727 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 745 strcpy(original_contents, output);728 asprintf(&original_contents, output); 746 729 output[0] = '\0'; 747 730 type_here = … … 760 743 myForm = newtForm(NULL, NULL, 0); 761 744 newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL); 762 center_string(blurb, 80); 745 /* BERLIOS: center_string is now broken replace it ! */ 746 //center_string(blurb, 80); 763 747 newtPushHelpLine(blurb); 748 paranoid_free(blurb); 764 749 b_res = newtRunForm(myForm); 765 750 strcpy(output, entry_value); … … 769 754 if (b_res == b_2) { 770 755 strcpy(output, original_contents); 771 paranoid_free(blurb);772 756 paranoid_free(original_contents); 773 757 return (FALSE); 774 758 } else { 775 paranoid_free(blurb);776 759 paranoid_free(original_contents); 777 760 return (TRUE); … … 790 773 791 774 /*@ buffers *********************************************************** */ 792 char *prompt, *tmp; 775 char *prompt; 776 char *tmp = NULL; 777 size_t n = 0; 793 778 794 779 /*@ newt ************************************************************** */ … … 799 784 newtComponent text; 800 785 801 prompt = malloc(MAX_NEWT_COMMENT_LEN);802 tmp = malloc(MAX_NEWT_COMMENT_LEN);803 786 assert_string_is_neither_NULL_nor_zerolength(p); 804 787 assert(button1 != NULL); … … 810 793 printf("%s (%s or %s) --> ", p, button1, button2); 811 794 } 812 for ( tmp[0] = '\0';795 for (asprintf(&tmp,""); 813 796 strcmp(tmp, button1) && (strlen(button2) == 0 814 797 || strcmp(tmp, button2));) { 815 798 printf("--> "); 816 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 799 paranoid_free(tmp); 800 (void) getline(&tmp, &n, stdin); 817 801 } 818 802 if (!strcmp(tmp, button1)) { 819 803 paranoid_free(tmp); 820 paranoid_free(prompt);821 804 return (TRUE); 822 805 } else { 823 806 paranoid_free(tmp); 824 paranoid_free(prompt);825 807 return (FALSE); 826 808 } 827 809 } 828 810 829 strcpy(prompt, p);811 asprintf(&prompt, p); 830 812 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 831 813 b_1 = … … 845 827 myForm = newtForm(NULL, NULL, 0); 846 828 newtFormAddComponents(myForm, text, b_1, b_2, NULL); 847 center_string(prompt, 80); 829 /* BERLIOS: center_string is now broken replace it ! */ 830 //center_string(prompt, 80); 848 831 newtPushHelpLine(prompt); 832 paranoid_free(prompt); 849 833 b_res = newtRunForm(myForm); 850 834 newtPopHelpLine(); … … 852 836 newtPopWindow(); 853 837 if (b_res == b_1) { 854 paranoid_free(tmp);855 paranoid_free(prompt);856 838 return (TRUE); 857 839 } else { 858 paranoid_free(tmp);859 paranoid_free(prompt);860 840 return (FALSE); 861 841 } … … 936 916 937 917 /** 938 * Update the evalcall form to show (<tt>num</tt>/<tt>denom</tt>)*100%.918 * Update the evalcall form to show <tt>num</tt> %. 939 919 * @param num The numerator of the ratio. 940 * @param denom The denomenator of the ratio.941 920 */ 942 921 void 943 update_evalcall_form _ratio(int num, int denom) {922 update_evalcall_form(int num) { 944 923 945 924 /*@ long ************************************************************ */ … … 953 932 char *pcline_str; 954 933 char *taskprogress; 934 char *tmp1; 935 char *tmp2; 936 char *p; 955 937 956 938 /*@ int ************************************************************** */ … … 959 941 int j = 0; 960 942 961 malloc_string(timeline_str); 962 malloc_string(pcline_str); 963 malloc_string(taskprogress); 964 timeline_str[0] = '\0'; 965 // log_it("update_eval_call_form called"); 966 if (num * 100 < denom) { 943 //log_it("update_eval_call_form called"); 944 if (num < 1) { 967 945 percentage = 1; 968 946 } else { 969 percentage = ( num * 100 + denom / 2) / denom;947 percentage = (int)trunc(num) ; 970 948 } 971 949 … … 973 951 time_taken = current_time - g_isoform_starttime; 974 952 if (num) { 975 time_total_est = time_taken * denom/ num;953 time_total_est = time_taken * 100 / num; 976 954 time_remaining = time_total_est - time_taken; 977 955 } else { … … 981 959 newtLabelSetText(g_isoform_header, g_isoform_header_str); 982 960 } 961 /* BERLIOS: 27 should be a parameter */ 983 962 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 984 963 if ((percentage < 3 && g_isoform_old_progress < 3) 985 964 || percentage > g_isoform_old_progress) { 986 965 g_isoform_old_progress = percentage; 987 sprintf(timeline_str,966 asprintf(&timeline_str, 988 967 "%2ld:%02ld taken %2ld:%02ld remaining", 989 968 time_taken / 60, time_taken % 60, time_remaining / 60, 990 969 time_remaining % 60); 991 970 if (percentage < 3) { 992 sprintf(pcline_str, " Working");993 for ( j = 0; j < g_mysterious_dot_counter; j++) {994 strcat(pcline_str, ".");971 tmp1 = (char *)malloc(g_mysterious_dot_counter * sizeof(char)); 972 for (i = 0, p = tmp1 ; i < g_mysterious_dot_counter - 1 ; i++, p++) { 973 *p = '.'; 995 974 } 996 for (; j < 27; j++) { 997 strcat(pcline_str, " "); 975 *p = '\0'; 976 977 /* BERLIOS: 27 should be a parameter */ 978 tmp2 = (char *)malloc(27-g_mysterious_dot_counter * sizeof(char)); 979 for (i = 0, p = tmp2 ; i < 27 - g_mysterious_dot_counter - 1 ; i++, p++) { 980 *p = ' '; 998 981 } 999 sprintf(pcline_str + strlen(pcline_str), " %c", 1000 special_dot_char(g_mysterious_dot_counter)); 982 *p = '\0'; 983 984 asprintf(&pcline_str, " Working%s%s %c", tmp1, tmp2, special_dot_char(g_mysterious_dot_counter)); 985 paranoid_free(tmp1); 986 paranoid_free(tmp2); 1001 987 } else { 1002 sprintf(pcline_str, " %3d%% done %3d%% to go",988 asprintf(&pcline_str, " %3d%% done %3d%% to go", 1003 989 percentage, 100 - percentage); 1004 990 } 1005 991 if (g_text_mode) { 1006 sprintf(taskprogress, "TASK: ["); 1007 for (i = 0; i < percentage; i += 5) { 1008 strcat(taskprogress, "*"); 992 j = trunc(percentage/5); 993 tmp1 = (char *)malloc((j + 1) * sizeof(char)); 994 for (i = 0, p = tmp1 ; i < j ; i++, p++) { 995 *p = '*'; 1009 996 } 1010 for (; i < 100; i += 5) { 1011 strcat(taskprogress, "."); 997 *p = '\0'; 998 999 tmp2 = (char *)malloc((20 - j + 1) * sizeof(char)); 1000 for (i = 0, p = tmp2 ; i < 20 - j ; i++, p++) { 1001 *p = '.'; 1012 1002 } 1003 *p = '\0'; 1004 1013 1005 if (percentage >= 3) { 1014 sprintf(taskprogress + strlen(taskprogress), 1015 "] %3d%% done; %2ld:%02ld to go", percentage, 1016 time_remaining / 60, time_remaining % 60); 1006 asprintf(&taskprogress, "TASK: [%s%s] %3d%% done; %2ld:%02ld to go", tmp1, tmp2, percentage, time_remaining / 60, time_remaining % 60); 1017 1007 printf("---evalcall---1--- %s\r\n", 1018 1008 g_isoform_header_str); 1019 1009 printf("---evalcall---2--- %s\r\n", taskprogress); 1020 1010 printf("---evalcall---E---\r\n"); 1011 paranoid_free(taskprogress); 1021 1012 } 1022 1013 } else { … … 1028 1019 } 1029 1020 } 1021 paranoid_free(timeline_str); 1022 paranoid_free(pcline_str); 1030 1023 } 1031 1024 if (!g_text_mode) { … … 1033 1026 newtRefresh(); 1034 1027 } 1035 paranoid_free(timeline_str); 1036 paranoid_free(pcline_str); 1037 paranoid_free(taskprogress); 1038 } 1039 1040 1041 1042 /** 1043 * Update the evalcall form to show @p curr %. 1044 * @param curr The current amount of progress (percentage) in the evalcall form. 1045 */ 1046 void 1047 update_evalcall_form(int curr) { 1048 update_evalcall_form_ratio(curr, 100); 1049 } 1050 1028 } 1051 1029 1052 1030 … … 1063 1041 return; 1064 1042 } 1065 strcpy(g_blurb_str_2, blurb3); 1043 paranoid_free(g_blurb_str_2); 1044 asprintf(&g_blurb_str_2, blurb3); 1066 1045 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1067 1046 g_blurb_str_3); … … 1086 1065 int percentage = 0; 1087 1066 int i = 0; 1067 int j = 0; 1088 1068 1089 1069 /*@ buffers *************************************************** */ … … 1092 1072 char *taskprogress; 1093 1073 char *tmp; 1074 char *tmp1; 1075 char *tmp2; 1076 char *p; 1094 1077 1095 1078 // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1096 percentline_str = malloc(MAX_NEWT_COMMENT_LEN);1097 timeline_str = malloc(MAX_NEWT_COMMENT_LEN);1098 taskprogress = malloc(MAX_NEWT_COMMENT_LEN);1099 malloc_string(tmp);1100 1079 if (!g_text_mode) { 1101 1080 assert(blurb1 != NULL); … … 1105 1084 } 1106 1085 1107 percentline_str[0] = '\0';1108 1109 1086 current_time = get_time(); 1110 1087 time_taken = current_time - g_start_time; … … 1113 1090 } else { 1114 1091 if (g_current_progress > g_maximum_progress) { 1115 sprintf(tmp,1092 asprintf(&tmp, 1116 1093 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1117 1094 blurb1, blurb2, blurb3, g_current_progress, 1118 1095 g_maximum_progress); 1119 1096 log_msg(0, tmp); 1097 paranoid_free(tmp); 1120 1098 g_current_progress = g_maximum_progress; 1121 1099 } … … 1137 1115 time_remaining = 0; 1138 1116 } 1139 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1140 sprintf(timeline_str, 1117 /* BERLIOS/ Is it useful here ? */ 1118 //g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1119 asprintf(&timeline_str, 1141 1120 "%2ld:%02ld taken %2ld:%02ld remaining ", 1142 1121 time_taken / 60, time_taken % 60, time_remaining / 60, 1143 1122 time_remaining % 60); 1144 sprintf(percentline_str, " %3d%% done %3d%% to go",1123 asprintf(&percentline_str, " %3d%% done %3d%% to go", 1145 1124 percentage, 100 - percentage); 1146 1125 … … 1150 1129 printf("---progress-form---3--- %s\r\n", blurb3); 1151 1130 printf("---progress-form---E---\n"); 1152 sprintf(taskprogress, "TASK: ["); 1153 for (i = 0; i < percentage; i += 5) { 1154 strcat(taskprogress, "*"); 1155 } 1156 for (; i < 100; i += 5) { 1157 strcat(taskprogress, "."); 1158 } 1131 1132 j = trunc(percentage/5); 1133 tmp1 = (char *)malloc((j + 1) * sizeof(char)); 1134 for (i = 0, p = tmp1 ; i < j ; i++, p++) { 1135 *p = '*'; 1136 } 1137 *p = '\0'; 1138 1139 tmp2 = (char *)malloc((20 - j + 1) * sizeof(char)); 1140 for (i = 0, p = tmp2 ; i < 20 - j ; i++, p++) { 1141 *p = '.'; 1142 } 1143 *p = '\0'; 1144 1159 1145 if (percentage > 100) { 1160 1146 log_msg(2, "percentage = %d", percentage); 1161 1147 } 1162 sprintf(taskprogress + strlen(taskprogress), 1163 "] %3d%c", percentage, '%'); 1164 sprintf(taskprogress + strlen(taskprogress), 1165 " done; %2ld:%02ld to go", 1166 time_remaining / 60, time_remaining % 60); 1148 asprintf(&taskprogress, "TASK: [%s%s] %3d%% done; %2ld:%02ld to go", tmp1, tmp2, percentage, time_remaining / 60, time_remaining % 60); 1149 1167 1150 printf("---progress-form---4--- %s\r\n", taskprogress); 1168 } else { 1169 center_string(blurb1, 54); 1170 center_string(blurb2, 54); 1171 center_string(blurb3, 54); 1151 paranoid_free(taskprogress); 1152 } else { 1153 /* BERLIOS: center_string is now broken replace it ! */ 1154 //center_string(blurb1, 54); 1155 /* BERLIOS: center_string is now broken replace it ! */ 1156 //center_string(blurb2, 54); 1157 /* BERLIOS: center_string is now broken replace it ! */ 1158 //center_string(blurb3, 54); 1172 1159 newtLabelSetText(g_blurb1, blurb1); 1173 1160 newtLabelSetText(g_blurb2, blurb3); … … 1182 1169 paranoid_free(percentline_str); 1183 1170 paranoid_free(timeline_str); 1184 paranoid_free(taskprogress); 1185 paranoid_free(tmp); 1186 } 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1171 } 1199 1172 1200 1173 … … 1222 1195 "nfs", "iso", NULL 1223 1196 }; 1224 char *outstr ;1197 char *outstr = NULL; 1225 1198 t_bkptype backup_type; 1226 1199 int i; 1200 size_t n = 0; 1227 1201 1228 1202 newtComponent b1; … … 1237 1211 newtComponent myForm; 1238 1212 1239 title_sz = malloc(MAX_NEWT_COMMENT_LEN);1240 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);1241 outstr = malloc(MAX_NEWT_COMMENT_LEN);1242 1213 if (g_text_mode) { 1243 1214 for (backup_type = none; backup_type == none;) { … … 1248 1219 } 1249 1220 printf(")\n--> "); 1250 (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);1221 (void) getline(&outstr, &n, stdin); 1251 1222 strip_spaces(outstr); 1252 1223 for (i = 0; possible_responses[i]; i++) { … … 1256 1227 } 1257 1228 } 1258 paranoid_free(title_sz);1259 paranoid_free(minimsg_sz);1260 1229 paranoid_free(outstr); 1261 1230 return (backup_type); … … 1263 1232 newtDrawRootText(18, 0, WELCOME_STRING); 1264 1233 if (restoring) { 1265 strcpy(title_sz,1234 asprintf(&title_sz, 1266 1235 "Please choose the backup media from which you want to read data."); 1267 strcpy(minimsg_sz, "Read from:");1268 } else { 1269 strcpy(title_sz,1236 asprintf(&minimsg_sz, "Read from:"); 1237 } else { 1238 asprintf(&title_sz, 1270 1239 "Please choose the backup media to which you want to archive data."); 1271 strcpy(minimsg_sz, "Backup to:");1240 asprintf(&minimsg_sz, "Backup to:"); 1272 1241 } 1273 1242 newtPushHelpLine(title_sz); 1243 paranoid_free(title_sz); 1244 1274 1245 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); 1275 1246 newtCenteredWindow(34, 17, minimsg_sz); 1247 paranoid_free(minimsg_sz); 1248 1276 1249 b1 = newtButton(1, 1, "CD-R disks "); 1277 1250 b2 = newtButton(17, 1, "CD-RW disks"); … … 1306 1279 } 1307 1280 newtPopHelpLine(); 1308 paranoid_free(title_sz);1309 paranoid_free(minimsg_sz);1310 paranoid_free(outstr);1311 1281 return (output); 1312 1282 } 1313 1314 1315 1283 1316 1284 … … 1368 1336 1369 1337 1370 1371 1372 1373 1338 /** 1374 1339 * Load @p source_file (a list of files) into @p filelist. There can be no more than … … 1381 1346 int i; 1382 1347 bool done; 1383 char *tmp; 1348 char *reason = NULL; 1349 char *tmp = NULL; 1350 size_t n = 0; 1384 1351 FILE *fin; 1385 1352 struct s_filelist_entry dummy_fle; 1386 1353 1387 malloc_string(tmp);1388 1354 assert(filelist != NULL); 1389 1355 assert_string_is_neither_NULL_nor_zerolength(source_file); … … 1394 1360 log_msg(2, "Can't open %s; therefore, cannot popup list", 1395 1361 source_file); 1396 paranoid_free(tmp);1397 1362 return (1); 1398 1363 } … … 1404 1369 break; 1405 1370 } 1406 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);1371 (void) getline(&tmp, &n, fin); 1407 1372 i = (int) strlen(tmp); 1408 1373 if (i < 2) { … … 1419 1384 } 1420 1385 filelist->el[filelist->entries].severity = 1421 severity_of_difference(tmp, NULL); 1386 severity_of_difference(tmp, reason); 1387 paranoid_free(reason); 1422 1388 strcpy(filelist->el[filelist->entries].filename, tmp); 1423 1389 if (feof(fin)) { … … 1431 1397 return (1); 1432 1398 } 1399 paranoid_free(tmp); 1400 1433 1401 for (done = FALSE; !done;) { 1434 1402 done = TRUE; … … 1456 1424 } 1457 1425 } 1458 paranoid_free(tmp);1459 1426 iamhere("leaving"); 1460 1427 return (0); … … 1470 1437 */ 1471 1438 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1472 static char comment[100]; 1473 char *tmp; 1439 char *comment; 1474 1440 1475 1441 iamhere("entering"); 1476 malloc_string(tmp);1477 1442 assert(flentry != NULL); 1478 1443 if (flentry->severity == 0) { 1479 strcpy(tmp, "0 ");1444 asprintf(&comment, "0 %93s", flentry->filename); 1480 1445 } else if (flentry->severity == 1) { 1481 strcpy(tmp, "low ");1446 asprintf(&comment, "low %93s", flentry->filename); 1482 1447 } else if (flentry->severity == 2) { 1483 strcpy(tmp, "med "); 1484 } else { 1485 strcpy(tmp, "high"); 1486 } 1487 strcat(tmp, " "); 1488 strncat(tmp, flentry->filename, 100); 1489 tmp[98] = '\0'; 1490 strcpy(comment, tmp); 1491 paranoid_free(tmp); 1448 asprintf(&comment, "med %93s", flentry->filename); 1449 } else { 1450 asprintf(&comment, "high %93s", flentry->filename); 1451 } 1492 1452 iamhere("leaving"); 1493 1453 return (comment); … … 1504 1464 */ 1505 1465 void popup_changelist_from_file(char *source_file) { 1506 char *reason ;1466 char *reason = NULL; 1507 1467 newtComponent myForm; 1508 1468 newtComponent bClose; … … 1527 1487 1528 1488 struct s_filelist *filelist; 1529 malloc_string(reason);1530 tmp = malloc(5000);1531 malloc_string(differ_sz);1532 1489 assert_string_is_neither_NULL_nor_zerolength(source_file); 1533 1490 if (g_text_mode) { 1534 1491 log_msg(2, "Text mode. Therefore, no popup list."); 1535 goto free_to_go;1492 return; 1536 1493 } 1537 1494 log_msg(2, "Examining file %s", source_file); … … 1540 1497 if (lng < 1) { 1541 1498 log_msg(2, "No lines in file. Therefore, no popup list."); 1542 paranoid_free(reason); 1543 goto free_to_go; 1499 return; 1544 1500 } else if (lng >= ARBITRARY_MAXIMUM) { 1545 1501 log_msg(2, "Too many files differ for me to list."); 1546 goto free_to_go;1502 return; 1547 1503 } 1548 1504 … … 1555 1511 log_msg(2, "Can't open %s; therefore, cannot popup list", 1556 1512 source_file); 1557 paranoid_free(reason);1558 1513 return; 1559 1514 } … … 1568 1523 keylist[i]); 1569 1524 } 1570 sprintf(differ_sz,1525 asprintf(&differ_sz, 1571 1526 " %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", 1572 1527 i); 1573 1528 newtPushHelpLine(differ_sz); 1529 paranoid_free(differ_sz); 1530 1574 1531 bClose = newtCompactButton(10, 15, " Close "); 1575 1532 bSelect = newtCompactButton(30, 15, " Select "); 1576 sprintf(tmp, "%-10s %-20s", "Priority", "Filename");1533 asprintf(&tmp, "%-10s %-20s", "Priority", "Filename"); 1577 1534 headerMsg = newtLabel(2, 1, tmp); 1535 paranoid_free(tmp); 1536 1578 1537 newtOpenWindow(5, 4, 70, 16, "Non-matching files"); 1579 1538 myForm = newtForm(NULL, NULL, 0); … … 1596 1555 severity_of_difference(filelist->el[currline]. 1597 1556 filename, reason); 1598 sprintf(tmp, "%s --- %s",1557 asprintf(&tmp, "%s --- %s", 1599 1558 filelist->el[currline].filename, reason); 1600 1559 popup_and_OK(tmp); 1560 paranoid_free(tmp); 1561 paranoid_free(reason); 1601 1562 } 1602 1563 } … … 1606 1567 newtPopWindow(); 1607 1568 newtPopHelpLine(); 1608 free_to_go:1609 paranoid_free(reason);1610 paranoid_free(tmp);1611 paranoid_free(differ_sz);1612 return;1613 1569 } 1614 1570
Note:
See TracChangeset
for help on using the changeset viewer.