| [AD] constness in ugetx() - patch |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
OK, attached is a patch, which:
- changes `ugetx', and the parameter in `register_uformat', to type
int (*)(char**)
- adds a new function, `ugetxc', which is of type
int (*)(AL_CONST char**)
- updates documentation to reflect change
- changes various instances of `ugetx' to `ugetxc' in the source, in
order to stop compilation warnings.
(NB: ugetxc actually points to the same function, but is a pointer of a
different type, thus circumventing warnings/errors).
Also, I noticed that nobody applied the patch I sent ages ago which
updated the documentation to reflect `const' parameters. Unfortunately,
I no longer have this patch. Is this an important thing to document?
diff -ru allegro/docs/allegro._tx al-const-fix/docs/allegro._tx
--- allegro/docs/allegro._tx Tue Nov 14 16:19:06 2000
+++ al-const-fix/docs/allegro._tx Thu Nov 16 19:02:14 2000
@@ -366,12 +366,15 @@
from the string.
@@int @ugetx(char **s);
+@@int @ugetxc(const char **s);
@xref ugetc, usetc, uwidth, ucwidth, uisok
Low level helper function for reading Unicode text data. Given the
address of a pointer to a string in the current encoding format, it
returns the next character from the string, and advances the pointer to
the character after the one just read.
+ ugetxc is provided for working with pointer-to-pointer-to-const char data.
+
@@int @usetc(char *s, int c);
@xref ugetc, ugetx, uwidth, ucwidth, uisok
Low level helper function for writing Unicode text data. It writes the
diff -ru allegro/include/allegro/aintern.h al-const-fix/include/allegro/aintern.h
--- allegro/include/allegro/aintern.h Wed Sep 27 10:44:34 2000
+++ al-const-fix/include/allegro/aintern.h Thu Nov 16 19:02:14 2000
@@ -63,7 +63,7 @@
{
int id;
AL_METHOD(int, u_getc, (AL_CONST char *s));
- AL_METHOD(int, u_getx, (AL_CONST char **s));
+ AL_METHOD(int, u_getx, (char **s));
AL_METHOD(int, u_setc, (char *s, int c));
AL_METHOD(int, u_width, (AL_CONST char *s));
AL_METHOD(int, u_cwidth, (int c));
diff -ru allegro/include/allegro.h al-const-fix/include/allegro.h
--- allegro/include/allegro.h Sun Oct 29 17:16:30 2000
+++ al-const-fix/include/allegro.h Thu Nov 16 19:02:14 2000
@@ -202,7 +202,7 @@
AL_FUNC(void, set_uformat, (int type));
AL_FUNC(int, get_uformat, (void));
-AL_FUNC(void, register_uformat, (int type, AL_METHOD(int, u_getc, (AL_CONST char *s)), AL_METHOD(int, u_getx, (AL_CONST char **s)), AL_METHOD(int, u_setc, (char *s, int c)), AL_METHOD(int, u_width, (AL_CONST char *s)), AL_METHOD(int, u_cwidth, (int c)), AL_METHOD(int, u_isok, (int c)), int u_width_max));
+AL_FUNC(void, register_uformat, (int type, AL_METHOD(int, u_getc, (AL_CONST char *s)), AL_METHOD(int, u_getx, (char **s)), AL_METHOD(int, u_setc, (char *s, int c)), AL_METHOD(int, u_width, (AL_CONST char *s)), AL_METHOD(int, u_cwidth, (int c)), AL_METHOD(int, u_isok, (int c)), int u_width_max));
AL_FUNC(void, set_ucodepage, (AL_CONST unsigned short *table, AL_CONST unsigned short *extras));
AL_FUNC(int, need_uconvert, (AL_CONST char *s, int type, int newtype));
@@ -219,7 +219,8 @@
AL_ARRAY(char, empty_string);
AL_FUNCPTR(int, ugetc, (AL_CONST char *s));
-AL_FUNCPTR(int, ugetx, (AL_CONST char **s));
+AL_FUNCPTR(int, ugetx, (char **s));
+AL_FUNCPTR(int, ugetxc, (AL_CONST char **s));
AL_FUNCPTR(int, usetc, (char *s, int c));
AL_FUNCPTR(int, uwidth, (AL_CONST char *s));
AL_FUNCPTR(int, ucwidth, (int c));
diff -ru allegro/src/config.c al-const-fix/src/config.c
--- allegro/src/config.c Sat Aug 5 23:43:40 2000
+++ al-const-fix/src/config.c Thu Nov 16 18:49:04 2000
@@ -1144,7 +1144,7 @@
s = umsg;
pos = 0;
- while ((c = ugetx(&s)) != 0) {
+ while ((c = ugetxc(&s)) != 0) {
if ((uisspace(c)) || (c == '=') || (c == '#'))
pos += usetc(name+pos, '_');
else
diff -ru allegro/src/datafile.c al-const-fix/src/datafile.c
--- allegro/src/datafile.c Wed Nov 15 06:59:26 2000
+++ al-const-fix/src/datafile.c Thu Nov 16 18:51:40 2000
@@ -1553,7 +1553,7 @@
/* split up the object name */
pos = 0;
- while ((c = ugetx(&objectname)) != 0) {
+ while ((c = ugetxc(&objectname)) != 0) {
if ((c == '#') || (c == '/') || (c == OTHER_PATH_SEPARATOR)) {
recurse = TRUE;
break;
diff -ru allegro/src/file.c al-const-fix/src/file.c
--- allegro/src/file.c Mon Jul 31 22:01:38 2000
+++ al-const-fix/src/file.c Thu Nov 16 18:52:06 2000
@@ -525,7 +525,7 @@
/* split up the object name */
pos = 0;
- while ((c = ugetx(&objname)) != 0) {
+ while ((c = ugetxc(&objname)) != 0) {
if ((c == '#') || (c == '/') || (c == OTHER_PATH_SEPARATOR)) {
recurse = TRUE;
break;
@@ -1056,7 +1056,7 @@
int c;
if (password) {
- while ((c = ugetx(&password)) != 0) {
+ while ((c = ugetxc(&password)) != 0) {
the_password[i++] = c;
if (i >= (int)sizeof(the_password)-1)
break;
diff -ru allegro/src/fsel.c al-const-fix/src/fsel.c
--- allegro/src/fsel.c Mon Nov 13 05:41:38 2000
+++ al-const-fix/src/fsel.c Thu Nov 16 18:52:24 2000
@@ -385,8 +385,8 @@
char *t1, *t2;
for (;;) {
- c1 = utolower(ugetx(&s1));
- c2 = utolower(ugetx(&s2));
+ c1 = utolower(ugetxc(&s1));
+ c2 = utolower(ugetxc(&s2));
if ((c1 >= '0') && (c1 <= '9') && (c2 >= '0') && (c2 <= '9')) {
x1 = ustrtol(s1 - ucwidth(c1), &t1, 10);
diff -ru allegro/src/gui.c al-const-fix/src/gui.c
--- allegro/src/gui.c Wed Sep 6 22:57:48 2000
+++ al-const-fix/src/gui.c Thu Nov 16 18:52:56 2000
@@ -1338,7 +1338,7 @@
{
int d;
- while ((d = ugetx(&s)) != 0) {
+ while ((d = ugetxc(&s)) != 0) {
if (d == '&') {
d = ugetc(s);
if ((d != '&') && (utolower(d) == utolower(c & 0xFF)))
@@ -1389,7 +1389,7 @@
for (c=0; m[c].text; c++) {
s = m[c].text;
- while ((d = ugetx(&s)) != 0) {
+ while ((d = ugetxc(&s)) != 0) {
if (d == '&') {
d = ugetc(s);
if ((d != '&') && (utolower(d) == utolower(k)))
diff -ru allegro/src/text.c al-const-fix/src/text.c
--- allegro/src/text.c Wed Sep 27 10:44:38 2000
+++ al-const-fix/src/text.c Thu Nov 16 18:53:42 2000
@@ -105,7 +105,7 @@
acquire_bitmap(bmp);
- while ((c = ugetx(&str)) != 0) {
+ while ((c = ugetxc(&str)) != 0) {
if ((!range) || (c < range->start) || (c > range->end)) {
/* search for a suitable character range */
range = find_range(f, c);
@@ -310,7 +310,7 @@
len = 0;
- while ((c = ugetx(&str)) != 0) {
+ while ((c = ugetxc(&str)) != 0) {
range = find_range(f, c);
if (!range)
diff -ru allegro/src/unicode.c al-const-fix/src/unicode.c
--- allegro/src/unicode.c Sun Oct 15 18:39:28 2000
+++ al-const-fix/src/unicode.c Thu Nov 16 18:56:46 2000
@@ -49,7 +49,7 @@
/* ascii_getx:
* Reads a character from an ASCII string, advancing the pointer position.
*/
-static int ascii_getx(AL_CONST char **s)
+static int ascii_getx(char **s)
{
return *((unsigned char *)((*s)++));
}
@@ -184,7 +184,7 @@
/* ascii_cp_getx:
* Reads from an ASCII codepage string, advancing pointer position.
*/
-static int ascii_cp_getx(AL_CONST char **s)
+static int ascii_cp_getx(char **s)
{
return codepage_table[*((unsigned char *)((*s)++))];
}
@@ -257,7 +257,7 @@
/* unicode_getx:
* Reads a character from a Unicode string, advancing the pointer position.
*/
-static int unicode_getx(AL_CONST char **s)
+static int unicode_getx(char **s)
{
int c = *((unsigned short *)(*s));
(*s) += sizeof(unsigned short);
@@ -340,7 +340,7 @@
/* utf8_getx:
* Reads a character from a UTF-8 string, advancing the pointer position.
*/
-static int utf8_getx(AL_CONST char **s)
+static int utf8_getx(char **s)
{
int c = *((unsigned char *)((*s)++));
int n, t;
@@ -483,7 +483,8 @@
static int utype = U_UTF8;
int (*ugetc)(AL_CONST char *s) = utf8_getc;
-int (*ugetx)(AL_CONST char **s) = utf8_getx;
+int (*ugetx)(char **s) = utf8_getx;
+int (*ugetxc)(AL_CONST char** s) = (int (*)(AL_CONST char**)) utf8_getx;
int (*usetc)(char *s, int c) = utf8_setc;
int (*uwidth)(AL_CONST char *s) = utf8_width;
int (*ucwidth)(int c) = utf8_cwidth;
@@ -520,7 +521,8 @@
if (info) {
utype = info->id;
ugetc = info->u_getc;
- ugetx = info->u_getx;
+ 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;
@@ -544,7 +546,7 @@
* Allows the user to hook in custom routines for supporting a new string
* encoding format.
*/
-void register_uformat(int type, int (*ugetc)(AL_CONST char *s), int (*ugetx)(AL_CONST char **s), int (*usetc)(char *s, int c), int (*uwidth)(AL_CONST char *s), int (*ucwidth)(int c), int (*uisok)(int c), int uwidth_max)
+void register_uformat(int type, int (*ugetc)(AL_CONST char *s), int (*ugetx)(char **s), int (*usetc)(char *s, int c), int (*uwidth)(AL_CONST char *s), int (*ucwidth)(int c), int (*uisok)(int c), int uwidth_max)
{
UTYPE_INFO *info = _find_utype(type);
@@ -627,7 +629,7 @@
size = 0;
- while ((c = info->u_getx(&s)) != 0)
+ while ((c = info->u_getx((char**)&s)) != 0)
size += outfo->u_cwidth(c);
return size + outfo->u_cwidth(0);
@@ -657,7 +659,7 @@
size -= outfo->u_cwidth(0);
- while ((c = info->u_getx(&s)) != 0) {
+ while ((c = info->u_getx((char**)&s)) != 0) {
if (!outfo->u_isok(c))
c = '^';
@@ -713,7 +715,7 @@
while (index-- > 0) {
last = s;
- if (!ugetx(&s)) {
+ if (!ugetxc(&s)) {
s = last;
break;
}
@@ -1727,7 +1729,7 @@
do {
last = s;
- } while (ugetx(&s) != 0);
+ } while (ugetxc(&s) != 0);
return (long)last - (long)orig;
}
@@ -1743,7 +1745,7 @@
AL_CONST char *orig = s;
do {
- } while (ugetx(&s) != 0);
+ } while (ugetxc(&s) != 0);
return (long)s - (long)orig;
}
@@ -1758,7 +1760,7 @@
int pos = 0;
int c;
- while ((c = ugetx(&src)) != 0)
+ while ((c = ugetxc(&src)) != 0)
pos += usetc(dest+pos, c);
usetc(dest+pos, 0);
@@ -1776,7 +1778,7 @@
int pos = ustrsize(dest);
int c;
- while ((c = ugetx(&src)) != 0)
+ while ((c = ugetxc(&src)) != 0)
pos += usetc(dest+pos, c);
usetc(dest+pos, 0);
@@ -1793,7 +1795,7 @@
{
int c = 0;
- while (ugetx(&s))
+ while (ugetxc(&s))
c++;
return c;
@@ -1809,8 +1811,8 @@
int c1, c2;
for (;;) {
- c1 = ugetx(&s1);
- c2 = ugetx(&s2);
+ c1 = ugetxc(&s1);
+ c2 = ugetxc(&s2);
if (c1 != c2)
return c1 - c2;
@@ -1832,7 +1834,7 @@
int pos = 0;
int c;
- while (((c = ugetx(&src)) != 0) && (pos < n))
+ while (((c = ugetxc(&src)) != 0) && (pos < n))
pos += usetc(dest+pos, c);
usetc(dest+pos, 0);
@@ -1853,7 +1855,7 @@
int pos = 0;
int c;
- while (((c = ugetx(&src)) != 0) && (pos < n))
+ while (((c = ugetxc(&src)) != 0) && (pos < n))
pos += usetc(d+pos, c);
usetc(d+pos, 0);
@@ -1876,8 +1878,8 @@
return 0;
for (;;) {
- c1 = ugetx(&s1);
- c2 = ugetx(&s2);
+ c1 = ugetxc(&s1);
+ c2 = ugetxc(&s2);
if (c1 != c2)
return c1 - c2;
@@ -1897,8 +1899,8 @@
int c1, c2;
for (;;) {
- c1 = utolower(ugetx(&s1));
- c2 = utolower(ugetx(&s2));
+ c1 = utolower(ugetxc(&s1));
+ c2 = utolower(ugetxc(&s2));
if (c1 != c2)
return c1 - c2;
@@ -2026,7 +2028,7 @@
while ((c = ugetc(s)) != 0) {
setp = set;
- while ((d = ugetx(&setp)) != 0) {
+ while ((d = ugetxc(&setp)) != 0) {
if (c == d)
return (char *)s;
}
@@ -2059,11 +2061,11 @@
skip_leading_delimiters:
prev_str = s;
- c = ugetx((AL_CONST char **)&s);
+ c = ugetxc((AL_CONST char **)&s);
setp = set;
- while ((sc = ugetx(&setp)) != 0) {
+ while ((sc = ugetxc(&setp)) != 0) {
if (c == sc)
goto skip_leading_delimiters;
}
@@ -2077,12 +2079,12 @@
for (;;) {
prev_str = s;
- c = ugetx((AL_CONST char **)&s);
+ c = ugetxc((AL_CONST char **)&s);
setp = set;
do {
- sc = ugetx(&setp);
+ sc = ugetxc(&setp);
if (sc == c) {
if (!c) {
last = NULL;
@@ -2470,7 +2472,7 @@
int len = 0;
int c;
- while ((c = ugetx(&s)) != 0) {
+ while ((c = ugetxc(&s)) != 0) {
if ((info->precision >= 0) && (len >= info->precision))
break;
@@ -2495,7 +2497,7 @@
int shift, shiftbytes, shiftfiller;
int len = 0;
- while ((c = ugetx(&format)) != 0) {
+ while ((c = ugetxc(&format)) != 0) {
if (c == '%') {
if (ugetc(format) == '%') {
Bye for now,
--
Laurence Withers, lwithers@xxxxxxxxxx
http://www.lwithers.demon.co.uk/
Attachment:
signature.asc
Description: PGP signature
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |