2 * Copyright 2010-2012 Chris Spiegel.
4 * This file is part of Bocfel.
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.
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.
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/>.
31 #include <libchimara/garglk.h>
34 #ifndef ZTERP_NO_SAFETY_CHECKS
35 unsigned long zassert_pc;
37 void assert_fail(const char *fmt, ...)
43 vsnprintf(str, sizeof str, fmt, ap);
46 snprintf(str + strlen(str), sizeof str - strlen(str), " (pc = 0x%lx)", zassert_pc);
52 void warning(const char *fmt, ...)
58 vsnprintf(str, sizeof str, fmt, ap);
61 show_message("WARNING: %s", str);
64 void die(const char *fmt, ...)
70 vsnprintf(str, sizeof str, fmt, ap);
73 show_message("fatal error: %s", str);
77 fprintf(stderr, "%s\n", str);
85 /* This is not POSIX compliant, but it gets the job done.
86 * It should not be called more than once.
88 static int zoptind = 0;
89 static const char *zoptarg;
90 static int zgetopt(int argc, char **argv, const char *optstring)
92 static const char *p = "";
98 /* No more arguments. */
99 if(++zoptind >= argc) return -1;
103 /* No more options. */
104 if(p[0] != '-' || p[1] == 0) return -1;
116 optp = strchr(optstring, c);
117 if(optp == NULL) return '?';
121 if(*p != 0) zoptarg = p;
122 else zoptarg = argv[++zoptind];
125 if(zoptarg == NULL) return '?';
131 char *xstrdup(const char *s)
139 if(r != NULL) memcpy(r, s, n);
144 int process_arguments(int argc, char **argv)
148 while( (c = zgetopt(argc, argv, "a:A:cCdDeE:fFgGiklLmn:N:rR:sS:tT:u:UvxXyz:Z:")) != -1 )
153 options.eval_stack_size = strtol(zoptarg, NULL, 10);
156 options.call_stack_size = strtol(zoptarg, NULL, 10);
159 options.disable_color = 1;
162 options.disable_config = 1;
165 options.disable_timed = 1;
168 options.disable_sound = 1;
171 options.enable_escape = 1;
174 options.escape_string = xstrdup(zoptarg);
177 options.disable_fixed = 1;
180 options.assume_fixed = 1;
183 options.disable_graphics_font = 1;
186 options.enable_alt_graphics = 1;
192 options.disable_term_keys = 1;
195 options.disable_utf8 = 1;
198 options.force_utf8 = 1;
201 options.disable_meta_commands = 1;
204 options.int_number = strtol(zoptarg, NULL, 10);
207 options.int_version = zoptarg[0];
210 options.replay_on = 1;
213 options.replay_name = xstrdup(zoptarg);
216 options.record_on = 1;
219 options.record_name = xstrdup(zoptarg);
222 options.transcript_on = 1;
225 options.transcript_name = xstrdup(zoptarg);
228 options.max_saves = strtol(zoptarg, NULL, 10);
231 options.disable_undo_compression = 1;
234 options.show_version = 1;
237 options.disable_abbreviations = 1;
240 options.enable_censorship = 1;
243 options.overwrite_transcript = 1;
246 options.random_seed = strtol(zoptarg, NULL, 10);
249 options.random_device = xstrdup(zoptarg);
256 /* Just ignore excess stories for now. */
257 if(zoptind < argc) game_file = argv[zoptind];