From 981ce4106c36c1b2b35ff657ed3fb355a666f63d Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 25 Apr 2015 09:51:29 -0400 Subject: [PATCH] 3rd release thanks to Peter Langston. Peter says it compiles on OS X 10.6.8 --- Makefile | 7 +- Wander.txt | 10 +- WanderExportReadMe.txt | 0 WanderMisc.txt | 0 WanderWrld.txt | 0 a3.misc | 1 + a3.wrld | 17 +-- castle.misc | 0 castle.wrld | 0 library.misc | 0 library.wrld | 0 tut.misc | 0 tut.wrld | 0 wand1.c | 220 +++++++++++++++-------------------- wand2.c | 255 +++++++++++++++++++---------------------- wanddef.h | 90 ++++++++++++--- wandglb.c | 141 ++++++++++++----------- wandsys.c | 0 18 files changed, 382 insertions(+), 359 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 Wander.txt mode change 100644 => 100755 WanderExportReadMe.txt mode change 100644 => 100755 WanderMisc.txt mode change 100644 => 100755 WanderWrld.txt mode change 100644 => 100755 a3.misc mode change 100644 => 100755 a3.wrld mode change 100644 => 100755 castle.misc mode change 100644 => 100755 castle.wrld mode change 100644 => 100755 library.misc mode change 100644 => 100755 library.wrld mode change 100644 => 100755 tut.misc mode change 100644 => 100755 tut.wrld mode change 100644 => 100755 wand1.c mode change 100644 => 100755 wand2.c mode change 100644 => 100755 wanddef.h mode change 100644 => 100755 wandglb.c mode change 100644 => 100755 wandsys.c diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 7179620..51be7c2 --- a/Makefile +++ b/Makefile @@ -2,7 +2,12 @@ DOCS = Wander.txt WanderExportReadMe.txt WanderMisc.txt WanderWrld.txt DOT_CS = wand1.c wand2.c wandglb.c wandsys.c DOT_OS = wand1.o wand2.o wandglb.o wandsys.o A3 = a3.misc a3.wrld -EXPORT = Makefile $(DOCS) wanddef.h $(DOT_CS) $(A3) +CASTLE = castle.misc castle.wrld +LIBRARY = library.misc library.wrld +TUT = tut.misc tut.wrld +EXPORT = Makefile $(DOCS) wanddef.h $(DOT_CS) $(A3) $(CASTLE) $(LIBRARY) $(TUT) + +default: wander clean: rm $(DOT_OS) $(DOCS) diff --git a/Wander.txt b/Wander.txt old mode 100644 new mode 100755 index 61ee71e..447685e --- a/Wander.txt +++ b/Wander.txt @@ -48,6 +48,7 @@ COMMANDS save quit & save environment for later continuation restore restore saved environment | look print the long description of the current location + history print the last N commands | init read new .wrld & .misc files, (switch worlds) | The following debugging verbs only work if you own the files ~snoop give a condensed list of possible actions @@ -57,7 +58,6 @@ COMMANDS ~version print miscellaneous parameter information Whenever the word "all" is encountered as the second recog‐ | - nized word of user input on a line it will be macro expand‐ | ‐ 1 ‐ @@ -68,6 +68,7 @@ COMMANDS WANDER 4/80 WANDER + nized word of user input on a line it will be macro expand‐ | ed. This expansion replaces the word "all" with each object | in the current location including objects being carried. | E.g. "drop all" may expand to "drop keys; drop net; drop | @@ -123,7 +124,6 @@ FILE PROTECTION files /u/smith/oz.misc and /u/smith/oz.wrld, the following program would suffice: - main() ‐ 2 ‐ @@ -134,6 +134,7 @@ FILE PROTECTION WANDER 4/80 WANDER + main() { execl("/usr/games/wander", "oz", "/u/smith/oz", 0); } @@ -189,7 +190,6 @@ VARIABLES NOW_HOUR 114 hour of day (0:23) NOW_MIN 115 minute of hour (0:59) NOW_SEC 116 second of minute (0:59) - NOW_ET 117 elapsed time in Wander (seconds) ‐ 3 ‐ @@ -200,6 +200,7 @@ VARIABLES WANDER 4/80 WANDER + NOW_ET 117 elapsed time in Wander (seconds) BREVITY 118 brevity of place descriptions | LOC_VIEW 119 location description override | OBJ_VIEW 120 object description override | @@ -255,7 +256,6 @@ SYNTACTIC CONVENTIONS \t is replaced by , | \r is replaced by , | \" is replaced by " (not considered a "quote"), | - \ is replaced by | ‐ 4 ‐ @@ -266,6 +266,7 @@ SYNTACTIC CONVENTIONS WANDER 4/80 WANDER + \ is replaced by | In reading the file, each unescaped tab is replaced by a | single space, and quotes are stripped off. The resulting | @@ -321,7 +322,6 @@ SEE ALSO - ‐ 5 ‐ diff --git a/WanderExportReadMe.txt b/WanderExportReadMe.txt old mode 100644 new mode 100755 diff --git a/WanderMisc.txt b/WanderMisc.txt old mode 100644 new mode 100755 diff --git a/WanderWrld.txt b/WanderWrld.txt old mode 100644 new mode 100755 diff --git a/a3.misc b/a3.misc old mode 100644 new mode 100755 index 671f7da..4e63060 --- a/a3.misc +++ b/a3.misc @@ -69,6 +69,7 @@ beer 1 liquor 2 subwalk\ tokens tokens 1 +token 2 half-empty\ wine\ bottle 0 101 bottle 1 shovel 0 12 diff --git a/a3.wrld b/a3.wrld old mode 100644 new mode 100755 index 9e93374..b2f5403 --- a/a3.wrld +++ b/a3.wrld @@ -4,7 +4,7 @@ You're in the Aldebaran III spaceport. An electrified chain link fence surrounds the area with gates leading west and south. south 2 west 100 - north|east|ne|nw|se|sw m="ZZZAAAAPPPP! OUCH!" + north|east|ne|nw|se|sw m="zzzZZZAAAAPPPP! OUCH!" take\ card o?card t+card m="\ Done Your account has 50 credits left. @@ -117,20 +117,23 @@ them anyway\", you are reminded." " bribe m="You haven't got anything that the official wants." out m="Which way out? East or west? (the spaceport is east)" - no m="\"If you really have nothing to declare you may go.\"" + no m="\"If you really have nothing to declare you may leave.\"" * t?papers t?notes v?NUM_CARRY.2 ... m=\ -"I don't believe you have anything left to declare, you may go..." +"I don't believe you have anything left to declare, you may leave..." declare\ papers|declare\ notes|declare\ tokens|show\ papers m=\ -"\"There is no duty on those\", barks the exasperated official." +"\"There is no duty on those\", barks the exasperated official, as he +slides them down the counter that passes through a hole in the west wall." declare\ card t?card v-6.5 o+card@3 m=\ -"\"Yes\", says the official and then mutters to himself, +"\"Yes\", says the official sliding it down the counter and muttering to himself, \"credit card -- five credits\"." declare\ condoms t?condoms v-6.1 o+condoms@3 m=\ -"The guard smiles discreetly and scribbles a \"1\" on his pad." +"The guard smiles discreetly, scribbles a \"1\" on his pad, +and flips the package down the counter." declare\ dictionary t?dictionary v-6.3 o+dictionary@3 m=\ "\"Hmm, looks pretty valuable\", he says as he scribbles a \"3\"." declare\ cigarettes v-6.1 t?cigarettes o+cigarettes@3 m=\ -"\"Filthy habit\", the official mutters, writing a \"1\" on his pad." +"\"Filthy habit\", the official mutters, writing a \"1\" on his pad +and tossing the pack down the counter." declare\ innocence m="Oh sure; we're all innocent of something, eh?" declare m="Declare what? Never heard of it..." diff --git a/castle.misc b/castle.misc old mode 100644 new mode 100755 diff --git a/castle.wrld b/castle.wrld old mode 100644 new mode 100755 diff --git a/library.misc b/library.misc old mode 100644 new mode 100755 diff --git a/library.wrld b/library.wrld old mode 100644 new mode 100755 diff --git a/tut.misc b/tut.misc old mode 100644 new mode 100755 diff --git a/tut.wrld b/tut.wrld old mode 100644 new mode 100755 diff --git a/wand1.c b/wand1.c old mode 100644 new mode 100755 index 68f3a15..aa0f874 --- a/wand1.c +++ b/wand1.c @@ -13,69 +13,16 @@ static char *whatwand = "@(#)wand1.c 1.6 2/23/85 -- (c) psl 1978"; static char *wand_h = H_SCCS; -#define FRESTART 0 /* flag args for get_files() */ -#define FMAINNEW 1 -#define FRESTORE 2 -#define FMAINRES 3 - char ungotlin[BUFSIZE]; int curstate, actrace, owner; -int vrbquit, vrbsave, vrbrest, vrbtake, vrbdrop, vrbgoto, vrbinve; -int vrblook, vrbinit, vrbstar, vrbsnoop, vrbvars, vrbvers; +int vrbquit, vrbsave, vrbrest, vrbtake, vrbdrop, vrbinve; +int vrblook, vrbinit, vrbstar, vrbhist; +int vrbsnoop, vrbgoto, vrbvars, vrbvers; int lstdirvrb; int objnum1, objnum2, objall; -FILE *mfp = (FILE *) NULL; -FILE *wfp = (FILE *) NULL; -FILE *fpungot, *monfp; -long lbegaddr; /* addr of begin of last getlin() line */ -long ungotaddr; /* addr of begin of last ungetlin() line */ - -// routines in wand1.c -int main(); -void prloc(); -char *getcom(); -int carry_out(); -int check_act(); -void get_loc(); -void setup(); -struct actstr *code_act(); -int get_files(); - -// routines in wand2.c -void restart(); -void takeobj(); -char *objdesc(); -char *deparity(char *from); -void bytecopy(); -char *movchars(); -int obj_at(); -int oneof(); -int class(); -void dotpair(); -void atpair(); -int atov(); -char *store(); -int length(); -int wdparse(); -char *msglin(); -void quit(); -void save(); -void restore(); -void monsav(); -long getndx(); -char *msgpara(); -char *msgfmt(); -void inventory(); -int wrdadd(); -int which(); -int wfnd(); -void ungetlin(); -int getlin(); -int getpara(); -int atoip(); -char *splur(); -char *cpy(char *tp, char *fp); -char *cpyn(char *tp, char *fp, int n); +FILE *fpungot, *monfp; +long lbegaddr; /* addr of begin of last getlin() line */ +long ungotaddr; /* addr of begin of last ungetlin() line */ uid_t myruid() { return(getuid()); } // normally in glib uid_t myeuid() { return(geteuid()); } // normally in glib @@ -105,6 +52,7 @@ char *argv[]; do { cp = getcom(i); } while (*cp == '\n' || *cp == '\0'); + boswell(cp); // record the history time(&t_now); tp = localtime(&t_now); var[NOW_YEAR] = tp->tm_year; @@ -128,7 +76,7 @@ char *argv[]; var[PREV_LOC] = beforeloc; if (i & COM_DESC) var[NUM_MOVES]++; - } + } } void @@ -220,12 +168,12 @@ char *com; var[INP_WC] = wdparse(com, &var[INP_W1], &var[INP_N1], 0); if (var[INP_W2] == objall) { for (i = 1; i < maxwrds && wrds[i].w_word != 0; i++) { - if (wrds[i].w_loc == var[CUR_LOC] || wrds[i].w_loc < 0) { + if ((wrds[i].w_loc == var[CUR_LOC] && var[INP_W1] != vrbdrop) + || (wrds[i].w_loc < 0 && var[INP_W1] != vrbtake)) { if (wrds[i].w_flg & W_DONLY) i++; - sprintf(junk, "%s %s", - wrds[var[INP_W1]].w_word, wrds[i].w_word); - printf("%s --- ", junk); + sprintf(junk, "%s %s", wrds[var[INP_W1]].w_word, wrds[i].w_word); + printf("%s --- ", deparity(junk)); retval |= carry_out(junk); } } @@ -256,39 +204,9 @@ char *com; if (retval & COM_COMPLETE) return(retval); } - if (actrace > 1) + if (actrace > 1) // built-in actions printf("built-in actions\n"); - if (var[INP_W1] == vrbquit) /* built-in acts */ - quit(QUIT_QUIET); - if (var[INP_W1] == vrbsave) { - save(movchars(com, com, fldels)); - return(COM_DESC | COM_DONE); - } - if (var[INP_W1] == vrbrest) { - restore(movchars(com, com, fldels), FRESTORE); - return(COM_DESC | COM_DONE); - } - if (var[INP_W1] == vrbinit) { - restart(movchars(com, com, fldels)); - return(COM_DESC | COM_DONE); - } - if (var[INP_W1] == vrbtake) { - j = 0; - for (i = 1; i < maxwrds && wrds[i].w_word != 0; i++) { - if (oneof(i, &var[INP_W2]) - && (wrds[i].w_loc == var[CUR_LOC] || wrds[i].w_loc < 0)) { - takeobj(i); - j++; - } - } - if (j == 0) - printf("Can't %s\n", com); - return(COM_DONE); - } - if (var[INP_W1] == vrbinve) { - inventory(); - return(COM_DONE); - } + if (var[INP_W1] == vrbdrop) { j = 0; for (i = 1; i < maxwrds && wrds[i].w_word != 0; i++) { @@ -304,12 +222,53 @@ char *com; printf("I'd like to %s, but ...\n", com); return(COM_DONE); } + if (var[INP_W1] == vrbgoto && owner) { + cp = movchars(com, com, fldels); + var[CUR_LOC] = atoi(cp); + while (*cp) + if (*cp++ == dotchar) { + locstate[var[CUR_LOC]] = atoi(cp); + break; + } + printf("Goto loc %d which is in state %d\n", var[CUR_LOC], + locstate[var[CUR_LOC]]); + return(COM_DESC | COM_DONE); + } + if (var[INP_W1] == vrbhist) { + i = 1; + if (var[INP_WC] == 2) + i = HISTLEN - var[INP_N1]; + for (; i < HISTLEN; i++) { + cp = history[(histi + i) % HISTLEN]; + if (*cp) + printf("%s%s", cp, i < (HISTLEN - 1)? "; " : "\n"); + } + return(COM_DONE); + } + if (var[INP_W1] == vrbinit) { + restart(movchars(com, com, fldels)); + return(COM_DESC | COM_DONE); + } + if (var[INP_W1] == vrbinve) { + inventory(); + return(COM_DONE); + } if (var[INP_W1] == vrblook) { locseen[var[CUR_LOC]] = 0; --var[NUM_PLACES]; return(COM_DONE | COM_DESC); } - if (owner && var[INP_W1] == vrbsnoop) { + if (var[INP_W1] == vrbquit) + quit(QUIT_QUIET); + if (var[INP_W1] == vrbrest) { + restore(movchars(com, com, fldels), FRESTORE); + return(COM_DESC | COM_DONE); + } + if (var[INP_W1] == vrbsave) { + save(movchars(com, com, fldels)); + return(COM_DESC | COM_DONE); + } + if (var[INP_W1] == vrbsnoop && owner) { printf("<==== loc:%d state:%d ====>", place.p_loc, place.p_state); printf(" %s\n", msglin(wfp, place.p_sdesc)); printf("%s", msgpara(wfp, place.p_ldesc)); @@ -331,32 +290,32 @@ char *com; } return(COM_DONE); } - if (owner && var[INP_W1] == vrbgoto) { - cp = movchars(com, com, fldels); - var[CUR_LOC] = atoi(cp); - while (*cp) - if (*cp++ == dotchar) { - locstate[var[CUR_LOC]] = atoi(cp); - break; + if (var[INP_W1] == vrbtake) { + j = 0; + for (i = 1; i < maxwrds && wrds[i].w_word != 0; i++) { + if (oneof(i, &var[INP_W2]) + && (wrds[i].w_loc == var[CUR_LOC] || wrds[i].w_loc < 0)) { + takeobj(i); + j++; } - printf("Goto loc %d which is in state %d\n", var[CUR_LOC], - locstate[var[CUR_LOC]]); - return(COM_DESC | COM_DONE); - } - if (owner && var[INP_W1] == vrbvars) { + } + if (j == 0) + printf("Can't %s\n", com); + return(COM_DONE); + } + if (var[INP_W1] == vrbvars && owner) { for (i = 0; i < maxvars; i++) if (var[i]) printf("var[%2d] = %d\n", i, var[i]); return(COM_DONE); } - if (owner && var[INP_W1] == vrbvers) { + if (var[INP_W1] == vrbvers && owner) { printf("Current Wander version:\n"); printf("MAXLOCS:%d\tMax # of locations possible.\n", maxlocs); printf("MAXACTS:%d\tMax # of actions per location.\n", maxacts); printf("MAXFIELDS:%d\tMax # of fields per action.\n", maxfields); printf("BUFSIZE:%d\tSize of long descriptions, etc.\n", BUFSIZE); - printf("PATHLENGTH:%d\tMax length of file path names.\n", - pathlength); + printf("PATHLENGTH:%d\tMax length of file path names.\n", PATHLENGTH); printf("MAXWRDS:%d\tMax # of words Wander will remember.\n", maxwrds); printf("MAXINDEX:%d\tMax # of location/states, total.\n", @@ -365,6 +324,7 @@ char *com; printf("MAXPOSTACTS:%d\tMax # of post actions.\n", maxpostacts); return(COM_DONE); } + if (retval & COM_DONE) return(retval); if (retval & COM_NDOBJ) { @@ -384,7 +344,7 @@ check_act(actp) /* if the action fits, do it */ struct actstr *actp; { struct actstr *ap; - char *newfile; + char *newwrld; int i, retval, fld1v, fld2v; long addr; struct fieldstr *fp; @@ -403,7 +363,7 @@ struct actstr *actp; } if (ap->a_wrd[i] != vrbstar) retval |= COM_RECOG; - newfile = 0; + newwrld = 0; for (fp = ap->a_field; fp < &ap->a_field[maxfields]; fp++) { if (fp->f_type == 0) break; @@ -568,7 +528,7 @@ struct actstr *actp; break; case FR_WORLD: addr = ((long) fp->f_fld1 & 0177777) | (fp->f_fld2 << 16); - newfile = msglin(ap->a_msgfp, addr); + newwrld = msglin(ap->a_msgfp, addr); break; case FR_SBIN: locseen[fld1v] = fld2v; @@ -587,8 +547,8 @@ struct actstr *actp; printf("\n"); if (ap->a_msgaddr) printf("%s\n", msglin(ap->a_msgfp, ap->a_msgaddr)); - if (newfile != 0) - restart(newfile); + if (newwrld != 0) + restart(newwrld); if (ap->a_rloc < 0) quit(ap->a_rloc); if (ap->a_rloc > 0) @@ -697,30 +657,32 @@ char *argv[]; fprintf(stderr, "More than 1 world file?\n"); goto syntax; } - cpyn(curfile, argv[argc], sizeof(curfile) - 1); + cpyn(curname, argv[argc], sizeof(curname) - 1); } } - // modify the syn field of wrds to hold root word index + // modify the w_word and w_syn fields of wrds from wandglb.c lastrw = 1; for (i = 1; wrds[i].w_word; i++) { + wrds[i].w_word = store(wrds[i].w_word); // put the word in storebuf if (wrds[i].w_syn) wrds[i].w_syn = lastrw; else lastrw = i; } - if (rflag == 0 && get_files(curfile, FMAINNEW) == -1) + if (rflag == 0 && get_files(curname, FMAINNEW) == -1) exit(2); srand(0); curstate = locstate[var[CUR_LOC]]; - vrbquit = which("quit", wrds); - vrbsave = which("save", wrds); - vrbrest = which("restore", wrds); - vrbtake = which("take", wrds); + lstdirvrb = which("nw", wrds); /* see comment on "nw" in wandglb */ vrbdrop = which("drop", wrds); + vrbhist = which("history", wrds); + vrbinit = which("init", wrds); vrbinve = which("inventory", wrds); vrblook = which("look", wrds); - vrbinit = which("init", wrds); - lstdirvrb = which("nw", wrds); /* see comment on "nw" in wandglb */ + vrbquit = which("quit", wrds); + vrbrest = which("restore", wrds); + vrbsave = which("save", wrds); + vrbtake = which("take", wrds); vrbsnoop = which("~snoop", wrds); vrbgoto = which("~goto", wrds); vrbvars = which("~vars", wrds); @@ -937,9 +899,9 @@ char *name; /* flag indicates caller & current initializations */ flag == FRESTART? "init" : "restore", name); monsav(); /* close & unlink temp monfile */ } - if (flag == FRESTORE && strcmp(name, curfile) != 0) { + if (flag == FRESTORE && strcmp(name, curname) != 0) { printf("Restoring from a different world, (%s instead of %s)\n", - name, curfile); + name, curname); flag = FRESTART; /* need to do more inits */ } if (flag != FRESTORE) { @@ -1093,7 +1055,7 @@ char *name; /* flag indicates caller & current initializations */ for (cp = buf; *cp; cp++); addr += cp - buf; } - cpyn(curfile, name, sizeof(curfile) - 1); + cpyn(curname, name, sizeof(curname) - 1); get_done: wseek(wfp, 0l, 0); return(0); diff --git a/wand2.c b/wand2.c old mode 100644 new mode 100755 index 93cd7c8..482629c --- a/wand2.c +++ b/wand2.c @@ -7,80 +7,27 @@ ** Copyright (c) 1978 by Peter S. Langston - New York, N.Y. */ -static char *whatwand = "@(#)wand2.c 1.4 2/23/85 -- (c) psl 1978"; - -static char *wand_h = H_SCCS; - -#define FRESTART 0 /* flag args for get_files() */ -#define FMAINNEW 1 -#define FRESTORE 2 -#define FMAINRES 3 - -extern char ungotlin[BUFSIZE]; -extern int curstate, actrace, owner; -extern int vrbquit, vrbsave, vrbrest, vrbtake, vrbdrop, vrbgoto, vrbinve; -extern int vrblook, vrbinit, vrbstar, vrbsnoop, vrbvars, vrbvers; -extern int lstdirvrb; -extern int objnum1, objnum2, objall; -extern FILE *mfp; -extern FILE *wfp; -extern FILE *fpungot, *monfp; +static char *whatwand = "@(#)wand2.c 1.4 2/23/85 -- (c) psl 1978"; + +static char *wand_h = H_SCCS; + +extern char ungotlin[BUFSIZE]; +extern int curstate, actrace, owner; +extern int vrbquit, vrbsave, vrbrest, vrbtake, vrbdrop, vrbgoto, vrbinve; +extern int vrblook, vrbinit, vrbstar, vrbsnoop, vrbvars, vrbvers; +extern int lstdirvrb; +extern int objnum1, objnum2, objall; +extern FILE *fpungot, *monfp; extern long lbegaddr; /* addr of begin of last getlin() line */ extern long ungotaddr; /* addr of begin of last ungetlin() line */ -// routines in wand1.c -int main(); -void prloc(); -char *getcom(); -int carry_out(); -int check_act(); -void get_loc(); -void setup(); -struct actstr *code_act(); -int get_files(); - -// routines in wand2.c -void restart(); -void takeobj(); -char *objdesc(); -char *deparity(char *from); -void bytecopy(); -char *movchars(); -int obj_at(); -int oneof(); -int class(); -void dotpair(); -void atpair(); -int atov(); -char *store(); -int length(); -int wdparse(); -char *msglin(); -void quit(); -void save(); -void restore(); -void monsav(); -long getndx(); -char *msgpara(); -char *msgfmt(); -void inventory(); -int wrdadd(); -int which(); -int wfnd(); -void ungetlin(); -int getlin(); -int getpara(); -int atoip(); -char *splur(); -char *cpy(char *tp, char *fp); -char *cpyn(char *tp, char *fp, int n); - +extern char *ctime(); extern long wtell(); extern FILE *fopen(), *wopen(); void restart(name) /* (init) restart from specified files */ -char *name; +char *name; { int i, numwrds; @@ -91,7 +38,7 @@ char *name; wrds[i].w_word = listunused; /* open new .misc & .wrld and create ndx */ if (get_files(name, FRESTART) == -1 - && get_files(curfile, FRESTART) == -1) + && get_files(curname, FRESTART) == -1) exit(2); for (i = maxlocs; --i >= 0; ) locseen[i] = 0; @@ -129,9 +76,9 @@ takeobj(obj) return; } -char * +char * objdesc(pre, art, wp, post) /* assemble an object description in buf */ -char *pre, *art, *post; +char *pre, *art, *post; struct wrdstr *wp; { char *cp, buf[1024]; @@ -174,7 +121,7 @@ deparity(char *fp) void bytecopy(from, to, length) -char *from, *to; +char *from, *to; { char *fp, *tp; int i; @@ -187,9 +134,9 @@ char *from, *to; return; } -char * // split off the next field +char * // split off the next field movchars(from, to, delims) -char *from, *to, *delims; +char *from, *to, *delims; { char *dp, c; @@ -223,7 +170,7 @@ obj_at(obj, loc) int oneof(wrd, w) /* return 1 if "wrd" is = one of w[0] ... w[MAXACTWDS] */ -int w[]; +int w[]; { int i; @@ -255,7 +202,7 @@ struct wrdstr *wp; /* 3 => plural */ void dotpair(type, string, fp) -char *string; +char *string; struct fieldstr *fp; { char *cp; @@ -277,7 +224,7 @@ struct fieldstr *fp; void atpair(type, string, fp) -char *string; +char *string; struct fieldstr *fp; { char *cp; @@ -307,7 +254,7 @@ struct fieldstr *fp; int atov(string) /* return coded form of number or variable */ -char *string; +char *string; { int i; @@ -322,30 +269,30 @@ char *string; return(wrdadd(string, 0, 0, 0)); /* hashed value */ } -char *storebuf = 0; -char *storebp = 0; -int storenleft = 0; +char *storebuf = 0; +char *storebp = 0; +int storenleft = 0; -char * -store(string) -char *string; +char * +store(string) // copy string into storebuf and return a pointer to it +char *string; { char *cp; extern char *sbrk(); if (storebp == 0) { - if ((storebp = storebuf = sbrk(storenleft = 512)) == (char *) -1) { - perror("Initial sbrk(512) failed"); + if ((storebp = storebuf = sbrk(storenleft = 4096)) == (char *) -1) { + perror("Initial sbrk(4096) failed"); exit(3); } } storenleft -= length(string); if (storenleft < 0) { - if (sbrk(512) == (char *) -1) { - perror("sbrk(512) failed"); + if (sbrk(4096) == (char *) -1) { + perror("sbrk(4096) failed"); exit(3); } - storenleft += 512; + storenleft += 4096; } storebp = cpy(cp = storebp, string) + 1; return(cp); @@ -353,7 +300,7 @@ char *string; int length(string) -char *string; +char *string; { char *cp; @@ -361,10 +308,10 @@ char *string; return(cp - string); } -int /* put wrd vals in w[0] ... */ +in /* put wrd vals in w[0], w[1], ... */ wdparse(string, w, nums, flag) /* if flag != 0 add to wrds list */ -char *string; /* if flag == 0 (user inp) put #s in nums */ -int w[], nums[]; /* and return # of words */ +char *string; /* if flag == 0 (user inp) put #s in nums */ +int w[], nums[]; /* and return # of words */ { char *bp; char wdbuf[128]; @@ -401,7 +348,7 @@ int w[], nums[]; /* and return # of words */ return(numactwds); } -char * +char * msglin(fp, addr) FILE *fp; long addr; @@ -437,35 +384,39 @@ quit(int n) void save(file) -char *file; +char *file; { - char *cp; - int fh; + char *cp, newname[PATHLENGTH]; + int fh, sbufsize; if (*file == '\0') { - for (cp = file = curfile; *cp; ) + for (cp = file = curname; *cp; ) if (*cp++ == '/') file = cp; - sprintf(newfile, "%s.save", file); - file = newfile; + sprintf(newname, "%s.save", file); + file = newname; } if ((fh = open(file, 1)) < 0 && (fh = creat(file, 0600)) < 0) { printf("Can't open \"%s\", sorry\n", file); return; } - printf("Saving the current environment under the name \"%s\" ...", - file); - param.p_pathlength = pathlength; + printf("Saving the current environment under the name \"%s\" ...", file); + param.p_pathlength = PATHLENGTH; + param.p_histlen = HISTLEN; + param.p_histi = histi; param.p_maxlocs = maxlocs; param.p_maxwrds = maxwrds; param.p_maxvars = maxvars; param.p_maxndx = maxndx; param.p_maxpre = maxpreacts; param.p_maxpost = maxpostacts; - param.p_stbuf = storebuf; - param.p_stbp = storebp; + param.p_storebuf = storebuf; + param.p_sbufsiz = storebp - storebuf; + param.p_time = time(0); + param.p_msize = fsize(mfp); + param.p_wsize = fsize(wfp); write(fh, ¶m, sizeof (struct paramstr)); - write(fh, curfile, pathlength); + write(fh, curname, PATHLENGTH); write(fh, locseen, sizeof(locseen[0]) * maxlocs); write(fh, locstate, sizeof(locstate[0]) * maxlocs); write(fh, var, sizeof(var[0]) * maxvars); @@ -473,56 +424,66 @@ char *file; write(fh, ndx, sizeof(struct ndxstr) * maxndx); write(fh, pre_acts, sizeof(struct actstr) * maxpreacts); write(fh, post_acts, sizeof(struct actstr) * maxpostacts); - write(fh, storebuf, param.p_stbp - param.p_stbuf); + write(fh, history, HISTLEN * PATHLENGTH); + write(fh, storebuf, param.p_sbufsiz); close(fh); printf("\n"); return; } void -restore(file, flag) -char *file; +restore(char *file, int flag) { - char *cp; - int diff, i, fh; + char *cp, newname[PATHLENGTH]; + int then, diff, i, fh; extern char *sbrk(); if (*file == '\0') { - for (cp = file = curfile; *cp; ) + for (cp = file = curname; *cp; ) if (*cp++ == '/') file = cp; - sprintf(newfile, "%s.save", file); - file = newfile; + sprintf(newname, "%s.save", file); + file = newname; } + printf("Restoring from the file \"%s\" ", file); if ((fh = open(file, 0)) < 0) { printf("Can't open \"%s\", sorry\n", file); exit(1); } - printf("Restoring from the file \"%s\" ", file); - read(fh, ¶m, sizeof (struct paramstr)); - read(fh, newfile, pathlength); + i = read(fh, ¶m, sizeof (struct paramstr)); + printf("saved %s", ctime(¶m.p_time)); + i = read(fh, newname, PATHLENGTH); printf("."); - if (get_files(newfile, flag) == -1) + if (get_files(newname, flag) == -1) exit(2); printf("."); if (storebuf == 0) { /* no sbrk() space yet */ - if ((storebuf = storebp = sbrk(512)) == (char *) -1) { - printf("Initial sbrk(512) failed\n"); + if ((storebuf = storebp = sbrk(4096)) == (char *) -1) { + printf("Initial sbrk(4096) failed\n"); exit(1); } - storenleft = 512; + storenleft = 4096; } - if (param.p_pathlength != pathlength + if (param.p_pathlength != PATHLENGTH + || param.p_histlen != HISTLEN || param.p_maxlocs != maxlocs || param.p_maxwrds != maxwrds || param.p_maxvars != maxvars || param.p_maxpre != maxpreacts || param.p_maxpost != maxpostacts - || param.p_maxndx != maxndx - || param.p_stbuf != storebuf) { + || param.p_maxndx != maxndx) { printf("\n`%s' saved from another version of Wander.\n", file); exit(1); } + if (param.p_msize != fsize(mfp)) { + printf("\n`%s' saved with a different %s.misc file.\n", file, newname); + exit(1); + } + if (param.p_wsize != fsize(wfp)) { + printf("\n`%s' saved with a different %s.wrld file.\n", file, newname); + exit(1); + } + histi = param.p_histi; read(fh, locseen, sizeof(locseen[0]) * maxlocs); read(fh, locstate, sizeof(locstate[0]) * maxlocs); read(fh, var, sizeof(var[0]) * maxvars); @@ -530,21 +491,30 @@ char *file; read(fh, ndx, sizeof(struct ndxstr) * maxndx); read(fh, pre_acts, sizeof(struct actstr) * maxpreacts); read(fh, post_acts, sizeof(struct actstr) * maxpostacts); + read(fh, history, HISTLEN * PATHLENGTH); printf("."); - diff = param.p_stbp - (storebp + storenleft); - storenleft = -diff; - if (diff > 0) { /* need more space than available */ - i = (diff + 077) & ~077; /* round up to mult of 64 */ + // to read the saved storebuf we can dump everything we have stored + storenleft += storebp - storebuf; // reclaim the space + storebp = storebuf; // now it's empty + storenleft -= param.p_sbufsiz; // will there be any left? + if (storenleft < 0) { // we'll need more + diff = -storenleft; // need at least this much + i = (diff + 07777) & ~07777; // round up to a mult of 4k if (sbrk(i) == (char *) -1) { printf("sbrk(%d) failed.\n", i); exit(1); } - storenleft += i; + storenleft += i; // suold be positive now } - storebp = param.p_stbp; - read(fh, storebuf, param.p_stbp - param.p_stbuf); + read(fh, storebuf, param.p_sbufsiz); + storebp = storebuf + param.p_sbufsiz; close(fh); + // now we need to readjust all the w_word pointers to the new storebuf offset + diff = storebuf - param.p_storebuf; + for (i = 1; wrds[i].w_word && i <= maxwrds; i++) + wrds[i].w_word += diff; printf("\n"); + boswell("restore"); place.p_loc = -1; inventory(); return; @@ -586,7 +556,7 @@ getndx(loc, state) return(-1l); } -char * +char * msgpara(fp, addr) FILE *fp; long addr; @@ -598,13 +568,13 @@ long addr; return(msgfmt(string)); } -char * +char * msgfmt(string) -char *string; +char *string; { /****/int xp; char *sp, *bp, c; - char junk[64]; + char junk[512]; int i; static char buf[BUFSIZE]; @@ -664,7 +634,7 @@ inventory() int wrdadd(word, syn, iloc, flg) /* return index of the root word, */ -char *word; /* adding it if necessary */ +char *word; /* adding it if necessary */ { char *wrd; int i, limit; @@ -691,7 +661,7 @@ char *word; /* adding it if necessary */ int which(word, wrds) /* find root (description) text for existing word */ -char *word; +char *word; struct wrdstr *wrds; { int i; @@ -872,3 +842,18 @@ cpyn(char *tp, char *fp, int n) return(tp); } +off_t +fsize(FILE *fp) +{ + struct stat sbuf; + + fstat(fp->_file, &sbuf); + return(sbuf.st_size); +} + +void +boswell(char *command) +{ + cpyn(history[histi], command, BUFSIZ); + histi = (histi + 1) % HISTLEN; +} diff --git a/wanddef.h b/wanddef.h old mode 100644 new mode 100755 index 8f8d3f4..fad3961 --- a/wanddef.h +++ b/wanddef.h @@ -1,4 +1,5 @@ -#include +#include +#include // for struct stat /* ** WANDDEF.H -- Non-deterministic fantasy story tool header ** Global definitions @@ -25,6 +26,7 @@ #define MAXVARS 128 /* [2] number of variables, must be == 128 */ #define BUFSIZE 4096 /* [2+6stack] size of line buffers */ #define MAXINPNUMS 2 /* numbers/utterance */ +#define HISTLEN 128 /* how many commands are remembered */ #define FIELDELIM ' ' /* delimit fields (MOD) */ #define LINEDELIM '\n' /* delimit lines (MOD) */ @@ -79,7 +81,6 @@ #define NUM_MOVES 123 /* number of "moves" */ #define NUM_PLACES 124 /* number of "places" visited */ - /* field types */ #define F_VOID 0 #define FT_OBJ 1 @@ -116,16 +117,26 @@ #define FR_IBIN 35 #define FR_DBIN 36 +#define FRESTART 0 /* flag args for get_files() */ +#define FMAINNEW 1 +#define FRESTORE 2 +#define FMAINRES 3 + struct paramstr { - int p_pathlength; - int p_maxlocs; - int p_maxwrds; - int p_maxvars; - int p_maxndx; - int p_maxpre; - int p_maxpost; - char *p_stbuf; - char *p_stbp; + int p_pathlength; // the size of buffers + int p_histlen; // how many commands we save in history + int p_histi; // where the next command goes in the history buffer + int p_maxlocs; // max number of locations + int p_maxwrds; // max number of words we can store + int p_maxvars; // max number of variables + int p_maxndx; // max number of wrld indices + int p_maxpre; // max number of pre-actions + int p_maxpost; // max number of post-actions + char *p_storebuf; // where store() was storing the words + int p_sbufsiz; // how much space is used to store() words + int p_time; // when this file was saved + off_t p_msize; // size of the .misc file + off_t p_wsize; // size of the .wrld file } param; struct placestr { @@ -175,9 +186,11 @@ extern char *thereis[], *aansome[]; extern char fldels[], vardel[], wrdels[]; extern char listunused[]; extern char locfile[], miscfile[], tmonfil[], monfile[PATHLENGTH]; -extern char curfile[PATHLENGTH], newfile[], *stdpath, *defmfile; +extern char curname[PATHLENGTH], *stdpath, *defmfile; extern char mfbuf[], wfbuf[]; -extern int maxwrds, maxactwds, pathlength, maxinpwd, maxlocs, maxndx; +extern char history[HISTLEN][BUFSIZE]; +extern int histi; +extern int maxwrds, maxactwds, maxinpwd, maxlocs, maxndx; extern int maxacts, maxpreacts, maxpostacts, maxfields, maxvars; extern int ldescfreq; extern char fieldelim, linedelim; @@ -187,4 +200,53 @@ extern int max_carry; extern char inwrd[][32]; extern char locseen[], locstate[]; extern int var[]; - +extern FILE *mfp, *wfp; + +// routines in wand1.c +int main(); +void prloc(); +char *getcom(); +int carry_out(); +int check_act(); +void get_loc(); +void setup(); +struct actstr *code_act(); +int get_files(); + +// routines in wand2.c +void restart(); +void takeobj(); +char *objdesc(); +char *deparity(char *from); +void bytecopy(); +char *movchars(); +int obj_at(); +int oneof(); +int class(); +void dotpair(); +void atpair(); +int atov(); +char *store(); +int length(); +int wdparse(); +char *msglin(); +void quit(); +void save(); +void restore(); +void monsav(); +long getndx(); +char *msgpara(); +char *msgfmt(); +void inventory(); +int wrdadd(); +int which(); +int wfnd(); +void ungetlin(); +int getlin(); +int getpara(); +int atoip(); +char *splur(); +char *cpy(char *tp, char *fp); +char *cpyn(char *tp, char *fp, int n); +off_t fsize(FILE *fp); +void boswell(char *command); diff --git a/wandglb.c b/wandglb.c old mode 100644 new mode 100755 index 143b1b9..ac5231a --- a/wandglb.c +++ b/wandglb.c @@ -28,74 +28,75 @@ struct actstr post_acts[MAXPOSTACTS]; // Note that the syn field must be turned into the index of the root word struct wrdstr wrds[MAXWRDS] = { - listunused, 0, 0, MAXWRDS, /* hopefully nothing matches this */ - "inventory", 0, 0, 0, - "take", 0, 0, 0, - "pick", 1, 0, 0, - "drop", 0, 0, 0, - "quit", 0, 0, 0, - "save", 0, 0, 0, - "restore", 0, 0, 0, - "look", 0, 0, 0, - "initialize", 0, 0, 0, - "north", 0, 0, 0, - "n", 1, 0, 0, - "south", 0, 0, 0, - "s", 1, 0, 0, - "east", 0, 0, 0, - "e", 1, 0, 0, - "west", 0, 0, 0, - "w", 1, 0, 0, - "up", 0, 0, 0, - "u", 1, 0, 0, - "down", 0, 0, 0, - "d", 1, 0, 0, - "northeast", 0, 0, 0, - "ne", 1, 0, 0, - "southeast", 0, 0, 0, - "se", 1, 0, 0, - "southwest", 0, 0, 0, - "sw", 1, 0, 0, - "northwest", 0, 0, 0, - "nw", 1, 0, 0, /* must be the last direction verb */ - "~snoop", 0, 0, 0, /* this only works if you are owner */ - "~goto", 0, 0, 0, /* this only works if you are owner */ - "~vars", 0, 0, 0, /* this only works if you are owner */ - "~version", 0, 0, 0, /* this only works if you are owner */ - "*", 0, 0, 0, - "N1", 0, 0, 0, - "N2", 0, 0, 0, - "all", 0, 0, 0, /* used in "take all" & "drop all" */ - 0, 0, 0, 0, /* "all" must be the last defined here */ + listunused, 0, 0, MAXWRDS, /* hopefully nothing matches this */ + "drop", 0, 0, 0, + "inventory", 0, 0, 0, + "quit", 0, 0, 0, + "save", 0, 0, 0, + "take", 0, 0, 0, + "pick", 1, 0, 0, + "restore", 0, 0, 0, + "look", 0, 0, 0, + "initialize", 0, 0, 0, + "history", 0, 0, 0, + "north", 0, 0, 0, + "n", 1, 0, 0, + "south", 0, 0, 0, + "s", 1, 0, 0, + "east", 0, 0, 0, + "e", 1, 0, 0, + "west", 0, 0, 0, + "w", 1, 0, 0, + "up", 0, 0, 0, + "u", 1, 0, 0, + "down", 0, 0, 0, + "d", 1, 0, 0, + "northeast", 0, 0, 0, + "ne", 1, 0, 0, + "southeast", 0, 0, 0, + "se", 1, 0, 0, + "southwest", 0, 0, 0, + "sw", 1, 0, 0, + "northwest", 0, 0, 0, + "nw", 1, 0, 0, /* must be the last direction verb */ + "~snoop", 0, 0, 0, /* this only works if you are owner */ + "~goto", 0, 0, 0, /* this only works if you are owner */ + "~vars", 0, 0, 0, /* this only works if you are owner */ + "~version", 0, 0, 0, /* this only works if you are owner */ + "*", 0, 0, 0, + "N1", 0, 0, 0, + "N2", 0, 0, 0, + "all", 0, 0, 0, /* used in "take all" & "drop all" */ + 0, 0, 0, 0, /* "all" must be the last defined here */ }; struct wrdstr spvars[] = { /* special construct & their meanings */ - "CUR_LOC", 0, 0, CUR_LOC, - "PREV_LOC", 0, 0, PREV_LOC, - "INP_W1", 0, 0, INP_W1, - "INP_W2", 0, 0, INP_W2, - "INP_W3", 0, 0, INP_W3, - "INP_W4", 0, 0, INP_W4, - "INP_W5", 0, 0, INP_W5, - "INP_WC", 0, 0, INP_WC, - "NUM_CARRY", 0, 0, NUM_CARRY, - "MAX_CARRY", 0, 0, MAX_CARRY, - "NOW_YEAR", 0, 0, NOW_YEAR, - "NOW_MONTH", 0, 0, NOW_MONTH, - "NOW_DOM", 0, 0, NOW_DOM, - "NOW_DOW", 0, 0, NOW_DOW, - "NOW_HOUR", 0, 0, NOW_HOUR, - "NOW_MIN", 0, 0, NOW_MIN, - "NOW_SEC", 0, 0, NOW_SEC, - "NOW_ET", 0, 0, NOW_ET, - "BREVITY", 0, 0, BREVITY, - "LOC_VIEW", 0, 0, LOC_VIEW, - "OBJ_VIEW", 0, 0, OBJ_VIEW, - "INP_N1", 0, 0, INP_N1, - "INP_N2", 0, 0, INP_N2, - "NUM_MOVES", 0, 0, NUM_MOVES, - "NUM_PLACES", 0, 0, NUM_PLACES, - 0, 0, 0, 0, + "CUR_LOC", 0, 0, CUR_LOC, + "PREV_LOC", 0, 0, PREV_LOC, + "INP_W1", 0, 0, INP_W1, + "INP_W2", 0, 0, INP_W2, + "INP_W3", 0, 0, INP_W3, + "INP_W4", 0, 0, INP_W4, + "INP_W5", 0, 0, INP_W5, + "INP_WC", 0, 0, INP_WC, + "NUM_CARRY", 0, 0, NUM_CARRY, + "MAX_CARRY", 0, 0, MAX_CARRY, + "NOW_YEAR", 0, 0, NOW_YEAR, + "NOW_MONTH", 0, 0, NOW_MONTH, + "NOW_DOM", 0, 0, NOW_DOM, + "NOW_DOW", 0, 0, NOW_DOW, + "NOW_HOUR", 0, 0, NOW_HOUR, + "NOW_MIN", 0, 0, NOW_MIN, + "NOW_SEC", 0, 0, NOW_SEC, + "NOW_ET", 0, 0, NOW_ET, + "BREVITY", 0, 0, BREVITY, + "LOC_VIEW", 0, 0, LOC_VIEW, + "OBJ_VIEW", 0, 0, OBJ_VIEW, + "INP_N1", 0, 0, INP_N1, + "INP_N2", 0, 0, INP_N2, + "NUM_MOVES", 0, 0, NUM_MOVES, + "NUM_PLACES", 0, 0, NUM_PLACES, + 0, 0, 0, 0, }; char *thereis[] = { @@ -120,15 +121,18 @@ char tmonfil[PATHLENGTH]; char monfile[PATHLENGTH]; char *stdpath = WANDPATH(/); /* where std. worlds live */ -char curfile[PATHLENGTH] = "a3"; /* default world */ -char newfile[PATHLENGTH]; /* temp for world name */ +char curname[PATHLENGTH] = "a3"; /* default world */ char *defmfile = WANDPATH(wand.mon); /* def monfil name */ char mfbuf[BUFSIZ]; /* so stdio won't sbrk() */ char wfbuf[BUFSIZ]; /* ditto */ +char history[HISTLEN][BUFSIZE]; /* the last HISTLEN commands */ +int histi; /* index into history */ + + + int maxwrds = MAXWRDS; -int pathlength = PATHLENGTH; int maxlocs = MAXLOCS; int maxndx = MAXINDEX; int maxacts = MAXACTS; @@ -154,3 +158,4 @@ int max_carry = 8; /* default max objects to carry at once */ char inwrd[MAXACTWDS][32]; /* current input words */ char locseen[MAXLOCS], locstate[MAXLOCS]; int var[MAXVARS]; +FILE *mfp, *wfp; diff --git a/wandsys.c b/wandsys.c old mode 100644 new mode 100755