~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to fdisk/cfdisk.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
#include <sys/stat.h>
90
90
#include <sys/ioctl.h>
91
91
 
92
 
#ifdef HAVE_LIBBLKID_INTERNAL
 
92
#ifdef HAVE_LIBBLKID
93
93
#include <blkid.h>
94
94
#endif
95
95
 
154
154
#define ESC '\033'
155
155
#define DEL '\177'
156
156
#define BELL '\007'
157
 
#define TAB '\011'
158
157
#define REDRAWKEY '\014'        /* ^L */
159
 
#define UPKEY '\020'            /* ^P */
160
 
#define UPKEYVI '\153'          /* k */
161
 
#define DOWNKEY '\016'          /* ^N */
162
 
#define DOWNKEYVI '\152'        /* j */
163
158
 
164
159
/* Display units */
165
160
#define GIGABYTES 1
581
576
}
582
577
 
583
578
static void
584
 
die(int dummy) {
 
579
die(int dummy __attribute__((__unused__))) {
585
580
    die_x(0);
586
581
}
587
582
 
617
612
        fatal(_("Cannot write disk drive"), 2);
618
613
}
619
614
 
620
 
#ifdef HAVE_LIBBLKID_INTERNAL
 
615
#ifdef HAVE_LIBBLKID
621
616
static void
622
617
get_fsinfo(int i)
623
618
{
954
949
    p_info[i].fstype[0] = 0;
955
950
    p_info[i].ostype[0] = 0;
956
951
 
957
 
#ifdef HAVE_LIBBLKID_INTERNAL
 
952
#ifdef HAVE_LIBBLKID
958
953
    if (want_label)
959
954
         get_fsinfo(i);
960
955
#endif
1006
1001
 */
1007
1002
 
1008
1003
/* Constants for menuType parameter of menuSelect function */
1009
 
#define MENU_HORIZ 1
1010
 
#define MENU_VERT 2
1011
1004
#define MENU_ACCEPT_OTHERS 4
1012
1005
#define MENU_BUTTON 8
1013
1006
/* Miscellenous constants */
1014
1007
#define MENU_SPACING 2
1015
1008
#define MENU_MAX_ITEMS 256 /* for simpleMenu function */
1016
 
#define MENU_UP 1
1017
 
#define MENU_DOWN 2
1018
 
#define MENU_RIGHT 3
1019
 
#define MENU_LEFT 4
1020
1009
 
1021
1010
struct MenuItem
1022
1011
{
1033
1022
static int
1034
1023
menuUpdate( int y, int x, struct MenuItem *menuItems, int itemLength,
1035
1024
            char *available, int menuType, int current ) {
1036
 
    int i, lmargin = x, ymargin = y;
 
1025
    int i, lmargin = x;
1037
1026
    char *mcd;
1038
1027
 
1039
1028
    /* Print available buttons */
1085
1074
        if( current == i ) /*attroff( A_REVERSE )*/ standend ();
1086
1075
 
1087
1076
        /* Calculate position for the next item */
1088
 
        if( menuType & MENU_VERT )
1089
 
        {
1090
 
            y += 1;
1091
 
            if( y >= WARNING_START )
1092
 
            {
1093
 
                y = ymargin;
1094
 
                x += itemLength + MENU_SPACING;
1095
 
                if( menuType & MENU_BUTTON ) x += 2;
1096
 
            }
1097
 
        }
1098
 
        else
1099
 
        {
1100
1077
            x += itemLength + MENU_SPACING;
1101
1078
            if( menuType & MENU_BUTTON ) x += 2;
1102
1079
            if( x > COLUMNS - lmargin - 12 )
1104
1081
                x = lmargin;
1105
1082
                y ++ ;
1106
1083
            }
1107
 
        }
1108
1084
    }
1109
1085
 
1110
1086
    /* Print the description of selected item */
1121
1097
            char *available, int menuType, int menuDefault ) {
1122
1098
    int i, ylast = y, key = 0, current = menuDefault;
1123
1099
 
1124
 
    if( !( menuType & ( MENU_HORIZ | MENU_VERT ) ) ) {
1125
 
        print_warning(_("Menu without direction. Defaulting to horizontal."));
1126
 
        menuType |= MENU_HORIZ;
1127
 
    }
1128
 
 
1129
1100
    /* Make sure that the current is one of the available items */
1130
1101
    while( !strchr(available, menuItems[current].key) ) {
1131
1102
        current ++ ;
1132
1103
        if( !menuItems[current].key ) current = 0;
1133
1104
    }
1134
1105
 
 
1106
    keypad(stdscr, TRUE);
 
1107
 
1135
1108
    /* Repeat until allowable choice has been made */
1136
1109
    while( !key ) {
1137
1110
        /* Display the menu and read a command */
1153
1126
        move( WARNING_START + 1, 0 );
1154
1127
        clrtoeol();
1155
1128
 
1156
 
        /* Cursor keys - possibly split by slow connection */
1157
 
        if( key == ESC ) {
1158
 
            /* Check whether this is a real ESC or one of extended keys */
1159
 
            /*nodelay(stdscr, TRUE);*/
1160
 
            key = getch();
1161
 
            /*nodelay(stdscr, FALSE);*/
1162
 
 
1163
 
            if( key == /*ERR*/ ESC ) {
1164
 
                /* This is a real ESC */
1165
 
                key = ESC;
1166
 
            }
1167
 
            if(key == '[' || key == 'O') {
1168
 
                /* This is one extended keys */
1169
 
                key = getch();
1170
 
 
1171
 
                switch(key) {
1172
 
                    case 'A': /* Up arrow */
1173
 
                        key = MENU_UP;
1174
 
                        break;
1175
 
                    case 'B': /* Down arrow */
1176
 
                        key = MENU_DOWN;
1177
 
                        break;
1178
 
                    case 'C': /* Right arrow */
1179
 
                        key = MENU_RIGHT;
1180
 
                        break;
1181
 
                    case 'D': /* Left arrow */
1182
 
                    case 'Z': /* Shift Tab */
1183
 
                        key = MENU_LEFT;
1184
 
                        break;
1185
 
                    default:
1186
 
                        key = 0;
1187
 
                }
1188
 
            }
1189
 
        }
1190
 
 
1191
 
        /* Enter equals the keyboard shortcut of current menu item */
1192
 
        if (key == '\r')
1193
 
            key = menuItems[current].key;
1194
 
 
1195
 
        /* Give alternatives for arrow keys in case the window manager
1196
 
           swallows these */
1197
 
        if (key == TAB)
1198
 
            key = MENU_RIGHT;
1199
 
        if (key == UPKEY || key == UPKEYVI)     /* ^P or k */
1200
 
            key = MENU_UP;
1201
 
        if (key == DOWNKEY || key == DOWNKEYVI) /* ^N or j */
1202
 
            key = MENU_DOWN;
1203
 
 
1204
 
        if (key == MENU_UP) {
1205
 
            if( menuType & MENU_VERT ) {
1206
 
                do {
1207
 
                    current -- ;
1208
 
                    if( current < 0 )
1209
 
                        while( menuItems[current+1].key )
1210
 
                            current ++ ;
1211
 
                } while( !strchr( available, menuItems[current].key ));
1212
 
                key = 0;
1213
 
            }
1214
 
        }
1215
 
 
1216
 
        if (key == MENU_DOWN) {
1217
 
            if( menuType & MENU_VERT ) {
1218
 
                do {
1219
 
                    current ++ ;
1220
 
                    if( !menuItems[current].key ) current = 0 ;
1221
 
                } while( !strchr( available, menuItems[current].key ));
1222
 
                key = 0;
1223
 
            }
1224
 
        }
1225
 
 
1226
 
        if (key == MENU_RIGHT) {
1227
 
            if( menuType & MENU_HORIZ ) {
1228
 
                do {
1229
 
                    current ++ ;
1230
 
                    if( !menuItems[current].key )
1231
 
                        current = 0 ;
1232
 
                } while( !strchr( available, menuItems[current].key ));
1233
 
                key = 0;
1234
 
            }
1235
 
        }
1236
 
 
1237
 
        if (key == MENU_LEFT) {
1238
 
             if( menuType & MENU_HORIZ ) {
1239
 
                 do {
1240
 
                     current -- ;
1241
 
                     if( current < 0 ) {
1242
 
                         while( menuItems[current + 1].key )
1243
 
                              current ++ ;
1244
 
                     }
1245
 
                 } while( !strchr( available, menuItems[current].key ));
1246
 
                 key = 0;
1247
 
             }
 
1129
        switch (key) {
 
1130
        case KEY_RIGHT:
 
1131
        case '\t':
 
1132
                /* Select next menu item */
 
1133
                do {
 
1134
                        current++;
 
1135
                        if (!menuItems[current].key)
 
1136
                                current = 0;
 
1137
                } while (!strchr(available, menuItems[current].key));
 
1138
                key = 0;
 
1139
                break;
 
1140
        case KEY_LEFT:
 
1141
#ifdef KEY_BTAB
 
1142
        case KEY_BTAB:  /* Back tab */
 
1143
#endif
 
1144
                /* Select previous menu item */
 
1145
                do {
 
1146
                        current--;
 
1147
                        if (current < 0) {
 
1148
                                while (menuItems[current + 1].key)
 
1149
                                        current++;
 
1150
                        }
 
1151
                } while (!strchr(available, menuItems[current].key));
 
1152
                key = 0;
 
1153
                break;
 
1154
        case KEY_ENTER:
 
1155
        case '\n':
 
1156
        case '\r':
 
1157
                /* Enter equals the keyboard shortcut of current menu item */
 
1158
                key = menuItems[current].key;
 
1159
                break;
1248
1160
        }
1249
1161
 
1250
1162
        /* Should all keys to be accepted? */
1262
1174
        }
1263
1175
    }
1264
1176
 
 
1177
    keypad(stdscr, FALSE);
 
1178
 
1265
1179
    /* Clear out prompts and such */
1266
1180
    clear_warning();
1267
1181
    for( i = y; i <= ylast; i ++ ) {
1286
1200
    };
1287
1201
 
1288
1202
    menuSelect(COMMAND_LINE_Y, COMMAND_LINE_X,
1289
 
        menuContinueBtn, 0, "c", MENU_HORIZ | MENU_ACCEPT_OTHERS, 0 );
 
1203
        menuContinueBtn, 0, "c", MENU_ACCEPT_OTHERS, 0 );
