diff options
author | Paul Gilbert | 2019-06-21 19:20:58 -0700 |
---|---|---|
committer | Paul Gilbert | 2019-06-22 14:40:50 -0700 |
commit | dd4108e7c79770ec8235bd4440e0cdc06becd9d9 (patch) | |
tree | c41d06548ac4c4fbb037b733c1cdab519822204c /engines | |
parent | 8f75589971d70b2ca749d5389a332e6761213a5b (diff) | |
download | scummvm-rg350-dd4108e7c79770ec8235bd4440e0cdc06becd9d9.tar.gz scummvm-rg350-dd4108e7c79770ec8235bd4440e0cdc06becd9d9.tar.bz2 scummvm-rg350-dd4108e7c79770ec8235bd4440e0cdc06becd9d9.zip |
GLK: ALAN2: Removing all the existing system specific ifdef blocks
I'm going to be shortly formatting the code and doing refactoring
to work around the setjmp calls in the original, so there's little
point in keeping the system specific ifdef blocks from the original
Diffstat (limited to 'engines')
-rw-r--r-- | engines/glk/alan2/acode.h | 19 | ||||
-rw-r--r-- | engines/glk/alan2/args.cpp | 234 | ||||
-rw-r--r-- | engines/glk/alan2/args.h | 2 | ||||
-rw-r--r-- | engines/glk/alan2/debug.cpp | 32 | ||||
-rw-r--r-- | engines/glk/alan2/exe.cpp | 204 | ||||
-rw-r--r-- | engines/glk/alan2/inter.cpp | 10 | ||||
-rw-r--r-- | engines/glk/alan2/main.cpp | 254 | ||||
-rw-r--r-- | engines/glk/alan2/parse.cpp | 46 | ||||
-rw-r--r-- | engines/glk/alan2/readline.cpp | 506 | ||||
-rw-r--r-- | engines/glk/alan2/rules.cpp | 12 | ||||
-rw-r--r-- | engines/glk/alan2/sysdep.cpp | 183 | ||||
-rw-r--r-- | engines/glk/alan2/sysdep.h | 288 | ||||
-rw-r--r-- | engines/glk/alan2/term.cpp | 75 | ||||
-rw-r--r-- | engines/glk/alan2/types.h | 4 |
14 files changed, 48 insertions, 1821 deletions
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h index ef218dd3a6..8cb3c8149b 100644 --- a/engines/glk/alan2/acode.h +++ b/engines/glk/alan2/acode.h @@ -36,29 +36,10 @@ typedef uint32 Abool; /* Type for an ACODE Boolean value */ typedef int32 Aint; /* Type for an ACODE Integer value */ typedef int CodeValue; /* Definition for the packing process */ -#ifdef UNUSED -#if INT_MAX==0x7fffffff -typedef unsigned int Aword; /* Type for an ACODE word */ -typedef unsigned int Aaddr; /* Type for an ACODE address */ -typedef unsigned int Abool; /* Type for an ACODE Boolean value */ -typedef signed int Aint; /* Type for an ACODE Integer value */ -typedef int CodeValue; /* Definition for the packing process */ -#elif LONG_MAX==0x7fffffff -typedef unsigned long Aword; /* Type for an ACODE word */ -typedef unsigned long Aaddr; /* Type for an ACODE address */ -typedef unsigned long Abool; /* Type for an ACODE Boolean value */ -typedef signed long Aint; /* Type for an ACODE Integer value */ -typedef long CodeValue; /* Definition for the packing process */ -#else -#error "Can't find a 32-bit integer type" -#endif -#endif - /* Constants for the Acode file, words/block & bytes/block */ #define BLOCKLEN 256L #define BLOCKSIZE (BLOCKLEN*sizeof(Aword)) - /* Definitions for the packing process */ #define VALUEBITS 16 diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp index caf32c1bec..2f760aedbb 100644 --- a/engines/glk/alan2/args.cpp +++ b/engines/glk/alan2/args.cpp @@ -21,208 +21,21 @@ */ #include <string> -#ifndef __PACIFIC__ -#include "glk/alan2/args.h" -#else -/* I have no idea at all why the include does not work in Pacific C ... */ -extern void args(int argc, char* argv[]); -#endif - -#include "glk/alan2/main.h" - -#ifdef __mac__ -#include "glk/alan2/macArgs.h" -#endif - -#ifdef __amiga__ -#include <libraries/dosextens.h> -#ifdef AZTEC_C -struct FileHandle *con = NULL; -#else -/* Geek Gadgets GCC */ -BPTR window; -BPTR cd; -#endif -#endif - -#ifdef GLK #include "glk/alan2/alan2.h" +#include "glk/alan2/args.h" #include "glk/alan2/glkio.h" +#include "glk/alan2/main.h" #include "glk/alan2/sysdep.h" -#endif namespace Glk { namespace Alan2 { static void switches(unsigned argc, char *argv[]) { -#ifndef GLK - uint i; - - advnam = ""; - for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { -#ifdef GLK - switch (g_vm->glk_char_to_lower(argv[i][1])) { -#else - switch (tolower(argv[i][1])) { -#endif - case 'i': - errflg = FALSE; - break; - case 't': - trcflg = TRUE; - break; - case 'd': - dbgflg = TRUE; - break; - case 's': - trcflg = TRUE; - stpflg = TRUE; - break; - case 'l': - logflg = TRUE; - break; - case 'v': - verbose = TRUE; - break; - case 'n': - statusflg = FALSE; - break; - default: - printf("Unrecognized switch, -%c\n", argv[i][1]); - usage(); - terminate(0); - } - } else { - advnam = argv[i]; - if (strcmp(&advnam[strlen(advnam)-4], ".acd") == 0 - || strcmp(&advnam[strlen(advnam)-4], ".ACD") == 0 - || strcmp(&advnam[strlen(advnam)-4], ".dat") == 0 - || strcmp(&advnam[strlen(advnam)-4], ".DAT") == 0) - advnam[strlen(advnam)-4] = '\0'; - } - } -#endif -} - - - -#ifdef __amiga__ - -#include <intuition/intuition.h> -#include <workbench/workbench.h> - -#include <clib/exec_protos.h> -#include <clib/dos_protos.h> -#include <clib/icon_protos.h> - -#include <fcntl.h> - -extern struct Library *IconBase; - -#ifndef AZTEC_C -/* Actually Geek Gadgets GCC with libnix */ - -/* Aztec C has its own pre-main wbparse which was used in Arun 2.7, with GCC we - need to do it ourselves. */ - -#include <clib/intuition_protos.h> - -extern unsigned long *__stdfiledes; /* The libnix standard I/O file descriptors */ - -void -wb_parse(void) -{ - char *cp; - struct DiskObject *dop; - struct FileHandle *fhp; - - if (_WBenchMsg->sm_NumArgs == 1) /* If no argument use program icon/info */ - dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[0].wa_Name); - else { - BPTR olddir = CurrentDir(_WBenchMsg->sm_ArgList[1].wa_Lock); - dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[1].wa_Name); - CurrentDir(olddir); - } - if (dop != 0 && (cp = (char *)FindToolType((UBYTE **)dop->do_ToolTypes, - (UBYTE *)"WINDOW")) != NULL) - ; - else /* Could not find a WINDOW tool type */ - cp = "CON:10/10/480/160/Arun:Default Window/CLOSE"; - if ((window = Open((UBYTE *)cp, (long)MODE_OLDFILE))) { - fhp = (struct FileHandle *) ((long)window << 2); - SetConsoleTask(fhp->fh_Type); - SelectInput(window); - SelectOutput(window); - __stdfiledes[0] = Input(); - __stdfiledes[1] = Output(); - } else - exit(-1L); - FreeDiskObject(dop); } -#endif -#endif void args(int argc, char * argv[]) { char *prgnam; -#ifdef __mac__ -#include <console.h> -#ifdef __MWERKS__ -#include <SIOUX.h> -#endif - short msg, files; - static char advbuf[256], prgbuf[256]; - /*AppFile af;*/ - OSErr oe; - -#ifdef __MWERKS__ - /*SIOUXSettings.setupmenus = FALSE;*/ - SIOUXSettings.autocloseonquit = FALSE; - SIOUXSettings.asktosaveonclose = FALSE; - SIOUXSettings.showstatusline = FALSE; -#endif - - GetMacArgs(advbuf); - advnam = advbuf; - -#else -#ifdef __amiga__ - - if (argc == 0) { /* If started from Workbench get WbArgs : Aztec C & GG GCC */ - struct WBStartup *WBstart; - - if ((IconBase = OpenLibrary("icon.library", 0)) == NULL) - syserr("Could not open 'icon.library'"); - /* If started from WB normal main is called with argc == 0 and argv = WBstartup message */ - WBstart = (struct WBStartup *)argv; -#ifndef AZTEC_C - /* Geek Gadgets GCC */ - wb_parse(); -#endif - advnam = prgnam = WBstart->sm_ArgList[0].wa_Name; - if (WBstart->sm_NumArgs > 0) { - cd = CurrentDir(DupLock(WBstart->sm_ArgList[1].wa_Lock)); - advnam = WBstart->sm_ArgList[1].wa_Name; - } - /* Possibly other tooltypes ... */ - } else { - /* Started from a CLI */ - if ((prgnam = strrchr(argv[0], '/')) == NULL - && (prgnam = strrchr(argv[0], ':')) == NULL) - prgnam = argv[0]; - else - prgnam++; - /* Now look at the switches and arguments */ - switches(argc, argv); - if (advnam[0] == '\0') - /* No game given, try program name */ - if (stricmp(prgnam, PROGNAME) != 0 - && strstr(prgnam, PROGNAME) == 0) - advnam = strdup(argv[0]); - } -#else -#if defined(__dos__) || defined(__win__) if ((prgnam = strrchr(argv[0], '\\')) == NULL && (prgnam = strrchr(argv[0], '/')) == NULL && (prgnam = strrchr(argv[0], ':')) == NULL) @@ -240,49 +53,6 @@ void args(int argc, char * argv[]) { if (stricmp(prgnam, PROGNAME) != 0 && strstr(prgnam, PROGNAME) == 0) advnam = strdup(argv[0]); -#else -#if defined __vms__ - if ((prgnam = strrchr(argv[0], ']')) == NULL - && (prgnam = strrchr(argv[0], '>')) == NULL - && (prgnam = strrchr(argv[0], ':')) == NULL) - prgnam = argv[0]; - else - prgnam++; - if (strrchr(prgnam, ';') != NULL) - *strrchr(prgnam, ';') = '\0'; - if (strlen(prgnam) > 4 - && (strcmp(&prgnam[strlen(prgnam)-4], ".EXE") == 0 - || strcmp(&prgnam[strlen(prgnam)-4], ".exe") == 0)) - prgnam[strlen(prgnam)-4] = '\0'; - /* Now look at the switches and arguments */ - switches(argc, argv); - if (advnam[0] == '\0') - /* No game given, try program name */ - if (strcmp(prgnam, PROGNAME) != 0 - && strstr(prgnam, PROGNAME) == 0) - advnam = strdup(argv[0]); -#else -#if defined(__unix__) || defined(__APPLE__) - if ((prgnam = strrchr(argv[0], '/')) == NULL) - prgnam = strdup(argv[0]); - else - prgnam = strdup(&prgnam[1]); - if (strrchr(prgnam, ';') != NULL) - *strrchr(prgnam, ';') = '\0'; - /* Now look at the switches and arguments */ - switches(argc, argv); - if (advnam[0] == '\0') - /* No game given, try program name */ - if (strcmp(prgnam, PROGNAME) != 0 - && strstr(prgnam, PROGNAME) == 0) - advnam = strdup(argv[0]); -#else - Unimplemented OS! -#endif -#endif -#endif -#endif -#endif } } // End of namespace Alan2 diff --git a/engines/glk/alan2/args.h b/engines/glk/alan2/args.h index dc2f0883a5..6eb32459c9 100644 --- a/engines/glk/alan2/args.h +++ b/engines/glk/alan2/args.h @@ -34,9 +34,7 @@ namespace Glk { namespace Alan2 { -#ifndef PROGNAME #define PROGNAME "alan2" -#endif extern void args(int argc, char *argv[]); diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp index 785cd54cbc..3c67fbe109 100644 --- a/engines/glk/alan2/debug.cpp +++ b/engines/glk/alan2/debug.cpp @@ -21,26 +21,15 @@ */ #include "glk/alan2/types.h" -#ifdef HAVE_SHORT_FILENAMES -#include "glk/alan2/av.h" -#else #include "glk/alan2/alan_version.h" -#endif - -#ifdef USE_READLINE -#include "glk/alan2/readline.h" -#endif - +#include "glk/alan2/debug.h" +#include "glk/alan2/exe.h" +#include "glk/alan2/glkio.h" #include "glk/alan2/inter.h" #include "glk/alan2/main.h" #include "glk/alan2/parse.h" -#include "glk/alan2/exe.h" - -#include "glk/alan2/debug.h" +#include "glk/alan2/readline.h" -#ifdef GLK -#include "glk/alan2/glkio.h" -#endif namespace Glk { namespace Alan2 { @@ -55,9 +44,6 @@ static void showatrs(Aword atradr) { i = 1; for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) { sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr)); -#if ISO == 0 - fromIso(str, str); -#endif output(str); i++; } @@ -258,9 +244,6 @@ static void showevts() { output("EVENTS:"); for (evt = EVTMIN; evt <= EVTMAX; evt++) { sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt-EVTMIN].stradr)); -#if ISO == 0 - fromIso(str, str); -#endif output(str); scheduled = FALSE; for (i = 0; i < etop; i++) @@ -304,11 +287,8 @@ void debug() { para(); do { output("ABUG> "); -#ifdef USE_READLINE - (void) readline(buf); -#else - fgets(buf, 255, stdin); -#endif + (void)readline(buf); + lin = 1; c = buf[0]; i = 0; diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp index d91c3aafc7..3cd16d8721 100644 --- a/engines/glk/alan2/exe.cpp +++ b/engines/glk/alan2/exe.cpp @@ -20,21 +20,16 @@ * */ -#include "glk/alan2/types.h" #include "glk/alan2/alan2.h" - -#ifdef USE_READLINE -#include "glk/alan2/readline.h" -#endif - +#include "glk/alan2/types.h" +#include "glk/alan2/exe.h" +#include "glk/alan2/inter.h" #include "glk/alan2/main.h" #include "glk/alan2/parse.h" -#include "glk/alan2/inter.h" +#include "glk/alan2/readline.h" #include "glk/alan2/stack.h" #include "glk/alan2/decode.h" -#include "glk/alan2/exe.h" - namespace Glk { namespace Alan2 { @@ -97,9 +92,6 @@ void print(Aword fpos, Aword len) { str[i] = ch; } str[i] = '\0'; -#if ISO == 0 - fromIso(str, str); -#endif output(str); } /* And restore */ @@ -168,11 +160,7 @@ Boolean confirm(MsgKind msgno) { it could be affirmative, but for now any input is NOT! */ prmsg(msgno); -#ifdef USE_READLINE if (!readline(buf)) return TRUE; -#else - if (gets(buf) == NULL) return TRUE; -#endif col = 1; return (buf[0] == '\0'); @@ -187,11 +175,8 @@ void quit() { col = 1; statusline(); prmsg(M_QUITACTION); -#ifdef USE_READLINE if (!readline(buf)) terminate(0); -#else - if (gets(buf) == NULL) terminate(0); -#endif + if (strcmp(buf, "restart") == 0) //longjmp(restart_label, TRUE); ::error("TODO: restart"); @@ -1082,95 +1067,10 @@ static char savfnm[256]; */ -#ifdef GARGLK void save() { g_vm->saveGame(); } -#else - -void save() { - int i; - char str[256]; - AtrElem *atr; - FILE *savfil; - - /* First save ? */ - if (savfnm[0] == '\0') { - strcpy(savfnm, advnam); - strcat(savfnm, ".sav"); - } - prmsg(M_SAVEWHERE); - sprintf(str, "(%s) : ", savfnm); - output(str); - -#ifdef USE_READLINE - readline(str); -#else - gets(str); -#endif - -frefid_t fref; -fref = g_vm->glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Write, 0); -if (fref == NULL) - error(M_SAVEFAILED); -strcpy(str, g_vm->garglk_fileref_get_name(fref)); -g_vm->glk_fileref_destroy(fref); - - if (str[0] == '\0') - strcpy(str, savfnm); - col = 1; - if ((savfil = fopen(str, READ_MODE)) != NULL) - /* It already existed */ - if (!confirm(M_SAVEOVERWRITE)) - error(MSGMAX); /* Return to player without saying anything */ - if ((savfil = fopen(str, WRITE_MODE)) == NULL) - error(M_SAVEFAILED); - strcpy(savfnm, str); - - /* Save version of interpreter and name of game */ - fwrite((void *)&header->vers, sizeof(Aword), 1, savfil); - fwrite((void *)advnam, strlen(advnam)+1, 1, savfil); - /* Save current values */ - fwrite((void *)&cur, sizeof(cur), 1, savfil); - /* Save actors */ - for (i = ACTMIN; i <= ACTMAX; i++) { - fwrite((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil); - fwrite((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil); - fwrite((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil); - fwrite((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil); - if (acts[i-ACTMIN].atrs) - for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++) - fwrite((void *)&atr->val, sizeof(Aword), 1, savfil); - } - - /* Save locations */ - for (i = LOCMIN; i <= LOCMAX; i++) { - fwrite((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil); - if (locs[i-LOCMIN].atrs) - for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++) - fwrite((void *)&atr->val, sizeof(Aword), 1, savfil); - } - - /* Save objects */ - for (i = OBJMIN; i <= OBJMAX; i++) { - fwrite((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil); - if (objs[i-OBJMIN].atrs) - for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++) - fwrite((void *)&atr->val, sizeof(atr->val), 1, savfil); - } - - /* Save the event queue */ - eventq[etop].time = 0; /* Mark the top */ - fwrite((void *)&eventq[0], sizeof(eventq[0]), etop+1, savfil); - - /* Save scores */ - for (i = 0; scores[i] != EOF; i++) - fwrite((void *)&scores[i], sizeof(Aword), 1, savfil); - - fclose(savfil); -} -#endif /*---------------------------------------------------------------------- @@ -1178,104 +1078,10 @@ g_vm->glk_fileref_destroy(fref); */ -#ifdef GARGLK void restore() { g_vm->loadGame(); } -#else - -void restore() { - int i,tmp; - FILE *savfil; - char str[256]; - AtrElem *atr; - char savedVersion[4]; - char savedName[256]; - - /* First save ? */ - if (savfnm[0] == '\0') { - strcpy(savfnm, advnam); - strcat(savfnm, ".sav"); - } - prmsg(M_RESTOREFROM); - sprintf(str, "(%s) : ", savfnm); - output(str); -#ifdef USE_READLINE - readline(str); -#else - gets(str); -#endif - - if (str[0] == '\0') - strcpy(str, savfnm); - col = 1; - if (str[0] == '\0') - strcpy(str, savfnm); /* Use the name temporarily */ - if ((savfil = fopen(str, READ_MODE)) == NULL) - error(M_SAVEMISSING); - strcpy(savfnm, str); /* Save it for future use */ - - tmp = fread((void *)&savedVersion, sizeof(Aword), 1, savfil); - /* 4f - save file version check doesn't seem to work on PC's! */ - if (strncmp(savedVersion, header->vers, 4)) { - fclose(savfil); - error(M_SAVEVERS); - return; - } - i = 0; - while ((savedName[i++] = fgetc(savfil)) != '\0'); - if (strcmp(savedName, advnam) != 0) { - fclose(savfil); - error(M_SAVENAME); - return; - } - - /* Restore current values */ - tmp = fread((void *)&cur, sizeof(cur), 1, savfil); - /* Restore actors */ - for (i = ACTMIN; i <= ACTMAX; i++) { - tmp = fread((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil); - tmp = fread((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil); - tmp = fread((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil); - tmp = fread((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil); - if (acts[i-ACTMIN].atrs) - for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++) - tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil); - } - - /* Restore locations */ - for (i = LOCMIN; i <= LOCMAX; i++) { - tmp = fread((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil); - if (locs[i-LOCMIN].atrs) - for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++) - tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil); - } - - /* Restore objects */ - for (i = OBJMIN; i <= OBJMAX; i++) { - tmp = fread((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil); - if (objs[i-OBJMIN].atrs) - for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++) - tmp = fread((void *)&atr->val, sizeof(atr->val), 1, savfil); - } - - /* Restore the eventq */ - etop = 0; - do { - tmp = fread((void *)&eventq[etop], sizeof(eventq[0]), 1, savfil); - etop++; - } while (eventq[etop-1].time != 0); - etop--; - - /* Restore scores */ - for (i = 0; scores[i] != EOF; i++) - tmp = fread((void *)&scores[i], sizeof(Aword), 1, savfil); - - fclose(savfil); -} - -#endif /*---------------------------------------------------------------------- diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp index 1d52b74acc..5e2827f482 100644 --- a/engines/glk/alan2/inter.cpp +++ b/engines/glk/alan2/inter.cpp @@ -22,18 +22,14 @@ #include <string> #include "glk/alan2/types.h" +#include "glk/alan2/exe.h" +#include "glk/alan2/inter.h" +#include "glk/alan2/glkio.h" #include "glk/alan2/main.h" #include "glk/alan2/parse.h" -#include "glk/alan2/exe.h" #include "glk/alan2/stack.h" #include "glk/alan2/sysdep.h" -#include "glk/alan2/inter.h" - -#ifdef GLK -#include "glk/alan2/glkio.h" -#endif - namespace Glk { namespace Alan2 { diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp index 7f1aa8da05..6b06e0bd80 100644 --- a/engines/glk/alan2/main.cpp +++ b/engines/glk/alan2/main.cpp @@ -22,39 +22,22 @@ #define V27COMPATIBLE -#include "glk/alan2/sysdep.h" - -#include "glk/alan2/types.h" -#include "glk/alan2/main.h" - -//#include <time.h> -#ifdef USE_READLINE -#include "glk/alan2/readline.h" -#endif - -#ifdef HAVE_SHORT_FILENAMES -#include "glk/alan2/av.h" -#else +#include "glk/alan2/alan2.h" #include "glk/alan2/alan_version.h" -#endif - #include "glk/alan2/args.h" -#include "glk/alan2/parse.h" +#include "glk/alan2/debug.h" +#include "glk/alan2/exe.h" +#include "glk/alan2/glkio.h" #include "glk/alan2/inter.h" -#include "glk/alan2/rules.h" -#ifdef REVERSED +#include "glk/alan2/main.h" +#include "glk/alan2/parse.h" #include "glk/alan2/reverse.h" -#endif -#include "glk/alan2/debug.h" +#include "glk/alan2/rules.h" #include "glk/alan2/stack.h" -#include "glk/alan2/exe.h" +#include "glk/alan2/sysdep.h" +#include "glk/alan2/types.h" #include "glk/alan2/term.h" - -#ifdef GLK #include "common/file.h" -#include "glk/alan2/alan2.h" -#include "glk/alan2/glkio.h" -#endif namespace Glk { namespace Alan2 { @@ -132,45 +115,12 @@ Boolean skipsp = FALSE; */ void terminate(int code) { -#ifdef __amiga__ -#ifdef AZTEC_C -#include <fcntl.h> - extern struct _dev *_devtab; - char buf[85]; - - if (con) { /* Running from WB, created a console so kill it */ - /* Running from WB, so we created a console and - hacked the Aztec C device table to use it for all I/O - so now we need to make it close it (once!) */ - _devtab[1].fd = _devtab[2].fd = 0; - } else -#else - /* Geek Gadgets GCC */ -#include <workbench/startup.h> -#include <clib/dos_protos.h> -#include <clib/intuition_protos.h> - - if (_WBenchMsg != NULL) { - Close(window); - if (_WBenchMsg->sm_ArgList != NULL) - UnLock(CurrentDir(cd)); - } else -#endif -#endif newline(); free(memory); if (logflg) fclose(logfil); -#ifdef __MWERKS__ - printf("Command-Q to close window."); -#endif - -#ifdef GLK g_vm->glk_exit(); -#else - exit(code); -#endif } /*====================================================================== @@ -182,9 +132,8 @@ void usage() { printf("Usage:\n\n"); printf(" %s [<switches>] <adventure>\n\n", PROGNAME); printf("where the possible optional switches are:\n"); -#ifdef GLK g_vm->glk_set_style(style_Preformatted); -#endif + printf(" -v verbose mode\n"); printf(" -l log player commands and game output to a file\n"); printf(" -i ignore version and checksum errors\n"); @@ -192,9 +141,7 @@ void usage() { printf(" -d enter debug mode\n"); printf(" -t trace game execution\n"); printf(" -s single instruction trace\n"); -#ifdef GLK g_vm->glk_set_style(style_Normal); -#endif } @@ -206,34 +153,7 @@ void usage() { */ void syserr(const char *str) { -#ifdef GLK ::error("%s", str); -#else - output("$n$nAs you enter the twilight zone of Adventures, you stumble \ -and fall to your knees. In front of you, you can vaguely see the outlines \ -of an Adventure that never was.$n$nSYSTEM ERROR: "); - output(str); - output("$n$n"); - - if (logflg) - fclose(logfil); - newline(); - -#ifdef __amiga__ -#ifdef AZTEC_C - { - char buf[80]; - - if (con) { /* Running from WB, wait for user ack. */ - printf("press RETURN to quit"); - gets(buf); - } - } -#endif -#endif - - terminate(0); -#endif } @@ -263,7 +183,6 @@ void error(MsgKind msgno /* IN - The error message number */) { */ void statusline() { -#ifdef GLK uint glkWidth; char line[100]; int pcol = col; @@ -295,31 +214,6 @@ needsp = FALSE; col = pcol; g_vm->glk_set_window(glkMainWin); -#else -#ifdef HAVE_ANSI - char line[100]; - int i; - int pcol = col; - - if (!statusflg) return; - /* ansi_position(1,1); ansi_bold_on(); */ - printf("\x1b[1;1H"); - printf("\x1b[7m"); - col = 1; - say(where(HERO)); - if (header->maxscore > 0) - sprintf(line, "Score %ld(%ld)/%ld moves", cur.score, (int)header->maxscore, cur.tick); - else - sprintf(line, "%ld moves", cur.tick); - for (i=0; i < pagwidth - col - strlen(line); i++) putchar(' '); - printf(line); - printf("\x1b[m"); - printf("\x1b[%d;1H", paglen); - needsp = FALSE; - - col = pcol; -#endif -#endif } @@ -345,29 +239,7 @@ void logprint(char str[]) { */ void newline() { -#ifdef GLK g_vm->glk_put_char('\n'); -#else - char buf[256]; - - col = 1; - if (lin >= paglen - 1) { - logprint("\n"); - needsp = FALSE; - prmsg(M_MORE); -#ifdef USE_READLINE - (void) readline(buf); -#else - fgets(buf, 256, stdin); -#endif - getPageSize(); - lin = 0; - } else - logprint("\n"); - - lin++; - needsp = FALSE; -#endif } @@ -393,15 +265,7 @@ void para() { */ void clear() { -#ifdef GLK g_vm->glk_window_clear(glkMainWin); -#else -#ifdef HAVE_ANSI - if (!statusflg) return; - printf("\x1b[2J"); - printf("\x1b[%d;1H", paglen); -#endif -#endif } @@ -430,37 +294,7 @@ void *allocate(unsigned long len /* IN - Length to allocate */) { */ static void just(char str[]) { -#ifdef GLK logprint(str); -#else - int i; - char ch; - - if (col >= pagwidth && !skipsp) - newline(); - - while (strlen(str) > pagwidth - col) { - i = pagwidth - col - 1; - while (!isSpace(str[i]) && i > 0) /* First find wrap point */ - i--; - if (i == 0 && col == 1) /* If it doesn't fit at all */ - /* Wrap immediately after this word */ - while (!isSpace(str[i]) && str[i] != '\0') - i++; - if (i > 0) { /* If it fits ... */ - ch = str[i]; /* Save space or NULL */ - str[i] = '\0'; /* Terminate string */ - logprint(str); /* and print it */ - skipsp = FALSE; /* If skipping, now we're done */ - str[i] = ch; /* Restore character */ - /* Skip white after printed portion */ - for (str = &str[i]; isSpace(str[0]) && str[0] != '\0'; str++); - } - newline(); /* Then start a new line */ - } - logprint(str); /* Print tail */ - col = col + strlen(str); /* Update column */ -#endif } @@ -712,46 +546,6 @@ Boolean exitto(int to, int from) { } -#ifdef CHECKOBJ -/*====================================================================== - - checkobj() - - Check that the object given is valid, else print an error message - or find out what he wanted. - - This routine is not used any longer, kept for sentimental reasons ;-) - - */ -void checkobj(obj) - Aword *obj; -{ - Aword oldobj; - - if (*obj != EOF) - return; - - oldobj = EOF; - for (cur.obj = OBJMIN; cur.obj <= OBJMAX; cur.obj++) { - /* If an object is present and it is possible to perform his action */ - if (isHere(cur.obj) && possible()) - if (oldobj == EOF) - oldobj = cur.obj; - else - error(WANT); /* And we didn't find multiple objects */ - } - - if (oldobj == EOF) - error(WANT); /* But we found ONE */ - - *obj = cur.obj = oldobj; - output("($o)"); /* Then he surely meant this object */ -} -#endif - - - - /*---------------------------------------------------------------------- count() @@ -1326,9 +1120,6 @@ static void load() { crc += (memory[i]>>8)&0xff; crc += (memory[i]>>16)&0xff; crc += (memory[i]>>24)&0xff; -#ifdef CRCLOG - printf("%6x\t%6lx\t%6lx\n", i, crc, memory[i]); -#endif } if (crc != tmphdr.acdcrc) { sprintf(err, "Checksum error in .ACD file (0x%lx instead of 0x%lx).", @@ -1379,13 +1170,6 @@ static void checkdebug() { trcflg = FALSE; stpflg = FALSE; } - -#ifndef GLK - if (dbgflg) /* If debugging */ - srand(0); /* use no randomization */ - else - srand(time(0)); /* seed random generator */ -#endif } @@ -1590,26 +1374,11 @@ static void openFiles() { char *usr = ""; time_t tick; -#ifndef GLK - /* Open Acode file */ - strcpy(codfnm, advnam); - strcat(codfnm, ".acd"); - - if ((codfil = fopen(codfnm, READ_MODE)) == NULL) { - strcpy(str, "Can't open adventure code file '"); - strcat(str, codfnm); - strcat(str, "'."); - syserr(str); - } -#endif - -#ifdef GARGLK { char *s = strrchr(codfnm, '\\'); if (!s) s = strrchr(codfnm, '/'); g_vm->garglk_set_story_name(s ? s + 1 : codfnm); } -#endif /* Open Text file */ strcpy(txtfnm, advnam); @@ -1650,9 +1419,6 @@ void run() { init(); /* Load, initialise and start the adventure */ while (TRUE) { -#ifdef MALLOC - if (malloc_verify() == 0) syserr("Error in heap."); -#endif if (dbgflg) debug(); diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp index a399605107..d83755bada 100644 --- a/engines/glk/alan2/parse.cpp +++ b/engines/glk/alan2/parse.cpp @@ -22,24 +22,16 @@ #include <string> #include "glk/alan2/alan2.h" -#include "glk/alan2/types.h" - -#ifdef USE_READLINE -#include "glk/alan2/readline.h" -#endif - -#include "glk/alan2/main.h" -#include "glk/alan2/inter.h" -#include "glk/alan2/exe.h" -#include "glk/alan2/term.h" #include "glk/alan2/debug.h" +#include "glk/alan2/exe.h" +#include "glk/alan2/glkio.h" +#include "glk/alan2/inter.h" +#include "glk/alan2/main.h" #include "glk/alan2/params.h" - #include "glk/alan2/parse.h" - -#ifdef GLK -#include "glk/alan2/glkio.h" -#endif +#include "glk/alan2/readline.h" +#include "glk/alan2/term.h" +#include "glk/alan2/types.h" namespace Glk { namespace Alan2 { @@ -103,9 +95,6 @@ static void unknown(char token[]) { str[0] = '\''; strcpy(&str[1], token); strcat(str, "'?"); -#if ISO == 0 - fromIso(str, str); -#endif output(str); free(str); eol = TRUE; @@ -164,13 +153,12 @@ static char *gettoken(char *buf) { static void agetline() { para(); do { -#if defined(HAVE_ANSI) || defined(GLK) statusline(); -#endif + printf("> "); if (logflg) fprintf(logfil, "> "); -#ifdef USE_READLINE + if (!readline(buf)) { if (g_vm->shouldQuit()) return; @@ -178,25 +166,13 @@ static void agetline() { newline(); quit(); } -#else - if (fgets(buf, LISTLEN, stdin) == NULL) { - newline(); - quit(); - } -#endif + getPageSize(); anyOutput = FALSE; if (logflg) -#ifndef __amiga__ fprintf(logfil, "%s\n", buf); -#else - fprintf(logfil, "%s", buf); -#endif -#if ISO == 0 - toIso(isobuf, buf, NATIVECHARSET); -#else strcpy(isobuf, buf); -#endif + token = gettoken(isobuf); if (token != NULL && strcmp("debug", token) == 0 && header->debug) { dbgflg = TRUE; diff --git a/engines/glk/alan2/readline.cpp b/engines/glk/alan2/readline.cpp index 5f1192df5a..7569721f22 100644 --- a/engines/glk/alan2/readline.cpp +++ b/engines/glk/alan2/readline.cpp @@ -20,14 +20,11 @@ * */ -#include "glk/alan2/types.h" - -#ifdef GLK - #include "glk/alan2/alan2.h" -#include "glk/alan2/readline.h" -#include "glk/alan2/main.h" +#include "glk/alan2/types.h" #include "glk/alan2/glkio.h" +#include "glk/alan2/main.h" +#include "glk/alan2/readline.h" namespace Glk { namespace Alan2 { @@ -65,500 +62,3 @@ Boolean readline(char usrbuf[]) } // End of namespace Alan2 } // End of namespace Glk -#else - -#include "glk/alan2/sysdep.h" - -#ifdef HAVE_TERMIO -#include <termios.h> -#endif - -#ifdef __PACIFIC__ -#include <unixio.h> -#else -//#include <unistd.h> -#endif - -#include "glk/alan2/readline.h" - -#include "glk/alan2/main.h" - -namespace Glk { -namespace Alan2 { - -#ifdef HAVE_TERMIO -/*----------------------------------------------------------------------*\ - - termio handling - -\*----------------------------------------------------------------------*/ - -static struct termios term; - -static void newtermio() -{ - struct termios newterm; - tcgetattr(0, &term); - newterm=term; - newterm.c_lflag&=~(ECHO|ICANON); - newterm.c_cc[VMIN]=1; - newterm.c_cc[VTIME]=0; - tcsetattr(0, TCSANOW, &newterm); -} - -static void restoretermio() -{ - tcsetattr(0, TCSANOW, &term); -} - -#endif - - -/*----------------------------------------------------------------------*\ - - Global character buffers etc. - -\*----------------------------------------------------------------------*/ - -static unsigned char buffer[LINELENGTH+1]; -static int bufidx; - -static unsigned char *history[HISTORYLENGTH]; -static int histidx; /* Index where to store next history */ -static int histp; /* Points to the history recalled last */ - -static unsigned char ch; -static int endOfInput = 0; -static Boolean change; -static Boolean insert = TRUE; - - -/*----------------------------------------------------------------------*\ - - Character map types and maps - -\*----------------------------------------------------------------------*/ - -typedef struct {unsigned char min, max; void (*hook)(char ch);} KeyMap; - -/* Forward declaration of hooks */ -static void escHook(char ch); -static void insertCh(char ch); -static void arrowHook(char ch); -static void upArrow(char ch); -static void downArrow(char ch); -static void rightArrow(char ch); -static void leftArrow(char ch); -static void insertToggle(char ch); -static void newLine(char ch); -static void delFwd(char ch); -static void delBwd(char ch); - -#ifdef __XXunix__ -static KeyMap keymap[] = { - {0x00, 0x07, NULL}, - {0x08, 0x08, delBwd}, - {0x09, 0x09, NULL}, - {0x0a, 0x0a, newLine}, - {0x1b, 0x1b, escHook}, - {0x1c, 0x7e, insertCh}, - {0x7f, 0x7f, delFwd}, - {0x80, 0xff, insertCh}, - {0x00, 0x00, NULL} -}; - -/* I can't figure out what really coverns the esc-map characters... */ -#ifdef __solarisX__ -static KeyMap escmap[] = { - {0x00, 0x4e, NULL}, - {0x4f, 0x4f, arrowHook}, - {0x50, 0xff, NULL}, - {0x00, 0x00, NULL} -}; -#else -static KeyMap escmap[] = { - {0x00, 0x5a, NULL}, - {0x5b, 0x5b, arrowHook}, - {0x5c, 0xff, NULL}, - {0x00, 0x00, NULL} -}; -#endif - -static KeyMap arrowmap[] = { - {0x00, 0x31, NULL}, - {0x32, 0x32, insertToggle}, - {0x33, 0x40, NULL}, - {0x41, 0x41, upArrow}, - {0x42, 0x42, downArrow}, - {0x43, 0x43, rightArrow}, - {0x44, 0x44, leftArrow}, - {0x45, 0xff, NULL}, - {0x00, 0x00, NULL} -}; - -#endif - -#ifdef __win__ -static KeyMap keymap[] = { - {0x00, 0x01, NULL}, - {0x02, 0x02, leftArrow}, - {0x03, 0x05, NULL}, - {0x06, 0x06, rightArrow}, - {0x07, 0x07, NULL}, - {0x08, 0x08, delBwd}, - {0x09, 0x09, NULL}, - {0x0a, 0x0a, newLine}, - {0x1b, 0x1b, escHook}, - {0x1c, 0x7e, insertCh}, - {0x7f, 0x7f, delFwd}, - {0x80, 0xff, insertCh}, - {0x00, 0x00, NULL} -}; - -static KeyMap escmap[] = { - {0x00, 0x5a, NULL}, - {0x5b, 0x5b, arrowHook}, - {0x5c, 0xff, NULL}, - {0x00, 0x00, NULL} -}; - -static KeyMap arrowmap[] = { - {0x00, 0x31, NULL}, - {0x32, 0x32, insertToggle}, - {0x33, 0x40, NULL}, - {0x41, 0x41, upArrow}, - {0x42, 0x42, downArrow}, - {0x43, 0x43, rightArrow}, - {0x44, 0x44, leftArrow}, - {0x45, 0xff, NULL}, - {0x00, 0x00, NULL} -}; - -#endif - -#ifdef __dos__ -static KeyMap keymap[] = { - {0x00, 0x01, NULL}, - {0x02, 0x02, leftArrow}, - {0x03, 0x05, NULL}, - {0x06, 0x06, rightArrow}, - {0x07, 0x07, NULL}, - {0x08, 0x08, delBwd}, - {0x09, 0x09, NULL}, - {0x0a, 0x0a, newLine}, - {0x1b, 0x1b, escHook}, - {0x1c, 0x7e, insertCh}, - {0x7f, 0x7f, delFwd}, - {0x80, 0xff, insertCh}, - {0x00, 0x00, NULL} -}; - -static KeyMap escmap[] = { - {0x00, 0x5a, NULL}, - {0x5b, 0x5b, arrowHook}, - {0x5c, 0xff, NULL}, - {0x00, 0x00, NULL} -}; - -static KeyMap arrowmap[] = { - {0x00, 0x31, NULL}, - {0x32, 0x32, insertToggle}, - {0x33, 0x40, NULL}, - {0x41, 0x41, upArrow}, - {0x42, 0x42, downArrow}, - {0x43, 0x43, rightArrow}, - {0x44, 0x44, leftArrow}, - {0x45, 0xff, NULL}, - {0x00, 0x00, NULL} -}; - -#endif - - -static void doBeep(void) -{ - write(1, "\7", 1); -} - - -static void backspace(void) -{ - write(1, "\b", 1); -} - - -static void erase() -{ - int i; - - for (i = 0; i < bufidx; i++) backspace(); /* Backup to beginning of text */ - for (i = 0; i < strlen((char *)buffer); i++) write(1, " ", 1); /* Erase all text */ - for (i = 0; i < strlen((char *)buffer); i++) backspace(); /* Backup to beginning of text */ -} - -/*----------------------------------------------------------------------*\ - - Character handling hook functions - -\*----------------------------------------------------------------------*/ - -static void execute(KeyMap map[], unsigned char ch) -{ - int i = 0; - - for (i = 0; i <= 256; i++) { - if (i > 0 && map[i].min == 0x00) break; /* End marker is a 0,0,NULL */ - if (map[i].min <= ch && ch <= map[i].max) { - if (map[i].hook != NULL) { - map[i].hook(ch); - return; - } else - doBeep(); - } - } - doBeep(); -} - - -static void upArrow(char ch) -{ - /* Is there more history ? */ - if (history[(histp+HISTORYLENGTH-1)%HISTORYLENGTH] == NULL || - (histp+HISTORYLENGTH-1)%HISTORYLENGTH == histidx) { - write(1, "\7", 1); - return; - } - - erase(); - - /* Backup history pointer */ - histp = (histp+HISTORYLENGTH-1)%HISTORYLENGTH; - - /* Copy the history and write it */ - strcpy((char *)buffer, (char *)history[histp]); - bufidx = strlen((char *)buffer); - write(1, (void *)buffer, strlen((char *)buffer)); - -} - - -static void downArrow(char ch) -{ - /* Is there more history ? */ - if (histp == histidx) { - write(1, "\7", 1); - return; - } - - erase(); - - /* Advance history pointer */ - histp = (histp+1)%HISTORYLENGTH; - - /* If we are not at the most recent history entry, copy the history and write it */ - if (histp != histidx) { - strcpy((char *)buffer, (char *)history[histp]); - bufidx = strlen((char *)buffer); - write(1, (void *)buffer, strlen((char *)buffer)); - } else { - bufidx = 0; - buffer[0] = '\0'; - } -} - - -static void rightArrow(char ch) -{ - if (bufidx > LINELENGTH || buffer[bufidx] == '\0') - doBeep(); - else { - write(1, (void *)&buffer[bufidx], 1); - bufidx++; - } -} - - -static void leftArrow(char ch) -{ - if (bufidx == 0) - doBeep(); - else { - bufidx--; - backspace(); - } -} - - -static void insertToggle(char ch) -{ - read(0, &ch, 1); - if (ch != 'z') - doBeep(); - else - insert = !insert; -} - - -static void delBwd(char ch) -{ - if (bufidx == 0) - doBeep(); - else { - int i; - - change = TRUE; - backspace(); - bufidx--; - for (i = 0; i <= strlen((char *)&buffer[bufidx+1]); i++) - buffer[bufidx+i] = buffer[bufidx+1+i]; - write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx])); - write(1, " ", 1); - for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace(); - } -} - -static void delFwd(char ch) -{ - if (bufidx > LINELENGTH || buffer[bufidx] == '\0') - doBeep(); - else { - int i; - - change = TRUE; - strcpy((char *)&buffer[bufidx], (char *)&buffer[bufidx+1]); - write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx])); - write(1, " ", 1); - for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace(); - } -} - -static void escHook(char ch) { - read(0, &ch, 1); - execute(escmap, ch); -} - -static void arrowHook(char ch) { - read(0, &ch, 1); - execute(arrowmap, ch); -} - -static void newLine(char ch) -{ - endOfInput = 1; - write(1, "\n", 1); - - /* If the input is not the same as the previous, save it in the history */ - if (change && strlen((char *)buffer) > 0) { - if (history[histidx] == NULL) - history[histidx] = (unsigned char *)allocate(LINELENGTH+1); - strcpy((char *)history[histidx], (char *)buffer); - histidx = (histidx+1)%HISTORYLENGTH; - } -} - - -static void insertCh(char ch) { - if (bufidx > LINELENGTH) - doBeep(); - else { - /* If at end advance the NULL */ - if (buffer[bufidx] == '\0') - buffer[bufidx+1] = '\0'; - else if (insert) { - int i; - - /* If insert mode is on, move the characters ahead */ - for (i = strlen((char *)buffer); i >= bufidx; i--) - buffer[i+1] = buffer[i]; - write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx])); - for (i = strlen((char *)&buffer[bufidx]); i > 0; i--) backspace(); - } - change = TRUE; - buffer[bufidx] = ch; - write(1, &ch, 1); - bufidx++; - } -} - - -/*---------------------------------------------------------------------- - - echoOff() - - */ -static void echoOff() -{ -#ifdef HAVE_TERMIO - newtermio(); -#else -#ifdef __win__ -#include <windows.h> -#include <winbase.h> -#include <wincon.h> - - DWORD handle = GetStdHandle(STD_INPUT_HANDLE); - - (void) SetConsoleMode(handle, 0); - -#endif -#endif -} - - -/*---------------------------------------------------------------------- - - echoOn() - - */ -static void echoOn() -{ -#ifdef HAVE_TERMIO - restoretermio(); -#else -#ifdef __win__ -#include <windows.h> -#include <winbase.h> -#include <wincon.h> - - DWORD handle = GetStdHandle(STD_INPUT_HANDLE); - (void) SetConsoleMode(handle, ENABLE_ECHO_INPUT); - -#endif -#endif -} - - -/*====================================================================== - - readline() - - Read a line from the user, with history and editing - - */ - -/* 4f - length of user buffer should be used */ -Boolean readline(char usrbuf[]) -{ - fflush(stdout); - bufidx = 0; - histp = histidx; - buffer[0] = '\0'; - change = TRUE; - echoOff(); - endOfInput = 0; - while (!endOfInput) { - if (read(0, (void *)&ch, 1) != 1) { - echoOn(); - return FALSE; - } - execute(keymap, ch); - } - echoOn(); - strcpy(usrbuf, (char *)buffer); - return TRUE; -} - -} // End of namespace Alan2 -} // End of namespace Glk - -#endif diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp index b558b183b5..323f6e72a4 100644 --- a/engines/glk/alan2/rules.cpp +++ b/engines/glk/alan2/rules.cpp @@ -21,17 +21,13 @@ */ #include "glk/alan2/types.h" -#include "glk/alan2/main.h" -#include "glk/alan2/inter.h" #include "glk/alan2/debug.h" #include "glk/alan2/exe.h" -#include "glk/alan2/stack.h" - -#include "glk/alan2/rules.h" - -#ifdef GLK +#include "glk/alan2/inter.h" #include "glk/alan2/glkio.h" -#endif +#include "glk/alan2/main.h" +#include "glk/alan2/rules.h" +#include "glk/alan2/stack.h" namespace Glk { namespace Alan2 { diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp index 312518f879..74d4fc98c8 100644 --- a/engines/glk/alan2/sysdep.cpp +++ b/engines/glk/alan2/sysdep.cpp @@ -21,17 +21,15 @@ */ #include <string.h> -#include "glk/alan2/sysdep.h" - -#ifdef GLK #include "glk/alan2/alan2.h" -#endif +#include "glk/alan2/sysdep.h" namespace Glk { namespace Alan2 { -#ifdef GLK -extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) { +void syserr(char str[]); + +void fprintf(Common::WriteStream *ws, const char *fmt, ...) { va_list args; va_start(args, fmt); Common::String s = Common::String::vformat(fmt, args); @@ -39,64 +37,6 @@ extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) { ws->write(s.c_str(), s.size()); } -#endif - -extern void syserr(char str[]); - -#ifdef __vms__ - -char *strdup(char str[]) /* IN - String to duplicate */ -{ - char *new = (char *) malloc(strlen(str)+1); - - if (!new) - syserr("Out of memory"); - strcpy(new, str); - return new; -} - -#endif - - -#ifdef __mac__ - -char *strdup(char str[]) /* IN - String to duplicate */ -{ - char *new = (char *) malloc((size_t)((int)strlen(str)+1)); - - if (!new) - syserr("Out of memory"); - strcpy(new, str); - return new; -} - -#endif - - -#ifdef __vms__ - -/* Cheat implementation of strftime */ -size_t strftime ( - char *outbuf, - size_t len, - const char *format, - const struct tm *t) -{ - char buf[100]; - time_t ticks; - - time(&ticks); - strcpy(buf, ctime(&ticks)); - buf[strlen(buf)-1] = '\0'; - strcpy(outbuf, &buf[4]); -} - -#endif - -#ifdef __dos__ -#endif - -#ifdef GLK /* Note to Glk maintainers: 'native' characters are used for output, in this case, Glk's Latin-1. ISO characters are Alan's internal representation, @@ -172,28 +112,6 @@ static char uppChrs[] = '\x00' }; -#else - -/* Theses work on native character sets */ - -static char spcChrs[] = " \t\n"; - -#ifdef __amiga__ - -/* Which can't read 8-bit chars but is ISO */ -static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377"; - -static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337"; - -#else - -/* Use native characters */ -static char lowChrs[] = "abcdefghijklmnopqrstuvwxyzàáâãäåæçéêëìíîïðñòóôõöøùúûüýþÿ"; - -static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÛÝÞß"; - -#endif -#endif int isSpace(int c) /* IN - Native character to test */ { @@ -220,56 +138,12 @@ int isLetter(int c) /* IN - Native character to test */ int toLower(int c) /* IN - Native character to convert */ { -#ifdef GLK return g_vm->glk_char_to_lower(c); -#else -#ifdef __dos__ - char *cp; - - if ((cp = strchr(uppChrs, c)) != 0) - return(lowChrs[cp-uppChrs]); - else - return c; -#else -#ifdef __mac__ - char *cp; - - if ((cp = strchr(uppChrs, c)) != 0) - return(lowChrs[cp-uppChrs]); - else - return c; -#else - return (isUpper(c)? c + ('a' - 'A'): c); -#endif -#endif -#endif } int toUpper(int c) /* IN - Native character to convert */ { -#ifdef GLK return g_vm->glk_char_to_upper(c); -#else -#ifdef __dos__ - char *cp; - - if ((cp = strchr(lowChrs, c)) != 0) - return(uppChrs[cp-lowChrs]); - else - return c; -#else -#ifdef __mac__ - char *cp; - - if ((cp = strchr(lowChrs, c)) != 0) - return(uppChrs[cp-lowChrs]); - else - return c; -#else - return (isLower(c)? c - ('a' - 'A'): c); -#endif -#endif -#endif } char *strlow(char str[]) /* INOUT - Native string to convert */ @@ -427,57 +301,8 @@ static unsigned char dosMap[256] void fromIso(char copy[], /* OUT - Mapped string */ char original[]) /* IN - string to convert */ { -#if ISO == 0 - static unsigned char map[256] -#if defined __mac__ - = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, - 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, - 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, - 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, - 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, - 0xCA,0xC1,0xA2,0xA3,0xB0,0xB4,0xBA,0xA4,0xAC,0xA9,0xBB,0xC7,0xC2,0xD0,0xA8,0xD1, - 0xA1,0xB1,0xAA,0xD5,0xAB,0xB5,0xA6,0xA5,0xD4,0xA0,0xBC,0xC8,0xD9,0xDA,0xDB,0xC0, - 0xCB,0xDC,0xD7,0xCC,0x80,0x81,0xAE,0x82,0xC5,0x83,0xB7,0xC9,0xB3,0xB2,0xC3,0xC4, - 0xC6,0x84,0xDD,0xDE,0xBD,0xCD,0x85,0xAD,0xAF,0xD3,0xD2,0xDF,0x86,0xCE,0xB8,0xA7, - 0x88,0x87,0x89,0x8B,0x8A,0x8C,0xBE,0x8D,0x8F,0x8E,0x90,0x91,0x93,0x92,0x94,0x95, - 0xB6,0x96,0x98,0x97,0x99,0x9B,0x9A,0xD6,0xBF,0x9D,0x9C,0x9E,0x9F,0xCF,0xB9,0xD8} -#else -#if defined __dos__ - = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, - 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, - 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, - 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, - 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, - 0xFF,0xD0,0x9B,0x9C,0xE5,0x9D,0x9F,0xD1,0xF7,0xE0,0xA6,0xAE,0xFB,0xD2,0xE7,0xFA, - 0xF8,0xF1,0xFD,0xD3,0xFE,0xE6,0xE3,0xF9,0xD4,0xD5,0xA7,0xAF,0xAC,0xAB,0xF0,0xA8, - 0xA9,0xAA,0xEF,0xD6,0x8E,0x8F,0x92,0x80,0xE2,0x90,0xE4,0xEE,0xF5,0xF4,0xD7,0xAD, - 0xE9,0xA5,0xD8,0xD9,0xEA,0xE8,0x99,0xEC,0xED,0xF2,0xF3,0xDA,0x9A,0xDB,0x9E,0xE1, - 0x85,0xA0,0x83,0xDC,0x84,0x86,0x91,0x87,0x8A,0x82,0x88,0x89,0x8D,0xA1,0x8C,0x8B, - 0xEB,0xA4,0x95,0xA2,0x93,0xDD,0x94,0xF6,0xDE,0x97,0xA3,0x96,0x81,0xDF,0xFC,0x98} -#endif - ; -#endif - unsigned char *o, *c; - - for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++) - *c = map[*o]; - *c = '\0'; -#else if (copy != original) (void)strcpy(copy, original); -#endif } diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h index e58e538f20..7fce53c3e7 100644 --- a/engines/glk/alan2/sysdep.h +++ b/engines/glk/alan2/sysdep.h @@ -45,7 +45,6 @@ namespace Alan2 { #define GLK #define __win__ -#ifdef GLK #undef isdigit #define isdigit Common::isDigit #undef stricmp @@ -56,300 +55,13 @@ namespace Alan2 { #define rand() g_vm->getRandomNumber(0x7fffffff) #undef fprintf extern void fprintf(Common::WriteStream *ws, const char *fmt, ...); -#endif - -/* Place definitions of OS and compiler here if necessary */ -#ifdef AZTEC_C -#define __amiga__ -#endif - -#ifndef __sun__ -#ifdef sun -#define __sun__ -#endif -#endif - -#ifdef _INCLUDE_HPUX_SOURCE -#define __hp__ -#endif - -#ifndef __unix__ -#ifdef unix -#define __unix__ -#endif -#endif - -#ifdef vax -#define __vms__ -#endif - -#ifdef THINK_C -#define __mac__ -#endif - -#ifdef __MWERKS__ -#ifdef macintosh -#define __mac__ -#else -#define __dos__ -#endif -#endif - -#ifdef DOS -#define __dos__ -#endif - -#ifdef __BORLANDC__ -#define __dos__ -#endif - -#ifdef __CYGWIN__ -#define __win__ -#endif - -#ifdef __MINGW32__ -#define __win__ -#endif - -#ifdef __PACIFIC__ -#define __dos__ -#define HAVE_SHORT_FILENAMES -#endif - - -/*---------------------------------------------------------------------- - - Below follows OS and compiler dependent settings. They should not be - changed except for introducing new sections when porting to new - environments. - - */ - -/************/ -/* Includes */ -/************/ - -#ifndef GLK -#include <stdio.h> -#include <ctype.h> -#endif - -#ifdef __STDC__ -#include <stdlib.h> -#include <string.h> -#endif - -#ifdef __vms__ -/* Our VAXC doesn't define __STDC__ */ -#include <stdlib.h> -#include <string.h> -#endif - - -#ifdef __mac__ -#include <stdlib.h> -#include <string.h> -#include <unix.h> -#endif - -#ifdef __MWERKS__ -#define strdup _strdup -#endif /***********************/ -/* ISO character sets? */ -/***********************/ /* Common case first */ #define ISO 1 #define NATIVECHARSET 0 -#ifdef GLK -#undef ISO -#define ISO 1 -#undef NATIVECHARSET -#define NATIVECHARSET 0 -#else /* Glk is ISO, no matter what the OS */ - -#ifdef __dos__ -#undef ISO -#define ISO 0 -#undef NATIVECHARSET -#define NATIVECHARSET 2 -#endif - -#ifdef __win__ -#undef ISO -#define ISO 1 -#undef NATIVECHARSET -#define NATIVECHARSET 2 -#endif - -#ifdef __mac__ -#undef ISO -#define ISO 0 -#undef NATIVECHARSET -#define NATIVECHARSET 1 -#endif - -#endif - -/**************************/ -/* Strings for file modes */ -/**************************/ -#define READ_MODE "r" -#define WRITE_MODE "w" - -#ifdef __mac__ -/* File open mode (binary) */ -#undef READ_MODE -#define READ_MODE "rb" -#undef WRITE_MODE -#define WRITE_MODE "wb" -#endif - -#ifdef __dos__ -/* File open mode (binary) */ -#undef READ_MODE -#define READ_MODE "rb" -#undef WRITE_MODE -#define WRITE_MODE "wb" -#endif - -#ifdef __win__ -/* File open mode (binary) */ -#undef READ_MODE -#define READ_MODE "rb" -#undef WRITE_MODE -#define WRITE_MODE "wb" -#endif - -/*****************/ -/* Byte ordering */ -/*****************/ - -#ifdef __dos__ -#define REVERSED -#endif - -#ifdef __vms__ -#define REVERSED -#endif - -#ifdef __win__ -#ifndef REVERSED -#define REVERSED -#endif -#endif - - -/****************************/ -/* Allocates cleared bytes? */ -/****************************/ - -#ifdef __CYGWIN__ -#define NOTCALLOC -#endif - -#ifdef __MINGW32__ -#define NOTCALLOC -#endif - -#ifdef __unix__ -#define NOTCALLOC -#endif - - -/****************/ -/* Have termio? */ -/****************/ - -#ifdef GLK -/* don't need TERMIO */ -#else - -#ifdef __CYGWIN__ -#define HAVE_TERMIO -#endif - -#ifdef __unix__ -#define HAVE_TERMIO -#endif - -#endif - -/*******************************/ -/* Is ANSI control available? */ -/*******************************/ - -#ifdef GLK -/* don't need ANSI */ -#else - -#ifdef __CYGWIN__ -#define HAVE_ANSI -#endif - -#endif - -/******************************/ -/* Use the READLINE function? */ -/******************************/ - -#ifdef GLK -/* Glk always uses readline(), no matter what the OS */ -#define USE_READLINE -#else - -#ifdef __unix__ -#define USE_READLINE -#endif - -#ifdef x__dos__ -#define USE_READLINE -#endif - -#ifdef __win__ -#define USE_READLINE -#endif - -#endif - -/* Special cases and definition overrides */ -#ifdef __unix__ -#define MULTI -#endif - - - - -#ifdef __vms__ - -#define MULTI - -extern char *strdup(char str[]); - -/* Cheat implementation of strftime */ -extern size_t strftime (char *, size_t, const char *, const struct tm *); - -#endif - -#ifdef __mac__ - -extern char *strdup(char *str); - -#endif - - -#ifdef __dos__ - -/* Return codes */ -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 - -#endif - - /* Native character functions */ extern int isSpace(int c); /* IN - Native character to test */ extern int isLower(int c); /* IN - Native character to test */ diff --git a/engines/glk/alan2/term.cpp b/engines/glk/alan2/term.cpp index 8f7b64a719..c758efe434 100644 --- a/engines/glk/alan2/term.cpp +++ b/engines/glk/alan2/term.cpp @@ -35,83 +35,8 @@ namespace Alan2 { */ void getPageSize() { -#ifdef GLK paglen = 0; pagwidth = 0; - -#else -#ifdef HAVE_TERMIO - -#include <sys/termios.h> - - extern int ioctl(); - - struct winsize win; - int ecode; - - ecode = ioctl(1, TIOCGWINSZ, &win); - - if (ecode != 0 || win.ws_row == 0) - paglen = header->paglen; - else - paglen = win.ws_row; - - if (ecode != 0 || win.ws_col == 0) - pagwidth = header->pagwidth; - else - pagwidth = win.ws_col; - -#else -#ifdef __amiga__ -#include <libraries/dosextens.h> -#include <intuition/intuition.h> -#include <graphics/text.h> -#include <clib/exec_protos.h> - - struct Process * proc; - struct InfoData *id; - struct Window *win; - struct TextFont *textFont; - struct StandardPacket *packet; - - proc = (struct Process *) FindTask(0L); - - id = (struct InfoData *) allocate(sizeof(struct InfoData)); - - if (proc->pr_ConsoleTask) { - packet = (struct StandardPacket *) allocate(sizeof(struct StandardPacket)); - packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt); - packet->sp_Pkt.dp_Link = & packet->sp_Msg; - packet->sp_Pkt.dp_Port = & proc->pr_MsgPort; - packet->sp_Pkt.dp_Type = ACTION_DISK_INFO; - - packet->sp_Pkt.dp_Arg1 = ((LONG) id) >> 2; - - PutMsg ((struct MsgPort *) proc->pr_ConsoleTask, & packet->sp_Msg); - WaitPort(&proc->pr_MsgPort); - GetMsg(&proc->pr_MsgPort); - free((char *)packet); - - win = (struct Window *) id->id_VolumeNode; - free(id); - - /* Calculate number of characters and lines w.r.t font size and borders */ - textFont = win->IFont; - paglen = win->Height/textFont->tf_YSize-2; - pagwidth = win->Width/textFont->tf_XSize-3; - } else { - paglen = header->paglen; - pagwidth = header->pagwidth; - } - -#else - - paglen = header->paglen; - pagwidth = header->pagwidth; - -#endif -#endif -#endif } } // End of namespace Alan2 diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h index 699dd0e149..34c5dda87f 100644 --- a/engines/glk/alan2/types.h +++ b/engines/glk/alan2/types.h @@ -33,14 +33,12 @@ namespace Alan2 { /* CONSTANTS */ -#ifndef __mac__ #ifndef TRUE #define TRUE (0==0) #endif #ifndef FALSE #define FALSE (!TRUE) #endif -#endif #define ACTMIN (header->actmin) #define ACTMAX (header->actmax) @@ -77,9 +75,7 @@ namespace Alan2 { /* TYPES */ -#ifndef __mac__ typedef int Boolean; /* Boolean values within interpreter */ -#endif /* Amachine variables */ struct CurVars { |