| 1 |
#include "utils.h" |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include "alan.version.h" |
| 6 |
#include "options.h" |
| 7 |
#include "memory.h" |
| 8 |
#include "output.h" |
| 9 |
#include "exe.h" |
| 10 |
#include "state.h" |
| 11 |
#include "lists.h" |
| 12 |
|
| 13 |
#include "fnmatch.h" |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
void terminate(int code) |
| 24 |
{ |
| 25 |
newline(); |
| 26 |
|
| 27 |
terminateStateStack(); |
| 28 |
|
| 29 |
stopTranscript(); |
| 30 |
|
| 31 |
if (memory) |
| 32 |
deallocate(memory); |
| 33 |
|
| 34 |
#ifdef HAVE_GLK |
| 35 |
glk_exit(); |
| 36 |
#else |
| 37 |
exit(code); |
| 38 |
#endif |
| 39 |
} |
| 40 |
|
| 41 |
#ifdef HAVE_GLK |
| 42 |
#include "glkio.h" |
| 43 |
#endif |
| 44 |
|
| 45 |
|
| 46 |
void printVersion(int buildNumber) { |
| 47 |
printf("Arun - Adventure Language Interpreter version %s", alan.version.string); |
| 48 |
if (buildNumber != 0) printf("-%d", buildNumber); |
| 49 |
printf(" (%s %s)", alan.date, alan.time); |
| 50 |
#ifdef GIT_VERSION |
| 51 |
printf("\nBuilt from git %s", GIT_VERSION); |
| 52 |
#endif |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
void printIFIDs(char *adventureName) { |
| 58 |
IfidEntry *ifidEntry; |
| 59 |
|
| 60 |
printf("'%s' contains the following IFIDs:\n", adventureName); |
| 61 |
for (ifidEntry = pointerTo(header->ifids); !isEndOfArray(ifidEntry); ifidEntry++) { |
| 62 |
printf(" %s:\t%s\n", (unsigned char *)pointerTo(ifidEntry->nameAddress), |
| 63 |
(unsigned char *)pointerTo(ifidEntry->valueAddress)); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void usage(char *programName) |
| 70 |
{ |
| 71 |
#if (BUILD+0) != 0 |
| 72 |
printVersion(BUILD); |
| 73 |
#else |
| 74 |
printVersion(0); |
| 75 |
#endif |
| 76 |
printf("\n\nUsage:\n\n"); |
| 77 |
printf(" %s [<switches>] <adventure>\n\n", programName); |
| 78 |
printf("where the possible optional switches are:\n"); |
| 79 |
#ifdef HAVE_GLK |
| 80 |
glk_set_style(style_Preformatted); |
| 81 |
#endif |
| 82 |
printf(" -u use UTF-8 encoding for input and output\n"); |
| 83 |
printf(" -i use ISO8859-1 encoding for input and output\n"); |
| 84 |
printf(" -h this help\n"); |
| 85 |
printf(" -v verbose mode\n"); |
| 86 |
printf(" -l log game transcript to a file ('.a3t')\n"); |
| 87 |
printf(" -c log player command input (the solution) to a file ('.a3s')\n"); |
| 88 |
printf(" -n don't show the Status Line\n"); |
| 89 |
printf(" -p don't page output\n"); |
| 90 |
printf(" -d enter debug mode immediately\n"); |
| 91 |
printf(" -t[<n>] trace game execution, higher <n> gives more trace\n"); |
| 92 |
printf(" -r make regression testing easier (don't timestamp, page break, randomize...)\n"); |
| 93 |
printf(" -e ignore version and checksum errors (dangerous)\n"); |
| 94 |
printf(" --version print version and exit\n"); |
| 95 |
#ifdef HAVE_GLK |
| 96 |
glk_set_style(style_Normal); |
| 97 |
#endif |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
#ifndef FNM_CASEFOLD |
| 102 |
#define FNM_CASEFOLD 0 |
| 103 |
#endif |
| 104 |
|
| 105 |
bool match(char *pattern, char *input) { |
| 106 |
return fnmatch(pattern, input, FNM_CASEFOLD) == 0; |
| 107 |
} |