]> skyeroc.xyz Git - dgamelaunch/commitdiff
ancient encodings: config option (Adam Borowski <kilobyte@angband.pl>)
authorPasi Kallinen <paxed@alt.org>
Mon, 3 Oct 2011 15:23:14 +0000 (15:23 +0000)
committerPasi Kallinen <paxed@alt.org>
Mon, 3 Oct 2011 15:23:14 +0000 (15:23 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@597 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.l
config.y
dgamelaunch.h
examples/dgamelaunch.conf
ttyrec.c
ttyrec.h

index e60493c76ace491ea6a690e9acde02fb6722ffb3..95eadb0e839bd524a51d2579fad16a6b59e4c724 100644 (file)
--- 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; }
index 4474b0c7e54c909e8512e67df8359bc83b4baaf5..c5000719dc49ad9326273b570487ec1419f580b2 100644 (file)
--- a/config.y
+++ b/config.y
@@ -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; }
index 7be7b3a76e9538d9ecb06cf8348b908d8c0eb5b1..41cc7645b1b5d4ffd83f6083a5ffb8745caa88e0 100644 (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 {
index 21c5ab1c90d65835d15c946fd31009066e7aa2db..cd78773b98cebd80ee00e7b54a1cedb31f8afe6e 100644 (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
 #}
 
 #
index 2056c85a60d07d3fb2285595af38ea6de221bc42..ad9bd3bfe0a92b55158c781b0498e650e78afe8f 100644 (file)
--- 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;
+}
index 34aa3c013f19aedd028798764f068a0a0be3b57a..a8bb35afd5b51c7d0861be9ac018508f95c75ea2 100644 (file)
--- 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