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)
28 void fatalError (const char * s)
30 fprintf (stderr, "*** fatal error: %s ***\n", s);
35 // Fast loader that uses some fancy Unix features.
37 const char * gFilename = 0;
39 int glkunix_startup_code(glkunix_startup_t *data)
43 printf ("usage: git gamefile.ulx\n");
46 gFilename = data->argv[1];
56 file = open (gFilename, O_RDONLY);
60 if (fstat (file, &info) != 0)
63 if (info.st_size < 256)
65 fprintf (stderr, "This is too small to be a glulx file.\n");
69 ptr = mmap (NULL, info.st_size, PROT_READ, MAP_PRIVATE, file, 0);
70 if (ptr == MAP_FAILED)
73 git (ptr, info.st_size, CACHE_SIZE, UNDO_SIZE);
74 munmap ((void*) ptr, info.st_size);
83 // Generic loader that should work anywhere.
87 int glkunix_startup_code(glkunix_startup_t *data)
91 printf ("usage: git gamefile.ulx\n");
94 gStream = glkunix_stream_open_pathname ((char*) data->argv[1], 0, 0);
101 fatalError ("could not open game file");
103 gitWithStream (gStream, CACHE_SIZE, UNDO_SIZE);