summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-02-21 16:50:57 +0000
committerCameron Katri <me@cameronkatri.com>2021-04-13 15:28:32 -0400
commit1a83ac917a1f82c20c8bd661975910fd206c87cd (patch)
tree613211c9a35f2e7c9de6041ae23bb47ba7ab4639
parentb4408559c1e6e0df3ce61a198f9a4d1f444ecb87 (diff)
downloadbsdgames-darwin-1a83ac917a1f82c20c8bd661975910fd206c87cd.tar.gz
bsdgames-darwin-1a83ac917a1f82c20c8bd661975910fd206c87cd.tar.zst
bsdgames-darwin-1a83ac917a1f82c20c8bd661975910fd206c87cd.zip
cgram: consistently use char for characters
Having to convert back and forth between char, unsigned char and int is confusing. Just stay with char, until the support for wide characters is added. No functional change.
-rw-r--r--cgram/cgram.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/cgram/cgram.c b/cgram/cgram.c
index 98f8bece..f5270950 100644
--- a/cgram/cgram.c
+++ b/cgram/cgram.c
@@ -56,6 +56,36 @@ xstrdup(const char *s)
return ret;
}
+static char
+ch_toupper(char ch)
+{
+ return (char)toupper((unsigned char)ch);
+}
+
+static char
+ch_tolower(char ch)
+{
+ return (char)tolower((unsigned char)ch);
+}
+
+static bool
+ch_isalpha(char ch)
+{
+ return isalpha((unsigned char)ch);
+}
+
+static bool
+ch_islower(char ch)
+{
+ return islower((unsigned char)ch);
+}
+
+static bool
+ch_isupper(char ch)
+{
+ return isupper((unsigned char)ch);
+}
+
////////////////////////////////////////////////////////////
struct stringarray {
@@ -148,11 +178,11 @@ encode(void)
for (int y = 0; y < lines.num; y++) {
for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
- if (islower((unsigned char)lines.v[y][x])) {
+ if (ch_islower(lines.v[y][x])) {
int q = lines.v[y][x] - 'a';
lines.v[y][x] = 'a' + key[q];
}
- if (isupper((unsigned char)lines.v[y][x])) {
+ if (ch_isupper(lines.v[y][x])) {
int q = lines.v[y][x] - 'A';
lines.v[y][x] = 'A' + key[q];
}
@@ -169,16 +199,16 @@ substitute(int ch)
return false;
}
- int och = lines.v[cury][curx];
- if (!isalpha((unsigned char)och)) {
+ char och = lines.v[cury][curx];
+ if (!ch_isalpha(och)) {
beep();
return false;
}
- int loch = tolower((unsigned char)och);
- int uoch = toupper((unsigned char)och);
- int lch = tolower((unsigned char)ch);
- int uch = toupper((unsigned char)ch);
+ char loch = ch_tolower(och);
+ char uoch = ch_toupper(och);
+ char lch = ch_tolower(ch);
+ char uch = ch_toupper(ch);
for (int y = 0; y < lines.num; y++) {
for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
@@ -208,14 +238,13 @@ redraw(void)
int ln = i + scrolldown;
if (ln < lines.num) {
for (unsigned j = 0; lines.v[i][j] != '\0'; j++) {
- int ch = lines.v[i][j];
- if (ch != sollines.v[i][j] &&
- isalpha((unsigned char)ch)) {
+ char ch = lines.v[i][j];
+ if (ch != sollines.v[i][j] && ch_isalpha(ch)) {
won = false;
}
bool bold = false;
if (hinting && ch == sollines.v[i][j] &&
- isalpha((unsigned char)ch)) {
+ ch_isalpha(ch)) {
bold = true;
attron(A_BOLD);
}