BSD 4_2 release
[unix-history] / usr / src / usr.bin / learn / mem.c
CommitLineData
eb7a6651 1#ifndef lint
0f4556f1 2static char sccsid[] = "@(#)mem.c 4.2 (Berkeley) 4/25/83";
eb7a6651
KM
3#endif not lint
4
5# include "stdio.h"
6# include "lrnref.h"
7# define SAME 0
8
9struct keys {
10 char *k_wd;
11 int k_val;
12} keybuff[] = {
13 {"ready", READY},
14 {"answer", READY},
15 {"#print", PRINT},
16 {"#copyin", COPYIN},
17 {"#uncopyin", UNCOPIN},
18 {"#copyout", COPYOUT},
19 {"#uncopyout", UNCOPOUT},
20 {"#pipe", PIPE},
21 {"#unpipe", UNPIPE},
22 {"#succeed", SUCCEED},
23 {"#fail", FAIL},
24 {"bye", BYE},
25 {"chdir", CHDIR},
26 {"cd", CHDIR},
27 {"learn", LEARN},
28 {"#log", LOG},
29 {"yes", YES},
30 {"no", NO},
2b9e3de9 31 {"again", AGAIN},
eb7a6651
KM
32 {"#mv", MV},
33 {"#user", USER},
34 {"#next", NEXT},
35 {"skip", SKIP},
2b9e3de9 36 {"where", WHERE},
eb7a6651
KM
37 {"#match", MATCH},
38 {"#bad", BAD},
39 {"#create", CREATE},
40 {"#cmp", CMP},
2b9e3de9 41 {"xyzzy", XYZZY},
eb7a6651
KM
42 {"#once", ONCE},
43 {"#", NOP},
44 {NULL, 0}
45};
46
47int *action(s)
48char *s;
49{
50 struct keys *kp;
51 for (kp=keybuff; kp->k_wd; kp++)
52 if (strcmp(kp->k_wd, s) == SAME)
53 return(&(kp->k_val));
54 return(NULL);
55}
56
57# define NW 100
58# define NWCH 800
59struct whichdid {
60 char *w_less;
61 int w_seq;
62} which[NW];
63int nwh = 0;
64char whbuff[NWCH];
65char *whcp = whbuff;
2b9e3de9 66static struct whichdid *pw;
eb7a6651
KM
67
68setdid(lesson, sequence)
69char *lesson;
2b9e3de9 70int sequence;
eb7a6651 71{
2b9e3de9
KM
72 if (already(lesson)) {
73 pw->w_seq = sequence;
74 return;
75 }
76 pw = which+nwh++;
eb7a6651 77 if (nwh >= NW) {
2b9e3de9
KM
78 fprintf(stderr, "Setdid: too many lessons\n");
79 tellwhich();
eb7a6651
KM
80 wrapup(1);
81 }
82 pw->w_seq = sequence;
83 pw->w_less = whcp;
84 while (*whcp++ = *lesson++);
85 if (whcp >= whbuff + NWCH) {
2b9e3de9
KM
86 fprintf(stderr, "Setdid: lesson names too long\n");
87 tellwhich();
eb7a6651
KM
88 wrapup(1);
89 }
90}
91
2b9e3de9
KM
92unsetdid(lesson)
93char *lesson;
94{
95 if (!already(lesson))
96 return;
97 nwh = pw - which; /* pretend the rest have not been done */
98 whcp = pw->w_less;
99}
100
101already(lesson)
eb7a6651
KM
102char *lesson;
103{
eb7a6651
KM
104 for (pw=which; pw < which+nwh; pw++)
105 if (strcmp(pw->w_less, lesson) == SAME)
106 return(1);
107 return(0);
108}
2b9e3de9
KM
109
110tellwhich()
111{
112 for (pw=which; pw < which+nwh; pw++)
113 printf("%3d lesson %7s sequence %3d\n",
114 pw-which, pw->w_less, pw->w_seq);
115}