summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-04-25 20:38:03 +0000
committerCameron Katri <me@cameronkatri.com>2021-04-28 16:38:48 -0400
commit2dbe3a72a9b248ec967612fe617888a1297ea202 (patch)
treea098220bdf43a91c877982cac7eed8612206cbfd
parentfcf2c9d81824f115900bc2e3e5ed8be2afbb7d46 (diff)
downloadbsdgames-darwin-2dbe3a72a9b248ec967612fe617888a1297ea202.tar.gz
bsdgames-darwin-2dbe3a72a9b248ec967612fe617888a1297ea202.tar.zst
bsdgames-darwin-2dbe3a72a9b248ec967612fe617888a1297ea202.zip
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.
-rw-r--r--cgram/cgram.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/cgram/cgram.c b/cgram/cgram.c
index 00701ab7..54b6429f 100644
--- a/cgram/cgram.c
+++ b/cgram/cgram.c
@@ -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/25 20:19:19 rillig Exp $");
#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