aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-21 19:15:55 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-21 19:15:55 +0200
commitb808614785d04753b689233d27614189e25f6f0c (patch)
tree5dbf53ffd12472065a530bf9d35ec25f6f111c51
parentd373355bf82d90b42f37bd25a3e0d73710138ee4 (diff)
downloadbusybox-w32-b808614785d04753b689233d27614189e25f6f0c.tar.gz
busybox-w32-b808614785d04753b689233d27614189e25f6f0c.tar.bz2
busybox-w32-b808614785d04753b689233d27614189e25f6f0c.zip
od: code shrink
function old new delta od_main 2147 2132 -15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/od_bloaty.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index bd6c75385..347f879d7 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -546,7 +546,6 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
546 unsigned field_width = 0; 546 unsigned field_width = 0;
547 int pos; 547 int pos;
548 548
549
550 switch (*s) { 549 switch (*s) {
551 case 'd': 550 case 'd':
552 case 'o': 551 case 'o':
@@ -916,9 +915,9 @@ write_block(off_t current_offset, size_t n_bytes,
916 (*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string); 915 (*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string);
917 if (spec[i].hexl_mode_trailer) { 916 if (spec[i].hexl_mode_trailer) {
918 /* space-pad out to full line width, then dump the trailer */ 917 /* space-pad out to full line width, then dump the trailer */
919 int datum_width = width_bytes[spec[i].size]; 918 unsigned datum_width = width_bytes[spec[i].size];
920 int blank_fields = (bytes_per_block - n_bytes) / datum_width; 919 unsigned blank_fields = (bytes_per_block - n_bytes) / datum_width;
921 int field_width = spec[i].field_width + 1; 920 unsigned field_width = spec[i].field_width + 1;
922 printf("%*s", blank_fields * field_width, ""); 921 printf("%*s", blank_fields * field_width, "");
923 dump_hexl_mode_trailer(n_bytes, curr_block); 922 dump_hexl_mode_trailer(n_bytes, curr_block);
924 } 923 }
@@ -983,7 +982,7 @@ dump(off_t current_offset, off_t end_offset)
983 int idx; 982 int idx;
984 size_t n_bytes_read; 983 size_t n_bytes_read;
985 984
986 block[0] = xmalloc(2*bytes_per_block); 985 block[0] = xmalloc(2 * bytes_per_block);
987 block[1] = block[0] + bytes_per_block; 986 block[1] = block[0] + bytes_per_block;
988 987
989 idx = 0; 988 idx = 0;
@@ -994,16 +993,14 @@ dump(off_t current_offset, off_t end_offset)
994 n_bytes_read = 0; 993 n_bytes_read = 0;
995 break; 994 break;
996 } 995 }
997 n_needed = MIN(end_offset - current_offset, 996 n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block);
998 (off_t) bytes_per_block);
999 read_block(n_needed, block[idx], &n_bytes_read); 997 read_block(n_needed, block[idx], &n_bytes_read);
1000 if (n_bytes_read < bytes_per_block) 998 if (n_bytes_read < bytes_per_block)
1001 break; 999 break;
1002 assert(n_bytes_read == bytes_per_block); 1000 assert(n_bytes_read == bytes_per_block);
1003 write_block(current_offset, n_bytes_read, 1001 write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
1004 block[!idx], block[idx]);
1005 current_offset += n_bytes_read; 1002 current_offset += n_bytes_read;
1006 idx = !idx; 1003 idx ^= 1;
1007 } 1004 }
1008 } else { 1005 } else {
1009 while (1) { 1006 while (1) {
@@ -1011,10 +1008,9 @@ dump(off_t current_offset, off_t end_offset)
1011 if (n_bytes_read < bytes_per_block) 1008 if (n_bytes_read < bytes_per_block)
1012 break; 1009 break;
1013 assert(n_bytes_read == bytes_per_block); 1010 assert(n_bytes_read == bytes_per_block);
1014 write_block(current_offset, n_bytes_read, 1011 write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
1015 block[!idx], block[idx]);
1016 current_offset += n_bytes_read; 1012 current_offset += n_bytes_read;
1017 idx = !idx; 1013 idx ^= 1;
1018 } 1014 }
1019 } 1015 }
1020 1016
@@ -1030,7 +1026,7 @@ dump(off_t current_offset, off_t end_offset)
1030 1026
1031 memset(block[idx] + n_bytes_read, 0, bytes_to_write - n_bytes_read); 1027 memset(block[idx] + n_bytes_read, 0, bytes_to_write - n_bytes_read);
1032 write_block(current_offset, bytes_to_write, 1028 write_block(current_offset, bytes_to_write,
1033 block[!idx], block[idx]); 1029 block[idx ^ 1], block[idx]);
1034 current_offset += n_bytes_read; 1030 current_offset += n_bytes_read;
1035 } 1031 }
1036 1032