inline strcmp(s, "-") [actually macro-ize it for now - gcc is too stupid]

This commit is contained in:
Denis Vlasenko
2006-12-16 23:49:13 +00:00
parent a597aaddfa
commit 9f739445cd
28 changed files with 69 additions and 63 deletions

View File

@@ -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, &ltok);
// 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);

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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");
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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]);

View File

@@ -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");