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.
20 // The only command-line argument is the filename.
21 glkunix_argumentlist_t glkunix_arguments[] =
23 { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
24 { NULL, glkunix_arg_End, NULL }
27 #define CACHE_SIZE (256 * 1024L)
28 #define UNDO_SIZE (512 * 1024L)
34 void fatalError (const char * s)
39 win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
42 /* pray that this goes somewhere reasonable... */
43 glk_put_string("\n*** fatal error: ");
44 glk_put_string((char*)s);
45 glk_put_string(" ***\n");
51 void fatalError (const char * s)
53 fprintf (stderr, "*** fatal error: %s ***\n", s);
60 // Fast loader that uses some fancy Unix features.
62 const char * gFilename = 0;
63 char * gStartupError = 0;
65 int glkunix_startup_code(glkunix_startup_t *data)
70 sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH);
71 garglk_set_program_name(buf);
72 sprintf(buf, "Git %d.%d.%d by Iain Merrick and David Kinder\n",
73 GIT_MAJOR, GIT_MINOR, GIT_PATCH);
74 garglk_set_program_info(buf);
80 gStartupError = "No file given";
87 s = strrchr(data->argv[1], '\\');
88 if (s) garglk_set_story_name(s+1);
89 s = strrchr(data->argv[1], '/');
90 if (s) garglk_set_story_name(s+1);
94 gFilename = data->argv[1];
105 fatalError(gStartupError);
107 file = open (gFilename, O_RDONLY);
111 if (fstat (file, &info) != 0)
114 if (info.st_size < 256)
115 fatalError("This is too small to be a glulx file.");
117 ptr = mmap (NULL, info.st_size, PROT_READ, MAP_PRIVATE, file, 0);
118 if (ptr == MAP_FAILED)
123 git (ptr, info.st_size, CACHE_SIZE, UNDO_SIZE);
124 munmap ((void*) ptr, info.st_size);
128 sprintf(errmsg, "git: %s", strerror(errno));
133 // Generic loader that should work anywhere.
136 char * gStartupError = 0;
138 int glkunix_startup_code(glkunix_startup_t *data)
143 sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH);
144 garglk_set_program_name(buf);
145 sprintf(buf, "Git %d.%d.%d by Iain Merrick and David Kinder\n",
146 GIT_MAJOR, GIT_MINOR, GIT_PATCH);
147 garglk_set_program_info(buf);
153 gStartupError = "No file given";
160 s = strrchr(data->argv[1], '\\');
161 if (s) garglk_set_story_name(s+1);
162 s = strrchr(data->argv[1], '/');
163 if (s) garglk_set_story_name(s+1);
167 gStream = glkunix_stream_open_pathname ((char*) data->argv[1], 0, 0);
174 fatalError(gStartupError);
177 fatalError ("could not open game file");
181 gitWithStream (gStream, CACHE_SIZE, UNDO_SIZE);