diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-16 23:49:13 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-16 23:49:13 +0000 |
commit | 9f739445cd3deddd0343c3a8d5a981ede26bef30 (patch) | |
tree | 6dc013e44d2281eb1e6f61c4bca1ae7546001f79 /coreutils | |
parent | a597aaddfa76d589d3e1a37b1f1c3401c2decffd (diff) | |
download | busybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.tar.gz busybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.tar.bz2 busybox-w32-9f739445cd3deddd0343c3a8d5a981ede26bef30.zip |
inline strcmp(s, "-") [actually macro-ize it for now - gcc is too stupid]
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cut.c | 13 | ||||
-rw-r--r-- | coreutils/diff.c | 10 | ||||
-rw-r--r-- | coreutils/env.c | 2 | ||||
-rw-r--r-- | coreutils/md5_sha1_sum.c | 4 | ||||
-rw-r--r-- | coreutils/sort.c | 2 | ||||
-rw-r--r-- | coreutils/sum.c | 11 | ||||
-rw-r--r-- | coreutils/tail.c | 4 | ||||
-rw-r--r-- | coreutils/uudecode.c | 2 |
8 files changed, 23 insertions, 25 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index a538e3d20..a72b2c29a 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -168,6 +168,8 @@ int cut_main(int argc, char **argv) | |||
168 | 168 | ||
169 | opt_complementary = "b--bcf:c--bcf:f--bcf"; | 169 | opt_complementary = "b--bcf:c--bcf:f--bcf"; |
170 | getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); | 170 | getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); |
171 | // argc -= optind; | ||
172 | argv += optind; | ||
171 | if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) | 173 | if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) |
172 | bb_error_msg_and_die("expected a list of bytes, characters, or fields"); | 174 | bb_error_msg_and_die("expected a list of bytes, characters, or fields"); |
173 | if (option_mask32 & BB_GETOPT_ERROR) | 175 | if (option_mask32 & BB_GETOPT_ERROR) |
@@ -262,22 +264,21 @@ int cut_main(int argc, char **argv) | |||
262 | qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc); | 264 | qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc); |
263 | } | 265 | } |
264 | 266 | ||
265 | /* argv[(optind)..(argc-1)] should be names of file to process. If no | 267 | /* argv[0..argc-1] should be names of file to process. If no |
266 | * files were specified or '-' was specified, take input from stdin. | 268 | * files were specified or '-' was specified, take input from stdin. |
267 | * Otherwise, we process all the files specified. */ | 269 | * Otherwise, we process all the files specified. */ |
268 | if (argv[optind] == NULL | 270 | if (argv[0] == NULL || LONE_DASH(argv[0])) { |
269 | || (argv[optind][0] == '-' && argv[optind][1] == '\0')) { | ||
270 | cut_file(stdin); | 271 | cut_file(stdin); |
271 | } else { | 272 | } else { |
272 | FILE *file; | 273 | FILE *file; |
273 | 274 | ||
274 | for (; optind < argc; optind++) { | 275 | do { |
275 | file = fopen_or_warn(argv[optind], "r"); | 276 | file = fopen_or_warn(argv[0], "r"); |
276 | if (file) { | 277 | if (file) { |
277 | cut_file(file); | 278 | cut_file(file); |
278 | fclose(file); | 279 | fclose(file); |
279 | } | 280 | } |
280 | } | 281 | } while (*++argv); |
281 | } | 282 | } |
282 | if (ENABLE_FEATURE_CLEAN_UP) | 283 | if (ENABLE_FEATURE_CLEAN_UP) |
283 | free(cut_lists); | 284 | free(cut_lists); |
diff --git a/coreutils/diff.c b/coreutils/diff.c index 0df9989b7..887679a0a 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c | |||
@@ -904,19 +904,19 @@ static int diffreg(char *ofile1, char *ofile2, int flags) | |||
904 | 904 | ||
905 | if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) | 905 | if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) |
906 | return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); | 906 | return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); |
907 | if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0) | 907 | if (LONE_DASH(file1) && LONE_DASH(file2)) |
908 | goto closem; | 908 | goto closem; |
909 | 909 | ||
910 | f1 = stdin; | 910 | f1 = stdin; |
911 | if (flags & D_EMPTY1) | 911 | if (flags & D_EMPTY1) |
912 | f1 = xfopen(bb_dev_null, "r"); | 912 | f1 = xfopen(bb_dev_null, "r"); |
913 | else if (file1[0] != '-' || file1[1]) /* not "-" */ | 913 | else if (NOT_LONE_DASH(file1)) |
914 | f1 = xfopen(file1, "r"); | 914 | f1 = xfopen(file1, "r"); |
915 | 915 | ||
916 | f2 = stdin; | 916 | f2 = stdin; |
917 | if (flags & D_EMPTY2) | 917 | if (flags & D_EMPTY2) |
918 | f2 = xfopen(bb_dev_null, "r"); | 918 | f2 = xfopen(bb_dev_null, "r"); |
919 | else if (file2[0] != '-' || file2[1]) /* not "-" */ | 919 | else if (NOT_LONE_DASH(file2)) |
920 | f2 = xfopen(file2, "r"); | 920 | f2 = xfopen(file2, "r"); |
921 | 921 | ||
922 | i = files_differ(f1, f2, flags); | 922 | i = files_differ(f1, f2, flags); |
@@ -1212,12 +1212,12 @@ int diff_main(int argc, char **argv) | |||
1212 | bb_error_msg("missing filename"); | 1212 | bb_error_msg("missing filename"); |
1213 | bb_show_usage(); | 1213 | bb_show_usage(); |
1214 | } | 1214 | } |
1215 | if (argv[0][0] == '-' && !argv[0][1]) { /* "-" */ | 1215 | if (LONE_DASH(argv[0])) { |
1216 | fstat(STDIN_FILENO, &stb1); | 1216 | fstat(STDIN_FILENO, &stb1); |
1217 | gotstdin = 1; | 1217 | gotstdin = 1; |
1218 | } else | 1218 | } else |
1219 | xstat(argv[0], &stb1); | 1219 | xstat(argv[0], &stb1); |
1220 | if (argv[1][0] == '-' && !argv[1][1]) { /* "-" */ | 1220 | if (LONE_DASH(argv[1])) { |
1221 | fstat(STDIN_FILENO, &stb2); | 1221 | fstat(STDIN_FILENO, &stb2); |
1222 | gotstdin = 1; | 1222 | gotstdin = 1; |
1223 | } else | 1223 | } else |
diff --git a/coreutils/env.c b/coreutils/env.c index 2ce99b0ad..e4cad271b 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -58,7 +58,7 @@ int env_main(int argc, char** argv) | |||
58 | opt = getopt32(argc, argv, "+iu:", &unset_env); | 58 | opt = getopt32(argc, argv, "+iu:", &unset_env); |
59 | 59 | ||
60 | argv += optind; | 60 | argv += optind; |
61 | if (*argv && (argv[0][0] == '-') && !argv[0][1]) { | 61 | if (*argv && LONE_DASH(argv[0])) { |
62 | opt |= 1; | 62 | opt |= 1; |
63 | ++argv; | 63 | ++argv; |
64 | } | 64 | } |
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index e8d3a1509..6fe1b0286 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -39,7 +39,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo) | |||
39 | void (*final)(void*, void*); | 39 | void (*final)(void*, void*); |
40 | 40 | ||
41 | src_fd = STDIN_FILENO; | 41 | src_fd = STDIN_FILENO; |
42 | if (filename[0] != '-' || filename[1]) { /* not "-" */ | 42 | if (NOT_LONE_DASH(filename)) { |
43 | src_fd = open(filename, O_RDONLY); | 43 | src_fd = open(filename, O_RDONLY); |
44 | if (src_fd < 0) { | 44 | if (src_fd < 0) { |
45 | bb_perror_msg("%s", filename); | 45 | bb_perror_msg("%s", filename); |
@@ -120,7 +120,7 @@ int md5_sha1_sum_main(int argc, char **argv) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | pre_computed_stream = stdin; | 122 | pre_computed_stream = stdin; |
123 | if (file_ptr[0] != '-' || file_ptr[1]) { /* not "-" */ | 123 | if (NOT_LONE_DASH(file_ptr)) { |
124 | pre_computed_stream = xfopen(file_ptr, "r"); | 124 | pre_computed_stream = xfopen(file_ptr, "r"); |
125 | } | 125 | } |
126 | 126 | ||
diff --git a/coreutils/sort.c b/coreutils/sort.c index c23bf9c60..c37810f1a 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -310,7 +310,7 @@ int sort_main(int argc, char **argv) | |||
310 | /* Open input files and read data */ | 310 | /* Open input files and read data */ |
311 | for (i = argv[optind] ? optind : optind-1; argv[i]; i++) { | 311 | for (i = argv[optind] ? optind : optind-1; argv[i]; i++) { |
312 | fp = stdin; | 312 | fp = stdin; |
313 | if (i >= optind && (argv[i][0] != '-' || argv[i][1])) | 313 | if (i >= optind && NOT_LONE_DASH(argv[i])) |
314 | fp = xfopen(argv[i], "r"); | 314 | fp = xfopen(argv[i], "r"); |
315 | for (;;) { | 315 | for (;;) { |
316 | line = GET_LINE(fp); | 316 | line = GET_LINE(fp); |
diff --git a/coreutils/sum.c b/coreutils/sum.c index 93f4e22eb..68a857816 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
@@ -18,9 +18,6 @@ | |||
18 | /* 1 if any of the files read were the standard input */ | 18 | /* 1 if any of the files read were the standard input */ |
19 | static int have_read_stdin; | 19 | static int have_read_stdin; |
20 | 20 | ||
21 | /* make a little more readable and avoid using strcmp for just 2 bytes */ | ||
22 | #define IS_STDIN(s) (s[0] == '-' && s[1] == '\0') | ||
23 | |||
24 | /* Calculate and print the rotated checksum and the size in 1K blocks | 21 | /* Calculate and print the rotated checksum and the size in 1K blocks |
25 | of file FILE, or of the standard input if FILE is "-". | 22 | of file FILE, or of the standard input if FILE is "-". |
26 | If PRINT_NAME is >1, print FILE next to the checksum and size. | 23 | If PRINT_NAME is >1, print FILE next to the checksum and size. |
@@ -34,7 +31,7 @@ static int bsd_sum_file(const char *file, int print_name) | |||
34 | int ch; /* Each character read. */ | 31 | int ch; /* Each character read. */ |
35 | int ret = 0; | 32 | int ret = 0; |
36 | 33 | ||
37 | if (IS_STDIN(file)) { | 34 | if (LONE_DASH(file)) { |
38 | fp = stdin; | 35 | fp = stdin; |
39 | have_read_stdin++; | 36 | have_read_stdin++; |
40 | } else { | 37 | } else { |
@@ -84,7 +81,7 @@ static int sysv_sum_file(const char *file, int print_name) | |||
84 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ | 81 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ |
85 | unsigned int s = 0; | 82 | unsigned int s = 0; |
86 | 83 | ||
87 | if (IS_STDIN(file)) { | 84 | if (LONE_DASH(file)) { |
88 | fd = 0; | 85 | fd = 0; |
89 | have_read_stdin = 1; | 86 | have_read_stdin = 1; |
90 | } else { | 87 | } else { |
@@ -103,7 +100,7 @@ static int sysv_sum_file(const char *file, int print_name) | |||
103 | release_and_ret: | 100 | release_and_ret: |
104 | bb_perror_msg(file); | 101 | bb_perror_msg(file); |
105 | RELEASE_CONFIG_BUFFER(buf); | 102 | RELEASE_CONFIG_BUFFER(buf); |
106 | if (!IS_STDIN(file)) | 103 | if (NOT_LONE_DASH(file)) |
107 | close(fd); | 104 | close(fd); |
108 | return 0; | 105 | return 0; |
109 | } | 106 | } |
@@ -113,7 +110,7 @@ release_and_ret: | |||
113 | s += buf[bytes_read]; | 110 | s += buf[bytes_read]; |
114 | } | 111 | } |
115 | 112 | ||
116 | if (!IS_STDIN(file) && close(fd) == -1) | 113 | if (NOT_LONE_DASH(file) && close(fd) == -1) |
117 | goto release_and_ret; | 114 | goto release_and_ret; |
118 | else | 115 | else |
119 | RELEASE_CONFIG_BUFFER(buf); | 116 | RELEASE_CONFIG_BUFFER(buf); |
diff --git a/coreutils/tail.c b/coreutils/tail.c index ed5ea1467..4c3c3b901 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -176,8 +176,8 @@ int tail_main(int argc, char **argv) | |||
176 | } | 176 | } |
177 | 177 | ||
178 | do { | 178 | do { |
179 | if ((argv[i][0] == '-') && !argv[i][1]) { | 179 | if (LONE_DASH(argv[i])) { |
180 | DO_STDIN: | 180 | DO_STDIN: |
181 | fds[nfiles] = STDIN_FILENO; | 181 | fds[nfiles] = STDIN_FILENO; |
182 | } else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) { | 182 | } else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) { |
183 | bb_perror_msg("%s", argv[i]); | 183 | bb_perror_msg("%s", argv[i]); |
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 8b7de74ff..06512119e 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c | |||
@@ -166,7 +166,7 @@ int uudecode_main(int argc, char **argv) | |||
166 | } | 166 | } |
167 | outname++; | 167 | outname++; |
168 | } | 168 | } |
169 | if (strcmp(outname, "-") == 0) { | 169 | if (LONE_DASH(outname)) { |
170 | dst_stream = stdout; | 170 | dst_stream = stdout; |
171 | } else { | 171 | } else { |
172 | dst_stream = xfopen(outname, "w"); | 172 | dst_stream = xfopen(outname, "w"); |