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:
nethack.allison
2006-10-17 23:55:42 +00:00
parent 3054c1c846
commit 7f0f43e6f9
22 changed files with 1193 additions and 177 deletions

View File

@@ -263,6 +263,10 @@
*/
#endif /* CHDIR */
/*
* Enable some UNICODE support.
*/
/*#define UNICODE_SUPPORT */ /* master on/off for any unicode support */
/*
@@ -356,7 +360,7 @@ typedef unsigned char uchar;
*/
/* display features */
#define LOADSYMSETS /* loadable symbol sets; only default symbols w/o this */
#define LOADSYMSETS /* loadable symbol sets; only default symbols w/o this */
/* dungeon features */
#define SINKS /* Kitchen sinks - Janet Walz */
/* dungeon levels */

View File

@@ -35,7 +35,7 @@ E NEARDATA int nsubroom;
E NEARDATA int occtime;
#define WARNCOUNT 6 /* number of different warning levels */
E uchar warnsyms[WARNCOUNT];
E nhsym warnsyms[WARNCOUNT];
E NEARDATA int warn_obj_cnt; /* count of monsters meeting criteria */
E int x_maze_max, y_maze_max;
@@ -334,7 +334,8 @@ E NEARDATA winid WIN_MESSAGE;
E NEARDATA winid WIN_STATUS;
#endif
E NEARDATA winid WIN_MAP, WIN_INVEN;
E char toplines[];
E nhwchar toplines[];
#ifndef TCAP_H
E struct tc_gbl_data { /* also declared in tcap.h */
char *tc_AS, *tc_AE; /* graphics start and end (tty font swapping) */

View File

@@ -721,6 +721,7 @@ E void NDECL(read_wizkit);
#ifdef LOADSYMSETS
E int FDECL(read_sym_file, (int));
E int FDECL(parse_sym_line, (char *,int));
E int FDECL(sym_val, (const char *));
#endif
E void FDECL(paniclog, (const char *, const char *));
E int FDECL(validate_prefix_locations, (char *));
@@ -829,6 +830,20 @@ E int NDECL(phase_of_the_moon);
E boolean NDECL(friday_13th);
E int NDECL(night);
E int NDECL(midnight);
#ifdef UNICODE_WIDEWINPORT
E nhwchar *FDECL(nhwstrncpy, (nhwchar *,const char *,size_t));
E nhwchar *FDECL(nhwncpy, (nhwchar *,const nhwchar *,size_t));
E nhwchar *FDECL(nhwcpy, (nhwchar *,const nhwchar *));
E nhwchar *FDECL(nhwstrcpy, (nhwchar *,const char *));
E char *FDECL(strnhwcpy, (char *,const nhwchar *));
E nhwchar *FDECL(nhwstrcat, (nhwchar *,const char *));
E nhwchar *FDECL(nhwcat, (nhwchar *,const nhwchar *));
E nhwchar *FDECL(nhwindex, (const nhwchar *,int));
E size_t FDECL(nhwlen, (const nhwchar *));
E int FDECL(nhwcmp, (const nhwchar *,const nhwchar *));
E int FDECL(nhwncmp, (const nhwchar *,const nhwchar *,int));
E int FDECL(nhwstrcmp, (const nhwchar *,const char *));
#endif
/* ### invent.c ### */
@@ -1544,7 +1559,6 @@ E void NDECL(free_autopickup_exceptions);
E int FDECL(load_symset, (const char *,int));
E void FDECL(parsesymbols, (char *));
E struct symparse *FDECL(match_sym, (char *));
E int FDECL(sym_val, (char *));
#endif
/* ### pager.c ### */

View File

@@ -182,6 +182,8 @@ struct instance_flags {
boolean rlecomp; /* run-length comp of levels when writing savefile */
uchar num_pad_mode;
boolean echo; /* 1 to echo characters */
boolean unicodecapable; /* unicode support is possible on platform */
boolean unicodedisp; /* unicode support is turned on */
#if 0
boolean DECgraphics; /* use DEC VT-xxx extended character set */
boolean IBMgraphics; /* use IBM extended character set */

View File

@@ -1,4 +1,4 @@
/* SCCS Id: @(#)global.h 3.5 2006/06/28 */
/* SCCS Id: @(#)global.h 3.5 2006/10/17 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -61,6 +61,41 @@ typedef xchar boolean; /* 0 or 1 */
#define FALSE ((boolean)0)
#endif
/*
* UNICODE_SUPPORT
* Unicode/wide character related support.
*/
#ifdef UNICODE_SUPPORT
# define UNICODE_DRAWING /* store drawing symbols in wchar_t data type */
# define UNICODE_WIDEWINPORT /* store and render wide chars in window port */
/*# define UNICODE_PLAYERTEXT*/ /* not implemented - player input in wide chars */
#else
# undef UNICODE_DRAWING
# undef UNICODE_WIDEWINPORT
# undef UNICODE_PLAYERTEXT
#endif
#if defined(UNICODE_DRAWING)
typedef wchar_t nhsym; /* nhsym is wide char */
#else
typedef char nhsym;
#endif
#if defined(UNICODE_WIDEWINPORT)
typedef wchar_t nhwchar; /* nhwchar (window port char) is wide char */
#else
typedef char nhwchar;
#endif
#if 0
/* Not Implemented presently */
#if defined(UNICODE_PLAYERTEXT)
typedef wchar_t nhptext; /* player input is wide char */
#else
typedef char nhptext;
#endif
#endif
#ifndef STRNCMPI
# ifndef __SASC_60 /* SAS/C already shifts to stricmp */
# define strcmpi(a,b) strncmpi((a),(b),-1)

View File

@@ -187,6 +187,11 @@ extern void NDECL(toggle_mouse_support);
extern void FDECL(map_subkeyvalue, (char *));
extern void NDECL(load_keyboard_handler);
extern void NDECL(raw_clear_screen);
# ifdef UNICODE_WIDEWINPORT
extern void FDECL(xputc, (NHWCHAR_P));
# else
extern void FDECL(xputc, (int));
# endif
#endif
#include <fcntl.h>

View File

@@ -223,6 +223,13 @@ struct symdef {
#endif
};
/*
* Graphics sets for display symbols
*/
#define PRIMARY 0 /* primary graphics */
#define ROGUESET 1 /* rogue graphics */
#define NUM_GRAPHICS 2
struct symparse {
unsigned range;
#define SYM_CONTROL 1 /* start/finish markers */
@@ -249,30 +256,23 @@ struct symsetentry {
Bitfield(nocolor,1); /* don't use color if set */
Bitfield(primary,1); /* restricted for use as primary set */
Bitfield(rogue,1); /* restricted for use as rogue lev set */
Bitfield(unicode,1); /* restricted for use as a unicode set */
/* 5 free bits */
};
/*
* Graphics sets for display symbols
*/
#define DEFAULT_GRAPHICS 0 /* regular characters: '-', '+', &c */
#define PRIMARY 0 /* primary graphics set */
#define ROGUESET 1 /* rogue graphics set */
#define NUM_GRAPHICS 2
/*
* special symbol set handling types ( for invoking callbacks, etc.)
* Must match the order of the known_handlers strings
* in drawing.c
*/
#define H_UNK 0
#define H_IBM 1
#define H_DEC 2
#define H_UNK 0
#define H_IBM 1
#define H_DEC 2
extern const struct symdef defsyms[MAXPCHARS]; /* defaults */
extern const struct symdef def_warnsyms[WARNCOUNT];
extern int currentgraphics; /* from drawing.c */
extern uchar showsyms[];
extern nhsym showsyms[];
#ifdef LOADSYMSETS
extern struct symsetentry symset[NUM_GRAPHICS]; /* from drawing.c */

View File

@@ -254,6 +254,7 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
# define BOOLEAN_P boolean
# endif
# define ALIGNTYP_P aligntyp
# define NHWCHAR_P nhwchar
#else
# ifdef WIDENED_PROTOTYPES
# define CHAR_P int
@@ -263,6 +264,7 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
# define SHORT_P int
# define BOOLEAN_P int
# define ALIGNTYP_P int
# define NHWCHAR_P int
# else
/* Neither widened nor unwidened prototypes. Argument list expansion
* by FDECL/VDECL always empty; all xxx_P vanish so defs aren't needed. */

View File

@@ -34,8 +34,8 @@ struct WinDesc {
/* maxcol is also used by WIN_MESSAGE for */
/* tracking the ^P command */
short *datlen; /* allocation size for *data */
char **data; /* window data [row][column] */
char *morestr; /* string to display instead of default */
nhwchar **data; /* window data [row][column] */
nhwchar *morestr; /* string to display instead of default */
tty_menu_item *mlist; /* menu information (MENU) */
tty_menu_item **plist; /* menu page pointers (MENU) */
short plist_size; /* size of allocated plist (MENU) */
@@ -86,7 +86,7 @@ extern struct WinDesc *wins[MAXWIN];
extern struct DisplayDesc *ttyDisplay; /* the tty display descriptor */
extern char morc; /* last character typed to xwaitforspace */
extern char defmorestr[]; /* default --more-- prompt */
extern nhwchar defmorestr[]; /* default --more-- prompt */
/* port specific external function references */
@@ -107,7 +107,9 @@ E void NDECL(tty_shutdown);
* actually would be expanded. So here, we have to make an exception. */
E void FDECL(xputc, (int));
#else
# ifndef WIN32CON
E void FDECL(xputc, (CHAR_P));
# endif
#endif
E void FDECL(xputs, (const char *));
#if defined(SCREEN_VGA) || defined(SCREEN_8514)
@@ -150,10 +152,10 @@ E int FDECL(has_color,(int color));
/* ### topl.c ### */
E void FDECL(addtopl, (const char *));
E void FDECL(addtopl, (const nhwchar *));
E void NDECL(more);
E void FDECL(update_topl, (const char *));
E void FDECL(putsyms, (const char*));
E void FDECL(update_topl, (const nhwchar *));
E void FDECL(putsyms, (const nhwchar *));
/* ### wintty.c ### */
#ifdef CLIPPING
@@ -163,6 +165,9 @@ E void FDECL(docorner, (int, int));
E void NDECL(end_glyphout);
E void FDECL(g_putch, (int));
E void NDECL(win_tty_init);
#ifdef UNICODE_WIDEWINPORT
E void FDECL(u_putch, (nhwchar));
#endif
/* external declarations */
E void FDECL(tty_init_nhwindows, (int *, char **));