1290
1204
}
1291
1205
 
1292
1206
/* Function menuSelect takes way too many parameters  *
1305
1219
    }
1306
1220
    available[i] = 0;
1307
1221
    return menuSelect(COMMAND_LINE_Y, COMMAND_LINE_X, menuItems, itemLength,
1308
 
        available, MENU_HORIZ | MENU_BUTTON, menuDefault);
 
1222
        available, MENU_BUTTON, menuDefault);
1309
1223
}
1310
1224
 
1311
1225
/* End of command menu support code */
1845
1759
fp_printf(FILE *fp, char *format, ...) {
1846
1760
    va_list args;
1847
1761
    char buf[1024];
1848
 
    int y, x;
 
1762
    int y, x __attribute__((unused));
1849
1763
 
1850
1764
    va_start(args, format);
1851
1765
    vsnprintf(buf, sizeof(buf), format, args);
2612
2526
    free(line);
2613
2527
}
2614
2528
 
2615
 
static int
 
2529
static void
2616
2530
draw_cursor(int move) {
2617
 
    if (move != 0 && (cur_part + move < 0 || cur_part + move >= num_parts))
2618
 
        return -1;
 
2531
    if (move != 0 && (cur_part + move < 0 || cur_part + move >= num_parts)) {
 
2532
        print_warning(_("No more partitions"));
 
2533
        return;
 
2534
    }
2619
2535
 
2620
2536
    if (arrow_cursor)
2621
2537
        mvaddstr(DISK_TABLE_START + cur_part + 2
2637
2553
        draw_partition(cur_part);
2638
2554
        standend();
2639
2555
    }
2640
 
 
2641
 
    return 0;
2642
2556
}
2643
2557
 
