diff options
Diffstat (limited to 'tr.c')
-rw-r--r-- | tr.c | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -30,6 +30,20 @@ | |||
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #include <sys/types.h> | 32 | #include <sys/types.h> |
33 | #define BB_DECLARE_EXTERN | ||
34 | #define bb_need_write_error | ||
35 | #include "messages.c" | ||
36 | |||
37 | const char *tr_usage="tr [-cds] STRING1 [STRING2]\n" | ||
38 | #ifndef BB_FEATURE_TRIVIAL_HELP | ||
39 | "\nTranslate, squeeze, and/or delete characters from\n" | ||
40 | "standard input, writing to standard output.\n\n" | ||
41 | "Options:\n" | ||
42 | "\t-c\ttake complement of STRING1\n" | ||
43 | "\t-d\tdelete input characters coded STRING1\n" | ||
44 | "\t-s\tsqueeze multiple output characters of STRING2 into one character\n" | ||
45 | #endif | ||
46 | ; | ||
33 | 47 | ||
34 | 48 | ||
35 | 49 | ||
@@ -60,7 +74,7 @@ static void convert() | |||
60 | if (in_index == read_chars) { | 74 | if (in_index == read_chars) { |
61 | if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) { | 75 | if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) { |
62 | if (write(1, (char *) output, out_index) != out_index) | 76 | if (write(1, (char *) output, out_index) != out_index) |
63 | write(2, "Bad write\n", 10); | 77 | write(2, write_error, strlen(write_error)); |
64 | exit(0); | 78 | exit(0); |
65 | } | 79 | } |
66 | in_index = 0; | 80 | in_index = 0; |
@@ -74,7 +88,7 @@ static void convert() | |||
74 | output[out_index++] = last = coded; | 88 | output[out_index++] = last = coded; |
75 | if (out_index == BUFSIZ) { | 89 | if (out_index == BUFSIZ) { |
76 | if (write(1, (char *) output, out_index) != out_index) { | 90 | if (write(1, (char *) output, out_index) != out_index) { |
77 | write(2, "Bad write\n", 10); | 91 | write(2, write_error, strlen(write_error)); |
78 | exit(1); | 92 | exit(1); |
79 | } | 93 | } |
80 | out_index = 0; | 94 | out_index = 0; |
@@ -167,16 +181,7 @@ extern int tr_main(int argc, char **argv) | |||
167 | sq_fl = TRUE; | 181 | sq_fl = TRUE; |
168 | break; | 182 | break; |
169 | default: | 183 | default: |
170 | usage("tr [-cds] STRING1 [STRING2]\n" | 184 | usage(tr_usage); |
171 | #ifndef BB_FEATURE_TRIVIAL_HELP | ||
172 | "\nTranslate, squeeze, and/or delete characters from\n" | ||
173 | "standard input, writing to standard output.\n\n" | ||
174 | "Options:\n" | ||
175 | "\t-c\ttake complement of STRING1\n" | ||
176 | "\t-d\tdelete input characters coded STRING1\n" | ||
177 | "\t-s\tsqueeze multiple output characters of STRING2 into one character\n" | ||
178 | #endif | ||
179 | ); | ||
180 | } | 185 | } |
181 | } | 186 | } |
182 | index++; | 187 | index++; |