1 /* unixstrt.c: Unix-specific code for Glulxe.
2 Designed by Andrew Plotkin <erkyrath@eblong.com>
3 http://eblong.com/zarf/glulx/index.html
8 #include "glkstart.h" /* This comes with the Glk library. */
11 /* The only command-line argument is the filename. */
12 glkunix_argumentlist_t glkunix_arguments[] = {
13 { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
14 { NULL, glkunix_arg_End, NULL }
17 int glkunix_startup_code(glkunix_startup_t *data)
19 /* It turns out to be more convenient if we return TRUE from here, even
20 when an error occurs, and display an error in glk_main(). */
22 unsigned char buf[12];
26 garglk_set_program_name("Glulxe 0.4.7");
27 garglk_set_program_info("Glulxe 0.4.7 by Andrew Plotkin");
30 if (data->argc <= 1) {
31 init_err = "You must supply the name of a game file.";
33 return TRUE; /* Hack! but I want error message in glk window */
39 gamefile = glkunix_stream_open_pathname(cx, FALSE, 1);
41 init_err = "The game file could not be opened.";
47 cx = strrchr(data->argv[1], '/');
48 if (!cx) cx = strrchr(data->argv[1], '\\');
49 garglk_set_story_name(cx ? cx + 1 : data->argv[1]);
52 /* Now we have to check to see if it's a Blorb file. */
54 glk_stream_set_position(gamefile, 0, seekmode_Start);
55 res = glk_get_buffer_stream(gamefile, (char *)buf, 12);
57 init_err = "The data in this stand-alone game is too short to read.";
61 if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') {
62 locate_gamefile(FALSE);
65 else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M'
66 && buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') {
67 locate_gamefile(TRUE);
71 init_err = "This is neither a Glulx game file nor a Blorb file "
72 "which contains one.";