1 /* unixstrt.c: Unix-specific code for Glulxe.
2 Designed by Andrew Plotkin <erkyrath@eblong.com>
3 http://eblong.com/zarf/glulx/index.html
9 #include "glkstart.h" /* This comes with the Glk library. */
11 /* The only command-line argument is the filename. And the profiling switch,
12 if that's compiled in. The only *two* command-line arguments are...
14 glkunix_argumentlist_t glkunix_arguments[] = {
17 { "--profile", glkunix_arg_ValueFollows, "Generate profiling information to a file." },
18 #endif /* VM_PROFILING */
20 { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
22 { NULL, glkunix_arg_End, NULL }
25 int glkunix_startup_code(glkunix_startup_t *data)
27 /* It turns out to be more convenient if we return TRUE from here, even
28 when an error occurs, and display an error in glk_main(). */
30 char *filename = NULL;
31 unsigned char buf[12];
36 garglk_set_program_name("Glulxe 0.4.7");
37 garglk_set_program_info("Glulxe 0.4.7 by Andrew Plotkin");
40 /* Parse out the arguments. They've already been checked for validity,
41 and the library-specific ones stripped out.
42 As usual for Unix, the zeroth argument is the executable name. */
43 for (ix=1; ix<data->argc; ix++) {
46 if (!strcmp(data->argv[ix], "--profile")) {
49 strid_t profstr = glkunix_stream_open_pathname_gen(data->argv[ix], TRUE, FALSE, 1);
51 init_err = "Unable to open profile output file.";
52 init_err2 = data->argv[ix];
55 setup_profile(profstr, NULL);
59 #endif /* VM_PROFILING */
62 init_err = "You must supply exactly one game file.";
65 filename = data->argv[ix];
69 init_err = "You must supply the name of a game file.";
71 return TRUE; /* Hack! but I want error message in glk window */
76 gamefile = glkunix_stream_open_pathname(filename, FALSE, 1);
78 init_err = "The game file could not be opened.";
84 cx = strrchr(filename, '/');
85 if (!cx) cx = strrchr(filename, '\\');
86 garglk_set_story_name(cx ? cx + 1 : filename);
89 /* Now we have to check to see if it's a Blorb file. */
91 glk_stream_set_position(gamefile, 0, seekmode_Start);
92 res = glk_get_buffer_stream(gamefile, (char *)buf, 12);
94 init_err = "The data in this stand-alone game is too short to read.";
98 if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') {
99 locate_gamefile(FALSE);
102 else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M'
103 && buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') {
104 locate_gamefile(TRUE);
108 init_err = "This is neither a Glulx game file nor a Blorb file "
109 "which contains one.";