diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-07-13 23:49:45 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-07-13 23:49:45 +0200 |
commit | c72b43c2f07e5fae288fff9e220b1f88e2889a72 (patch) | |
tree | 4577ff27d4aefdb610b3e26fbf13651f8a01c81d | |
parent | 0dacb68e1a660b235f9098abd33577be2e147c67 (diff) | |
download | busybox-w32-c72b43c2f07e5fae288fff9e220b1f88e2889a72.tar.gz busybox-w32-c72b43c2f07e5fae288fff9e220b1f88e2889a72.tar.bz2 busybox-w32-c72b43c2f07e5fae288fff9e220b1f88e2889a72.zip |
Commonalize typical [b,]k,m suffix struct
function old new delta
bkm_suffixes - 32 +32
static.km_suffixes 24 - -24
suffixes 32 - -32
static.bkm 32 - -32
head_tail_suffixes 32 - -32
------------------------------------------------------------------------------
(add/remove: 2/6 grow/shrink: 0/0 up/down: 72/-160) Total: -88 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | coreutils/head.c | 4 | ||||
-rw-r--r-- | coreutils/head_tail.c | 14 | ||||
-rw-r--r-- | coreutils/head_tail.h | 6 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 12 | ||||
-rw-r--r-- | coreutils/split.c | 11 | ||||
-rw-r--r-- | coreutils/tail.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/xatonum.c | 7 | ||||
-rw-r--r-- | runit/svlogd.c | 5 | ||||
-rw-r--r-- | util-linux/hexdump.c | 9 |
11 files changed, 22 insertions, 58 deletions
@@ -132,11 +132,6 @@ stty / catv | |||
132 | stty's visible() function and catv's guts are identical. Merge them into | 132 | stty's visible() function and catv's guts are identical. Merge them into |
133 | an appropriate libbb function. | 133 | an appropriate libbb function. |
134 | --- | 134 | --- |
135 | struct suffix_mult | ||
136 | Several duplicate users of: grep -r "1024\*1024" * -B2 -A1 | ||
137 | Merge to a single size_suffixes[] in libbb. | ||
138 | Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd | ||
139 | --- | ||
140 | tail | 135 | tail |
141 | ./busybox tail -f foo.c~ TODO | 136 | ./busybox tail -f foo.c~ TODO |
142 | should not print fmt=header_fmt for subsequent date >> TODO; i.e. only | 137 | should not print fmt=header_fmt for subsequent date >> TODO; i.e. only |
diff --git a/coreutils/head.c b/coreutils/head.c index 291e1ce37..9388b026a 100644 --- a/coreutils/head.c +++ b/coreutils/head.c | |||
@@ -12,7 +12,6 @@ | |||
12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ | 12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ |
13 | 13 | ||
14 | //kbuild:lib-$(CONFIG_HEAD) += head.o | 14 | //kbuild:lib-$(CONFIG_HEAD) += head.o |
15 | //kbuild:lib-$(CONFIG_HEAD) += head_tail.o | ||
16 | 15 | ||
17 | //usage:#define head_trivial_usage | 16 | //usage:#define head_trivial_usage |
18 | //usage: "[OPTIONS] [FILE]..." | 17 | //usage: "[OPTIONS] [FILE]..." |
@@ -35,7 +34,6 @@ | |||
35 | //usage: "daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n" | 34 | //usage: "daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n" |
36 | 35 | ||
37 | #include "libbb.h" | 36 | #include "libbb.h" |
38 | #include "head_tail.h" | ||
39 | 37 | ||
40 | /* This is a NOEXEC applet. Be very careful! */ | 38 | /* This is a NOEXEC applet. Be very careful! */ |
41 | 39 | ||
@@ -140,7 +138,7 @@ eat_num(bool *negative_N, const char *p) | |||
140 | p++; | 138 | p++; |
141 | } | 139 | } |
142 | #endif | 140 | #endif |
143 | return xatoul_sfx(p, head_tail_suffixes); | 141 | return xatoul_sfx(p, bkm_suffixes); |
144 | } | 142 | } |
145 | 143 | ||
146 | static const char head_opts[] ALIGN1 = | 144 | static const char head_opts[] ALIGN1 = |
diff --git a/coreutils/head_tail.c b/coreutils/head_tail.c deleted file mode 100644 index 1658c0d1b..000000000 --- a/coreutils/head_tail.c +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Denys Vlasenko | ||
3 | * | ||
4 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | #include "libbb.h" | ||
7 | #include "head_tail.h" | ||
8 | |||
9 | const struct suffix_mult head_tail_suffixes[] = { | ||
10 | { "b", 512 }, | ||
11 | { "k", 1024 }, | ||
12 | { "m", 1024*1024 }, | ||
13 | { "", 0 } | ||
14 | }; | ||
diff --git a/coreutils/head_tail.h b/coreutils/head_tail.h deleted file mode 100644 index df19e41e0..000000000 --- a/coreutils/head_tail.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Denys Vlasenko | ||
3 | * | ||
4 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
5 | */ | ||
6 | extern const struct suffix_mult head_tail_suffixes[]; | ||
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index b408a8477..2c26dda16 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -1166,12 +1166,6 @@ parse_old_offset(const char *s, off_t *offset) | |||
1166 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1166 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1167 | int od_main(int argc UNUSED_PARAM, char **argv) | 1167 | int od_main(int argc UNUSED_PARAM, char **argv) |
1168 | { | 1168 | { |
1169 | static const struct suffix_mult bkm[] = { | ||
1170 | { "b", 512 }, | ||
1171 | { "k", 1024 }, | ||
1172 | { "m", 1024*1024 }, | ||
1173 | { "", 0 } | ||
1174 | }; | ||
1175 | #if ENABLE_LONG_OPTS | 1169 | #if ENABLE_LONG_OPTS |
1176 | static const char od_longopts[] ALIGN1 = | 1170 | static const char od_longopts[] ALIGN1 = |
1177 | "skip-bytes\0" Required_argument "j" | 1171 | "skip-bytes\0" Required_argument "j" |
@@ -1230,7 +1224,7 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1230 | address_pad_len_char = doxn_address_pad_len_char[pos]; | 1224 | address_pad_len_char = doxn_address_pad_len_char[pos]; |
1231 | } | 1225 | } |
1232 | if (opt & OPT_N) { | 1226 | if (opt & OPT_N) { |
1233 | max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm); | 1227 | max_bytes_to_format = xstrtooff_sfx(str_N, 0, bkm_suffixes); |
1234 | } | 1228 | } |
1235 | if (opt & OPT_a) decode_format_string("a"); | 1229 | if (opt & OPT_a) decode_format_string("a"); |
1236 | if (opt & OPT_b) decode_format_string("oC"); | 1230 | if (opt & OPT_b) decode_format_string("oC"); |
@@ -1239,7 +1233,7 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1239 | if (opt & OPT_f) decode_format_string("fF"); | 1233 | if (opt & OPT_f) decode_format_string("fF"); |
1240 | if (opt & OPT_h) decode_format_string("x2"); | 1234 | if (opt & OPT_h) decode_format_string("x2"); |
1241 | if (opt & OPT_i) decode_format_string("d2"); | 1235 | if (opt & OPT_i) decode_format_string("d2"); |
1242 | if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm); | 1236 | if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); |
1243 | if (opt & OPT_l) decode_format_string("d4"); | 1237 | if (opt & OPT_l) decode_format_string("d4"); |
1244 | if (opt & OPT_o) decode_format_string("o2"); | 1238 | if (opt & OPT_o) decode_format_string("o2"); |
1245 | while (lst_t) { | 1239 | while (lst_t) { |
@@ -1248,7 +1242,7 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1248 | if (opt & OPT_x) decode_format_string("x2"); | 1242 | if (opt & OPT_x) decode_format_string("x2"); |
1249 | if (opt & OPT_s) decode_format_string("d2"); | 1243 | if (opt & OPT_s) decode_format_string("d2"); |
1250 | if (opt & OPT_S) { | 1244 | if (opt & OPT_S) { |
1251 | string_min = xstrtou_sfx(str_S, 0, bkm); | 1245 | string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); |
1252 | } | 1246 | } |
1253 | 1247 | ||
1254 | // Bloat: | 1248 | // Bloat: |
diff --git a/coreutils/split.c b/coreutils/split.c index 11e640442..1e1673efb 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -23,17 +23,15 @@ | |||
23 | 23 | ||
24 | #include "libbb.h" | 24 | #include "libbb.h" |
25 | 25 | ||
26 | static const struct suffix_mult split_suffices[] = { | ||
27 | #if ENABLE_FEATURE_SPLIT_FANCY | 26 | #if ENABLE_FEATURE_SPLIT_FANCY |
27 | static const struct suffix_mult split_suffixes[] = { | ||
28 | { "b", 512 }, | 28 | { "b", 512 }, |
29 | #endif | ||
30 | { "k", 1024 }, | 29 | { "k", 1024 }, |
31 | { "m", 1024*1024 }, | 30 | { "m", 1024*1024 }, |
32 | #if ENABLE_FEATURE_SPLIT_FANCY | ||
33 | { "g", 1024*1024*1024 }, | 31 | { "g", 1024*1024*1024 }, |
34 | #endif | ||
35 | { "", 0 } | 32 | { "", 0 } |
36 | }; | 33 | }; |
34 | #endif | ||
37 | 35 | ||
38 | /* Increment the suffix part of the filename. | 36 | /* Increment the suffix part of the filename. |
39 | * Returns NULL if we are out of filenames. | 37 | * Returns NULL if we are out of filenames. |
@@ -86,7 +84,10 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
86 | if (opt & SPLIT_OPT_l) | 84 | if (opt & SPLIT_OPT_l) |
87 | cnt = XATOOFF(count_p); | 85 | cnt = XATOOFF(count_p); |
88 | if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF | 86 | if (opt & SPLIT_OPT_b) // FIXME: also needs XATOOFF |
89 | cnt = xatoull_sfx(count_p, split_suffices); | 87 | cnt = xatoull_sfx(count_p, |
88 | IF_FEATURE_SPLIT_FANCY(split_suffixes) | ||
89 | IF_NOT_FEATURE_SPLIT_FANCY(km_suffixes) | ||
90 | ); | ||
90 | sfx = "x"; | 91 | sfx = "x"; |
91 | 92 | ||
92 | argv += optind; | 93 | argv += optind; |
diff --git a/coreutils/tail.c b/coreutils/tail.c index c9f9d00f6..07c71ca4b 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -25,7 +25,6 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | //kbuild:lib-$(CONFIG_TAIL) += tail.o | 27 | //kbuild:lib-$(CONFIG_TAIL) += tail.o |
28 | //kbuild:lib-$(CONFIG_TAIL) += head_tail.o | ||
29 | 28 | ||
30 | //usage:#define tail_trivial_usage | 29 | //usage:#define tail_trivial_usage |
31 | //usage: "[OPTIONS] [FILE]..." | 30 | //usage: "[OPTIONS] [FILE]..." |
@@ -51,7 +50,6 @@ | |||
51 | //usage: "nameserver 10.0.0.1\n" | 50 | //usage: "nameserver 10.0.0.1\n" |
52 | 51 | ||
53 | #include "libbb.h" | 52 | #include "libbb.h" |
54 | #include "head_tail.h" | ||
55 | 53 | ||
56 | struct globals { | 54 | struct globals { |
57 | bool from_top; | 55 | bool from_top; |
@@ -89,7 +87,7 @@ static unsigned eat_num(const char *p) | |||
89 | p++; | 87 | p++; |
90 | G.from_top = 1; | 88 | G.from_top = 1; |
91 | } | 89 | } |
92 | return xatou_sfx(p, head_tail_suffixes); | 90 | return xatou_sfx(p, bkm_suffixes); |
93 | } | 91 | } |
94 | 92 | ||
95 | int tail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 93 | int tail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
diff --git a/include/libbb.h b/include/libbb.h index 085210431..f22c1252b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -832,6 +832,9 @@ struct suffix_mult { | |||
832 | char suffix[4]; | 832 | char suffix[4]; |
833 | unsigned mult; | 833 | unsigned mult; |
834 | }; | 834 | }; |
835 | extern const struct suffix_mult bkm_suffixes[]; | ||
836 | #define km_suffixes (bkm_suffixes + 1) | ||
837 | |||
835 | #include "xatonum.h" | 838 | #include "xatonum.h" |
836 | /* Specialized: */ | 839 | /* Specialized: */ |
837 | 840 | ||
diff --git a/libbb/xatonum.c b/libbb/xatonum.c index 62bbe53e7..6f4e023bb 100644 --- a/libbb/xatonum.c +++ b/libbb/xatonum.c | |||
@@ -68,3 +68,10 @@ uint16_t FAST_FUNC xatou16(const char *numstr) | |||
68 | { | 68 | { |
69 | return xatou_range(numstr, 0, 0xffff); | 69 | return xatou_range(numstr, 0, 0xffff); |
70 | } | 70 | } |
71 | |||
72 | const struct suffix_mult bkm_suffixes[] = { | ||
73 | { "b", 512 }, | ||
74 | { "k", 1024 }, | ||
75 | { "m", 1024*1024 }, | ||
76 | { "", 0 } | ||
77 | }; | ||
diff --git a/runit/svlogd.c b/runit/svlogd.c index b7a0a6e71..8b8a6d858 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -745,11 +745,6 @@ static NOINLINE unsigned logdir_open(struct logdir *ld, const char *fn) | |||
745 | ld->inst = new; | 745 | ld->inst = new; |
746 | break; | 746 | break; |
747 | case 's': { | 747 | case 's': { |
748 | static const struct suffix_mult km_suffixes[] = { | ||
749 | { "k", 1024 }, | ||
750 | { "m", 1024*1024 }, | ||
751 | { "", 0 } | ||
752 | }; | ||
753 | ld->sizemax = xatou_sfx(&s[1], km_suffixes); | 748 | ld->sizemax = xatou_sfx(&s[1], km_suffixes); |
754 | break; | 749 | break; |
755 | } | 750 | } |
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index 4d998b916..ac7e24ff8 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c | |||
@@ -66,13 +66,6 @@ static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\""; | |||
66 | 66 | ||
67 | static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v" IF_FEATURE_HEXDUMP_REVERSE("R"); | 67 | static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v" IF_FEATURE_HEXDUMP_REVERSE("R"); |
68 | 68 | ||
69 | static const struct suffix_mult suffixes[] = { | ||
70 | { "b", 512 }, | ||
71 | { "k", 1024 }, | ||
72 | { "m", 1024*1024 }, | ||
73 | { "", 0 } | ||
74 | }; | ||
75 | |||
76 | int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 69 | int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
77 | int hexdump_main(int argc, char **argv) | 70 | int hexdump_main(int argc, char **argv) |
78 | { | 71 | { |
@@ -120,7 +113,7 @@ int hexdump_main(int argc, char **argv) | |||
120 | optarg, | 113 | optarg, |
121 | /*base:*/ 0, | 114 | /*base:*/ 0, |
122 | /*lo:*/ 0, /*hi:*/ OFF_T_MAX, | 115 | /*lo:*/ 0, /*hi:*/ OFF_T_MAX, |
123 | suffixes | 116 | bkm_suffixes |
124 | ); | 117 | ); |
125 | } /* else */ | 118 | } /* else */ |
126 | if (ch == 'v') { | 119 | if (ch == 'v') { |