X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=interpreters%2Fgit%2Fgit_unix.c;h=3159c32bf0932586fab34d97abe9faeea20ae7df;hb=75009f8f40bbb580194e1722db76f4644bf18641;hp=04cfe60ec59f3c5ff18724a75dc8e3c45a37be73;hpb=5f927b0d7c728e389f3295ac39acb85ecb3a6ef0;p=projects%2Fchimara%2Fchimara.git diff --git a/interpreters/git/git_unix.c b/interpreters/git/git_unix.c index 04cfe60..3159c32 100644 --- a/interpreters/git/git_unix.c +++ b/interpreters/git/git_unix.c @@ -8,6 +8,8 @@ #include #include // This comes with the Glk library. +#include + #ifdef USE_MMAP #include #include @@ -25,24 +27,70 @@ glkunix_argumentlist_t glkunix_arguments[] = #define CACHE_SIZE (256 * 1024L) #define UNDO_SIZE (512 * 1024L) +int gHasInited = 0; + +#ifdef GARGLK + +void fatalError (const char * s) +{ + winid_t win; + if (!gHasInited) + { + win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); + glk_set_window(win); + } + /* pray that this goes somewhere reasonable... */ + glk_put_string("\n*** fatal error: "); + glk_put_string((char*)s); + glk_put_string(" ***\n"); + glk_exit(); +} + +#else + void fatalError (const char * s) { fprintf (stderr, "*** fatal error: %s ***\n", s); exit (1); } +#endif /* GARGLK */ + #ifdef USE_MMAP // Fast loader that uses some fancy Unix features. const char * gFilename = 0; +char * gStartupError = 0; int glkunix_startup_code(glkunix_startup_t *data) { +#ifdef GARGLK + { + char buf[255]; + sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH); + garglk_set_program_name(buf); + sprintf(buf, "Git %d.%d.%d by Iain Merrick and David Kinder\n", + GIT_MAJOR, GIT_MINOR, GIT_PATCH); + garglk_set_program_info(buf); + } +#endif /* GARGLK */ + if (data->argc <= 1) { - printf ("usage: git gamefile.ulx\n"); - return 0; + gStartupError = "No file given"; + return 1; } + +#ifdef GARGLK + { + char *s; + s = strrchr(data->argv[1], '\\'); + if (s) garglk_set_story_name(s+1); + s = strrchr(data->argv[1], '/'); + if (s) garglk_set_story_name(s+1); + } +#endif /* GARGLK */ + gFilename = data->argv[1]; return 1; } @@ -52,7 +100,10 @@ void glk_main () int file; struct stat info; const char * ptr; - + + if (gStartupError) + fatalError(gStartupError); + file = open (gFilename, O_RDONLY); if (file < 0) goto error; @@ -61,45 +112,72 @@ void glk_main () goto error; if (info.st_size < 256) - { - fprintf (stderr, "This is too small to be a glulx file.\n"); - exit (1); - } + fatalError("This is too small to be a glulx file."); ptr = mmap (NULL, info.st_size, PROT_READ, MAP_PRIVATE, file, 0); if (ptr == MAP_FAILED) goto error; + + gHasInited = 1; git (ptr, info.st_size, CACHE_SIZE, UNDO_SIZE); munmap ((void*) ptr, info.st_size); return; error: - perror ("git"); - exit (errno); + sprintf(errmsg, "git: %s", strerror(errno)); + fatalError(errmsg); } #else // Generic loader that should work anywhere. strid_t gStream = 0; +char * gStartupError = 0; int glkunix_startup_code(glkunix_startup_t *data) { +#ifdef GARGLK + { + char buf[255]; + sprintf(buf, "Git %d.%d.%d", GIT_MAJOR, GIT_MINOR, GIT_PATCH); + garglk_set_program_name(buf); + sprintf(buf, "Git %d.%d.%d by Iain Merrick and David Kinder\n", + GIT_MAJOR, GIT_MINOR, GIT_PATCH); + garglk_set_program_info(buf); + } +#endif /* GARGLK */ + if (data->argc <= 1) { - printf ("usage: git gamefile.ulx\n"); - return 0; + gStartupError = "No file given"; + return 1; } + +#ifdef GARGLK + { + char *s; + s = strrchr(data->argv[1], '\\'); + if (s) garglk_set_story_name(s+1); + s = strrchr(data->argv[1], '/'); + if (s) garglk_set_story_name(s+1); + } +#endif /* GARGLK */ + gStream = glkunix_stream_open_pathname ((char*) data->argv[1], 0, 0); return 1; } void glk_main () { + if (gStartupError) + fatalError(gStartupError); + if (gStream == NULL) fatalError ("could not open game file"); + gHasInited = 1; + gitWithStream (gStream, CACHE_SIZE, UNDO_SIZE); }