1 // $Id: git_unix.c,v 1.5 2004/01/25 18:44:51 iain Exp $
3 // unixstrt.c: Unix-specific code for Glulxe.
4 // Designed by Andrew Plotkin <erkyrath@eblong.com>
5 // http://www.eblong.com/zarf/glulx/index.html
9 #include <glkstart.h> // This comes with the Glk library.
18 // The only command-line argument is the filename.
19 glkunix_argumentlist_t glkunix_arguments[] =
21 { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
22 { NULL, glkunix_arg_End, NULL }
25 #define CACHE_SIZE (256 * 1024L)
26 #define UNDO_SIZE (512 * 1024L)
30 #ifdef CHIMARA_EXTENSIONS
32 void fatalError (const char * s)
37 win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
40 /* pray that this goes somewhere reasonable... */
41 glk_put_string("\n*** fatal error: ");
42 glk_put_string((char*)s);
43 glk_put_string(" ***\n");
49 void fatalError (const char * s)
51 fprintf (stderr, "*** fatal error: %s ***\n", s);
55 #endif /* CHIMARA_EXTENSIONS */
58 // Fast loader that uses some fancy Unix features.
60 const char * gFilename = 0;
61 char * gStartupError = 0;
63 int glkunix_startup_code(glkunix_startup_t *data)
67 gStartupError = "No file given";
70 gFilename = data->argv[1];
81 fatalError(gStartupError);
83 file = open (gFilename, O_RDONLY);
87 if (fstat (file, &info) != 0)
90 if (info.st_size < 256)
91 fatalError("This is too small to be a glulx file.");
93 ptr = mmap (NULL, info.st_size, PROT_READ, MAP_PRIVATE, file, 0);
94 if (ptr == MAP_FAILED)
99 git (ptr, info.st_size, CACHE_SIZE, UNDO_SIZE);
100 munmap ((void*) ptr, info.st_size);
104 sprintf(errmsg, "git: %s", strerror(errno));
109 // Generic loader that should work anywhere.
112 char * gStartupError = 0;
114 int glkunix_startup_code(glkunix_startup_t *data)
118 gStartupError = "No file given";
121 gStream = glkunix_stream_open_pathname ((char*) data->argv[1], 0, 0);
128 fatalError(gStartupError);
131 fatalError ("could not open game file");
135 gitWithStream (gStream, CACHE_SIZE, UNDO_SIZE);