diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-24 12:14:24 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-12-24 12:14:24 +0000 |
commit | e4bc603f0ba296647bd5fc3f1e8e7231effe6676 (patch) | |
tree | 75292365070482fc3c3adbbcbe747e56bd6aa27f /coreutils | |
parent | ef36c04ccfbb8fa22f7262d8db392c032a297c83 (diff) | |
download | busybox-w32-e4bc603f0ba296647bd5fc3f1e8e7231effe6676.tar.gz busybox-w32-e4bc603f0ba296647bd5fc3f1e8e7231effe6676.tar.bz2 busybox-w32-e4bc603f0ba296647bd5fc3f1e8e7231effe6676.zip |
od: reduce data/bss usage (code size went down too)
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/od_bloaty.c | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 54029ff5b..4fb825ee7 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -181,14 +181,8 @@ static void (*format_address)(off_t, char); | |||
181 | /* The difference between the old-style pseudo starting address and | 181 | /* The difference between the old-style pseudo starting address and |
182 | the number of bytes to skip. */ | 182 | the number of bytes to skip. */ |
183 | static off_t pseudo_offset; | 183 | static off_t pseudo_offset; |
184 | /* The number of input bytes to skip before formatting and writing. */ | ||
185 | static off_t n_bytes_to_skip; | ||
186 | /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all | 184 | /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all |
187 | input is formatted. */ | 185 | input is formatted. */ |
188 | /* The maximum number of bytes that will be formatted. */ | ||
189 | static off_t max_bytes_to_format; | ||
190 | /* The offset of the first byte after the last byte to be formatted. */ | ||
191 | static off_t end_offset; | ||
192 | 186 | ||
193 | /* The number of input bytes formatted per output line. It must be | 187 | /* The number of input bytes formatted per output line. It must be |
194 | a multiple of the least common multiple of the sizes associated with | 188 | a multiple of the least common multiple of the sizes associated with |
@@ -196,22 +190,14 @@ static off_t end_offset; | |||
196 | no larger than 16 -- unless specified with the -w option. */ | 190 | no larger than 16 -- unless specified with the -w option. */ |
197 | static size_t bytes_per_block; | 191 | static size_t bytes_per_block; |
198 | 192 | ||
199 | /* Human-readable representation of *file_list (for error messages). | ||
200 | It differs from *file_list only when *file_list is "-". */ | ||
201 | static char const *input_filename; | ||
202 | |||
203 | /* A NULL-terminated list of the file-arguments from the command line. */ | 193 | /* A NULL-terminated list of the file-arguments from the command line. */ |
204 | static char const *const *file_list; | 194 | static const char *const *file_list; |
205 | |||
206 | /* Initializer for file_list if no file-arguments | ||
207 | were specified on the command line. */ | ||
208 | static char const *const default_file_list[] = { "-", NULL }; | ||
209 | 195 | ||
210 | /* The input stream associated with the current file. */ | 196 | /* The input stream associated with the current file. */ |
211 | static FILE *in_stream; | 197 | static FILE *in_stream; |
212 | 198 | ||
213 | #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) | 199 | #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) |
214 | static unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { | 200 | static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { |
215 | [sizeof(char)] = CHAR, | 201 | [sizeof(char)] = CHAR, |
216 | #if USHRT_MAX != UCHAR_MAX | 202 | #if USHRT_MAX != UCHAR_MAX |
217 | [sizeof(short)] = SHORT, | 203 | [sizeof(short)] = SHORT, |
@@ -228,7 +214,7 @@ static unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { | |||
228 | }; | 214 | }; |
229 | 215 | ||
230 | #define MAX_FP_TYPE_SIZE sizeof(longdouble_t) | 216 | #define MAX_FP_TYPE_SIZE sizeof(longdouble_t) |
231 | static unsigned char fp_type_size[MAX_FP_TYPE_SIZE + 1] ALIGN1 = { | 217 | static const unsigned char fp_type_size[MAX_FP_TYPE_SIZE + 1] ALIGN1 = { |
232 | /* gcc seems to allow repeated indexes. Last one stays */ | 218 | /* gcc seems to allow repeated indexes. Last one stays */ |
233 | [sizeof(longdouble_t)] = FLOAT_LONG_DOUBLE, | 219 | [sizeof(longdouble_t)] = FLOAT_LONG_DOUBLE, |
234 | [sizeof(double)] = FLOAT_DOUBLE, | 220 | [sizeof(double)] = FLOAT_DOUBLE, |
@@ -481,14 +467,10 @@ static void | |||
481 | open_next_file(void) | 467 | open_next_file(void) |
482 | { | 468 | { |
483 | while (1) { | 469 | while (1) { |
484 | input_filename = *file_list; | 470 | if (!*file_list) |
485 | if (!input_filename) | ||
486 | return; | 471 | return; |
487 | file_list++; | 472 | in_stream = fopen_or_warn_stdin(*file_list++); |
488 | in_stream = fopen_or_warn_stdin(input_filename); | ||
489 | if (in_stream) { | 473 | if (in_stream) { |
490 | if (in_stream == stdin) | ||
491 | input_filename = bb_msg_standard_input; | ||
492 | break; | 474 | break; |
493 | } | 475 | } |
494 | ioerror = 1; | 476 | ioerror = 1; |
@@ -510,7 +492,10 @@ check_and_close(void) | |||
510 | { | 492 | { |
511 | if (in_stream) { | 493 | if (in_stream) { |
512 | if (ferror(in_stream)) { | 494 | if (ferror(in_stream)) { |
513 | bb_error_msg("%s: read error", input_filename); | 495 | bb_error_msg("%s: read error", (in_stream == stdin) |
496 | ? bb_msg_standard_input | ||
497 | : file_list[-1] | ||
498 | ); | ||
514 | ioerror = 1; | 499 | ioerror = 1; |
515 | } | 500 | } |
516 | fclose_if_not_stdin(in_stream); | 501 | fclose_if_not_stdin(in_stream); |
@@ -804,8 +789,9 @@ skip(off_t n_skip) | |||
804 | } else { | 789 | } else { |
805 | /* If it's not a regular file with nonnegative size, | 790 | /* If it's not a regular file with nonnegative size, |
806 | position the file pointer by reading. */ | 791 | position the file pointer by reading. */ |
807 | char buf[BUFSIZ]; | 792 | char buf[1024]; |
808 | size_t n_bytes_read, n_bytes_to_read = BUFSIZ; | 793 | size_t n_bytes_to_read = 1024; |
794 | size_t n_bytes_read; | ||
809 | 795 | ||
810 | while (n_skip > 0) { | 796 | while (n_skip > 0) { |
811 | if (n_skip < n_bytes_to_read) | 797 | if (n_skip < n_bytes_to_read) |
@@ -1019,18 +1005,15 @@ parse_old_offset(const char *s, off_t *offset) | |||
1019 | Otherwise, return zero. */ | 1005 | Otherwise, return zero. */ |
1020 | 1006 | ||
1021 | static void | 1007 | static void |
1022 | dump(void) | 1008 | dump(off_t current_offset, off_t end_offset) |
1023 | { | 1009 | { |
1024 | char *block[2]; | 1010 | char *block[2]; |
1025 | off_t current_offset; | ||
1026 | int idx; | 1011 | int idx; |
1027 | size_t n_bytes_read; | 1012 | size_t n_bytes_read; |
1028 | 1013 | ||
1029 | block[0] = xmalloc(2*bytes_per_block); | 1014 | block[0] = xmalloc(2*bytes_per_block); |
1030 | block[1] = block[0] + bytes_per_block; | 1015 | block[1] = block[0] + bytes_per_block; |
1031 | 1016 | ||
1032 | current_offset = n_bytes_to_skip; | ||
1033 | |||
1034 | idx = 0; | 1017 | idx = 0; |
1035 | if (limit_bytes_to_format) { | 1018 | if (limit_bytes_to_format) { |
1036 | while (1) { | 1019 | while (1) { |
@@ -1133,11 +1116,10 @@ read_char(int *c) | |||
1133 | occurs. Otherwise, return zero. */ | 1116 | occurs. Otherwise, return zero. */ |
1134 | 1117 | ||
1135 | static void | 1118 | static void |
1136 | dump_strings(void) | 1119 | dump_strings(off_t address, off_t end_offset) |
1137 | { | 1120 | { |
1138 | size_t bufsize = MAX(100, string_min); | 1121 | size_t bufsize = MAX(100, string_min); |
1139 | char *buf = xmalloc(bufsize); | 1122 | char *buf = xmalloc(bufsize); |
1140 | off_t address = n_bytes_to_skip; | ||
1141 | 1123 | ||
1142 | while (1) { | 1124 | while (1) { |
1143 | size_t i; | 1125 | size_t i; |
@@ -1169,7 +1151,7 @@ dump_strings(void) | |||
1169 | if (i < string_min) /* Too short! */ | 1151 | if (i < string_min) /* Too short! */ |
1170 | goto tryline; | 1152 | goto tryline; |
1171 | 1153 | ||
1172 | /* If we get here, the string is all printable and null-terminated, | 1154 | /* If we get here, the string is all printable and NUL-terminated, |
1173 | * so print it. It is all in 'buf' and 'i' is its length. */ | 1155 | * so print it. It is all in 'buf' and 'i' is its length. */ |
1174 | buf[i] = 0; | 1156 | buf[i] = 0; |
1175 | format_address(address - i - 1, ' '); | 1157 | format_address(address - i - 1, ' '); |
@@ -1183,7 +1165,7 @@ dump_strings(void) | |||
1183 | case '\r': fputs("\\r", stdout); break; | 1165 | case '\r': fputs("\\r", stdout); break; |
1184 | case '\t': fputs("\\t", stdout); break; | 1166 | case '\t': fputs("\\t", stdout); break; |
1185 | case '\v': fputs("\\v", stdout); break; | 1167 | case '\v': fputs("\\v", stdout); break; |
1186 | default: bb_putchar(c); | 1168 | default: putchar(c); |
1187 | } | 1169 | } |
1188 | } | 1170 | } |
1189 | putchar('\n'); | 1171 | putchar('\n'); |
@@ -1199,17 +1181,13 @@ dump_strings(void) | |||
1199 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1181 | int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1200 | int od_main(int argc, char **argv) | 1182 | int od_main(int argc, char **argv) |
1201 | { | 1183 | { |
1184 | static char const *const default_file_list[] = { "-", NULL }; | ||
1202 | static const struct suffix_mult bkm[] = { | 1185 | static const struct suffix_mult bkm[] = { |
1203 | { "b", 512 }, | 1186 | { "b", 512 }, |
1204 | { "k", 1024 }, | 1187 | { "k", 1024 }, |
1205 | { "m", 1024*1024 }, | 1188 | { "m", 1024*1024 }, |
1206 | { } | 1189 | { } |
1207 | }; | 1190 | }; |
1208 | unsigned opt; | ||
1209 | int l_c_m; | ||
1210 | /* The old-style 'pseudo starting address' to be printed in parentheses | ||
1211 | after any true address. */ | ||
1212 | off_t pseudo_start = 0; // only for gcc | ||
1213 | enum { | 1191 | enum { |
1214 | OPT_A = 1 << 0, | 1192 | OPT_A = 1 << 0, |
1215 | OPT_N = 1 << 1, | 1193 | OPT_N = 1 << 1, |
@@ -1246,6 +1224,17 @@ int od_main(int argc, char **argv) | |||
1246 | char *str_A, *str_N, *str_j, *str_S; | 1224 | char *str_A, *str_N, *str_j, *str_S; |
1247 | char *str_w = NULL; | 1225 | char *str_w = NULL; |
1248 | llist_t *lst_t = NULL; | 1226 | llist_t *lst_t = NULL; |
1227 | unsigned opt; | ||
1228 | int l_c_m; | ||
1229 | /* The old-style 'pseudo starting address' to be printed in parentheses | ||
1230 | after any true address. */ | ||
1231 | off_t pseudo_start = pseudo_start; // for gcc | ||
1232 | /* The number of input bytes to skip before formatting and writing. */ | ||
1233 | off_t n_bytes_to_skip = 0; | ||
1234 | /* The offset of the first byte after the last byte to be formatted. */ | ||
1235 | off_t end_offset = 0; | ||
1236 | /* The maximum number of bytes that will be formatted. */ | ||
1237 | off_t max_bytes_to_format = 0; | ||
1249 | 1238 | ||
1250 | spec = NULL; | 1239 | spec = NULL; |
1251 | format_address = format_address_std; | 1240 | format_address = format_address_std; |
@@ -1441,9 +1430,9 @@ int od_main(int argc, char **argv) | |||
1441 | #endif | 1430 | #endif |
1442 | 1431 | ||
1443 | if (flag_dump_strings) | 1432 | if (flag_dump_strings) |
1444 | dump_strings(); | 1433 | dump_strings(n_bytes_to_skip, end_offset); |
1445 | else | 1434 | else |
1446 | dump(); | 1435 | dump(n_bytes_to_skip, end_offset); |
1447 | 1436 | ||
1448 | if (fclose(stdin) == EOF) | 1437 | if (fclose(stdin) == EOF) |
1449 | bb_perror_msg_and_die(bb_msg_standard_input); | 1438 | bb_perror_msg_and_die(bb_msg_standard_input); |