[hackers] [sbase] Remove handrolled strcmp()'s || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 21 May 2015 16:43:43 +0200 (CEST)

commit 9a074144c91ef8d792a7d05e7ce0291ac487c876
Author: FRIGN <dev_AT_frign.de>
Date: Tue May 19 17:44:15 2015 +0200

    Remove handrolled strcmp()'s
    
    Favor readability over bare-metal.

diff --git a/cat.c b/cat.c
index a0cd961..fb569f1 100644
--- a/cat.c
+++ b/cat.c
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "text.h"
_AT_@ -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
index 4ad78a1..9a0d195 100644
--- a/cksum.c
+++ b/cksum.c
_AT_@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include <inttypes.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "util.h"
 
_AT_@ -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
index 47ea1e4..c04fce6 100644
--- a/cmp.c
+++ b/cmp.c
_AT_@ -1,6 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "util.h"
 
_AT_@ -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
index e5eec71..6f43e35 100644
--- a/cols.c
+++ b/cols.c
_AT_@ -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
index 4464c43..661aed2 100644
--- a/comm.c
+++ b/comm.c
_AT_@ -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
index b5e176e..33eecd0 100644
--- a/cut.c
+++ b/cut.c
_AT_@ -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
index c6057f7..985dc96 100644
--- a/expand.c
+++ b/expand.c
_AT_@ -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"
_AT_@ -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
index 0a55c61..69493c0 100644
--- a/fold.c
+++ b/fold.c
_AT_@ -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
index e51ce09..5836eaa 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -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
index 3f331ce..bb6b180 100644
--- a/head.c
+++ b/head.c
_AT_@ -2,6 +2,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "util.h"
 
_AT_@ -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
index 0d8f152..572bed0 100644
--- a/join.c
+++ b/join.c
_AT_@ -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
index 8c7b41f..3685221 100644
--- a/nl.c
+++ b/nl.c
_AT_@ -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
index 6f3fac2..417d93c 100644
--- a/paste.c
+++ b/paste.c
_AT_@ -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
index 65b3708..586cecb 100644
--- a/sed.c
+++ b/sed.c
_AT_@ -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
index 2aa4aee..f98a428 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -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
index 51b7eb6..0a14c20 100644
--- a/strings.c
+++ b/strings.c
_AT_@ -2,6 +2,7 @@
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "utf.h"
 #include "util.h"
_AT_@ -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
index 3489da7..a53dcd1 100644
--- a/tail.c
+++ b/tail.c
_AT_@ -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
index feb6592..c107dbf 100644
--- a/unexpand.c
+++ b/unexpand.c
_AT_@ -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"
_AT_@ -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
index 4641fb8..7140db7 100644
--- a/uudecode.c
+++ b/uudecode.c
_AT_@ -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
index 17b59ea..fdde3d2 100644
--- a/uuencode.c
+++ b/uuencode.c
_AT_@ -2,6 +2,7 @@
 #include <sys/stat.h>
 
 #include <stdio.h>
+#include <string.h>
 
 #include "util.h"
 
_AT_@ -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
index b1bd0df..8870761 100644
--- a/wc.c
+++ b/wc.c
_AT_@ -1,4 +1,6 @@
 /* See LICENSE file for copyright and license details. */
+#include <string.h>
+
 #include "utf.h"
 #include "util.h"
 
_AT_@ -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"))) {
Received on Thu May 21 2015 - 16:43:43 CEST

This archive was generated by hypermail 2.3.0 : Thu May 21 2015 - 16:48:10 CEST