1: # include "stdio.h" 2: # include "lrnref" 3: # define SAME 0 4: 5: struct keys { 6: char *k_wd; 7: int k_val; 8: } keybuff[] = { 9: {"ready", READY}, 10: {"answer", READY}, 11: {"#print", PRINT}, 12: {"#copyin", COPYIN}, 13: {"#uncopyin", UNCOPIN}, 14: {"#copyout", COPYOUT}, 15: {"#uncopyout", UNCOPOUT}, 16: {"#pipe", PIPE}, 17: {"#unpipe", UNPIPE}, 18: {"#succeed", SUCCEED}, 19: {"#fail", FAIL}, 20: {"bye", BYE}, 21: {"chdir", CHDIR}, 22: {"cd", CHDIR}, 23: {"learn", LEARN}, 24: {"#log", LOG}, 25: {"yes", YES}, 26: {"no", NO}, 27: {"#mv", MV}, 28: {"#user", USER}, 29: {"#next", NEXT}, 30: {"skip", SKIP}, 31: {"#where", WHERE}, 32: {"#match", MATCH}, 33: {"#bad", BAD}, 34: {"#create", CREATE}, 35: {"#cmp", CMP}, 36: {"#goto", GOTO}, 37: {"#once", ONCE}, 38: {"#", NOP}, 39: {NULL, 0} 40: }; 41: 42: int *action(s) 43: char *s; 44: { 45: struct keys *kp; 46: for (kp=keybuff; kp->k_wd; kp++) 47: if (strcmp(kp->k_wd, s) == SAME) 48: return(&(kp->k_val)); 49: return(NULL); 50: } 51: 52: # define NW 100 53: # define NWCH 800 54: struct whichdid { 55: char *w_less; 56: int w_seq; 57: } which[NW]; 58: int nwh = 0; 59: char whbuff[NWCH]; 60: char *whcp = whbuff; 61: 62: setdid(lesson, sequence) 63: char *lesson; 64: { 65: struct whichdid *pw; 66: for(pw=which; pw < which+nwh; pw++) 67: if (strcmp(pw->w_less, lesson) == SAME) 68: { 69: pw->w_seq = sequence; 70: return; 71: } 72: pw=which+nwh++; 73: if (nwh >= NW) { 74: fprintf(stderr, "nwh>=NW\n"); 75: wrapup(1); 76: } 77: pw->w_seq = sequence; 78: pw->w_less = whcp; 79: while (*whcp++ = *lesson++); 80: if (whcp >= whbuff + NWCH) { 81: fprintf(stderr, "lesson name too long\n"); 82: wrapup(1); 83: } 84: } 85: 86: already(lesson, sequence) 87: char *lesson; 88: { 89: struct whichdid *pw; 90: for (pw=which; pw < which+nwh; pw++) 91: if (strcmp(pw->w_less, lesson) == SAME) 92: return(1); 93: return(0); 94: }