commit 9a074144c91ef8d792a7d05e7ce0291ac487c876
parent 1797df01e7c6354b82f2b924c9a461a97331f08c
Author: FRIGN <dev@frign.de>
Date: Tue, 19 May 2015 17:44:15 +0200
Remove handrolled strcmp()'s
Favor readability over bare-metal.
Diffstat:
21 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/cat.c b/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"))) {
diff --git a/cksum.c b/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"))) {
diff --git a/cmp.c b/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 {
diff --git a/cols.c b/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"))) {
diff --git a/comm.c b/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"))) {
diff --git a/cut.c b/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"))) {
diff --git a/expand.c b/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"))) {
diff --git a/fold.c b/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"))) {
diff --git a/grep.c b/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"))) {
diff --git a/head.c b/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"))) {
diff --git a/join.c b/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"))) {
diff --git a/nl.c b/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"))) {
diff --git a/paste.c b/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"))) {
diff --git a/sed.c b/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"))) {
diff --git a/sort.c b/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"))) {
diff --git a/strings.c b/strings.c
@@ -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"))) {
diff --git a/tail.c b/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"))) {
diff --git a/unexpand.c b/unexpand.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"
@@ -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"))) {
diff --git a/uudecode.c b/uudecode.c
@@ -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 {
diff --git a/uuencode.c b/uuencode.c
@@ -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
diff --git a/wc.c b/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"))) {