Remove handrolled strcmp()'s

Favor readability over bare-metal.
This commit is contained in:
FRIGN 2015-05-19 17:44:15 +02:00 committed by sin
parent 1797df01e7
commit 9a074144c9
21 changed files with 31 additions and 21 deletions

3
cat.c
View File

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

View File

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

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

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

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

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

View File

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

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

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

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

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

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

View File

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

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

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

View File

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

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

View File

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

View File

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

View File

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

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