From 47cfe66d43027aa85855d3ff264b14e8e8c0cdd4 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 3 Oct 2011 15:23:14 +0000 Subject: [PATCH] ancient encodings: config option (Adam Borowski ) git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@597 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- config.l | 1 + config.y | 14 ++++++++++++++ dgamelaunch.h | 1 + examples/dgamelaunch.conf | 6 ++++++ ttyrec.c | 13 +++++++++++++ ttyrec.h | 1 + 6 files changed, 36 insertions(+) diff --git a/config.l b/config.l index e60493c..95eadb0 100644 --- a/config.l +++ b/config.l @@ -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; } diff --git a/config.y b/config.y index 4474b0c..c500071 100644 --- a/config.y +++ b/config.y @@ -11,6 +11,7 @@ #include #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 TYPE_VALUE %token TYPE_NUMBER TYPE_CMDQUEUENAME %type 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; } diff --git a/dgamelaunch.h b/dgamelaunch.h index 7be7b3a..41cc764 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -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 { diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index 21c5ab1..cd78773 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -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 #} # diff --git a/ttyrec.c b/ttyrec.c index 2056c85..ad9bd3b 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -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; +} diff --git a/ttyrec.h b/ttyrec.h index 34aa3c0..a8bb35a 100644 --- a/ttyrec.h +++ b/ttyrec.h @@ -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 -- 2.47.3