openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/disk-utils/cfdisk.c
static int ui_create_label(struct cfdisk* cf)
{
    struct cfdisk_menuitem *d, *cm;
    int rc = 1, refresh_menu = 1;
    size_t i = 0, nitems;
    struct fdisk_label* lb = NULL;

    assert(cf);

    DBG(UI, ul_debug("asking for new disklabe."));

    /* create cfdisk menu according to libfdisk labels, note that the
     * last cm[] item has to be empty -- so nitems + 1 */
    nitems = fdisk_get_nlabels(cf->cxt);
    cm = xcalloc(nitems + 1, sizeof(struct cfdisk_menuitem));

    while (fdisk_next_label(cf->cxt, &lb) == 0)
    {
        if (fdisk_label_is_disabled(lb) ||
            fdisk_label_get_type(lb) == FDISK_DISKLABEL_BSD)
            continue;
        cm[i++].name = fdisk_label_get_name(lb);
    }

    erase();

    /* make the new menu active */
    menu_push(cf, cm);
    cf->menu->vertical = 1;
    menu_set_title(cf->menu, _("Select label type"));

    if (!cf->zero_start)
        ui_info(_("Device does not contain a recognized partition table."));

    while (!sig_die)
    {
        int key;

        if (refresh_menu)
        {
            ui_draw_menu(cf);
            ui_hint(_("Select a type to create a new label or press 'L' to "
                      "load script file."));
            refresh();
            refresh_menu = 0;
        }

        key = getch();

        if (sig_die)
            break;
        if (sig_resize)
            ui_menu_resize(cf);
        if (ui_menu_move(cf, key) == 0)
            continue;
        switch (key)
        {
            case KEY_ENTER:
            case '\n':
            case '\r':
                d = menu_get_menuitem(cf, cf->menu->idx);
                if (d)
                    rc = fdisk_create_disklabel(cf->cxt, d->name);
                goto done;
            case KEY_ESC:
            case 'q':
            case 'Q':
                goto done;
            case 'l':
            case 'L':
                rc = ui_script_read(cf);
                if (rc == 0)
                    goto done;
                refresh_menu = 1;
                break;
        }
    }

    if (sig_die)
        die_on_signal();
done:
    menu_pop(cf);
    free(cm);
    DBG(UI, ul_debug("create label done [rc=%d] ", rc));
    return rc;
}
/* prints menu with libfdisk labels and waits for users response */
prints menu with libfdisk labels and waits for users response
prints menu with libfdisk labels and waits for users response
static int ui_create_label(struct cfdisk* cf)
{
    struct cfdisk_menuitem *d, *cm;
    int rc = 1, refresh_menu = 1;
    size_t i = 0, nitems;
    struct fdisk_label* lb = NULL;
    assert(cf);
    DBG(UI, ul_debug("asking for new disklabe."));
    nitems = fdisk_get_nlabels(cf->cxt);
    cm = xcalloc(nitems + 1, sizeof(struct cfdisk_menuitem));
    while (fdisk_next_label(cf->cxt, &lb) == 0)
    {
        if (fdisk_label_is_disabled(lb) ||
            fdisk_label_get_type(lb) == FDISK_DISKLABEL_BSD)
            continue;
        cm[i++].name = fdisk_label_get_name(lb);
    }
    erase();
    menu_push(cf, cm);
    cf->menu->vertical = 1;
    menu_set_title(cf->menu, _("Select label type"));
    if (!cf->zero_start)
        ui_info(_("Device does not contain a recognized partition table."));
    while (!sig_die)
    {
        int key;
        if (refresh_menu)
        {
            ui_draw_menu(cf);
            ui_hint(_("Select a type to create a new label or press 'L' to "
                      "load script file."));
            refresh();
            refresh_menu = 0;
        }
        key = getch();
        if (sig_die)
            break;
        if (sig_resize)
            ui_menu_resize(cf);
        if (ui_menu_move(cf, key) == 0)
            continue;
        switch (key)
        {
            case KEY_ENTER:
            case '\n':
            case '\r':
                d = menu_get_menuitem(cf, cf->menu->idx);
                if (d)
                    rc = fdisk_create_disklabel(cf->cxt, d->name);
                goto done;
            case KEY_ESC:
            case 'q':
            case 'Q':
                goto done;
            case 'l':
            case 'L':
                rc = ui_script_read(cf);
                if (rc == 0)
                    goto done;
                refresh_menu = 1;
                break;
        }
    }
    if (sig_die)
        die_on_signal();
done:
    menu_pop(cf);
    free(cm);
    DBG(UI, ul_debug("create label done [rc=%d] ", rc));
    return rc;
}
static int ui_create_label ( struct cfdisk * cf ) { struct cfdisk_menuitem * d , * cm ; int rc = 1 , refresh_menu = 1 ; size_t i = 0 , nitems ; struct fdisk_label * lb = NULL ; assert ( cf ) ; DBG ( UI , ul_debug ( " " ) ) ; nitems = fdisk_get_nlabels ( cf -> cxt ) ; cm = xcalloc ( nitems + 1 , sizeof ( struct cfdisk_menuitem ) ) ; while ( fdisk_next_label ( cf -> cxt , & lb ) == 0 ) { if ( fdisk_label_is_disabled ( lb ) || fdisk_label_get_type ( lb ) == FDISK_DISKLABEL_BSD ) continue ; cm [ i ++ ] . name = fdisk_label_get_name ( lb ) ; } erase ( ) ; menu_push ( cf , cm ) ; cf -> menu -> vertical = 1 ; menu_set_title ( cf -> menu , _ ( " " ) ) ; if ( ! cf -> zero_start ) ui_info ( _ ( " " ) ) ; while ( ! sig_die ) { int key ; if ( refresh_menu ) { ui_draw_menu ( cf ) ; ui_hint ( _ ( " " " " ) ) ; refresh ( ) ; refresh_menu = 0 ; } key = getch ( ) ; if ( sig_die ) break ; if ( sig_resize ) ui_menu_resize ( cf ) ; if ( ui_menu_move ( cf , key ) == 0 ) continue ; switch ( key ) { case KEY_ENTER : case ' \n ' : case ' \r ' : d = menu_get_menuitem ( cf , cf -> menu -> idx ) ; if ( d ) rc = fdisk_create_disklabel ( cf -> cxt , d -> name ) ; goto done ; case KEY_ESC : case ' ' : case ' ' : goto done ; case ' ' : case ' ' : rc = ui_script_read ( cf ) ; if ( rc == 0 ) goto done ; refresh_menu = 1 ; break ; } } if ( sig_die ) die_on_signal ( ) ; done : menu_pop ( cf ) ; free ( cm ) ; DBG ( UI , ul_debug ( " " , rc ) ) ; return rc ; }
prints menu with libfdisk labels and waits for users response
prints menu with libfdisk labels and waits for users response
/* create cfdisk menu according to libfdisk labels, note that the
     * last cm[] item has to be empty -- so nitems + 1 */ /* make the new menu active */