ancient encodings: config option (Adam Borowski <kilobyte@angband.pl>)

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@597 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Pasi Kallinen 2011-10-03 15:23:14 +00:00
parent 70fd9c005b
commit 47cfe66d43
6 changed files with 36 additions and 0 deletions

View File

@ -92,6 +92,7 @@ sortmode { return TYPE_WATCH_SORTMODE; }
watch_columns { return TYPE_WATCH_COLUMNS; }
commands { return TYPE_CMDQUEUE; }
postcommands { return TYPE_POSTCMDQUEUE; }
encoding { return TYPE_ENCODING; }
yes { yylval.i = 1; return TYPE_BOOL; }
no { yylval.i = 0; return TYPE_BOOL; }
dglstart { yylval.i = DGLTIME_DGLSTART; return TYPE_CMDQUEUENAME; }

View File

@ -11,6 +11,7 @@
#include <string.h>
#include "dgamelaunch.h"
#include "ttyrec.h"
extern int yylex(void);
extern void yyerror(const char*);
@ -58,6 +59,7 @@ static int sortmode_number(const char *sortmode_name) {
%token TYPE_CMDQUEUE TYPE_DEFINE_MENU TYPE_BANNER_FILE TYPE_CURSOR
%token TYPE_POSTCMDQUEUE
%token TYPE_MAX_IDLE_TIME TYPE_MENU_MAX_IDLE_TIME TYPE_EXTRA_INFO_FILE
%token TYPE_ENCODING
%token <s> TYPE_VALUE
%token <i> TYPE_NUMBER TYPE_CMDQUEUENAME
%type <kt> KeyType
@ -473,6 +475,17 @@ game_definition : TYPE_CMDQUEUE
myconfig[ncnf]->inprogressdir = strdup($3);
break;
case TYPE_ENCODING:
if (!strcasecmp($3, "ask"))
myconfig[ncnf]->encoding = -1;
else if ((myconfig[ncnf]->encoding = encoding_by_name($3)) == -1)
{
fprintf(stderr, "%s:%d: invalid value for encoding: \"%s\"\n",
config, line, $3);
exit(1);
}
break;
default:
fprintf(stderr, "%s:%d: token does not belong into game definition, bailing out\n",
config, line);
@ -608,6 +621,7 @@ KeyType : TYPE_SUSER { $$ = TYPE_SUSER; }
| TYPE_PATH_PASSWD { $$ = TYPE_PATH_PASSWD; }
| TYPE_PATH_LOCKFILE { $$ = TYPE_PATH_LOCKFILE; }
| TYPE_PATH_INPROGRESS { $$ = TYPE_PATH_INPROGRESS; }
| TYPE_ENCODING { $$ = TYPE_ENCODING; }
| TYPE_RC_FMT { $$ = TYPE_RC_FMT; }
| TYPE_WATCH_SORTMODE { $$ = TYPE_WATCH_SORTMODE; }
| TYPE_SERVER_ID { $$ = TYPE_SERVER_ID; }

View File

@ -198,6 +198,7 @@ struct dg_config
struct dg_cmdpart *postcmdqueue;
int max_idle_time;
char *extra_info_file;
int encoding; // -1 = run --print-charset
};
struct dg_watchcols {

View File

@ -242,6 +242,11 @@ menu["watchmenu_help"] {
# # We can also define per-game commands executed after the game ends,
# # but before commands[gameend]
# postcommands = chdir "/"
#
# # If the game uses an ancient encoding, you may specify "ibm" or "dec".
# # If set to "ask", the game will be run with --print-charset beforehand,
# # expected to return one of these values.
# encoding = "unicode"
#}
@ -301,6 +306,7 @@ DEFINE {
# rc_template = "/dgl-default-rcfile.crawl"
# rc_fmt = "%rrcfiles/%n.crawlrc"
# inprogressdir = "%rinprogress-crawlss017/"
# encoding = ask
#}
#

View File

@ -410,3 +410,16 @@ remove_ipfile (void)
}
signal(SIGALRM, SIG_IGN);
}
int encoding_by_name(const char *enc)
{
if (!strcasecmp(enc, "UTF-8") || !strcasecmp(enc, "UNICODE"))
return 0;
if (!strcasecmp(enc, "IBM") || !strcasecmp(enc, "CP437"))
return 1;
if (!strcasecmp(enc, "DEC"))
return 2;
if (!strcasecmp(enc, "ASCII"))
return 1; // what to do with invalid chars?
return -1;
}

View File

@ -28,4 +28,5 @@ extern int master, slave;
extern struct termios tt;
extern struct winsize win;
extern int encoding_by_name(const char *enc);
#endif