Module Name: src Committed By: rillig Date: Sun Apr 25 20:38:03 UTC 2021
Modified Files: src/games/cgram: cgram.c Log Message: cgram: use ASCII-only implementation of <ctype.h> functions The function 'encode' already assumes that all letter characters are contiguous and that there are only 26 letters of each case. At the moment, cgram cannot handle UTF-8 anyway since it reads the input byte-wise, assuming that each byte is exacty one character. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/games/cgram/cgram.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/games/cgram/cgram.c diff -u src/games/cgram/cgram.c:1.20 src/games/cgram/cgram.c:1.21 --- src/games/cgram/cgram.c:1.20 Sun Apr 25 20:19:19 2021 +++ src/games/cgram/cgram.c Sun Apr 25 20:38:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $ */ +/* $NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $ */ /*- * Copyright (c) 2013, 2021 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.c,v 1.20 2021/04/25 20:19:19 rillig Exp $"); +__RCSID("$NetBSD: cgram.c,v 1.21 2021/04/25 20:38:03 rillig Exp $"); #endif #include <assert.h> @@ -46,42 +46,41 @@ __RCSID("$NetBSD: cgram.c,v 1.20 2021/04 #include "pathnames.h" -//////////////////////////////////////////////////////////// -static char -ch_toupper(char ch) +static bool +ch_isspace(char ch) { - return (char)toupper((unsigned char)ch); + return isspace((unsigned char)ch) != 0; } -static char -ch_tolower(char ch) +static bool +ch_islower(char ch) { - return (char)tolower((unsigned char)ch); + return ch >= 'a' && ch <= 'z'; } static bool -ch_isalpha(char ch) +ch_isupper(char ch) { - return isalpha((unsigned char)ch) != 0; + return ch >= 'A' && ch <= 'Z'; } static bool -ch_islower(char ch) +ch_isalpha(char ch) { - return islower((unsigned char)ch) != 0; + return ch_islower(ch) || ch_isupper(ch); } -static bool -ch_isspace(char ch) +static char +ch_toupper(char ch) { - return isspace((unsigned char)ch) != 0; + return ch_islower(ch) ? (char)(ch - 'a' + 'A') : ch; } -static bool -ch_isupper(char ch) +static char +ch_tolower(char ch) { - return isupper((unsigned char)ch) != 0; + return ch_isupper(ch) ? (char)(ch - 'A' + 'a') : ch; } static int