|
|
1.1 root 1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
2:
3: * /////////////////////////////////////
4: * /////////////////////////////////////
5: * ///////////// encode.c //////////////
6: * /// J. P. Hawkins WH X4610 8C-001 ///
7: * ///// Sun Aug 26 06:33:03 1979 //////
8: * /////////////////////////////////////
9: * /////////////////////////////////////
10:
11: *
12: * ENCODE BASIC COMMAND
13: * mod,J.P.Hawkins,17-JUL-79, add "else" and "endif" commands
14: */
15: /* "@(#) encode.c: V 1.3 11/29/81" */
16: #include "bas.h"
17: /*
18: *
19: * //////// BASIC INTERPRETER COMMAND TABLE ////////
20: *
21: */
22: int delete(); /* delete specified line number(s) */
23: int brake(); /* break out of a for loop */
24: int cont();
25: int dim(); /* alloc specified data array */
26: int __end(); /* define end of program */
27: int expunge(); /* expunge variables */
28: int _for(); /* initialize and/or test "for" loop */
29: int gosub(); /* goto subroutine, return to next statement */
30: int call(); /* overlay and gosub */
31: int __goto(); /* goto specified statement number */
32: int __if(); /* if/then/goto test */
33: int __input(); /* accept input from stdio dev */
34: int new(); /* clean out BASIC program txtbuf */
35: int let(); /* execute assignment */
36: int list(); /* reverse translate, then list */
37: int next(); /* terminate last "for" statement */
38: int pause(); /* wait for spacebar or panel pause button */
39: int __print(); /* print string and/or variables */
40: int _random(); /* plant random "seed" for "rnd" cmd */
41: int __read(); /* initialized data */
42: int no_op(); /* ignore this statemtnt */
43: int restore(); /* restore initialized data area pointer */
44: int __return(); /* return from subroutine called by gosub */
45: int sub(); /* substitute command for editing */
46: int run(); /* run or load and run a BASIC core image */
47: int sing(); /* single step execution */
48: int con(); /* continue from single step */
49: int stop(); /* halt program execution and re-init */
50: int minus(); /* print previous program line */
51: int reseq(); /* resequence line numbers */
52: int mov(); /* move a group of lines */
53: int autnum(); /* start auto line numbering */
54: int save(); /*save basic program full ascii text form*/
55: int f(); /* print current filename */
56: int load(); /*read in basic file in full ascii text form*/
57: int old(); /* clear user core, the read in BASIC prog */
58: int corleft(); /* returns amount of core bytes remaining in decimal */
59: int undo(); /* undoes the last substite command */
60: int _common(); /* preserve variables for next "run" */
61: int on(); /* on goto, on gosub */
62: int goaway(); /* "bye" command exits the interpreter */
63: int openo(); /* OPEN file(s) for write */
64: int openi(); /* OPEN file(s) for reading */
65: int __seek(); /* random access */
66: int rewin(); /* Rewind to beginning of file */
67: int append(); /* Open file for append, create if non-exist */
68: int _closef(); /* CLOSE FILE */
69: int clall(); /* Close all open files */
70: int iprintf(); /* interpretive printf */
71: int _else(); /* ELSE command for structured "if" */
72: int _endif(); /* Structured "if" terminator */
73: int sysls(); /* direct call to ls */
74: int sysrm(); /* direct call to rm */
75:
76: #ifndef LSX
77: int bsys(); /* "!" command for system calls */
78: #endif
79: #ifdef TEST
80: int buscmd(); /* IEEE BUS COMMAND */
81: int buspr(); /* print to IEEE BUS */
82: int ps(); /* set power supply */
83: int relay(); /* set relays command */
84: int bscan(); /* set scanner command */
85: int bdelay(); /* 1/60 sec delay command */
86: int bdvminit(); /* dvm initializer */
87: int bdvms(); /* dvm setup command */
88: int bhprintf(); /* strip printer driver */
89: int lodset(); /* load setting driver */
90: #endif
91: #ifdef LSX
92: int chdir();
93: int lsdir();
94: int pwd();
95: #endif
96: /*
97: *
98: * This is the BASIC interpreter command string and routine
99: * dispatch table.
100: * This table is used for forward translation of a BASIC text
101: * file to it's core image form and is also used in the reverse
102: * translation process.
103: * In loadin the basic text file (.b) the table is searched
104: * for each command encountered in the file and is used to replace
105: * the command with a "PSEUDO CODE" or the relative position of the
106: * code in the table. This process also occurs when an input line is typed
107: * before it is stored for a run.
108: * When a run command is executed the table need-NOT be searched
109: * as the offset is already "compiled" in the code.
110: * The basic execution routine is then executed by an indirect,
111: * indexed jump through this table.
112: * The format of a line in a BASIC core image is as follows:
113: * first two bytes represent the integer value of the line number.
114: * Second two bytes represent the PSEUDO code or table offset.
115: * Then the rest of the line is in it's original TEXT form,
116: * terminated by a line-feed (NO-NULL)
117: *
118: *
119: */
120:
121: /*
122: * each entry contains the text for the BASIC command
123: * in question and the address of the routine which sevices it
124: */
125: struct COMMAND cmdtbl[] = {
126: {"common", _common},
127: {"on", on},
128: {"com", _common},
129: {"data", no_op},
130: {"delete", delete},
131: {"break", brake},
132: {"continue", cont},
133: {"del", delete},
134: {"dim", dim},
135: {"end", __end},
136: {"bye", goaway},
137: {"q", goaway},
138: {"expunge", expunge},
139: {"for", _for},
140: {"gosub", gosub},
141: {"call", call},
142: {"goto", __goto},
143: {"go to", __goto},
144: {"if", __if},
145: {"input", __input},
146: {"new", new},
147: {"let", let},
148: {"\010", let},
149: {"list", list},
150: {"l", list},
151: {"n", list},
152: {"next", next},
153: {"pause", pause},
154: {"pr", __print},
155: {"print", __print},
156: {"randomize", _random},
157: {"read", __read},
158: {"rem", no_op},
159: {"restore", restore},
160: {"return", __return},
161: {"s", sub}, /* substitute command */
162: {"undo", undo},
163: {"run", run},
164: {"sing", sing},
165: {"con", con},
166: {"stop", stop},
167: {"-", minus},
168: {"reseq", reseq},
169: {"mov", mov},
170: {"auto", autnum},
171: {"a", autnum},
172: {"save", save},
173: {"w", save},
174: {"f", f},
175: {"load", load},
176: {"old", old},
177: {"size", corleft},
178: {"openo", openo},
179: {"openi", openi},
180: {"seek", __seek},
181: {"rewin", rewin},
182: {"close", _closef},
183: {"closeall", clall},
184: {"append", append},
185: {"printf", iprintf},
186: {"else", _else},
187: {"endif", _endif},
188: {"ls", sysls},
189: {"rm", sysrm},
190: #ifndef LSX
191: {"!", bsys},
192: #endif
193: #ifdef TEST
194: {"cmd", buscmd},
195: {"buspr", buspr},
196: {"ps", ps},
197: {"relay", relay},
198: {"dvminit", bdvminit},
199: {"scan", bscan},
200: {"delay", bdelay},
201: {"dvms", bdvms},
202: {"hprintf", bhprintf},
203: {"lodset", lodset},
204: #endif
205: #ifdef LSX
206: {"cd", chdir},
207: {"ls", lsdir},
208: {"pwd", pwd},
209: #endif
210: {0, 0} /* null terminator */
211: };
212:
213: goaway()
214: {
215: clall();
216: exit(0);
217: }
218: /*
219: *
220: * calling format:
221: * code = encode(string);
222: *
223: * where: code = integer returned as opcode (table offset)
224: * -1 (minus one) returned if search failed
225: * string = pointer to string containing code text
226: * to be translated or encoded (null terminated)
227: */
228:
229: encode(s)
230: char s[];
231: {
232: register int i; /* index reg. for expediency */
233: /*
234: * compare each string in table with s
235: * when match is found, return index (OPCODE)
236: * if end-of-table (null) encountered return -1
237: */
238: for(i=0; cmdtbl[i].cmdtxt != 0 ; i++)
239: {
240: if(!(strcmp(s, cmdtbl[i].cmdtxt)))
241: return(i); /* we found it! */
242: }
243: return(-1); /* oops not in this table, pal */
244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.