Ignore:
Timestamp:
Aug 18, 2009, 2:34:29 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3327@localhost: bruno | 2009-08-04 00:17:46 +0200
popup_and_get_string and build_partition_name now return an allocated string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/newt-specific.c

    r2296 r2316  
    358358            log_msg(0, fatalstr);
    359359            log_msg(0, error_string);
    360             //      popup_and_OK (error_string);
    361360            newtFinished();
    362361        }
     
    400399     finish(int signal) {
    401400        char *command = NULL;
    402 
    403         /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
    404 
    405         /* newtPopHelpLine(); */
    406401
    407402        chdir("/");
     
    750745 * @param title The title of the dialog box.
    751746 * @param b The blurb (e.g. what you want the user to enter).
    752  * @param output The string to put the user's answer in.
    753  * @param maxsize The size in bytes allocated to @p output.
    754  * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    755  */
    756     bool popup_and_get_string(char *title, char *b, char *output,
    757                               int maxsize) {
     747 * @param input The string given originaly as default
     748 * @return output string if the user pressed OK, NULL if they pressed Cancel.
     749 */
     750    char *popup_and_get_string(char *title, char *b, char *input) {
    758751
    759752        /*@ newt ************************************************************ */
     
    769762
    770763        /*@ buffers ********************************************************** */
    771         char *blurb;
    772         char *original_contents;
    773 
    774         blurb = malloc(MAX_NEWT_COMMENT_LEN);
    775         original_contents = malloc(MAX_NEWT_COMMENT_LEN);
     764        char *blurb = NULL;
     765        char *output = NULL;
     766
    776767        assert_string_is_neither_NULL_nor_zerolength(title);
    777768        assert(b != NULL);
    778         assert(output != NULL);
    779769
    780770        if (g_text_mode) {
    781             printf
    782                 ("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n-->  ",
    783                  title, b);
    784             (void) fgets(output, maxsize, stdin);
     771            printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q--- [%s]\n-->  ", title, b, input);
     772            mr_getline(&output, stdin);
     773            if (! strcmp(output,"\n")) {
     774                /* take default if ENTER was typed */
     775                mr_free(output);
     776                mr_asprintf(&output, "%s", input);
     777            }
    785778            if (output[strlen(output) - 1] == '\n')
    786779                output[strlen(output) - 1] = '\0';
    787             paranoid_free(blurb);
    788             paranoid_free(original_contents);
    789             return (TRUE);
    790         }
    791         strcpy(blurb, b);
     780            return (output);
     781        }
     782
     783        mr_asprintf(&blurb, "%s", b);
    792784        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
    793         strcpy(original_contents, output);
    794         output[0] = '\0';
    795785        type_here =
    796786            newtEntry(2, newtTextboxGetNumLines(text) + 2,
    797                       original_contents, 50,
     787                      input, 50,
    798788#ifdef __cplusplus
    799789                      0, NEWT_FLAG_RETURNEXIT
     
    804794        b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
    805795        b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
    806         //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
    807796        newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
    808797        myForm = newtForm(NULL, NULL, 0);
     
    811800        newtPushHelpLine(blurb);
    812801        b_res = newtRunForm(myForm);
    813         strcpy(output, entry_value);
     802
     803        if (b_res == b_1) {
     804            mr_asprintf(&output, "%s", newtEntryGetValue(type_here));
     805        }
    814806        newtPopHelpLine();
    815807        newtFormDestroy(myForm);
    816808        newtPopWindow();
    817         if (b_res == b_2) {
    818             strcpy(output, original_contents);
    819             paranoid_free(blurb);
    820             paranoid_free(original_contents);
    821             return (FALSE);
    822         } else {
    823             paranoid_free(blurb);
    824             paranoid_free(original_contents);
    825             return (TRUE);
    826         }
     809        mr_free(blurb);
     810
     811        return (output);
    827812    }
    828813
     
    11791164        } else {
    11801165            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);
    1181             mr_asprintf(percentline_str, " %3d%% done                 %3d%% to go", percentage, 100 - percentage);
     1166            mr_asprintf(&percentline_str, " %3d%% done                 %3d%% to go", percentage, 100 - percentage);
    11821167
    11831168            center_string(blurb1, 54);
Note: See TracChangeset for help on using the changeset viewer.