summaryrefslogtreecommitdiffstats
path: root/usr.bin/look
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2016-09-13 15:27:47 +0000
committermillert <millert@openbsd.org>2016-09-13 15:27:47 +0000
commit5b15d0a1dc04d4c38d3f794b96c96a7a210f8dc2 (patch)
tree6a7b4ec5bc1b10b423829a0527576086c3dbf52f /usr.bin/look
parentadd a little more typing to the first callback argument. (diff)
downloadwireguard-openbsd-5b15d0a1dc04d4c38d3f794b96c96a7a210f8dc2.tar.xz
wireguard-openbsd-5b15d0a1dc04d4c38d3f794b96c96a7a210f8dc2.zip
Eliminate the FOLD and DICT macros. There's no need to check for
isascii() with ANSI ctype macros/functions. Eliminating the macros makes the code clearer. OK jca@
Diffstat (limited to 'usr.bin/look')
-rw-r--r--usr.bin/look/look.c26
1 files changed, 5 insertions, 21 deletions
diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c
index be81ee53d42..a91abaf26bd 100644
--- a/usr.bin/look/look.c
+++ b/usr.bin/look/look.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: look.c,v 1.18 2015/10/09 01:37:08 deraadt Exp $ */
+/* $OpenBSD: look.c,v 1.19 2016/09/13 15:27:47 millert Exp $ */
/* $NetBSD: look.c,v 1.7 1995/08/31 22:41:02 jtc Exp $ */
/*-
@@ -57,20 +57,9 @@
#include "pathnames.h"
-/*
- * FOLD and DICT convert characters to a normal form for comparison,
- * according to the user specified flags.
- *
- * DICT expects integers because it uses a non-character value to
- * indicate a character which should not participate in comparisons.
- */
#define EQUAL 0
#define GREATER 1
#define LESS (-1)
-#define NO_COMPARE (-2)
-
-#define FOLD(c) (isascii(c) && isupper(c) ? tolower(c) : (c))
-#define DICT(c) (isascii(c) && isalnum(c) ? (c) : NO_COMPARE)
int dflag, fflag;
@@ -147,10 +136,8 @@ look(char *string, char *front, char *back)
/* Reformat string to avoid doing it multiple times later. */
for (readp = writep = string; ch = *readp++;) {
if (fflag)
- ch = FOLD((unsigned char)ch);
- if (dflag)
- ch = DICT((unsigned char)ch);
- if (ch != NO_COMPARE)
+ ch = tolower((unsigned char)ch);
+ if (!dflag || isalnum((unsigned char)ch))
*(writep++) = ch;
}
*writep = '\0';
@@ -294,11 +281,8 @@ compare(char *s1, char *s2, char *back)
for (; *s1 && s2 < back && *s2 != '\n'; ++s1, ++s2) {
ch = *s2;
if (fflag)
- ch = FOLD((unsigned char)ch);
- if (dflag)
- ch = DICT((unsigned char)ch);
-
- if (ch == NO_COMPARE) {
+ ch = tolower((unsigned char)ch);
+ if (dflag && !isalnum((unsigned char)ch)) {
++s2; /* Ignore character in comparison. */
continue;
}