diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 15:10:29 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-07 15:10:29 +0000 |
commit | 53354ac47df03bdccebad66bc22958fa2b4da520 (patch) | |
tree | b3d85b6cd19f81293848235560b24cbce86f77d7 | |
parent | f0d6c255860509b10148c70ef7cb518eb81bea6d (diff) | |
download | busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.tar.gz busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.tar.bz2 busybox-w32-53354ac47df03bdccebad66bc22958fa2b4da520.zip |
libbb: introduce and use print_flags().
Mostly by Natanael Copa <natanael.copa AT gmail.com>
function old new delta
print_e2flags - 189 +189
print_flags_separated - 86 +86
static.flag_labels - 60 +60
static.dma_wmode_masks - 32 +32
static.flag_masks - 28 +28
static.arp_labels - 16 +16
static.arp_masks - 12 +12
ls_main 836 843 +7
...
popstring 140 134 -6
arp_show 740 708 -32
print_flags 189 25 -164
ipaddr_list_or_flush 2396 2170 -226
process_dev 5306 4706 -600
------------------------------------------------------------------------------
(add/remove: 10/0 grow/shrink: 5/10 up/down: 458/-1043) Total: -585 bytes
text data bss dec hex filename
810564 624 7060 818248 c7c48 busybox_old
810002 624 7060 817686 c7a16 busybox_unstripped
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 2 | ||||
-rw-r--r-- | e2fsprogs/e2fs_lib.h | 2 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 4 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/e2p/e2p.h | 2 | ||||
-rw-r--r-- | e2fsprogs/old_e2fsprogs/lsattr.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 8 | ||||
-rw-r--r-- | libbb/Kbuild | 1 | ||||
-rw-r--r-- | miscutils/hdparm.c | 62 | ||||
-rw-r--r-- | networking/arp.c | 38 | ||||
-rw-r--r-- | networking/libiproute/ipaddress.c | 19 | ||||
-rw-r--r-- | util-linux/fdisk_osf.c | 11 |
11 files changed, 77 insertions, 76 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index 89e050051..839109e3f 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -192,7 +192,7 @@ static const char e2attr_flags_lname[] = | |||
192 | "Top_of_Directory_Hierarchies" "\0" | 192 | "Top_of_Directory_Hierarchies" "\0" |
193 | /* Another trailing NUL is added by compiler */; | 193 | /* Another trailing NUL is added by compiler */; |
194 | 194 | ||
195 | void print_flags(FILE *f, unsigned long flags, unsigned options) | 195 | void print_e2flags(FILE *f, unsigned long flags, unsigned options) |
196 | { | 196 | { |
197 | const uint32_t *fv; | 197 | const uint32_t *fv; |
198 | const char *fn; | 198 | const char *fn; |
diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h index 40bbd1c83..e21a0f917 100644 --- a/e2fsprogs/e2fs_lib.h +++ b/e2fsprogs/e2fs_lib.h | |||
@@ -31,7 +31,7 @@ int fgetsetflags(const char *name, unsigned long *get_flags, unsigned long set_f | |||
31 | /* Must be 1 for compatibility with `int long_format'. */ | 31 | /* Must be 1 for compatibility with `int long_format'. */ |
32 | #define PFOPT_LONG 1 | 32 | #define PFOPT_LONG 1 |
33 | /* Print file attributes on an ext2 file system */ | 33 | /* Print file attributes on an ext2 file system */ |
34 | void print_flags(FILE *f, unsigned long flags, unsigned options); | 34 | void print_e2flags(FILE *f, unsigned long flags, unsigned options); |
35 | 35 | ||
36 | extern const uint32_t e2attr_flags_value[]; | 36 | extern const uint32_t e2attr_flags_value[]; |
37 | extern const char e2attr_flags_sname[]; | 37 | extern const char e2attr_flags_sname[]; |
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 13eeb35f5..066af86c7 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c | |||
@@ -45,10 +45,10 @@ static void list_attributes(const char *name) | |||
45 | 45 | ||
46 | if (option_mask32 & OPT_PF_LONG) { | 46 | if (option_mask32 & OPT_PF_LONG) { |
47 | printf("%-28s ", name); | 47 | printf("%-28s ", name); |
48 | print_flags(stdout, fsflags, PFOPT_LONG); | 48 | print_e2flags(stdout, fsflags, PFOPT_LONG); |
49 | bb_putchar('\n'); | 49 | bb_putchar('\n'); |
50 | } else { | 50 | } else { |
51 | print_flags(stdout, fsflags, 0); | 51 | print_e2flags(stdout, fsflags, 0); |
52 | printf(" %s\n", name); | 52 | printf(" %s\n", name); |
53 | } | 53 | } |
54 | 54 | ||
diff --git a/e2fsprogs/old_e2fsprogs/e2p/e2p.h b/e2fsprogs/old_e2fsprogs/e2p/e2p.h index cae28f115..452470047 100644 --- a/e2fsprogs/old_e2fsprogs/e2p/e2p.h +++ b/e2fsprogs/old_e2fsprogs/e2p/e2p.h | |||
@@ -13,7 +13,7 @@ | |||
13 | #define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 | 13 | #define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | /* `options' for print_flags() */ | 16 | /* `options' for print_e2flags() */ |
17 | 17 | ||
18 | #define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ | 18 | #define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ |
19 | 19 | ||
diff --git a/e2fsprogs/old_e2fsprogs/lsattr.c b/e2fsprogs/old_e2fsprogs/lsattr.c index 277ec7c2c..294bf2f2e 100644 --- a/e2fsprogs/old_e2fsprogs/lsattr.c +++ b/e2fsprogs/old_e2fsprogs/lsattr.c | |||
@@ -56,10 +56,10 @@ static void list_attributes(const char *name) | |||
56 | 56 | ||
57 | if (flags & OPT_PF_LONG) { | 57 | if (flags & OPT_PF_LONG) { |
58 | printf("%-28s ", name); | 58 | printf("%-28s ", name); |
59 | print_flags(stdout, fsflags, PFOPT_LONG); | 59 | print_e2flags(stdout, fsflags, PFOPT_LONG); |
60 | bb_putchar('\n'); | 60 | bb_putchar('\n'); |
61 | } else { | 61 | } else { |
62 | print_flags(stdout, fsflags, 0); | 62 | print_e2flags(stdout, fsflags, 0); |
63 | printf(" %s\n", name); | 63 | printf(" %s\n", name); |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/include/libbb.h b/include/libbb.h index c4d802ffd..97aae0bb4 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1304,6 +1304,14 @@ extern const char bb_default_login_shell[]; | |||
1304 | /* "sh" */ | 1304 | /* "sh" */ |
1305 | #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) | 1305 | #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) |
1306 | 1306 | ||
1307 | typedef struct masks_labels_t { | ||
1308 | const char *labels; | ||
1309 | const int masks[]; | ||
1310 | } masks_labels_t; | ||
1311 | |||
1312 | int print_flags_separated(const int *masks, const char *labels, | ||
1313 | int flags, const char *separator); | ||
1314 | extern int print_flags(const masks_labels_t *ml, int flags); | ||
1307 | 1315 | ||
1308 | #if ENABLE_FEATURE_DEVFS | 1316 | #if ENABLE_FEATURE_DEVFS |
1309 | # define CURRENT_VC "/dev/vc/0" | 1317 | # define CURRENT_VC "/dev/vc/0" |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 201d795ad..7bb0f3bfe 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -68,6 +68,7 @@ lib-y += perror_nomsg.o | |||
68 | lib-y += perror_nomsg_and_die.o | 68 | lib-y += perror_nomsg_and_die.o |
69 | lib-y += pidfile.o | 69 | lib-y += pidfile.o |
70 | lib-y += printable.o | 70 | lib-y += printable.o |
71 | lib-y += print_flags.o | ||
71 | lib-y += process_escape_sequence.o | 72 | lib-y += process_escape_sequence.o |
72 | lib-y += procps.o | 73 | lib-y += procps.o |
73 | lib-y += ptr_to_globals.o | 74 | lib-y += ptr_to_globals.o |
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index aa95b89b0..983de6d7b 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -1228,54 +1228,46 @@ static void dump_identity(const struct hd_driveid *id) | |||
1228 | if (id->tPIO >= 2) printf("pio2 "); | 1228 | if (id->tPIO >= 2) printf("pio2 "); |
1229 | } | 1229 | } |
1230 | if (id->field_valid & 2) { | 1230 | if (id->field_valid & 2) { |
1231 | if (id->eide_pio_modes & 1) printf("pio3 "); | 1231 | static const masks_labels_t pio_modes = { |
1232 | if (id->eide_pio_modes & 2) printf("pio4 "); | 1232 | .masks = { 1, 2, ~3 }, |
1233 | if (id->eide_pio_modes &~3) printf("pio? "); | 1233 | .labels = "pio3 \0""pio4 \0""pio? \0", |
1234 | }; | ||
1235 | print_flags(&pio_modes, id->eide_pio_modes); | ||
1234 | } | 1236 | } |
1235 | if (id->capability & 1) { | 1237 | if (id->capability & 1) { |
1236 | if (id->dma_1word | id->dma_mword) { | 1238 | if (id->dma_1word | id->dma_mword) { |
1239 | static const int dma_wmode_masks[] = { 0x100, 1, 0x200, 2, 0x400, 4, 0xf800, 0xf8 }; | ||
1237 | printf("\n DMA modes: "); | 1240 | printf("\n DMA modes: "); |
1238 | if (id->dma_1word & 0x100) bb_putchar('*'); | 1241 | print_flags_separated(dma_wmode_masks, |
1239 | if (id->dma_1word & 1) printf("sdma0 "); | 1242 | "*\0""sdma0 \0""*\0""sdma1 \0""*\0""sdma2 \0""*\0""sdma? \0", |
1240 | if (id->dma_1word & 0x200) bb_putchar('*'); | 1243 | id->dma_1word, NULL); |
1241 | if (id->dma_1word & 2) printf("sdma1 "); | 1244 | print_flags_separated(dma_wmode_masks, |
1242 | if (id->dma_1word & 0x400) bb_putchar('*'); | 1245 | "*\0""mdma0\0""*\0""mdma1\0""*\0""mdma2\0""*\0""mdma?\0", |
1243 | if (id->dma_1word & 4) printf("sdma2 "); | 1246 | id->dma_mword, NULL); |
1244 | if (id->dma_1word & 0xf800) bb_putchar('*'); | ||
1245 | if (id->dma_1word & 0xf8) printf("sdma? "); | ||
1246 | if (id->dma_mword & 0x100) bb_putchar('*'); | ||
1247 | if (id->dma_mword & 1) printf("mdma0 "); | ||
1248 | if (id->dma_mword & 0x200) bb_putchar('*'); | ||
1249 | if (id->dma_mword & 2) printf("mdma1 "); | ||
1250 | if (id->dma_mword & 0x400) bb_putchar('*'); | ||
1251 | if (id->dma_mword & 4) printf("mdma2 "); | ||
1252 | if (id->dma_mword & 0xf800) bb_putchar('*'); | ||
1253 | if (id->dma_mword & 0xf8) printf("mdma? "); | ||
1254 | } | 1247 | } |
1255 | } | 1248 | } |
1256 | if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) { | 1249 | if (((id->capability & 8) || (id->field_valid & 2)) && id->field_valid & 4) { |
1250 | static const masks_labels_t ultra_modes1 = { | ||
1251 | .masks = { 0x100, 0x001, 0x200, 0x002, 0x400, 0x004 }, | ||
1252 | .labels = "*\0""udma0 \0""*\0""udma1 \0""*\0""udma2 \0", | ||
1253 | }; | ||
1254 | |||
1257 | printf("\n UDMA modes: "); | 1255 | printf("\n UDMA modes: "); |
1258 | if (id->dma_ultra & 0x100) bb_putchar('*'); | 1256 | print_flags(&ultra_modes1, id->dma_ultra); |
1259 | if (id->dma_ultra & 0x001) printf("udma0 "); | ||
1260 | if (id->dma_ultra & 0x200) bb_putchar('*'); | ||
1261 | if (id->dma_ultra & 0x002) printf("udma1 "); | ||
1262 | if (id->dma_ultra & 0x400) bb_putchar('*'); | ||
1263 | if (id->dma_ultra & 0x004) printf("udma2 "); | ||
1264 | #ifdef __NEW_HD_DRIVE_ID | 1257 | #ifdef __NEW_HD_DRIVE_ID |
1265 | if (id->hw_config & 0x2000) { | 1258 | if (id->hw_config & 0x2000) { |
1266 | #else /* !__NEW_HD_DRIVE_ID */ | 1259 | #else /* !__NEW_HD_DRIVE_ID */ |
1267 | if (id->word93 & 0x2000) { | 1260 | if (id->word93 & 0x2000) { |
1268 | #endif /* __NEW_HD_DRIVE_ID */ | 1261 | #endif /* __NEW_HD_DRIVE_ID */ |
1269 | if (id->dma_ultra & 0x0800) bb_putchar('*'); | 1262 | static const masks_labels_t ultra_modes2 = { |
1270 | if (id->dma_ultra & 0x0008) printf("udma3 "); | 1263 | .masks = { 0x0800, 0x0008, 0x1000, 0x0010, |
1271 | if (id->dma_ultra & 0x1000) bb_putchar('*'); | 1264 | 0x2000, 0x0020, 0x4000, 0x0040, |
1272 | if (id->dma_ultra & 0x0010) printf("udma4 "); | 1265 | 0x8000, 0x0080 }, |
1273 | if (id->dma_ultra & 0x2000) bb_putchar('*'); | 1266 | .labels = "*\0""udma3 \0""*\0""udma4 \0" |
1274 | if (id->dma_ultra & 0x0020) printf("udma5 "); | 1267 | "*\0""udma5 \0""*\0""udma6 \0" |
1275 | if (id->dma_ultra & 0x4000) bb_putchar('*'); | 1268 | "*\0""udma7 \0" |
1276 | if (id->dma_ultra & 0x0040) printf("udma6 "); | 1269 | }; |
1277 | if (id->dma_ultra & 0x8000) bb_putchar('*'); | 1270 | print_flags(&ultra_modes2, id->dma_ultra); |
1278 | if (id->dma_ultra & 0x0080) printf("udma7 "); | ||
1279 | } | 1271 | } |
1280 | } | 1272 | } |
1281 | printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes"); | 1273 | printf("\n AdvancedPM=%s", (!(id_regs[83] & 8)) ? "no" : "yes"); |
diff --git a/networking/arp.c b/networking/arp.c index f42e09f7c..f85a91022 100644 --- a/networking/arp.c +++ b/networking/arp.c | |||
@@ -313,6 +313,26 @@ static void | |||
313 | arp_disp(const char *name, char *ip, int type, int arp_flags, | 313 | arp_disp(const char *name, char *ip, int type, int arp_flags, |
314 | char *hwa, char *mask, char *dev) | 314 | char *hwa, char *mask, char *dev) |
315 | { | 315 | { |
316 | static const int arp_masks[] = { | ||
317 | ATF_PERM, ATF_PUBL, | ||
318 | #ifdef HAVE_ATF_MAGIC | ||
319 | ATF_MAGIC, | ||
320 | #endif | ||
321 | #ifdef HAVE_ATF_DONTPUB | ||
322 | ATF_DONTPUB, | ||
323 | #endif | ||
324 | ATF_USETRAILERS, | ||
325 | }; | ||
326 | static const char arp_labels[] ALIGN1 = "PERM\0""PUP\0" | ||
327 | #ifdef HAVE_ATF_MAGIC | ||
328 | "AUTO\0" | ||
329 | #endif | ||
330 | #ifdef HAVE_ATF_DONTPUB | ||
331 | "DONTPUB\0" | ||
332 | #endif | ||
333 | "TRAIL\0" | ||
334 | ; | ||
335 | |||
316 | const struct hwtype *xhw; | 336 | const struct hwtype *xhw; |
317 | 337 | ||
318 | xhw = get_hwntype(type); | 338 | xhw = get_hwntype(type); |
@@ -333,22 +353,8 @@ arp_disp(const char *name, char *ip, int type, int arp_flags, | |||
333 | if (arp_flags & ATF_NETMASK) | 353 | if (arp_flags & ATF_NETMASK) |
334 | printf("netmask %s ", mask); | 354 | printf("netmask %s ", mask); |
335 | 355 | ||
336 | if (arp_flags & ATF_PERM) | 356 | print_flags_separated(arp_masks, arp_labels, arp_flags, " "); |
337 | printf("PERM "); | 357 | printf(" on %s\n", dev); |
338 | if (arp_flags & ATF_PUBL) | ||
339 | printf("PUP "); | ||
340 | #ifdef HAVE_ATF_MAGIC | ||
341 | if (arp_flags & ATF_MAGIC) | ||
342 | printf("AUTO "); | ||
343 | #endif | ||
344 | #ifdef HAVE_ATF_DONTPUB | ||
345 | if (arp_flags & ATF_DONTPUB) | ||
346 | printf("DONTPUB "); | ||
347 | #endif | ||
348 | if (arp_flags & ATF_USETRAILERS) | ||
349 | printf("TRAIL "); | ||
350 | |||
351 | printf("on %s\n", dev); | ||
352 | } | 358 | } |
353 | 359 | ||
354 | /* Display the contents of the ARP cache in the kernel. */ | 360 | /* Display the contents of the ARP cache in the kernel. */ |
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 07b27870d..faa3f2d06 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -45,16 +45,15 @@ typedef struct filter_t { | |||
45 | 45 | ||
46 | static void print_link_flags(unsigned flags, unsigned mdown) | 46 | static void print_link_flags(unsigned flags, unsigned mdown) |
47 | { | 47 | { |
48 | static const int flag_masks[] = { | ||
49 | IFF_LOOPBACK, IFF_BROADCAST, IFF_POINTOPOINT, | ||
50 | IFF_MULTICAST, IFF_NOARP, IFF_UP, IFF_LOWER_UP }; | ||
51 | static const char flag_labels[] ALIGN1 = | ||
52 | "LOOPBACK\0""BROADCAST\0""POINTOPOINT\0" | ||
53 | "MULTICAST\0""NOARP\0""UP\0""LOWER_UP\0"; | ||
54 | |||
48 | bb_putchar('<'); | 55 | bb_putchar('<'); |
49 | flags &= ~IFF_RUNNING; | 56 | flags &= ~IFF_RUNNING; |
50 | #define _PF(f) if (flags & IFF_##f) { \ | ||
51 | flags &= ~IFF_##f; \ | ||
52 | printf(#f "%s", flags ? "," : ""); } | ||
53 | _PF(LOOPBACK); | ||
54 | _PF(BROADCAST); | ||
55 | _PF(POINTOPOINT); | ||
56 | _PF(MULTICAST); | ||
57 | _PF(NOARP); | ||
58 | #if 0 | 57 | #if 0 |
59 | _PF(ALLMULTI); | 58 | _PF(ALLMULTI); |
60 | _PF(PROMISC); | 59 | _PF(PROMISC); |
@@ -66,9 +65,7 @@ static void print_link_flags(unsigned flags, unsigned mdown) | |||
66 | _PF(PORTSEL); | 65 | _PF(PORTSEL); |
67 | _PF(NOTRAILERS); | 66 | _PF(NOTRAILERS); |
68 | #endif | 67 | #endif |
69 | _PF(UP); | 68 | flags = print_flags_separated(flag_masks, flag_labels, flags, ","); |
70 | _PF(LOWER_UP); | ||
71 | #undef _PF | ||
72 | if (flags) | 69 | if (flags) |
73 | printf("%x", flags); | 70 | printf("%x", flags); |
74 | if (mdown) | 71 | if (mdown) |
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index e281ea5d9..30c42553b 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c | |||
@@ -502,6 +502,8 @@ xbsd_print_disklabel(int show_all) | |||
502 | int i, j; | 502 | int i, j; |
503 | 503 | ||
504 | if (show_all) { | 504 | if (show_all) { |
505 | static const int d_masks[] = { BSD_D_REMOVABLE, BSD_D_ECC, BSD_D_BADSECT }; | ||
506 | |||
505 | #if defined(__alpha__) | 507 | #if defined(__alpha__) |
506 | printf("# %s:\n", disk_device); | 508 | printf("# %s:\n", disk_device); |
507 | #else | 509 | #else |
@@ -513,13 +515,8 @@ xbsd_print_disklabel(int show_all) | |||
513 | printf("type: %d\n", lp->d_type); | 515 | printf("type: %d\n", lp->d_type); |
514 | printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); | 516 | printf("disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); |
515 | printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); | 517 | printf("label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); |
516 | printf("flags:"); | 518 | printf("flags: "); |
517 | if (lp->d_flags & BSD_D_REMOVABLE) | 519 | print_flags_separated(d_masks, "removable\0""ecc\0""badsect\0", lp->d_flags, " "); |
518 | printf(" removable"); | ||
519 | if (lp->d_flags & BSD_D_ECC) | ||
520 | printf(" ecc"); | ||
521 | if (lp->d_flags & BSD_D_BADSECT) | ||
522 | printf(" badsect"); | ||
523 | bb_putchar('\n'); | 520 | bb_putchar('\n'); |
524 | /* On various machines the fields of *lp are short/int/long */ | 521 | /* On various machines the fields of *lp are short/int/long */ |
525 | /* In order to avoid problems, we cast them all to long. */ | 522 | /* In order to avoid problems, we cast them all to long. */ |