add some unicode support (trunk only)
This patch attempts to add some levels of unicode support to NetHack. The master on/off switch for any Unicode support is defining UNICODE_SUPPORT in config.h. Currently there is code support for two subsets of unicode support: UNICODE_DRAWING If UNICODE_DRAWING is defined, then the data structures used to house drawing symbols are expanded to the size of wchar_t, big enough to hold unicode characters. A typdef called `nhsym' is involved and if UNICODE_DRAWING is defined, it is wchar_t, otherwise it is uchar. UNICODE_WIDEWINPORT If UNICODE_WIDEWINPORT is defined, then the data structures inside the window port are expanded to the size of wchar_t, big enough to hold unicode characters. Both map symbols and text within the window port are expanded, in order for potential support for displaying multinational characters some day, but this patch only provides viewing of map symbols. A typdef called `nhwchar' is involved and if UNICODE_WIDEWINPORT is defined, it is wchar_t, otherwise it is char. The only window port with code support for UNICODE_WIDEWINPORT currently is the TTY port. Don't enable UNICODE_WIDEWINPORT unless: - it is a TTY port - the underlying platform specific routines can handle the larger data structures. Don't enable UNICODE_SUPPORT unless: - your compiler can handle wchar_t. - your compiler can accept L'a' characters. - your compiler can accept L"wide" strings. Note that if your compiler can handle the above, you could enable the larger data structures (currently if TTY) even if your platform can't actually display unicode or UTF-8, by messing with u_putch() in win/tty/wintty.c to only deal regular chars. That should be the only function that actually pushes wide characters out to the display. If you enable UNICODE_SUPPORT, and your platform is capable you will need to turn on the unicode run-time option to be able to load unicode character sets from the symbol file, to be able to push unicode characters to the display. You'll also want to load a unicode symbol set once the unicode option is toggled on. In a config file you would do that via these two lines: OPTIONS=unicode OPTIONS=symset:Unicode_non_US The repository was stamped with NETHACK_PRE_UNICODE prior to applying this patch, and stamped with NETHACK_POST_UNICODE afterwards. The code differences between those two tagged versions are this patch.
This commit is contained in:
188
src/hacklib.c
188
src/hacklib.c
@@ -624,4 +624,192 @@ midnight()
|
||||
return(getlt()->tm_hour == 0);
|
||||
}
|
||||
|
||||
#ifdef UNICODE_WIDEWINPORT
|
||||
nhwchar *
|
||||
nhwstrncpy(dest, strSource, cnt)
|
||||
nhwchar *dest;
|
||||
const char *strSource;
|
||||
size_t cnt;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const char *s = strSource;
|
||||
size_t dcnt = 0;
|
||||
|
||||
while(*s && dcnt < cnt) {
|
||||
*d++ = (nhwchar)*s++;
|
||||
dcnt++;
|
||||
}
|
||||
if (dcnt < cnt) *d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwncpy(dest, src, cnt)
|
||||
nhwchar *dest;
|
||||
const nhwchar *src;
|
||||
size_t cnt;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const nhwchar *s = src;
|
||||
size_t dcnt = 0;
|
||||
|
||||
while(*s && dcnt < cnt) {
|
||||
*d++ = *s++;
|
||||
dcnt++;
|
||||
}
|
||||
if (dcnt < cnt) *d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwcpy(dest, src)
|
||||
nhwchar *dest;
|
||||
const nhwchar *src;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const nhwchar *s = src;
|
||||
|
||||
while(*s) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
*d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwstrcpy(dest, strSource)
|
||||
nhwchar *dest;
|
||||
const char *strSource;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const char *s = strSource;
|
||||
|
||||
while(*s) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
*d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *
|
||||
strnhwcpy(strDest, src)
|
||||
char *strDest;
|
||||
const nhwchar *src;
|
||||
{
|
||||
char *d = strDest;
|
||||
const nhwchar *s = src;
|
||||
|
||||
while(*s) {
|
||||
*d++ = (char)*s++;
|
||||
}
|
||||
*d = 0;
|
||||
return strDest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwstrcat(dest, strSource)
|
||||
nhwchar *dest;
|
||||
const char *strSource;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const char *s = strSource;
|
||||
|
||||
while(*d) d++;
|
||||
while(*s) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
*d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwcat(dest, src)
|
||||
nhwchar *dest;
|
||||
const nhwchar *src;
|
||||
{
|
||||
nhwchar *d = dest;
|
||||
const nhwchar *s = src;
|
||||
|
||||
while(*d) d++;
|
||||
while(*s) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
*d = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
nhwchar *
|
||||
nhwindex(ss, c)
|
||||
const nhwchar *ss;
|
||||
int c;
|
||||
{
|
||||
const nhwchar *s = ss;
|
||||
|
||||
while (*s) {
|
||||
if (*s == c) return (nhwchar *)s;
|
||||
s++;
|
||||
}
|
||||
if (*s == c) return (nhwchar *)s;
|
||||
return (nhwchar *)0;
|
||||
}
|
||||
|
||||
size_t nhwlen(src)
|
||||
const nhwchar *src;
|
||||
{
|
||||
register size_t dl = 0;
|
||||
|
||||
while(*src++) dl++;
|
||||
return dl;
|
||||
}
|
||||
|
||||
int
|
||||
nhwcmp(s1, s2) /* case insensitive counted string comparison */
|
||||
register const nhwchar *s1, *s2;
|
||||
{ /*{ aka strncasecmp }*/
|
||||
register nhwchar t1, t2;
|
||||
|
||||
for (;;) {
|
||||
if (!*s2) return (*s1 != 0); /* s1 >= s2 */
|
||||
else if (!*s1) return -1; /* s1 < s2 */
|
||||
t1 = *s1++;
|
||||
t2 = *s2++;
|
||||
if (t1 != t2) return (t1 > t2) ? 1 : -1;
|
||||
}
|
||||
return 0; /* s1 == s2 */
|
||||
}
|
||||
|
||||
int
|
||||
nhwncmp(s1, s2, n) /* case sensitive counted nhwchar (wide string) comparison */
|
||||
register const nhwchar *s1, *s2;
|
||||
register int n; /*(should probably be size_t, which is usually unsigned)*/
|
||||
{
|
||||
register nhwchar t1, t2;
|
||||
|
||||
while (n--) {
|
||||
if (!*s2) return (*s1 != 0); /* s1 >= s2 */
|
||||
else if (!*s1) return -1; /* s1 < s2 */
|
||||
t1 = *s1++;
|
||||
t2 = *s2++;
|
||||
if (t1 != t2) return (t1 > t2) ? 1 : -1;
|
||||
}
|
||||
return 0; /* s1 == s2 */
|
||||
}
|
||||
|
||||
int
|
||||
nhwstrcmp(s1, s2)
|
||||
register const nhwchar *s1;
|
||||
const char *s2;
|
||||
{ /*{ aka strncasecmp }*/
|
||||
register nhwchar t1, t2;
|
||||
|
||||
for (;;) {
|
||||
if (!*s2) return (*s1 != 0); /* s1 >= s2 */
|
||||
else if (!*s1) return -1; /* s1 < s2 */
|
||||
t1 = *s1++;
|
||||
t2 = (nhwchar)*s2++;
|
||||
if (t1 != t2) return (t1 > t2) ? 1 : -1;
|
||||
}
|
||||
return 0; /* s1 == s2 */
|
||||
}
|
||||
#endif
|
||||
/*hacklib.c*/
|
||||
|
||||
Reference in New Issue
Block a user