Add Bocfel interpreter
[projects/chimara/chimara.git] / interpreters / bocfel / glkstart.c
1 /*-
2  * Copyright 2010-2012 Chris Spiegel.
3  *
4  * This file is part of Bocfel.
5  *
6  * Bocfel is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version
8  * 2 or 3, as published by the Free Software Foundation.
9  *
10  * Bocfel is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Bocfel.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <glk.h>
20 #include <libchimara/garglk.h>
21
22 /* Even on Win32, Gargoyle provides a glkunix startup. */
23 #if defined(ZTERP_UNIX) || defined(GARGLK)
24 #include <string.h>
25
26 #include <glkstart.h>
27
28 #include "util.h"
29 #include "zterp.h"
30
31 zexternally_visible
32 glkunix_argumentlist_t glkunix_arguments[] =
33 {
34   { "-a",       glkunix_arg_NumberValue,        "-a N           set the size of the evaluation stack" },
35   { "-A",       glkunix_arg_NumberValue,        "-A N           set the size of the call stack" },
36   { "-c",       glkunix_arg_NoValue,            "-c             disable color" },
37   { "-C",       glkunix_arg_NoValue,            "-C             disable the use of a config file" },
38   { "-d",       glkunix_arg_NoValue,            "-d             disable timed input" },
39   { "-D",       glkunix_arg_NoValue,            "-D             disable sound effects" },
40   { "-e",       glkunix_arg_NoValue,            "-e             enable ANSI escapes in the transcript" },
41   { "-E",       glkunix_arg_ValueFollows,       "-E string      set the escape string for -e" },
42   { "-f",       glkunix_arg_NoValue,            "-f             disable fixed-width fonts" },
43   { "-F",       glkunix_arg_NoValue,            "-F             assume font is fixed-width" },
44   { "-g",       glkunix_arg_NoValue,            "-g             disable the character graphics font" },
45   { "-G",       glkunix_arg_NoValue,            "-G             enable alternative box-drawing character graphics" },
46   { "-i",       glkunix_arg_NoValue,            "-i             display the id of the story file and exit" },
47   { "-k",       glkunix_arg_NoValue,            "-k             disable the use of terminating keys (notably used in Beyond Zork)" },
48   { "-l",       glkunix_arg_NoValue,            "-l             disable utf-8 transcripts" },
49   { "-L",       glkunix_arg_NoValue,            "-L             force utf-8 transcrips" },
50   { "-m",       glkunix_arg_NoValue,            "-m             disable meta commands" },
51   { "-n",       glkunix_arg_NumberValue,        "-n N           set the interpreter number (see 11.1.3 in The Z-machine Standards Document 1.0)" },
52   { "-N",       glkunix_arg_NumberValue,        "-N N           set the interpreter version (see 11.1.3.1 in The Z-machine Standards Document 1.0)" },
53   { "-r",       glkunix_arg_NoValue,            "-r             start the story by replaying a command record" },
54   { "-R",       glkunix_arg_NoValue,            "-R filename    set the filename to be used if replaying a command record" },
55   { "-s",       glkunix_arg_NoValue,            "-s             start the story with command recording on" },
56   { "-S",       glkunix_arg_NoValue,            "-S filename    set the filename to be used if command recording is turned on" },
57   { "-t",       glkunix_arg_NoValue,            "-t             start the story with transcripting on" },
58   { "-T",       glkunix_arg_ValueFollows,       "-T filename    set the filename to be used if transcription is turned on" },
59   { "-u",       glkunix_arg_NumberValue,        "-u N           set the maximum number of undo slots" },
60   { "-U",       glkunix_arg_NoValue,            "-U             disable compression in undo slots" },
61   { "-v",       glkunix_arg_NoValue,            "-v             display version information" },
62   { "-x",       glkunix_arg_NoValue,            "-x             disable expansion of abbreviations" },
63   { "-X",       glkunix_arg_NoValue,            "-X             enable tandy censorship" },
64   { "-y",       glkunix_arg_NoValue,            "-y             when opening a transcript, overwrite rather than append to an existing file" },
65   { "-z",       glkunix_arg_NumberValue,        "-z N           set initial random seed" },
66   { "-Z",       glkunix_arg_ValueFollows,       "-Z device      read initial random seed from device" },
67   { "",         glkunix_arg_ValueFollows,       "filename       file to load" },
68
69   { NULL, glkunix_arg_End, NULL }
70 };
71
72 zexternally_visible
73 int glkunix_startup_code(glkunix_startup_t *data)
74 {
75   if(!process_arguments(data->argc, data->argv)) return 0;
76
77 #ifdef GARGLK
78   garglk_set_program_name("Bocfel");
79   if(game_file != NULL)
80   {
81     char *p = strrchr(game_file, '/');
82     garglk_set_story_name(p == NULL ? game_file : p + 1);
83   }
84 #endif
85
86   return 1;
87 }
88 #elif defined(ZTERP_WIN32)
89 #include <windows.h>
90
91 #include <WinGlk.h>
92
93 #include "util.h"
94
95 int InitGlk(unsigned int);
96
97 zexternally_visible
98 int WINAPI WinMain(HINSTANCE instance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow)
99 {
100   /* This works (with a linker message) under MinGW, but I don’t
101    * know if it’s supposed to; I am unfamiliar with how Windows
102    * handles command-line arguments.
103    */
104   extern int __argc;
105   extern char **__argv;
106
107   if(!InitGlk(0x00000700)) exit(EXIT_FAILURE);
108
109   if(!process_arguments(__argc, __argv)) exit(EXIT_FAILURE);
110
111   winglk_app_set_name("Bocfel");
112
113   glk_main();
114   glk_exit();
115
116   return 0;
117 }
118 #else
119 #error Glk on this platform is not supported.
120 #endif