Remove handrolled strcmp()'s
Favor readability over bare-metal.
This commit is contained in:
parent
1797df01e7
commit
9a074144c9
3
cat.c
3
cat.c
|
@ -1,5 +1,6 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "text.h"
|
||||
|
@ -29,7 +30,7 @@ main(int argc, char *argv[])
|
|||
concat(stdin, "<stdin>", stdout, "<stdout>");
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
3
cksum.c
3
cksum.c
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -96,7 +97,7 @@ main(int argc, char *argv[])
|
|||
cksum(stdin, NULL);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
3
cmp.c
3
cmp.c
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -32,7 +33,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
for (n = 0; n < 2; n++) {
|
||||
if (argv[n][0] == '-' && !argv[n][1]) {
|
||||
if (!strcmp(argv[n], "-")) {
|
||||
argv[n] = "<stdin>";
|
||||
fp[n] = stdin;
|
||||
} else {
|
||||
|
|
2
cols.c
2
cols.c
|
@ -48,7 +48,7 @@ main(int argc, char *argv[])
|
|||
getlines(stdin, &b);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
2
comm.c
2
comm.c
|
@ -50,7 +50,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (argv[i][0] == '-' && !argv[i][1]) {
|
||||
if (!strcmp(argv[i], "-")) {
|
||||
argv[i] = "<stdin>";
|
||||
fp[i] = stdin;
|
||||
} else if (!(fp[i] = fopen(argv[i], "r"))) {
|
||||
|
|
2
cut.c
2
cut.c
|
@ -187,7 +187,7 @@ main(int argc, char *argv[])
|
|||
cut(stdin, "<stdin>");
|
||||
else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
3
expand.c
3
expand.c
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utf.h"
|
||||
#include "util.h"
|
||||
|
@ -110,7 +111,7 @@ main(int argc, char *argv[])
|
|||
expand("<stdin>", stdin);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
2
fold.c
2
fold.c
|
@ -95,7 +95,7 @@ main(int argc, char *argv[])
|
|||
fold(stdin, "<stdin>");
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
2
grep.c
2
grep.c
|
@ -260,7 +260,7 @@ main(int argc, char *argv[])
|
|||
match = grep(stdin, "<stdin>");
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
3
head.c
3
head.c
|
@ -2,6 +2,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -50,7 +51,7 @@ main(int argc, char *argv[])
|
|||
} else {
|
||||
many = argc > 1;
|
||||
for (newline = 0; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
2
join.c
2
join.c
|
@ -528,7 +528,7 @@ main(int argc, char *argv[])
|
|||
usage();
|
||||
|
||||
for (n = 0; n < 2; n++) {
|
||||
if (argv[n][0] == '-' && !argv[n][1]) {
|
||||
if (!strcmp(argv[n], "-")) {
|
||||
argv[n] = "<stdin>";
|
||||
fp[n] = stdin;
|
||||
} else if (!(fp[n] = fopen(argv[n], "r"))) {
|
||||
|
|
2
nl.c
2
nl.c
|
@ -190,7 +190,7 @@ main(int argc, char *argv[])
|
|||
if (!argc) {
|
||||
nl("<stdin>", stdin);
|
||||
} else {
|
||||
if (argv[0][0] == '-' && !argv[0][1]) {
|
||||
if (!strcmp(argv[0], "-")) {
|
||||
argv[0] = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(argv[0], "r"))) {
|
||||
|
|
2
paste.c
2
paste.c
|
@ -116,7 +116,7 @@ main(int argc, char *argv[])
|
|||
dsc = ereallocarray(NULL, argc, sizeof(*dsc));
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (argv[i][0] == '-' && !argv[i][1]) {
|
||||
if (!strcmp(argv[i], "-")) {
|
||||
argv[i] = "<stdin>";
|
||||
dsc[i].fp = stdin;
|
||||
} else if (!(dsc[i].fp = fopen(argv[i], "r"))) {
|
||||
|
|
2
sed.c
2
sed.c
|
@ -1114,7 +1114,7 @@ next_file(void)
|
|||
if (first) /* given no files, default to stdin */
|
||||
file = stdin;
|
||||
/* else we've used all our files, leave file = NULL */
|
||||
} else if ((*files)[0] == '-' && !(*files)[1]) {
|
||||
} else if (!strcmp(*files, "-")) {
|
||||
file = stdin;
|
||||
files++;
|
||||
} else if (!(file = fopen(*files++, "r"))) {
|
||||
|
|
2
sort.c
2
sort.c
|
@ -301,7 +301,7 @@ main(int argc, char *argv[])
|
|||
getlines(stdin, &linebuf);
|
||||
}
|
||||
} else for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utf.h"
|
||||
#include "util.h"
|
||||
|
@ -79,7 +80,7 @@ main(int argc, char *argv[])
|
|||
strings(stdin, "<stdin>", len);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
2
tail.c
2
tail.c
|
@ -115,7 +115,7 @@ main(int argc, char *argv[])
|
|||
if ((many = argc > 1) && fflag)
|
||||
usage();
|
||||
for (newline = 0; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utf.h"
|
||||
#include "util.h"
|
||||
|
@ -153,7 +154,7 @@ main(int argc, char *argv[])
|
|||
unexpand("<stdin>", stdin);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
|
@ -246,7 +246,7 @@ main(int argc, char *argv[])
|
|||
if (argc > 1)
|
||||
usage();
|
||||
|
||||
if (!argc || (argv[0][0] == '-' && !argv[0][1])) {
|
||||
if (!argc || !strcmp(argv[0], "-")) {
|
||||
fp = stdin;
|
||||
ifname = "<stdin>";
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <sys/stat.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
|
@ -114,7 +115,7 @@ main(int argc, char *argv[])
|
|||
if (!argc || argc > 2)
|
||||
usage();
|
||||
|
||||
if (argc == 1 || (argv[0][0] == '-' && !argv[0][1])) {
|
||||
if (argc == 1 || !strcmp(argv[0], "-")) {
|
||||
if (mflag)
|
||||
uuencodeb64(stdin, argv[0], "<stdin>");
|
||||
else
|
||||
|
|
4
wc.c
4
wc.c
|
@ -1,4 +1,6 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <string.h>
|
||||
|
||||
#include "utf.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -84,7 +86,7 @@ main(int argc, char *argv[])
|
|||
wc(stdin, NULL);
|
||||
} else {
|
||||
for (many = (argc > 1); *argv; argc--, argv++) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
if (!strcmp(*argv, "-")) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user