Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/cgram cgram: consistently use char for characters
details: https://anonhg.NetBSD.org/src/rev/545f27013578
branches: trunk
changeset: 959681:545f27013578
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Feb 21 16:50:57 2021 +0000
description:
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.
diffstat:
games/cgram/cgram.c | 53 +++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 41 insertions(+), 12 deletions(-)
diffs (95 lines):
diff -r 6463daf33378 -r 545f27013578 games/cgram/cgram.c
--- a/games/cgram/cgram.c Sun Feb 21 16:37:26 2021 +0000
+++ b/games/cgram/cgram.c Sun Feb 21 16:50:57 2021 +0000
@@ -56,6 +56,36 @@
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 @@
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 @@
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 @@
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);
}
Home |
Main Index |
Thread Index |
Old Index