[Scummvm-git-logs] scummvm master -> a950522f7d18c8293a71523b2cd97184cb469324
dreammaster
dreammaster at scummvm.org
Tue Jul 13 02:52:42 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a950522f7d AGS: Properly implement ASCII methods for use in unicode code
Commit: a950522f7d18c8293a71523b2cd97184cb469324
https://github.com/scummvm/scummvm/commit/a950522f7d18c8293a71523b2cd97184cb469324
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-07-12T19:50:20-07:00
Commit Message:
AGS: Properly implement ASCII methods for use in unicode code
Changed paths:
engines/ags/lib/allegro/unicode.cpp
engines/ags/lib/allegro/unicode.h
diff --git a/engines/ags/lib/allegro/unicode.cpp b/engines/ags/lib/allegro/unicode.cpp
index bd3ee1d6bf..3a5ba52639 100644
--- a/engines/ags/lib/allegro/unicode.cpp
+++ b/engines/ags/lib/allegro/unicode.cpp
@@ -41,10 +41,54 @@ int (*ucwidth)(int c) = utf8_cwidth;
/* uisok: */
int (*uisok)(int c) = utf8_isok;
+struct UTYPE_INFO {
+ int id;
+ AL_METHOD(int, u_getc, (const char *s));
+ AL_METHOD(int, u_getx, (char **s));
+ AL_METHOD(int, u_setc, (char *s, int c));
+ AL_METHOD(int, u_width, (const char *s));
+ AL_METHOD(int, u_cwidth, (int c));
+ AL_METHOD(int, u_isok, (int c));
+ int u_width_max;
+};
+
+static UTYPE_INFO utypes[] =
+{
+ { U_ASCII, ascii_getc, ascii_getx, ascii_setc, ascii_width, ascii_cwidth, ascii_isok, 1 },
+ { U_UTF8, utf8_getc, utf8_getx, utf8_setc, utf8_width, utf8_cwidth, utf8_isok, 4 }
+};
+
+
+/* _find_utype:
+ * Helper for locating a string type description.
+ */
+static UTYPE_INFO *find_utype(int type) {
+ int i;
+
+ if (type == U_CURRENT)
+ type = _G(utype);
+
+ for (i = 0; i < (int)(sizeof(utypes) / sizeof(UTYPE_INFO)); i++)
+ if (utypes[i].id == type)
+ return &utypes[i];
-void set_uformat(int format) {
- // TODO: implementation
- _G(utype) = format;
+ return NULL;
+}
+
+void set_uformat(int type) {
+ UTYPE_INFO *info = find_utype(type);
+ assert(info);
+
+ if (info) {
+ _G(utype) = info->id;
+ ugetc = info->u_getc;
+ ugetx = (int (*)(char **)) info->u_getx;
+ ugetxc = (int (*)(AL_CONST char **)) info->u_getx;
+ usetc = info->u_setc;
+ uwidth = info->u_width;
+ ucwidth = info->u_cwidth;
+ uisok = info->u_isok;
+ }
}
int get_uformat(void) {
@@ -176,6 +220,34 @@ int utf8_isok(int c) {
return true;
}
+
+int ascii_getc(const char *s) {
+ return *((unsigned char *)s);
+}
+
+int ascii_getx(char **s) {
+ return *((unsigned char *)((*s)++));
+}
+
+int ascii_setc(char *s, int c) {
+ *s = c;
+ return 1;
+}
+
+int ascii_width(const char *s) {
+ return 1;
+}
+
+int ascii_cwidth(int c) {
+ return 1;
+}
+
+int ascii_isok(int c) {
+ return ((c >= 0) && (c <= 255));
+}
+
+
+
int ustrlen(const char *s) {
int c = 0;
assert(s);
diff --git a/engines/ags/lib/allegro/unicode.h b/engines/ags/lib/allegro/unicode.h
index e642c880d5..e5b0067eab 100644
--- a/engines/ags/lib/allegro/unicode.h
+++ b/engines/ags/lib/allegro/unicode.h
@@ -36,12 +36,22 @@ namespace AGS3 {
/* UTF-8 support functions
*/
-int utf8_getc(const char *s);
-int utf8_getx(char **s);
-int utf8_setc(char *s, int c);
-int utf8_width(const char *s);
-int utf8_cwidth(int c);
-int utf8_isok(int c);
+extern int utf8_getc(const char *s);
+extern int utf8_getx(char **s);
+extern int utf8_setc(char *s, int c);
+extern int utf8_width(const char *s);
+extern int utf8_cwidth(int c);
+extern int utf8_isok(int c);
+
+/**
+ * ASCII support functions
+ */
+extern int ascii_getc(const char *s);
+extern int ascii_getx(char **s);
+extern int ascii_setc(char *s, int c);
+extern int ascii_width(const char *s);
+extern int ascii_cwidth(int c);
+extern int ascii_isok(int c);
/* ugetc: */
extern int (*ugetc)(const char *s);
@@ -61,7 +71,7 @@ extern int (*uisok)(int c);
/* set_uformat:
* Selects a new text encoding format.
*/
-extern void set_uformat(int format);
+extern void set_uformat(int type);
/* get_uformat:
* Returns the current text encoding format.
More information about the Scummvm-git-logs
mailing list