diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-17 02:49:13 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-17 02:49:13 +0300 |
commit | 9f739445cd3deddd0343c3a8d5a981ede26bef30 (patch) | |
tree | 6dc013e44d2281eb1e6f61c4bca1ae7546001f79 /coreutils | |
parent | a597aaddfa76d589d3e1a37b1f1c3401c2decffd (diff) |
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) opt_complementary = "b--bcf:c--bcf:f--bcf"; getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); +// argc -= optind; + argv += optind; if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) bb_error_msg_and_die("expected a list of bytes, characters, or fields"); if (option_mask32 & BB_GETOPT_ERROR) @@ -262,22 +264,21 @@ int cut_main(int argc, char **argv) qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc); } - /* argv[(optind)..(argc-1)] should be names of file to process. If no + /* argv[0..argc-1] should be names of file to process. If no * files were specified or '-' was specified, take input from stdin. * Otherwise, we process all the files specified. */ - if (argv[optind] == NULL - || (argv[optind][0] == '-' && argv[optind][1] == '\0')) { + if (argv[0] == NULL || LONE_DASH(argv[0])) { cut_file(stdin); } else { FILE *file; - for (; optind < argc; optind++) { - file = fopen_or_warn(argv[optind], "r"); + do { + file = fopen_or_warn(argv[0], "r"); if (file) { cut_file(file); fclose(file); } - } + } while (*++argv); } if (ENABLE_FEATURE_CLEAN_UP) 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) if (S_ISDIR(stb1.st_mode) != S_ISDIR(stb2.st_mode)) return (S_ISDIR(stb1.st_mode) ? D_MISMATCH1 : D_MISMATCH2); - if (strcmp(file1, "-") == 0 && strcmp(file2, "-") == 0) + if (LONE_DASH(file1) && LONE_DASH(file2)) goto closem; f1 = stdin; if (flags & D_EMPTY1) f1 = xfopen(bb_dev_null, "r"); - else if (file1[0] != '-' || file1[1]) /* not "-" */ + else if (NOT_LONE_DASH(file1)) f1 = xfopen(file1, "r"); f2 = stdin; if (flags & D_EMPTY2) f2 = xfopen(bb_dev_null, "r"); - else if (file2[0] != '-' || file2[1]) /* not "-" */ + else if (NOT_LONE_DASH(file2)) f2 = xfopen(file2, "r"); i = files_differ(f1, f2, flags); @@ -1212,12 +1212,12 @@ int diff_main(int argc, char **argv) bb_error_msg("missing filename"); bb_show_usage(); } - if (argv[0][0] == '-' && !argv[0][1]) { /* "-" */ + if (LONE_DASH(argv[0])) { fstat(STDIN_FILENO, &stb1); gotstdin = 1; } else xstat(argv[0], &stb1); - if (argv[1][0] == '-' && !argv[1][1]) { /* "-" */ + if (LONE_DASH(argv[1])) { fstat(STDIN_FILENO, &stb2); gotstdin = 1; } 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) opt = getopt32(argc, argv, "+iu:", &unset_env); argv += optind; - if (*argv && (argv[0][0] == '-') && !argv[0][1]) { + if (*argv && LONE_DASH(argv[0])) { opt |= 1; ++argv; } 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) void (*final)(void*, void*); src_fd = STDIN_FILENO; - if (filename[0] != '-' || filename[1]) { /* not "-" */ + if (NOT_LONE_DASH(filename)) { src_fd = open(filename, O_RDONLY); if (src_fd < 0) { bb_perror_msg("%s", filename); @@ -120,7 +120,7 @@ int md5_sha1_sum_main(int argc, char **argv) } pre_computed_stream = stdin; - if (file_ptr[0] != '-' || file_ptr[1]) { /* not "-" */ + if (NOT_LONE_DASH(file_ptr)) { pre_computed_stream = xfopen(file_ptr, "r"); } 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) /* Open input files and read data */ for (i = argv[optind] ? optind : optind-1; argv[i]; i++) { fp = stdin; - if (i >= optind && (argv[i][0] != '-' || argv[i][1])) + if (i >= optind && NOT_LONE_DASH(argv[i])) fp = xfopen(argv[i], "r"); for (;;) { 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 @@ /* 1 if any of the files read were the standard input */ static int have_read_stdin; -/* make a little more readable and avoid using strcmp for just 2 bytes */ -#define IS_STDIN(s) (s[0] == '-' && s[1] == '\0') - /* Calculate and print the rotated checksum and the size in 1K blocks of file FILE, or of the standard input if FILE is "-". 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) int ch; /* Each character read. */ int ret = 0; - if (IS_STDIN(file)) { + if (LONE_DASH(file)) { fp = stdin; have_read_stdin++; } else { @@ -84,7 +81,7 @@ static int sysv_sum_file(const char *file, int print_name) /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ unsigned int s = 0; - if (IS_STDIN(file)) { + if (LONE_DASH(file)) { fd = 0; have_read_stdin = 1; } else { @@ -103,7 +100,7 @@ static int sysv_sum_file(const char *file, int print_name) release_and_ret: bb_perror_msg(file); RELEASE_CONFIG_BUFFER(buf); - if (!IS_STDIN(file)) + if (NOT_LONE_DASH(file)) close(fd); return 0; } @@ -113,7 +110,7 @@ release_and_ret: s += buf[bytes_read]; } - if (!IS_STDIN(file) && close(fd) == -1) + if (NOT_LONE_DASH(file) && close(fd) == -1) goto release_and_ret; else 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) } do { - if ((argv[i][0] == '-') && !argv[i][1]) { - DO_STDIN: + if (LONE_DASH(argv[i])) { + DO_STDIN: fds[nfiles] = STDIN_FILENO; } else if ((fds[nfiles] = open(argv[i], O_RDONLY)) < 0) { 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) } outname++; } - if (strcmp(outname, "-") == 0) { + if (LONE_DASH(outname)) { dst_stream = stdout; } else { dst_stream = xfopen(outname, "w"); |