2644
2558
static void
2645
2559
do_curses_fdisk(void) {
2646
2560
    int done = FALSE;
2647
 
    char command;
 
2561
    int command;
2648
2562
    int is_first_run = TRUE;
2649
2563
 
2650
2564
    static struct MenuItem menuMain[] = {
2683
2597
    while (!done) {
2684
2598
        char *s;
2685
2599
 
2686
 
        (void)draw_cursor(0);
 
2600
        draw_cursor(0);
2687
2601
 
2688
2602
        if (p_info[cur_part].id == FREE_SPACE) {
2689
2603
            s = ((opentype == O_RDWR) ? "hnpquW" : "hnpqu");
2690
2604
            command = menuSelect(COMMAND_LINE_Y, COMMAND_LINE_X, menuMain, 10,
2691
 
                s, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, 5);
 
2605
                s, MENU_BUTTON | MENU_ACCEPT_OTHERS, 5);
2692
2606
        } else if (p_info[cur_part].id > 0) {
2693
2607
            s = ((opentype == O_RDWR) ? "bdhmpqtuW" : "bdhmpqtu");
2694
2608
            command = menuSelect(COMMAND_LINE_Y, COMMAND_LINE_X, menuMain, 10,
2695
 
                s, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, is_first_run ? 7 : 0);
 
2609
                s, MENU_BUTTON | MENU_ACCEPT_OTHERS, is_first_run ? 7 : 0);
2696
2610
        } else {
2697
2611
            s = ((opentype == O_RDWR) ? "hpquW" : "hpqu");
2698
2612
            command = menuSelect(COMMAND_LINE_Y, COMMAND_LINE_X, menuMain, 10,
2699
 
                s, MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, 0);
 
2613
                s, MENU_BUTTON | MENU_ACCEPT_OTHERS, 0);
2700
2614
        }
