date and time created 83/02/24 12:56:03 by mckusick
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 25 Feb 1983 04:56:03 +0000 (20:56 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 25 Feb 1983 04:56:03 +0000 (20:56 -0800)
SCCS-vsn: usr.bin/learn/learn/mem.c 4.1

usr/src/usr.bin/learn/learn/mem.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/learn/learn/mem.c b/usr/src/usr.bin/learn/learn/mem.c
new file mode 100644 (file)
index 0000000..a495586
--- /dev/null
@@ -0,0 +1,98 @@
+#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);
+}