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