There's no need to check for isascii() with ANSI ctype macros/functions. Eliminating the macros makes the code clearer.
- todd Index: usr.bin/look/look.c =================================================================== RCS file: /cvs/src/usr.bin/look/look.c,v retrieving revision 1.18 diff -u -p -u -r1.18 look.c --- usr.bin/look/look.c 9 Oct 2015 01:37:08 -0000 1.18 +++ usr.bin/look/look.c 7 Sep 2016 21:44:53 -0000 @@ -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 *ba /* 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; }