|
|
1.1 root 1: /* Copyright Bell Telephone Labotatories Whippany, N.J.
2:
3: * *******************************************
4: * *******************************************
5: * *** FETCH LINES FROM THE PROGRAM BUFFER ***
6: * ******* R. B. Drake WH 8C-005 X4163 *******
7: * ******** Fri Aug 24 17:25:20 1979 *********
8: * *******************************************
9: * *******************************************
10:
11: */
12: /* "@(#) fetch.c: V 1.1 12/21/80" */
13:
14: /*
15: This routine fetches lines from the program txtbuf as described
16: below:
17: *
18: *
19: * calling sequence: fetch([0 -1 n],&ptr)
20: * result: if arg1 is 0, fetches the first line of the program
21: * if arg1 is -1, fetches the next sequential line
22: * if arg1 is n, fetches line number n
23: * ptr is the adress of a character pointer to be used by fetch
24: * a zero is returned if the operation was successful
25: * a minus 1 is returned if the operation failed
26: * a minus 2 is returned if a line was found but not line n
27: * data is returned as follows:
28: * inst.thing.linno contains the line number
29: * inst.opcode.lobyte contains the operation code
30: * expr points to the first character of the expression string
31: *
32: */
33: #include "bas.h"
34: char *expr;
35: extern char *curptr;
36: fetch(i,ptr)
37: int i;
38: char **ptr;
39: {
40: int j;
41: /* if line n is requested, search the page index for the
42: * page which contains the requested line. Then search
43: * that page sequentially until the line is found
44: */
45: curptr = *ptr;
46: if(i>0)
47: {
48: if(!index[0].maxlin)
49: {
50: curptr = *ptr = txtbuf;
51: return(-1);
52: } /*empty txtbuf */
53: for(j=0;j<32;j++)
54: {
55: if((i>index[j].maxlin) && (index[j+1].maxlin != 0))
56: continue;
57: *ptr = index[j].begin;
58: inst.thing.linno=0;
59: while((i>inst.thing.linno)&&(fetch(-1,ptr) == 0));
60: if(i== inst.thing.linno) return(0);
61: return(-2); /* -2 used to indicate that
62: * a line was found but it
63: * is not the one asked for */
64: }
65: }
66: /* if the first line of the program is requested
67: * set the pointer to the beginnig of the txtbuf
68: * retrieve the line found there and leave the
69: * pointer at the beginning of the next line
70: */
71: if(i==0)
72: curptr= *ptr=txtbuf;
73: /* otherwise use ptr to retrieve the next line */
74: if(**ptr == '\0' && *(*ptr+1) == '\0' || *ptr >= linptr)
75: return(-1);
76: for(j=0;j<4;j++)
77: inst.byte[j] = *(*ptr)++;
78: expr = *ptr;
79: while(*(*ptr)++);
80: return(0);
81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.