1 /* main.c: Glulxe top-level code.
2 Designed by Andrew Plotkin <erkyrath@eblong.com>
3 http://eblong.com/zarf/glulx/index.html
9 strid_t gamefile = NULL; /* The stream containing the Glulx file. */
10 glui32 gamefile_start = 0; /* The position within the stream. (This will not
11 be zero if the Glulx file is a chunk inside a Blorb archive.) */
12 glui32 gamefile_len = 0; /* The length within the stream. */
13 char *init_err = NULL;
14 char *init_err2 = NULL;
16 static winid_t get_error_win(void);
17 static void stream_hexnum(glsi32 val);
20 The top-level routine. This does everything, and consequently is
26 fatal_error_2(init_err, init_err2);
30 if (!is_gamefile_valid()) {
31 /* The fatal error has already been displayed. */
36 if (!init_dispatch()) {
39 if (!init_profile()) {
52 Return a window in which to display errors. The first time this is called,
53 it creates a new window; after that it returns the window it first
56 static winid_t get_error_win()
58 static winid_t errorwin = NULL;
61 winid_t rootwin = glk_window_get_root();
63 errorwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
66 errorwin = glk_window_open(rootwin, winmethod_Below | winmethod_Fixed,
67 3, wintype_TextBuffer, 0);
76 /* fatal_error_handler():
77 Display an error in the error window, and then exit.
79 void fatal_error_handler(char *str, char *arg, int useval, glsi32 val)
81 winid_t win = get_error_win();
84 glk_put_string("Glulxe fatal error: ");
101 /* nonfatal_warning_handler():
102 Display a warning in the error window, and then continue.
104 void nonfatal_warning_handler(char *str, char *arg, int useval, glsi32 val)
106 winid_t win = get_error_win();
108 strid_t oldstr = glk_stream_get_current();
110 glk_put_string("Glulxe warning: ");
113 glk_put_string(" (");
122 glk_put_string("\n");
123 glk_stream_set_current(oldstr);
128 Write a signed integer to the current Glk output stream.
130 static void stream_hexnum(glsi32 val)
151 buf[ix] = (ival % 16) + '0';
153 buf[ix] += ('A' - ('9' + 1));
160 glk_put_char(buf[ix]);