2701
2615
        is_first_run = FALSE;
2702
2616
        switch ( command ) {
2787
2701
            display_help();
2788
2702
            draw_screen();
2789
2703
            break;
2790
 
        case MENU_UP : /* Up arrow */
2791
 
            if (!draw_cursor(-1))
2792
 
                command = 0;
2793
 
            else
2794
 
                print_warning(_("No more partitions"));
 
2704
        case KEY_UP:    /* Up arrow key */
 
2705
        case '\020':    /* ^P */
 
2706
        case 'k':       /* Vi-like alternative */
 
2707
            draw_cursor(-1);
2795
2708
            break;
2796
 
        case MENU_DOWN : /* Down arrow */
2797
 
            if (!draw_cursor(1))
2798
 
                command = 0;
2799
 
            else
2800
 
                print_warning(_("No more partitions"));
 
2709
        case KEY_DOWN:  /* Down arrow key */
 
2710
        case '\016':    /* ^N */
 
2711
        case 'j':       /* Vi-like alternative */
 
2712
            draw_cursor(1);
2801
2713
            break;
2802
2714
        case REDRAWKEY:
2803
2715
            clear();
2804
2716
            draw_screen();
2805
2717
            break;
 
2718
        case KEY_HOME:
 
2719
                draw_cursor(-cur_part);
 
2720
                break;
 
2721
        case KEY_END:
 
2722
                draw_cursor(num_parts - cur_part - 1);
 
2723
                break;
2806
2724
        default:
2807
2725
            print_warning(_("Illegal command"));
2808
2726
            putchar(BELL); /* CTRL-G */