aboutsummaryrefslogtreecommitdiff
path: root/coreutils/fold.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:07:36 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 09:07:36 +0000
commit62a90cdd7435f09f4bb8673e8b7b213067f9d5cc (patch)
treeac7f86c4de0ce0c095b59820c7ba238369c65f71 /coreutils/fold.c
parentd02db892440499a072ea8c83c2370e9d9c103098 (diff)
downloadbusybox-w32-62a90cdd7435f09f4bb8673e8b7b213067f9d5cc.tar.gz
busybox-w32-62a90cdd7435f09f4bb8673e8b7b213067f9d5cc.tar.bz2
busybox-w32-62a90cdd7435f09f4bb8673e8b7b213067f9d5cc.zip
*: shrink by using [f]open_or_warn_stdin where appropriate
function old new delta lsattr_main 62 143 +81 open_or_warn_stdin - 36 +36 fclose_if_not_stdin 20 47 +27 xfopen_stdin - 20 +20 tac_main 336 356 +20 cksum_main 249 259 +10 bb_argv_dash - 8 +8 su_main 448 455 +7 cmp_main 630 633 +3 passwd_main 1072 1074 +2 uudecode_main 317 315 -2 text_yank 110 108 -2 handle_incoming_and_exit 2653 2651 -2 flags 5 1 -4 write_leases 235 230 -5 fopen_or_warn_stdin 48 42 -6 fold_main 648 642 -6 static.argv_dash 8 - -8 sum_main 142 128 -14 tail_main 1237 1221 -16 sed_main 711 695 -16 cmp_xfopen_input 17 - -17 bb_cat 113 96 -17 catv_main 328 306 -22 strings_main 457 434 -23 hash_file 298 274 -24 sum_file 353 325 -28 sort_main 904 859 -45 expand_main 736 686 -50 cut_main 1116 1065 -51 md5_sha1_sum_main 549 493 -56 lsattr_args 90 - -90 read_stduu 408 255 -153 ------------------------------------------------------------------------------ (add/remove: 3/3 grow/shrink: 7/20 up/down: 214/-657) Total: -443 bytes text data bss dec hex filename 797417 658 7428 805503 c4a7f busybox_old 796973 658 7428 805059 c48c3 busybox_unstripped
Diffstat (limited to 'coreutils/fold.c')
-rw-r--r--coreutils/fold.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/coreutils/fold.c b/coreutils/fold.c
index ed484edf0..e2a30d5d4 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -12,18 +12,17 @@
12 12
13#include "libbb.h" 13#include "libbb.h"
14 14
15static unsigned long flags; 15/* Must match getopt32 call */
16#define FLAG_COUNT_BYTES 1 16#define FLAG_COUNT_BYTES 1
17#define FLAG_BREAK_SPACES 2 17#define FLAG_BREAK_SPACES 2
18#define FLAG_WIDTH 4 18#define FLAG_WIDTH 4
19 19
20/* Assuming the current column is COLUMN, return the column that 20/* Assuming the current column is COLUMN, return the column that
21 printing C will move the cursor to. 21 printing C will move the cursor to.
22 The first column is 0. */ 22 The first column is 0. */
23
24static int adjust_column(int column, char c) 23static int adjust_column(int column, char c)
25{ 24{
26 if (!(flags & FLAG_COUNT_BYTES)) { 25 if (!(option_mask32 & FLAG_COUNT_BYTES)) {
27 if (c == '\b') { 26 if (c == '\b') {
28 if (column > 0) 27 if (column > 0)
29 column--; 28 column--;
@@ -54,29 +53,27 @@ int fold_main(int argc, char **argv)
54 char const *a = argv[i]; 53 char const *a = argv[i];
55 54
56 if (*a++ == '-') { 55 if (*a++ == '-') {
57 if (*a == '-' && !a[1]) 56 if (*a == '-' && !a[1]) /* "--" */
58 break; 57 break;
59 if (isdigit(*a)) { 58 if (isdigit(*a))
60 argv[i] = xasprintf("-w%s", a); 59 argv[i] = xasprintf("-w%s", a);
61 }
62 } 60 }
63 } 61 }
64 } 62 }
65 63
66 flags = getopt32(argv, "bsw:", &w_opt); 64 getopt32(argv, "bsw:", &w_opt);
67 if (flags & FLAG_WIDTH) 65 if (option_mask32 & FLAG_WIDTH)
68 width = xatoul_range(w_opt, 1, 10000); 66 width = xatoul_range(w_opt, 1, 10000);
69 67
70 argv += optind; 68 argv += optind;
71 if (!*argv) { 69 if (!*argv)
72 *--argv = (char*)"-"; 70 *--argv = (char*)"-";
73 }
74 71
75 do { 72 do {
76 FILE *istream = fopen_or_warn_stdin(*argv); 73 FILE *istream = fopen_or_warn_stdin(*argv);
77 int c; 74 int c;
78 int column = 0; /* Screen column where next char will go. */ 75 int column = 0; /* Screen column where next char will go. */
79 int offset_out = 0; /* Index in `line_out' for next char. */ 76 int offset_out = 0; /* Index in 'line_out' for next char. */
80 77
81 if (istream == NULL) { 78 if (istream == NULL) {
82 errs |= EXIT_FAILURE; 79 errs |= EXIT_FAILURE;
@@ -102,7 +99,7 @@ int fold_main(int argc, char **argv)
102 /* This character would make the line too long. 99 /* This character would make the line too long.
103 Print the line plus a newline, and make this character 100 Print the line plus a newline, and make this character
104 start the next line. */ 101 start the next line. */
105 if (flags & FLAG_BREAK_SPACES) { 102 if (option_mask32 & FLAG_BREAK_SPACES) {
106 /* Look for the last blank. */ 103 /* Look for the last blank. */
107 int logical_end; 104 int logical_end;
108 105
@@ -144,7 +141,7 @@ int fold_main(int argc, char **argv)
144 fwrite(line_out, sizeof(char), (size_t) offset_out, stdout); 141 fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
145 } 142 }
146 143
147 if (ferror(istream) || fclose_if_not_stdin(istream)) { 144 if (fclose_if_not_stdin(istream)) {
148 bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ 145 bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
149 errs |= EXIT_FAILURE; 146 errs |= EXIT_FAILURE;
150 } 147 }