diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 02:51:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 02:51:56 +0200 |
commit | f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99 (patch) | |
tree | 13ae921c9328cdb3679924ffadb2f2f996c655eb | |
parent | c4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1 (diff) | |
download | busybox-w32-f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99.tar.gz busybox-w32-f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99.tar.bz2 busybox-w32-f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99.zip |
od: get rid of (almost all) statics
function old new delta
od_main 2565 2600 +35
check_and_close 113 115 +2
static.prev_pair_equal 1 - -1
static.first 1 - -1
exit_code 1 - -1
string_min 4 - -4
n_specs 4 - -4
in_stream 4 - -4
format_address 4 - -4
file_list 4 - -4
bytes_per_block 4 - -4
get_lcm 120 115 -5
pseudo_offset 8 - -8
------------------------------------------------------------------------------
(add/remove: 0/10 grow/shrink: 2/1 up/down: 37/-40) Total: -3 bytes
text data bss dec hex filename
938487 932 17392 956811 e998b busybox_old
938519 924 17360 956803 e9983 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/od_bloaty.c | 230 |
1 files changed, 122 insertions, 108 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index ab7ea997d..f47f84b54 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -66,7 +66,7 @@ enum { | |||
66 | /* -S was -s and also had optional parameter */ \ | 66 | /* -S was -s and also had optional parameter */ \ |
67 | /* but in coreutils 6.3 it was renamed and now has */ \ | 67 | /* but in coreutils 6.3 it was renamed and now has */ \ |
68 | /* _mandatory_ parameter */ \ | 68 | /* _mandatory_ parameter */ \ |
69 | &str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block) | 69 | &str_A, &str_N, &str_j, &lst_t, &str_S, &G.bytes_per_block) |
70 | 70 | ||
71 | 71 | ||
72 | /* Check for 0x7f is a coreutils 6.3 addition */ | 72 | /* Check for 0x7f is a coreutils 6.3 addition */ |
@@ -174,38 +174,52 @@ struct ERR_width_bytes_has_bad_size { | |||
174 | char ERR_width_bytes_has_bad_size[ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1]; | 174 | char ERR_width_bytes_has_bad_size[ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1]; |
175 | }; | 175 | }; |
176 | 176 | ||
177 | static smallint exit_code; | 177 | struct globals { |
178 | smallint exit_code; | ||
178 | 179 | ||
179 | static unsigned string_min; | 180 | unsigned string_min; |
180 | 181 | ||
181 | /* An array of specs describing how to format each input block. */ | 182 | /* An array of specs describing how to format each input block. */ |
182 | static size_t n_specs; | 183 | unsigned n_specs; |
183 | static struct tspec *spec; | 184 | struct tspec *spec; |
184 | 185 | ||
185 | /* Function that accepts an address and an optional following char, | 186 | /* Function that accepts an address and an optional following char, |
186 | and prints the address and char to stdout. */ | 187 | and prints the address and char to stdout. */ |
187 | static void (*format_address)(off_t, char); | 188 | void (*format_address)(off_t, char); |
188 | /* The difference between the old-style pseudo starting address and | 189 | |
189 | the number of bytes to skip. */ | 190 | /* The difference between the old-style pseudo starting address and |
191 | the number of bytes to skip. */ | ||
190 | #if ENABLE_LONG_OPTS | 192 | #if ENABLE_LONG_OPTS |
191 | static off_t pseudo_offset; | 193 | off_t pseudo_offset; |
192 | #else | 194 | # define G_pseudo_offset G.pseudo_offset |
193 | enum { pseudo_offset = 0 }; | ||
194 | #endif | 195 | #endif |
195 | /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all | 196 | /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all |
196 | input is formatted. */ | 197 | input is formatted. */ |
197 | 198 | ||
198 | /* The number of input bytes formatted per output line. It must be | 199 | /* The number of input bytes formatted per output line. It must be |
199 | a multiple of the least common multiple of the sizes associated with | 200 | a multiple of the least common multiple of the sizes associated with |
200 | the specified output types. It should be as large as possible, but | 201 | the specified output types. It should be as large as possible, but |
201 | no larger than 16 -- unless specified with the -w option. */ | 202 | no larger than 16 -- unless specified with the -w option. */ |
202 | static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */ | 203 | unsigned bytes_per_block; /* have to use unsigned, not size_t */ |
203 | 204 | ||
204 | /* A NULL-terminated list of the file-arguments from the command line. */ | 205 | /* A NULL-terminated list of the file-arguments from the command line. */ |
205 | static const char *const *file_list; | 206 | const char *const *file_list; |
207 | |||
208 | /* The input stream associated with the current file. */ | ||
209 | FILE *in_stream; | ||
210 | |||
211 | bool not_first; | ||
212 | bool prev_pair_equal; | ||
213 | } FIX_ALIASING; | ||
214 | #if !ENABLE_LONG_OPTS | ||
215 | enum { G_pseudo_offset = 0 }; | ||
216 | #endif | ||
217 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
218 | #define INIT_G() do { \ | ||
219 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | ||
220 | G.bytes_per_block = 32; \ | ||
221 | } while (0) | ||
206 | 222 | ||
207 | /* The input stream associated with the current file. */ | ||
208 | static FILE *in_stream; | ||
209 | 223 | ||
210 | #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) | 224 | #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) |
211 | static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { | 225 | static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { |
@@ -476,17 +490,17 @@ static void | |||
476 | open_next_file(void) | 490 | open_next_file(void) |
477 | { | 491 | { |
478 | while (1) { | 492 | while (1) { |
479 | if (!*file_list) | 493 | if (!*G.file_list) |
480 | return; | 494 | return; |
481 | in_stream = fopen_or_warn_stdin(*file_list++); | 495 | G.in_stream = fopen_or_warn_stdin(*G.file_list++); |
482 | if (in_stream) { | 496 | if (G.in_stream) { |
483 | break; | 497 | break; |
484 | } | 498 | } |
485 | exit_code = 1; | 499 | G.exit_code = 1; |
486 | } | 500 | } |
487 | 501 | ||
488 | if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N) | 502 | if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N) |
489 | setbuf(in_stream, NULL); | 503 | setbuf(G.in_stream, NULL); |
490 | } | 504 | } |
491 | 505 | ||
492 | /* Test whether there have been errors on in_stream, and close it if | 506 | /* Test whether there have been errors on in_stream, and close it if |
@@ -499,16 +513,16 @@ open_next_file(void) | |||
499 | static void | 513 | static void |
500 | check_and_close(void) | 514 | check_and_close(void) |
501 | { | 515 | { |
502 | if (in_stream) { | 516 | if (G.in_stream) { |
503 | if (ferror(in_stream)) { | 517 | if (ferror(G.in_stream)) { |
504 | bb_error_msg("%s: read error", (in_stream == stdin) | 518 | bb_error_msg("%s: read error", (G.in_stream == stdin) |
505 | ? bb_msg_standard_input | 519 | ? bb_msg_standard_input |
506 | : file_list[-1] | 520 | : G.file_list[-1] |
507 | ); | 521 | ); |
508 | exit_code = 1; | 522 | G.exit_code = 1; |
509 | } | 523 | } |
510 | fclose_if_not_stdin(in_stream); | 524 | fclose_if_not_stdin(G.in_stream); |
511 | in_stream = NULL; | 525 | G.in_stream = NULL; |
512 | } | 526 | } |
513 | 527 | ||
514 | if (ferror(stdout)) { | 528 | if (ferror(stdout)) { |
@@ -744,9 +758,9 @@ decode_format_string(const char *s) | |||
744 | 758 | ||
745 | assert(s != next); | 759 | assert(s != next); |
746 | s = next; | 760 | s = next; |
747 | spec = xrealloc_vector(spec, 4, n_specs); | 761 | G.spec = xrealloc_vector(G.spec, 4, G.n_specs); |
748 | memcpy(&spec[n_specs], &tspec, sizeof(spec[0])); | 762 | memcpy(&G.spec[G.n_specs], &tspec, sizeof(G.spec[0])); |
749 | n_specs++; | 763 | G.n_specs++; |
750 | } | 764 | } |
751 | } | 765 | } |
752 | 766 | ||
@@ -763,7 +777,7 @@ skip(off_t n_skip) | |||
763 | if (n_skip == 0) | 777 | if (n_skip == 0) |
764 | return; | 778 | return; |
765 | 779 | ||
766 | while (in_stream) { /* !EOF */ | 780 | while (G.in_stream) { /* !EOF */ |
767 | struct stat file_stats; | 781 | struct stat file_stats; |
768 | 782 | ||
769 | /* First try seeking. For large offsets, this extra work is | 783 | /* First try seeking. For large offsets, this extra work is |
@@ -781,15 +795,15 @@ skip(off_t n_skip) | |||
781 | If the number of bytes left to skip is at least | 795 | If the number of bytes left to skip is at least |
782 | as large as the size of the current file, we can | 796 | as large as the size of the current file, we can |
783 | decrement n_skip and go on to the next file. */ | 797 | decrement n_skip and go on to the next file. */ |
784 | if (fstat(fileno(in_stream), &file_stats) == 0 | 798 | if (fstat(fileno(G.in_stream), &file_stats) == 0 |
785 | && S_ISREG(file_stats.st_mode) && file_stats.st_size > 0 | 799 | && S_ISREG(file_stats.st_mode) && file_stats.st_size > 0 |
786 | ) { | 800 | ) { |
787 | if (file_stats.st_size < n_skip) { | 801 | if (file_stats.st_size < n_skip) { |
788 | n_skip -= file_stats.st_size; | 802 | n_skip -= file_stats.st_size; |
789 | /* take "check & close / open_next" route */ | 803 | /* take "check & close / open_next" route */ |
790 | } else { | 804 | } else { |
791 | if (fseeko(in_stream, n_skip, SEEK_CUR) != 0) | 805 | if (fseeko(G.in_stream, n_skip, SEEK_CUR) != 0) |
792 | exit_code = 1; | 806 | G.exit_code = 1; |
793 | return; | 807 | return; |
794 | } | 808 | } |
795 | } else { | 809 | } else { |
@@ -802,7 +816,7 @@ skip(off_t n_skip) | |||
802 | while (n_skip > 0) { | 816 | while (n_skip > 0) { |
803 | if (n_skip < n_bytes_to_read) | 817 | if (n_skip < n_bytes_to_read) |
804 | n_bytes_to_read = n_skip; | 818 | n_bytes_to_read = n_skip; |
805 | n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream); | 819 | n_bytes_read = fread(buf, 1, n_bytes_to_read, G.in_stream); |
806 | n_skip -= n_bytes_read; | 820 | n_skip -= n_bytes_read; |
807 | if (n_bytes_read != n_bytes_to_read) | 821 | if (n_bytes_read != n_bytes_to_read) |
808 | break; /* EOF on this file or error */ | 822 | break; /* EOF on this file or error */ |
@@ -855,7 +869,7 @@ static void | |||
855 | format_address_label(off_t address, char c) | 869 | format_address_label(off_t address, char c) |
856 | { | 870 | { |
857 | format_address_std(address, ' '); | 871 | format_address_std(address, ' '); |
858 | format_address_paren(address + pseudo_offset, c); | 872 | format_address_paren(address + G_pseudo_offset, c); |
859 | } | 873 | } |
860 | #endif | 874 | #endif |
861 | 875 | ||
@@ -886,36 +900,34 @@ static void | |||
886 | write_block(off_t current_offset, size_t n_bytes, | 900 | write_block(off_t current_offset, size_t n_bytes, |
887 | const char *prev_block, const char *curr_block) | 901 | const char *prev_block, const char *curr_block) |
888 | { | 902 | { |
889 | static char first = 1; | 903 | unsigned i; |
890 | static char prev_pair_equal = 0; | ||
891 | size_t i; | ||
892 | 904 | ||
893 | if (!(option_mask32 & OPT_v) | 905 | if (!(option_mask32 & OPT_v) |
894 | && !first | 906 | && G.not_first |
895 | && n_bytes == bytes_per_block | 907 | && n_bytes == G.bytes_per_block |
896 | && memcmp(prev_block, curr_block, bytes_per_block) == 0 | 908 | && memcmp(prev_block, curr_block, G.bytes_per_block) == 0 |
897 | ) { | 909 | ) { |
898 | if (prev_pair_equal) { | 910 | if (G.prev_pair_equal) { |
899 | /* The two preceding blocks were equal, and the current | 911 | /* The two preceding blocks were equal, and the current |
900 | block is the same as the last one, so print nothing. */ | 912 | block is the same as the last one, so print nothing. */ |
901 | } else { | 913 | } else { |
902 | puts("*"); | 914 | puts("*"); |
903 | prev_pair_equal = 1; | 915 | G.prev_pair_equal = 1; |
904 | } | 916 | } |
905 | } else { | 917 | } else { |
906 | first = 0; | 918 | G.not_first = 1; |
907 | prev_pair_equal = 0; | 919 | G.prev_pair_equal = 0; |
908 | for (i = 0; i < n_specs; i++) { | 920 | for (i = 0; i < G.n_specs; i++) { |
909 | if (i == 0) | 921 | if (i == 0) |
910 | format_address(current_offset, '\0'); | 922 | G.format_address(current_offset, '\0'); |
911 | else | 923 | else |
912 | printf("%*s", address_pad_len_char - '0', ""); | 924 | printf("%*s", address_pad_len_char - '0', ""); |
913 | (*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string); | 925 | (*G.spec[i].print_function) (n_bytes, curr_block, G.spec[i].fmt_string); |
914 | if (spec[i].hexl_mode_trailer) { | 926 | if (G.spec[i].hexl_mode_trailer) { |
915 | /* space-pad out to full line width, then dump the trailer */ | 927 | /* space-pad out to full line width, then dump the trailer */ |
916 | unsigned datum_width = width_bytes[spec[i].size]; | 928 | unsigned datum_width = width_bytes[G.spec[i].size]; |
917 | unsigned blank_fields = (bytes_per_block - n_bytes) / datum_width; | 929 | unsigned blank_fields = (G.bytes_per_block - n_bytes) / datum_width; |
918 | unsigned field_width = spec[i].field_width + 1; | 930 | unsigned field_width = G.spec[i].field_width + 1; |
919 | printf("%*s", blank_fields * field_width, ""); | 931 | printf("%*s", blank_fields * field_width, ""); |
920 | dump_hexl_mode_trailer(n_bytes, curr_block); | 932 | dump_hexl_mode_trailer(n_bytes, curr_block); |
921 | } | 933 | } |
@@ -927,19 +939,19 @@ write_block(off_t current_offset, size_t n_bytes, | |||
927 | static void | 939 | static void |
928 | read_block(size_t n, char *block, size_t *n_bytes_in_buffer) | 940 | read_block(size_t n, char *block, size_t *n_bytes_in_buffer) |
929 | { | 941 | { |
930 | assert(0 < n && n <= bytes_per_block); | 942 | assert(0 < n && n <= G.bytes_per_block); |
931 | 943 | ||
932 | *n_bytes_in_buffer = 0; | 944 | *n_bytes_in_buffer = 0; |
933 | 945 | ||
934 | if (n == 0) | 946 | if (n == 0) |
935 | return; | 947 | return; |
936 | 948 | ||
937 | while (in_stream != NULL) { /* EOF. */ | 949 | while (G.in_stream != NULL) { /* EOF. */ |
938 | size_t n_needed; | 950 | size_t n_needed; |
939 | size_t n_read; | 951 | size_t n_read; |
940 | 952 | ||
941 | n_needed = n - *n_bytes_in_buffer; | 953 | n_needed = n - *n_bytes_in_buffer; |
942 | n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, in_stream); | 954 | n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, G.in_stream); |
943 | *n_bytes_in_buffer += n_read; | 955 | *n_bytes_in_buffer += n_read; |
944 | if (n_read == n_needed) | 956 | if (n_read == n_needed) |
945 | break; | 957 | break; |
@@ -958,8 +970,8 @@ get_lcm(void) | |||
958 | size_t i; | 970 | size_t i; |
959 | int l_c_m = 1; | 971 | int l_c_m = 1; |
960 | 972 | ||
961 | for (i = 0; i < n_specs; i++) | 973 | for (i = 0; i < G.n_specs; i++) |
962 | l_c_m = lcm(l_c_m, width_bytes[(int) spec[i].size]); | 974 | l_c_m = lcm(l_c_m, width_bytes[(int) G.spec[i].size]); |
963 | return l_c_m; | 975 | return l_c_m; |
964 | } | 976 | } |
965 | 977 | ||
@@ -980,8 +992,8 @@ dump(off_t current_offset, off_t end_offset) | |||
980 | int idx; | 992 | int idx; |
981 | size_t n_bytes_read; | 993 | size_t n_bytes_read; |
982 | 994 | ||
983 | block[0] = xmalloc(2 * bytes_per_block); | 995 | block[0] = xmalloc(2 * G.bytes_per_block); |
984 | block[1] = block[0] + bytes_per_block; | 996 | block[1] = block[0] + G.bytes_per_block; |
985 | 997 | ||
986 | idx = 0; | 998 | idx = 0; |
987 | if (option_mask32 & OPT_N) { | 999 | if (option_mask32 & OPT_N) { |
@@ -991,21 +1003,21 @@ dump(off_t current_offset, off_t end_offset) | |||
991 | n_bytes_read = 0; | 1003 | n_bytes_read = 0; |
992 | break; | 1004 | break; |
993 | } | 1005 | } |
994 | n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block); | 1006 | n_needed = MIN(end_offset - current_offset, (off_t) G.bytes_per_block); |
995 | read_block(n_needed, block[idx], &n_bytes_read); | 1007 | read_block(n_needed, block[idx], &n_bytes_read); |
996 | if (n_bytes_read < bytes_per_block) | 1008 | if (n_bytes_read < G.bytes_per_block) |
997 | break; | 1009 | break; |
998 | assert(n_bytes_read == bytes_per_block); | 1010 | assert(n_bytes_read == G.bytes_per_block); |
999 | write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); | 1011 | write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); |
1000 | current_offset += n_bytes_read; | 1012 | current_offset += n_bytes_read; |
1001 | idx ^= 1; | 1013 | idx ^= 1; |
1002 | } | 1014 | } |
1003 | } else { | 1015 | } else { |
1004 | while (1) { | 1016 | while (1) { |
1005 | read_block(bytes_per_block, block[idx], &n_bytes_read); | 1017 | read_block(G.bytes_per_block, block[idx], &n_bytes_read); |
1006 | if (n_bytes_read < bytes_per_block) | 1018 | if (n_bytes_read < G.bytes_per_block) |
1007 | break; | 1019 | break; |
1008 | assert(n_bytes_read == bytes_per_block); | 1020 | assert(n_bytes_read == G.bytes_per_block); |
1009 | write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); | 1021 | write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); |
1010 | current_offset += n_bytes_read; | 1022 | current_offset += n_bytes_read; |
1011 | idx ^= 1; | 1023 | idx ^= 1; |
@@ -1028,7 +1040,7 @@ dump(off_t current_offset, off_t end_offset) | |||
1028 | current_offset += n_bytes_read; | 1040 | current_offset += n_bytes_read; |
1029 | } | 1041 | } |
1030 | 1042 | ||
1031 | format_address(current_offset, '\n'); | 1043 | G.format_address(current_offset, '\n'); |
1032 | 1044 | ||
1033 | if ((option_mask32 & OPT_N) && current_offset >= end_offset) | 1045 | if ((option_mask32 & OPT_N) && current_offset >= end_offset) |
1034 | check_and_close(); | 1046 | check_and_close(); |
@@ -1059,16 +1071,16 @@ dump(off_t current_offset, off_t end_offset) | |||
1059 | static void | 1071 | static void |
1060 | dump_strings(off_t address, off_t end_offset) | 1072 | dump_strings(off_t address, off_t end_offset) |
1061 | { | 1073 | { |
1062 | unsigned bufsize = MAX(100, string_min); | 1074 | unsigned bufsize = MAX(100, G.string_min); |
1063 | unsigned char *buf = xmalloc(bufsize); | 1075 | unsigned char *buf = xmalloc(bufsize); |
1064 | 1076 | ||
1065 | while (1) { | 1077 | while (1) { |
1066 | size_t i; | 1078 | size_t i; |
1067 | int c; | 1079 | int c; |
1068 | 1080 | ||
1069 | /* See if the next 'string_min' chars are all printing chars. */ | 1081 | /* See if the next 'G.string_min' chars are all printing chars. */ |
1070 | tryline: | 1082 | tryline: |
1071 | if ((option_mask32 & OPT_N) && (end_offset - string_min <= address)) | 1083 | if ((option_mask32 & OPT_N) && (end_offset - G.string_min <= address)) |
1072 | break; | 1084 | break; |
1073 | i = 0; | 1085 | i = 0; |
1074 | while (!(option_mask32 & OPT_N) || address < end_offset) { | 1086 | while (!(option_mask32 & OPT_N) || address < end_offset) { |
@@ -1077,8 +1089,8 @@ dump_strings(off_t address, off_t end_offset) | |||
1077 | buf = xrealloc(buf, bufsize); | 1089 | buf = xrealloc(buf, bufsize); |
1078 | } | 1090 | } |
1079 | 1091 | ||
1080 | while (in_stream) { /* !EOF */ | 1092 | while (G.in_stream) { /* !EOF */ |
1081 | c = fgetc(in_stream); | 1093 | c = fgetc(G.in_stream); |
1082 | if (c != EOF) | 1094 | if (c != EOF) |
1083 | goto got_char; | 1095 | goto got_char; |
1084 | check_and_close(); | 1096 | check_and_close(); |
@@ -1095,12 +1107,12 @@ dump_strings(off_t address, off_t end_offset) | |||
1095 | buf[i++] = c; /* String continues; store it all. */ | 1107 | buf[i++] = c; /* String continues; store it all. */ |
1096 | } | 1108 | } |
1097 | 1109 | ||
1098 | if (i < string_min) /* Too short! */ | 1110 | if (i < G.string_min) /* Too short! */ |
1099 | goto tryline; | 1111 | goto tryline; |
1100 | 1112 | ||
1101 | /* If we get here, the string is all printable and NUL-terminated */ | 1113 | /* If we get here, the string is all printable and NUL-terminated */ |
1102 | buf[i] = 0; | 1114 | buf[i] = 0; |
1103 | format_address(address - i - 1, ' '); | 1115 | G.format_address(address - i - 1, ' '); |
1104 | 1116 | ||
1105 | for (i = 0; (c = buf[i]); i++) { | 1117 | for (i = 0; (c = buf[i]); i++) { |
1106 | switch (c) { | 1118 | switch (c) { |
@@ -1118,7 +1130,7 @@ dump_strings(off_t address, off_t end_offset) | |||
1118 | } | 1130 | } |
1119 | 1131 | ||
1120 | /* We reach this point only if we search through | 1132 | /* We reach this point only if we search through |
1121 | (max_bytes_to_format - string_min) bytes before reaching EOF. */ | 1133 | (max_bytes_to_format - G.string_min) bytes before reaching EOF. */ |
1122 | check_and_close(); | 1134 | check_and_close(); |
1123 | ret: | 1135 | ret: |
1124 | free(buf); | 1136 | free(buf); |
@@ -1190,8 +1202,10 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1190 | /* The maximum number of bytes that will be formatted. */ | 1202 | /* The maximum number of bytes that will be formatted. */ |
1191 | off_t max_bytes_to_format = 0; | 1203 | off_t max_bytes_to_format = 0; |
1192 | 1204 | ||
1193 | spec = NULL; | 1205 | INIT_G(); |
1194 | format_address = format_address_std; | 1206 | |
1207 | /*G.spec = NULL; - already is */ | ||
1208 | G.format_address = format_address_std; | ||
1195 | address_base_char = 'o'; | 1209 | address_base_char = 'o'; |
1196 | address_pad_len_char = '7'; | 1210 | address_pad_len_char = '7'; |
1197 | 1211 | ||
@@ -1217,7 +1231,7 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1217 | bb_error_msg_and_die("bad output address radix " | 1231 | bb_error_msg_and_die("bad output address radix " |
1218 | "'%c' (must be [doxn])", str_A[0]); | 1232 | "'%c' (must be [doxn])", str_A[0]); |
1219 | pos = p - doxn; | 1233 | pos = p - doxn; |
1220 | if (pos == 3) format_address = format_address_none; | 1234 | if (pos == 3) G.format_address = format_address_none; |
1221 | address_base_char = doxn_address_base_char[pos]; | 1235 | address_base_char = doxn_address_base_char[pos]; |
1222 | address_pad_len_char = doxn_address_pad_len_char[pos]; | 1236 | address_pad_len_char = doxn_address_pad_len_char[pos]; |
1223 | } | 1237 | } |
@@ -1240,11 +1254,11 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1240 | if (opt & OPT_x) decode_format_string("x2"); | 1254 | if (opt & OPT_x) decode_format_string("x2"); |
1241 | if (opt & OPT_s) decode_format_string("d2"); | 1255 | if (opt & OPT_s) decode_format_string("d2"); |
1242 | if (opt & OPT_S) { | 1256 | if (opt & OPT_S) { |
1243 | string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); | 1257 | G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); |
1244 | } | 1258 | } |
1245 | 1259 | ||
1246 | // Bloat: | 1260 | // Bloat: |
1247 | //if ((option_mask32 & OPT_S) && n_specs > 0) | 1261 | //if ((option_mask32 & OPT_S) && G.n_specs > 0) |
1248 | // bb_error_msg_and_die("no type may be specified when dumping strings"); | 1262 | // bb_error_msg_and_die("no type may be specified when dumping strings"); |
1249 | 1263 | ||
1250 | /* If the --traditional option is used, there may be from | 1264 | /* If the --traditional option is used, there may be from |
@@ -1300,14 +1314,14 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1300 | } | 1314 | } |
1301 | 1315 | ||
1302 | if (pseudo_start >= 0) { | 1316 | if (pseudo_start >= 0) { |
1303 | if (format_address == format_address_none) { | 1317 | if (G.format_address == format_address_none) { |
1304 | address_base_char = 'o'; | 1318 | address_base_char = 'o'; |
1305 | address_pad_len_char = '7'; | 1319 | address_pad_len_char = '7'; |
1306 | format_address = format_address_paren; | 1320 | G.format_address = format_address_paren; |
1307 | } else { | 1321 | } else { |
1308 | format_address = format_address_label; | 1322 | G.format_address = format_address_label; |
1309 | } | 1323 | } |
1310 | pseudo_offset = pseudo_start - n_bytes_to_skip; | 1324 | G_pseudo_offset = pseudo_start - n_bytes_to_skip; |
1311 | } | 1325 | } |
1312 | } | 1326 | } |
1313 | /* else: od --traditional (without args) */ | 1327 | /* else: od --traditional (without args) */ |
@@ -1320,45 +1334,45 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1320 | bb_error_msg_and_die("SKIP + SIZE is too large"); | 1334 | bb_error_msg_and_die("SKIP + SIZE is too large"); |
1321 | } | 1335 | } |
1322 | 1336 | ||
1323 | if (n_specs == 0) { | 1337 | if (G.n_specs == 0) { |
1324 | decode_format_string("o2"); | 1338 | decode_format_string("o2"); |
1325 | /*n_specs = 1; - done by decode_format_string */ | 1339 | /*G.n_specs = 1; - done by decode_format_string */ |
1326 | } | 1340 | } |
1327 | 1341 | ||
1328 | /* If no files were listed on the command line, | 1342 | /* If no files were listed on the command line, |
1329 | set the global pointer FILE_LIST so that it | 1343 | set the global pointer FILE_LIST so that it |
1330 | references the null-terminated list of one name: "-". */ | 1344 | references the null-terminated list of one name: "-". */ |
1331 | file_list = bb_argv_dash; | 1345 | G.file_list = bb_argv_dash; |
1332 | if (argv[0]) { | 1346 | if (argv[0]) { |
1333 | /* Set the global pointer FILE_LIST so that it | 1347 | /* Set the global pointer FILE_LIST so that it |
1334 | references the first file-argument on the command-line. */ | 1348 | references the first file-argument on the command-line. */ |
1335 | file_list = (char const *const *) argv; | 1349 | G.file_list = (char const *const *) argv; |
1336 | } | 1350 | } |
1337 | 1351 | ||
1338 | /* Open the first input file */ | 1352 | /* Open the first input file */ |
1339 | open_next_file(); | 1353 | open_next_file(); |
1340 | /* Skip over any unwanted header bytes */ | 1354 | /* Skip over any unwanted header bytes */ |
1341 | skip(n_bytes_to_skip); | 1355 | skip(n_bytes_to_skip); |
1342 | if (!in_stream) | 1356 | if (!G.in_stream) |
1343 | return EXIT_FAILURE; | 1357 | return EXIT_FAILURE; |
1344 | 1358 | ||
1345 | /* Compute output block length */ | 1359 | /* Compute output block length */ |
1346 | l_c_m = get_lcm(); | 1360 | l_c_m = get_lcm(); |
1347 | 1361 | ||
1348 | if (opt & OPT_w) { /* -w: width */ | 1362 | if (opt & OPT_w) { /* -w: width */ |
1349 | if (!bytes_per_block || bytes_per_block % l_c_m != 0) { | 1363 | if (!G.bytes_per_block || G.bytes_per_block % l_c_m != 0) { |
1350 | bb_error_msg("warning: invalid width %u; using %d instead", | 1364 | bb_error_msg("warning: invalid width %u; using %d instead", |
1351 | (unsigned)bytes_per_block, l_c_m); | 1365 | (unsigned)G.bytes_per_block, l_c_m); |
1352 | bytes_per_block = l_c_m; | 1366 | G.bytes_per_block = l_c_m; |
1353 | } | 1367 | } |
1354 | } else { | 1368 | } else { |
1355 | bytes_per_block = l_c_m; | 1369 | G.bytes_per_block = l_c_m; |
1356 | if (l_c_m < DEFAULT_BYTES_PER_BLOCK) | 1370 | if (l_c_m < DEFAULT_BYTES_PER_BLOCK) |
1357 | bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m; | 1371 | G.bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m; |
1358 | } | 1372 | } |
1359 | 1373 | ||
1360 | #ifdef DEBUG | 1374 | #ifdef DEBUG |
1361 | for (i = 0; i < n_specs; i++) { | 1375 | for (i = 0; i < G.n_specs; i++) { |
1362 | printf("%d: fmt=\"%s\" width=%d\n", | 1376 | printf("%d: fmt=\"%s\" width=%d\n", |
1363 | i, spec[i].fmt_string, width_bytes[spec[i].size]); | 1377 | i, spec[i].fmt_string, width_bytes[spec[i].size]); |
1364 | } | 1378 | } |
@@ -1372,5 +1386,5 @@ int od_main(int argc UNUSED_PARAM, char **argv) | |||
1372 | if (fclose(stdin)) | 1386 | if (fclose(stdin)) |
1373 | bb_perror_msg_and_die(bb_msg_standard_input); | 1387 | bb_perror_msg_and_die(bb_msg_standard_input); |
1374 | 1388 | ||
1375 | return exit_code; | 1389 | return G.exit_code; |
1376 | } | 1390 | } |