1: # include "../ingres.h"
2: # include "../symbol.h"
3: # include "../tree.h"
4: # include "decomp.h"
5: # include "../pipes.h"
6:
7:
8: /*
9: ** READQUERY
10: **
11: ** Reads in query symbols from input pipe into core
12: ** locations and sets up information needed for later
13: ** processing.
14: **
15: ** Returns:
16: ** pointer to start of tree
17: **
18: ** Side Effects:
19: **
20: ** Sets Qmode to mode of query
21: ** Resultvar gets result variable number or -1
22: ** Range table gets initialized.
23: */
24:
25: struct pipfrmt Inpipe;
26:
27: struct querytree *readqry()
28: {
29: register struct symbol *s;
30: register struct querytree *q;
31: register int mark;
32: int i;
33: struct querytree *readnode();
34:
35: # ifdef xDTR1
36: if (tTf(1, -1))
37: printf("READQUERY:\n");
38: # endif
39:
40: Resultvar = -1;
41: Qmode = -1;
42: mark = markbuf(Qbuf);
43: for (;;)
44: {
45: freebuf(Qbuf, mark);
46: q = readnode(Qbuf);
47: s = &(q->sym);
48: # ifdef xDTR1
49: if (tTf(1, 1))
50: {
51: printf("%d, %d, %d/", s->type, s->len, s->value[0] & 0377);
52: if (s->type == SOURCEID)
53: printf("%.12s", ((struct srcid *)s)->srcname);
54: printf("\n");
55: }
56: # endif
57: switch (s->type)
58: {
59: case QMODE:
60: Qmode = s->value[0];
61: break;
62:
63: case RESULTVAR:
64: Resultvar = s->value[0];
65: break;
66:
67: case SOURCEID:
68: i = ((struct srcid *)s)->srcvar;
69: Rangev[i].relnum = rnum_assign(((struct srcid *)s)->srcname);
70: break;
71:
72: case TREE:
73: readtree(Qbuf);
74: return (q);
75:
76: default:
77: syserr("readq: bad symbol %d", s->type);
78: }
79: }
80: }
81:
82: struct querytree *readnode(buf)
83: char *buf;
84: {
85: register int len, user;
86: register struct querytree *q;
87: extern struct querytree *need();
88:
89: q = need(buf, 6); /* space for left,right ptrs + type & len */
90:
91: /* read in type and length */
92: if (rdpipe(P_NORM, &Inpipe, R_up, &(q->sym), 2) < 2)
93: goto err3;
94: len = q->sym.len & I1MASK;
95:
96: if (len)
97: {
98: need(buf, len);
99: if (rdpipe(P_NORM, &Inpipe, R_up, q->sym.value, len) < len)
100: goto err3;
101: return (q);
102: }
103:
104: /* if type is and, root, or aghead, allocate 6 or 8 byte for var maps */
105: user = FALSE;
106: switch (q->sym.type)
107: {
108:
109: case ROOT:
110: user = TRUE;
111: case AGHEAD:
112: len = 8;
113: need(buf, len);
114: ((struct qt_root *)q)->rootuser = user;
115: break;
116:
117: case AND:
118: len = 6;
119: need(buf, len);
120: }
121: q->sym.len = len;
122: return (q);
123: err3:
124: syserr("readsym: read error on R_up");
125: }
126:
127:
128: /*
129: * readtree
130: *
131: * reads in tree symbols into a buffer up to an end root symbol
132: *
133: */
134: readtree(buf)
135: char *buf;
136: {
137: register struct querytree *nod;
138:
139: do
140: {
141: nod = readnode(buf);
142: # ifdef xDTR1
143: if (tTf(1, 2))
144: {
145: printf("\t");
146: writenod(nod);
147: }
148: # endif
149: } while (nod->sym.type != ROOT);
150: clearpipe(); /* This is needed in case query was multiple of 120 bytes */
151: }
Defined functions
Defined variables