Changeset 87 in MondoRescue for trunk/mondo/mondo/common/newt-specific.c


Ignore:
Timestamp:
Oct 27, 2005, 10:03:00 PM (19 years ago)
Author:
bcornec
Message:
  • Now use -Wall to compile
  • asprintf for newt-specific.c
  • Bug in libmondo-string.c line 1120: if we use %% in this format, then the percentage is printeed wrongly (after the real percentage we have a huge number)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/newt-specific.c

    r75 r87  
    4949    bool g_exiting = FALSE;
    5050
    51 /**
    52  * Padding below the Newt components, to overcome bugs in Newt.
    53  */
    54     char g_haharrrrr[500];
    55 
    56 
    5751    newtComponent g_timeline = NULL,    ///< The line of the progress form that shows the time elapsed/remaining
    5852        g_percentline = NULL,   ///< The line of the progress form that shows the percent completed/remaining
     
    6761 * Padding above the Newt components, to overcome bugs in Newt.
    6862 */
    69     char g_jim_lad_yarr[500];
    7063    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 form
    72         g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "",   ///< The string for line 2 of the blurb in the progress form
    73         g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = "";   ///< The string for line 3 (updated continuously) of the blurb in the progress form
     64        *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
    7467    newtComponent g_isoform_main = NULL,    ///< The evalcall form component itself
    7568        g_isoform_header = NULL,    ///< The component for the evalcall form title
     
    7972    long g_isoform_starttime;   ///< The time (in seconds since the epoch) that the evalcall form was opened.
    8073    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.
    8275    int g_mysterious_dot_counter;   ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3
    8376    int g_noof_log_lines = 6;   ///< The number of lines to show in the log at the bottom of the screen.
     
    9184    long g_start_time = 0;      ///< The time (in seconds since the epoch) that the progress form was opened.
    9285    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.
    9586    bool g_called_by_xmondo = FALSE;    ///< @bug Unneeded w/current XMondo.
    9687    char *g_erase_tmpdir_and_scratchdir;    ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.
     
    255246     fatal_error(char *error_string) {
    256247        /*@ buffers ***************************************************** */
    257         char fatalstr[MAX_NEWT_COMMENT_LEN] =
    258             "-------FATAL ERROR---------";
     248        char *fatalstr;
    259249        char *tmp;
    260250        char *command;
     
    264254        /*@ end vars **************************************************** */
    265255
    266         malloc_string(command);
     256        asprintf(&fatalstr, "-------FATAL ERROR---------");
    267257        set_signals(FALSE);     // link to external func
    268258        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);
    271261        if (getpid() == g_mastermind_pid) {
    272262            log_msg(2, "mastermind %d is exiting", (int) getpid());
     
    323313        }
    324314
    325         printf("---FATALERROR--- %s\n", error_string);
    326315        system
    327316            ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null");
    328317        if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) {
    329318            printf
    330                 ("Please try the snapshot (the version with 'cvs' and the date in its filename)");
     319                ("Please try the latest SVN version ");
    331320            printf
    332                 ("to see if that fixes the problem. Please don't bother the mailing list with");
     321                ("to see if that fixes the problem.\nPlease don't bother the mailing list with");
    333322            printf
    334                 ("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes");
     323                ("your problem UNTIL you've tried the snapshot.\nThe snapshot contains bugfixes");
    335324            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");
    338327            log_msg(0,
    339328                    "Please DON'T contact the mailing list. Try the SNAPSHOTS.");
     
    565554        g_isoform_old_progress = -1;
    566555        g_mysterious_dot_counter = 0;
    567         malloc_string(title);
    568         malloc_string(tmp);
    569556
    570557        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);
    574562        if (g_text_mode) {
    575563            log_msg(0, title);
    576564        } 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);
    579568            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);
    582573        g_isoform_starttime = get_time();
    583574        if (g_text_mode) {
     
    597588        }
    598589        update_evalcall_form(0);
    599         paranoid_free(tmp);
    600590        paranoid_free(title);
    601591    }
     
    625615        g_mysterious_dot_counter = 0;
    626616
    627         malloc_string(b1c);
    628         malloc_string(blurb1);
    629         malloc_string(blurb2);
    630         malloc_string(blurb3);
    631 
    632617        assert(title != NULL);
    633618        assert(b1 != NULL);
     
    635620        assert(b3 != NULL);
    636621
    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);
    642628        if (max_val <= 0) {
    643629            max_val = 1;
     
    647633        g_maximum_progress = max_val;
    648634        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);
    652639        if (g_text_mode) {
    653640            log_msg(0, blurb1);
     
    724711        char *original_contents;
    725712
    726         blurb = malloc(MAX_NEWT_COMMENT_LEN);
    727         original_contents = malloc(MAX_NEWT_COMMENT_LEN);
    728713        assert_string_is_neither_NULL_nor_zerolength(title);
    729714        assert(b != NULL);
     
    737722            if (output[strlen(output) - 1] == '\n')
    738723                output[strlen(output) - 1] = '\0';
    739             paranoid_free(blurb);
    740             paranoid_free(original_contents);
    741724            return (TRUE);
    742725        }
    743         strcpy(blurb, b);
     726        asprintf(&blurb, b);
    744727        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
    745         strcpy(original_contents, output);
     728        asprintf(&original_contents, output);
    746729        output[0] = '\0';
    747730        type_here =
     
    760743        myForm = newtForm(NULL, NULL, 0);
    761744        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);
    763747        newtPushHelpLine(blurb);
     748        paranoid_free(blurb);
    764749        b_res = newtRunForm(myForm);
    765750        strcpy(output, entry_value);
     
    769754        if (b_res == b_2) {
    770755            strcpy(output, original_contents);
    771             paranoid_free(blurb);
    772756            paranoid_free(original_contents);
    773757            return (FALSE);
    774758        } else {
    775             paranoid_free(blurb);
    776759            paranoid_free(original_contents);
    777760            return (TRUE);
     
    790773
    791774        /*@ buffers *********************************************************** */
    792         char *prompt, *tmp;
     775        char *prompt;
     776        char *tmp = NULL;
     777        size_t n = 0;
    793778
    794779        /*@ newt ************************************************************** */
     
    799784        newtComponent text;
    800785
    801         prompt = malloc(MAX_NEWT_COMMENT_LEN);
    802         tmp = malloc(MAX_NEWT_COMMENT_LEN);
    803786        assert_string_is_neither_NULL_nor_zerolength(p);
    804787        assert(button1 != NULL);
     
    810793                printf("%s (%s or %s) --> ", p, button1, button2);
    811794            }
    812             for (tmp[0] = '\0';
     795            for (asprintf(&tmp,"");
    813796                 strcmp(tmp, button1) && (strlen(button2) == 0
    814797                                          || strcmp(tmp, button2));) {
    815798                printf("--> ");
    816                 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     799                paranoid_free(tmp);
     800                (void) getline(&tmp, &n, stdin);
    817801            }
    818802            if (!strcmp(tmp, button1)) {
    819803                paranoid_free(tmp);
    820                 paranoid_free(prompt);
    821804                return (TRUE);
    822805            } else {
    823806                paranoid_free(tmp);
    824                 paranoid_free(prompt);
    825807                return (FALSE);
    826808            }
    827809        }
    828810
    829         strcpy(prompt, p);
     811        asprintf(&prompt, p);
    830812        text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
    831813        b_1 =
     
    845827        myForm = newtForm(NULL, NULL, 0);
    846828        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);
    848831        newtPushHelpLine(prompt);
     832        paranoid_free(prompt);
    849833        b_res = newtRunForm(myForm);
    850834        newtPopHelpLine();
     
    852836        newtPopWindow();
    853837        if (b_res == b_1) {
    854             paranoid_free(tmp);
    855             paranoid_free(prompt);
    856838            return (TRUE);
    857839        } else {
    858             paranoid_free(tmp);
    859             paranoid_free(prompt);
    860840            return (FALSE);
    861841        }
     
    936916
    937917/**
    938  * Update the evalcall form to show (<tt>num</tt>/<tt>denom</tt>)*100 %.
     918 * Update the evalcall form to show <tt>num</tt> %.
    939919 * @param num The numerator of the ratio.
    940  * @param denom The denomenator of the ratio.
    941920 */
    942921    void
    943      update_evalcall_form_ratio(int num, int denom) {
     922     update_evalcall_form(int num) {
    944923
    945924        /*@ long ************************************************************ */
     
    953932        char *pcline_str;
    954933        char *taskprogress;
     934        char *tmp1;
     935        char *tmp2;
     936        char *p;
    955937
    956938        /*@ int ************************************************************** */
     
    959941        int j = 0;
    960942
    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) {
    967945            percentage = 1;
    968946        } else {
    969             percentage = (num * 100 + denom / 2) / denom;
     947            percentage = (int)trunc(num) ;
    970948        }
    971949
     
    973951        time_taken = current_time - g_isoform_starttime;
    974952        if (num) {
    975             time_total_est = time_taken * denom / num;
     953            time_total_est = time_taken * 100 / num;
    976954            time_remaining = time_total_est - time_taken;
    977955        } else {
     
    981959            newtLabelSetText(g_isoform_header, g_isoform_header_str);
    982960        }
     961        /* BERLIOS: 27 should be a parameter */
    983962        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    984963        if ((percentage < 3 && g_isoform_old_progress < 3)
    985964            || percentage > g_isoform_old_progress) {
    986965            g_isoform_old_progress = percentage;
    987             sprintf(timeline_str,
     966            asprintf(&timeline_str,
    988967                    "%2ld:%02ld taken            %2ld:%02ld remaining",
    989968                    time_taken / 60, time_taken % 60, time_remaining / 60,
    990969                    time_remaining % 60);
    991970            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 = '.';
    995974                }
    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 = ' ';
    998981                }
    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);
    1001987            } else {
    1002                 sprintf(pcline_str, " %3d%% done              %3d%% to go",
     988                asprintf(&pcline_str, " %3d%% done              %3d%% to go",
    1003989                        percentage, 100 - percentage);
    1004990            }
    1005991            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 = '*';
    1009996                }
    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 = '.';
    10121002                }
     1003                *p = '\0';
     1004
    10131005                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);
    10171007                    printf("---evalcall---1--- %s\r\n",
    10181008                           g_isoform_header_str);
    10191009                    printf("---evalcall---2--- %s\r\n", taskprogress);
    10201010                    printf("---evalcall---E---\r\n");
     1011                    paranoid_free(taskprogress);
    10211012                }
    10221013            } else {
     
    10281019                }
    10291020            }
     1021            paranoid_free(timeline_str);
     1022            paranoid_free(pcline_str);
    10301023        }
    10311024        if (!g_text_mode) {
     
    10331026            newtRefresh();
    10341027        }
    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    }
    10511029
    10521030
     
    10631041            return;
    10641042        }
    1065         strcpy(g_blurb_str_2, blurb3);
     1043        paranoid_free(g_blurb_str_2);
     1044        asprintf(&g_blurb_str_2, blurb3);
    10661045        update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
    10671046                                  g_blurb_str_3);
     
    10861065        int percentage = 0;
    10871066        int i = 0;
     1067        int j = 0;
    10881068
    10891069        /*@ buffers *************************************************** */
     
    10921072        char *taskprogress;
    10931073        char *tmp;
     1074        char *tmp1;
     1075        char *tmp2;
     1076        char *p;
    10941077
    10951078//  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);
    11001079        if (!g_text_mode) {
    11011080            assert(blurb1 != NULL);
     
    11051084        }
    11061085
    1107         percentline_str[0] = '\0';
    1108 
    11091086        current_time = get_time();
    11101087        time_taken = current_time - g_start_time;
     
    11131090        } else {
    11141091            if (g_current_progress > g_maximum_progress) {
    1115                 sprintf(tmp,
     1092                asprintf(&tmp,
    11161093                        "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    11171094                        blurb1, blurb2, blurb3, g_current_progress,
    11181095                        g_maximum_progress);
    11191096                log_msg(0, tmp);
     1097                paranoid_free(tmp);
    11201098                g_current_progress = g_maximum_progress;
    11211099            }
     
    11371115            time_remaining = 0;
    11381116        }
    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,
    11411120                "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    11421121                time_taken / 60, time_taken % 60, time_remaining / 60,
    11431122                time_remaining % 60);
    1144         sprintf(percentline_str, " %3d%% done                 %3d%% to go",
     1123        asprintf(&percentline_str, " %3d%% done                 %3d%% to go",
    11451124                percentage, 100 - percentage);
    11461125
     
    11501129            printf("---progress-form---3--- %s\r\n", blurb3);
    11511130            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
    11591145            if (percentage > 100) {
    11601146                log_msg(2, "percentage = %d", percentage);
    11611147            }
    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
    11671150            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);
    11721159            newtLabelSetText(g_blurb1, blurb1);
    11731160            newtLabelSetText(g_blurb2, blurb3);
     
    11821169        paranoid_free(percentline_str);
    11831170        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    }
    11991172
    12001173
     
    12221195            "nfs", "iso", NULL
    12231196        };
    1224         char *outstr;
     1197        char *outstr = NULL;
    12251198        t_bkptype backup_type;
    12261199        int i;
     1200        size_t n = 0;
    12271201
    12281202        newtComponent b1;
     
    12371211        newtComponent myForm;
    12381212
    1239         title_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1240         minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1241         outstr = malloc(MAX_NEWT_COMMENT_LEN);
    12421213        if (g_text_mode) {
    12431214            for (backup_type = none; backup_type == none;) {
     
    12481219                }
    12491220                printf(")\n--> ");
    1250                 (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
     1221                (void) getline(&outstr, &n, stdin);
    12511222                strip_spaces(outstr);
    12521223                for (i = 0; possible_responses[i]; i++) {
     
    12561227                }
    12571228            }
    1258             paranoid_free(title_sz);
    1259             paranoid_free(minimsg_sz);
    12601229            paranoid_free(outstr);
    12611230            return (backup_type);
     
    12631232        newtDrawRootText(18, 0, WELCOME_STRING);
    12641233        if (restoring) {
    1265             strcpy(title_sz,
     1234            asprintf(&title_sz,
    12661235                   "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,
    12701239                   "Please choose the backup media to which you want to archive data.");
    1271             strcpy(minimsg_sz, "Backup to:");
     1240            asprintf(&minimsg_sz, "Backup to:");
    12721241        }
    12731242        newtPushHelpLine(title_sz);
     1243        paranoid_free(title_sz);
     1244
    12741245        //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
    12751246        newtCenteredWindow(34, 17, minimsg_sz);
     1247        paranoid_free(minimsg_sz);
     1248
    12761249        b1 = newtButton(1, 1, "CD-R disks ");
    12771250        b2 = newtButton(17, 1, "CD-RW disks");
     
    13061279        }
    13071280        newtPopHelpLine();
    1308         paranoid_free(title_sz);
    1309         paranoid_free(minimsg_sz);
    1310         paranoid_free(outstr);
    13111281        return (output);
    13121282    }
    1313 
    1314 
    13151283
    13161284
     
    13681336
    13691337
    1370 
    1371 
    1372 
    13731338/**
    13741339 * Load @p source_file (a list of files) into @p filelist. There can be no more than
     
    13811346        int i;
    13821347        bool done;
    1383         char *tmp;
     1348        char *reason = NULL;
     1349        char *tmp = NULL;
     1350        size_t n = 0;
    13841351        FILE *fin;
    13851352        struct s_filelist_entry dummy_fle;
    13861353
    1387         malloc_string(tmp);
    13881354        assert(filelist != NULL);
    13891355        assert_string_is_neither_NULL_nor_zerolength(source_file);
     
    13941360            log_msg(2, "Can't open %s; therefore, cannot popup list",
    13951361                    source_file);
    1396             paranoid_free(tmp);
    13971362            return (1);
    13981363        }
     
    14041369                break;
    14051370            }
    1406             (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
     1371            (void) getline(&tmp, &n, fin);
    14071372            i = (int) strlen(tmp);
    14081373            if (i < 2) {
     
    14191384            }
    14201385            filelist->el[filelist->entries].severity =
    1421                 severity_of_difference(tmp, NULL);
     1386                severity_of_difference(tmp, reason);
     1387            paranoid_free(reason);
    14221388            strcpy(filelist->el[filelist->entries].filename, tmp);
    14231389            if (feof(fin)) {
     
    14311397            return (1);
    14321398        }
     1399        paranoid_free(tmp);
     1400
    14331401        for (done = FALSE; !done;) {
    14341402            done = TRUE;
     
    14561424            }
    14571425        }
    1458         paranoid_free(tmp);
    14591426        iamhere("leaving");
    14601427        return (0);
     
    14701437 */
    14711438    char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
    1472         static char comment[100];
    1473         char *tmp;
     1439        char *comment;
    14741440
    14751441        iamhere("entering");
    1476         malloc_string(tmp);
    14771442        assert(flentry != NULL);
    14781443        if (flentry->severity == 0) {
    1479             strcpy(tmp, "0   ");
     1444            asprintf(&comment, "0     %93s", flentry->filename);
    14801445        } else if (flentry->severity == 1) {
    1481             strcpy(tmp, "low ");
     1446            asprintf(&comment, "low   %93s", flentry->filename);
    14821447        } 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        }
    14921452        iamhere("leaving");
    14931453        return (comment);
     
    15041464 */
    15051465    void popup_changelist_from_file(char *source_file) {
    1506         char *reason;
     1466        char *reason = NULL;
    15071467        newtComponent myForm;
    15081468        newtComponent bClose;
     
    15271487
    15281488        struct s_filelist *filelist;
    1529         malloc_string(reason);
    1530         tmp = malloc(5000);
    1531         malloc_string(differ_sz);
    15321489        assert_string_is_neither_NULL_nor_zerolength(source_file);
    15331490        if (g_text_mode) {
    15341491            log_msg(2, "Text mode. Therefore, no popup list.");
    1535             goto free_to_go;
     1492            return;
    15361493        }
    15371494        log_msg(2, "Examining file %s", source_file);
     
    15401497        if (lng < 1) {
    15411498            log_msg(2, "No lines in file. Therefore, no popup list.");
    1542             paranoid_free(reason);
    1543             goto free_to_go;
     1499            return;
    15441500        } else if (lng >= ARBITRARY_MAXIMUM) {
    15451501            log_msg(2, "Too many files differ for me to list.");
    1546             goto free_to_go;
     1502            return;
    15471503        }
    15481504
     
    15551511            log_msg(2, "Can't open %s; therefore, cannot popup list",
    15561512                    source_file);
    1557             paranoid_free(reason);
    15581513            return;
    15591514        }
     
    15681523                                   keylist[i]);
    15691524        }
    1570         sprintf(differ_sz,
     1525        asprintf(&differ_sz,
    15711526                "  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
    15721527                i);
    15731528        newtPushHelpLine(differ_sz);
     1529        paranoid_free(differ_sz);
     1530
    15741531        bClose = newtCompactButton(10, 15, " Close  ");
    15751532        bSelect = newtCompactButton(30, 15, " Select ");
    1576         sprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
     1533        asprintf(&tmp, "%-10s               %-20s", "Priority", "Filename");
    15771534        headerMsg = newtLabel(2, 1, tmp);
     1535        paranoid_free(tmp);
     1536
    15781537        newtOpenWindow(5, 4, 70, 16, "Non-matching files");
    15791538        myForm = newtForm(NULL, NULL, 0);
     
    15961555                        severity_of_difference(filelist->el[currline].
    15971556                                               filename, reason);
    1598                         sprintf(tmp, "%s --- %s",
     1557                        asprintf(&tmp, "%s --- %s",
    15991558                                filelist->el[currline].filename, reason);
    16001559                        popup_and_OK(tmp);
     1560                        paranoid_free(tmp);
     1561                        paranoid_free(reason);
    16011562                    }
    16021563                }
     
    16061567        newtPopWindow();
    16071568        newtPopHelpLine();
    1608       free_to_go:
    1609         paranoid_free(reason);
    1610         paranoid_free(tmp);
    1611         paranoid_free(differ_sz);
    1612         return;
    16131569    }
    16141570
Note: See TracChangeset for help on using the changeset viewer.