| 1 | /* glkstart.c: Unix-specific startup code -- sample file. |
| 2 | Designed by Andrew Plotkin <[email protected]> |
| 3 | http://www.eblong.com/zarf/glk/index.html |
| 4 | |
| 5 | This is Unix startup code for the simplest possible kind of Glk |
| 6 | program -- no command-line arguments; no startup files; no nothing. |
| 7 | |
| 8 | Remember, this is a sample file. You should copy it into the Glk |
| 9 | program you are compiling, and modify it to your needs. This should |
| 10 | *not* be compiled into the Glk library itself. |
| 11 | */ |
| 12 | |
| 13 | #include "jacl.h" |
| 14 | #include "glk.h" |
| 15 | #include "glkstart.h" |
| 16 | #include "language.h" |
| 17 | #include "prototypes.h" |
| 18 | #include <string.h> |
| 19 | |
| 20 | int jpp_error = FALSE; |
| 21 | |
| 22 | short int encrypt; |
| 23 | extern short int release; |
| 24 | |
| 25 | glkunix_startup_t *arguments; |
| 26 | |
| 27 | /* THE STREAM FOR OPENING UP THE ARCHIVE CONTAINING GRAPHICS AND SOUND */ |
| 28 | strid_t blorb_stream; |
| 29 | |
| 30 | glkunix_argumentlist_t glkunix_arguments[] = { |
| 31 | {"", glkunix_arg_ValueFollows, "filename: The game file to load." }, |
| 32 | |
| 33 | {"-noencrypt", glkunix_arg_NoValue, "-noencrypt: Don't encrypt the processed game file."}, |
| 34 | {"-release", glkunix_arg_NoValue, "-release: Don't include the debug libraries in the .j2 file."}, |
| 35 | { NULL, glkunix_arg_End, NULL } |
| 36 | }; |
| 37 | |
| 38 | int glkunix_startup_code(glkunix_startup_t *data) |
| 39 | { |
| 40 | int index = 0; |
| 41 | |
| 42 | arguments = data; |
| 43 | |
| 44 | #ifdef GARGLK |
| 45 | sprintf(temp_buffer, "JACL %d.%d.%d", J_VERSION, J_RELEASE, J_BUILD); |
| 46 | garglk_set_program_name(temp_buffer); |
| 47 | sprintf(temp_buffer, "JACL %d.%d.%d by Stuart Allen.\n", J_VERSION, J_RELEASE, J_BUILD); |
| 48 | garglk_set_program_info(temp_buffer); |
| 49 | #endif |
| 50 | |
| 51 | /* YOU CAN PUT OTHER STARTUP CODE IN glkunix_startup_code(). THIS SHOULD |
| 52 | * GENERALLY BE LIMITED TO FINDING AND OPENING DATA FILES. */ |
| 53 | |
| 54 | if (arguments->argc == 1) { |
| 55 | sprintf (error_buffer, "%s^", NO_GAME); |
| 56 | jpp_error = TRUE; |
| 57 | |
| 58 | /* WE NEED TO RETURN TRUE HERE SO THE INTERPRETER WILL OPEN A |
| 59 | * GLK WINDOWS TO DISPLAY THE ERROR MESSAGE IN */ |
| 60 | return (TRUE); |
| 61 | } else { |
| 62 | strcpy(temp_buffer, arguments->argv[1]); |
| 63 | |
| 64 | /* THERE IS AT LEAST ONE ARGUMENT, POSSIBLY JUST THE GAME FILE, BUT |
| 65 | * LOOK THROUGH THE LIST FOR ANYTHING THAT NEEDS ACTING ON */ |
| 66 | for (index = 0; index < data->argc; index++) { |
| 67 | if (!strcmp(*data->argv, "-noencrypt")) { |
| 68 | encrypt = FALSE; |
| 69 | } else if (!strcmp(*data->argv, "-release")) { |
| 70 | release = TRUE; |
| 71 | } |
| 72 | |
| 73 | /* INCREMENT THE POINTER TO THE NEXT ARGUMENT */ |
| 74 | data->argv++; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* SETUP ALL THE EXPECTED PATHS */ |
| 79 | create_paths(temp_buffer); |
| 80 | |
| 81 | /* PREPROCESS THE FILE AND WRITE IT OUT TO THE NEW FILE */ |
| 82 | /* WARNING: THIS FUNCTION USES stdio FUNCTIONS TO CREATE FILES |
| 83 | * IN SUBDIRECTORIES. IT IS PORTABLE ACROSS MODERN DESKTOPS, IE |
| 84 | * WINDOWS, MAC, UNIX ETC, BUT IT'S NOT GLK CODE... */ |
| 85 | if (jpp() == FALSE) { |
| 86 | jpp_error = TRUE; |
| 87 | |
| 88 | /* WE NEED TO RETURN TRUE HERE SO THE INTERPRETER WILL OPEN A |
| 89 | * GLK WINDOWS TO DISPLAY THE ERROR MESSAGE IN */ |
| 90 | return (TRUE); |
| 91 | } |
| 92 | |
| 93 | /* THIS OPENS AN ARBITRARY FILE, IN READ-ONLY MODE. NOTE THAT THIS FUNCTION |
| 94 | * IS *ONLY* AVAILABLE DURING glkunix_startup_code(). IT IS INHERENT |
| 95 | * NON-PORTABLE; IT SHOULD NOT AND CANNOT BE CALLED FROM INSIDE |
| 96 | * glk_main() NOTE: The middle argument FALSE indicates a binary file. */ |
| 97 | game_stream = glkunix_stream_open_pathname(processed_file, FALSE, 0); |
| 98 | |
| 99 | if (!game_stream) { |
| 100 | strcpy (error_buffer, NOT_FOUND); |
| 101 | jpp_error = TRUE; |
| 102 | |
| 103 | /* WE NEED TO RETURN TRUE HERE SO THE INTERPRETER WILL OPEN A |
| 104 | * GLK WINDOWS TO DISPLAY THE ERROR MESSAGE IN */ |
| 105 | return (TRUE); |
| 106 | } |
| 107 | |
| 108 | /* SET THE LIBRARY'S IDEA OF THE "CURRENT DIRECTORY" FOR THE EXECUTING |
| 109 | * PROGRAM. THE ARGUMENT SHOULD BE THE NAME OF A FILE (NOT A DIRECTORY). |
| 110 | * WHEN THIS IS SET, fileref_create_by_name() WILL CREATE FILES IN THE SAME |
| 111 | * DIRECTORY AS THAT FILE, AND create_by_prompt() WILL BASE DEFAULT |
| 112 | * FILENAMES OFF OF THE FILE. IF THIS IS NOT CALLED, THE LIBRARY WORKS IN |
| 113 | * THE UNIX CURRENT WORKING DIRECTORY, AND PICKS REASONABLE DEFAULT |
| 114 | * DEFAULTS. */ |
| 115 | glkunix_set_base_file(game_file); |
| 116 | |
| 117 | /* Set title of game */ |
| 118 | #ifdef GARGLK |
| 119 | char *s; |
| 120 | s = strrchr(game_file, '\\'); |
| 121 | if (!s) s = strrchr(game_file, '/'); |
| 122 | garglk_set_story_name(s ? s + 1 : game_file); |
| 123 | #endif |
| 124 | |
| 125 | /* RETURN TRUE ERRORS OR NOT SO THE MAIN WINDOWS CAN BE OPENED AND |
| 126 | * ANY ERROR MESSAGE DISPLAYED */ |
| 127 | return (TRUE); |
| 128 | } |
| 129 |