+#ifndef lint
+static char sccsid[] = "@(#)mem.c 4.1 (Berkeley) %G%";
+#endif not lint
+
+# include "stdio.h"
+# include "lrnref.h"
+# define SAME 0
+
+struct keys {
+ char *k_wd;
+ int k_val;
+} keybuff[] = {
+ {"ready", READY},
+ {"answer", READY},
+ {"#print", PRINT},
+ {"#copyin", COPYIN},
+ {"#uncopyin", UNCOPIN},
+ {"#copyout", COPYOUT},
+ {"#uncopyout", UNCOPOUT},
+ {"#pipe", PIPE},
+ {"#unpipe", UNPIPE},
+ {"#succeed", SUCCEED},
+ {"#fail", FAIL},
+ {"bye", BYE},
+ {"chdir", CHDIR},
+ {"cd", CHDIR},
+ {"learn", LEARN},
+ {"#log", LOG},
+ {"yes", YES},
+ {"no", NO},
+ {"#mv", MV},
+ {"#user", USER},
+ {"#next", NEXT},
+ {"skip", SKIP},
+ {"#where", WHERE},
+ {"#match", MATCH},
+ {"#bad", BAD},
+ {"#create", CREATE},
+ {"#cmp", CMP},
+ {"#goto", GOTO},
+ {"#once", ONCE},
+ {"#", NOP},
+ {NULL, 0}
+};
+
+int *action(s)
+char *s;
+{
+ struct keys *kp;
+ for (kp=keybuff; kp->k_wd; kp++)
+ if (strcmp(kp->k_wd, s) == SAME)
+ return(&(kp->k_val));
+ return(NULL);
+}
+
+# define NW 100
+# define NWCH 800
+struct whichdid {
+ char *w_less;
+ int w_seq;
+} which[NW];
+int nwh = 0;
+char whbuff[NWCH];
+char *whcp = whbuff;
+
+setdid(lesson, sequence)
+char *lesson;
+{
+ struct whichdid *pw;
+ for(pw=which; pw < which+nwh; pw++)
+ if (strcmp(pw->w_less, lesson) == SAME)
+ {
+ pw->w_seq = sequence;
+ return;
+ }
+ pw=which+nwh++;
+ if (nwh >= NW) {
+ fprintf(stderr, "nwh>=NW\n");
+ wrapup(1);
+ }
+ pw->w_seq = sequence;
+ pw->w_less = whcp;
+ while (*whcp++ = *lesson++);
+ if (whcp >= whbuff + NWCH) {
+ fprintf(stderr, "lesson name too long\n");
+ wrapup(1);
+ }
+}
+
+already(lesson, sequence)
+char *lesson;
+{
+ struct whichdid *pw;
+ for (pw=which; pw < which+nwh; pw++)
+ if (strcmp(pw->w_less, lesson) == SAME)
+ return(1);
+ return(0);
+}