diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-10 19:44:20 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-10 19:44:20 +0000 |
commit | 04e11c9209f88b878d6bef0b56a4d8345c89c217 (patch) | |
tree | dc67a11b65d3d7e4a03b955dd2f5d1b3c7721b2f /util-linux/fdisk.c | |
parent | 9304d6ea92f7fc1529669800b75456d549cf1bfc (diff) | |
download | busybox-w32-04e11c9209f88b878d6bef0b56a4d8345c89c217.tar.gz busybox-w32-04e11c9209f88b878d6bef0b56a4d8345c89c217.tar.bz2 busybox-w32-04e11c9209f88b878d6bef0b56a4d8345c89c217.zip |
getpot: add support for "a+" specifier for nonnegative int parameters.
By Vladimir Dronnikov <dronnikov at gmail.com>.
fdisk and top are converted as an example.
function old new delta
getopt32 1340 1370 +30
top_main 1137 1120 -17
fdisk_main 3033 2949 -84
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 30/-101) Total: -71 bytes
Diffstat (limited to 'util-linux/fdisk.c')
-rw-r--r-- | util-linux/fdisk.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index cd053b876..c98a74fc0 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -2754,7 +2754,6 @@ unknown_command(int c) | |||
2754 | int fdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 2754 | int fdisk_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
2755 | int fdisk_main(int argc, char **argv) | 2755 | int fdisk_main(int argc, char **argv) |
2756 | { | 2756 | { |
2757 | char *str_b, *str_C, *str_H, *str_S; | ||
2758 | unsigned opt; | 2757 | unsigned opt; |
2759 | /* | 2758 | /* |
2760 | * fdisk -v | 2759 | * fdisk -v |
@@ -2776,8 +2775,9 @@ int fdisk_main(int argc, char **argv) | |||
2776 | 2775 | ||
2777 | INIT_G(); | 2776 | INIT_G(); |
2778 | 2777 | ||
2778 | opt_complementary = "b+:C+:H+:S+"; /* numeric params */ | ||
2779 | opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), | 2779 | opt = getopt32(argv, "b:C:H:lS:u" USE_FEATURE_FDISK_BLKSIZE("s"), |
2780 | &str_b, &str_C, &str_H, &str_S); | 2780 | §or_size, &user_cylinders, &user_heads, &user_sectors); |
2781 | argc -= optind; | 2781 | argc -= optind; |
2782 | argv += optind; | 2782 | argv += optind; |
2783 | if (opt & OPT_b) { // -b | 2783 | if (opt & OPT_b) { // -b |
@@ -2785,27 +2785,18 @@ int fdisk_main(int argc, char **argv) | |||
2785 | so cannot be combined with multiple disks, | 2785 | so cannot be combined with multiple disks, |
2786 | and the same goes for the C/H/S options. | 2786 | and the same goes for the C/H/S options. |
2787 | */ | 2787 | */ |
2788 | sector_size = xatoi_u(str_b); | 2788 | if (sector_size != 512 && sector_size != 1024 |
2789 | if (sector_size != 512 && sector_size != 1024 && | 2789 | && sector_size != 2048) |
2790 | sector_size != 2048) | ||
2791 | bb_show_usage(); | 2790 | bb_show_usage(); |
2792 | sector_offset = 2; | 2791 | sector_offset = 2; |
2793 | user_set_sector_size = 1; | 2792 | user_set_sector_size = 1; |
2794 | } | 2793 | } |
2795 | if (opt & OPT_C) user_cylinders = xatoi_u(str_C); // -C | 2794 | if (user_heads <= 0 || user_heads >= 256) |
2796 | if (opt & OPT_H) { // -H | 2795 | user_heads = 0; |
2797 | user_heads = xatoi_u(str_H); | 2796 | if (user_sectors <= 0 || user_sectors >= 64) |
2798 | if (user_heads <= 0 || user_heads >= 256) | 2797 | user_sectors = 0; |
2799 | user_heads = 0; | 2798 | if (opt & OPT_u) |
2800 | } | 2799 | display_in_cyl_units = 0; // -u |
2801 | //if (opt & OPT_l) // -l | ||
2802 | if (opt & OPT_S) { // -S | ||
2803 | user_sectors = xatoi_u(str_S); | ||
2804 | if (user_sectors <= 0 || user_sectors >= 64) | ||
2805 | user_sectors = 0; | ||
2806 | } | ||
2807 | if (opt & OPT_u) display_in_cyl_units = 0; // -u | ||
2808 | //if (opt & OPT_s) // -s | ||
2809 | 2800 | ||
2810 | if (user_set_sector_size && argc != 1) | 2801 | if (user_set_sector_size && argc != 1) |
2811 | printf("Warning: the -b (set sector size) option should" | 2802 | printf("Warning: the -b (set sector size) option should" |