1: # include <ingres.h>
2: # include "globs.h"
3: # include <sccs.h>
4:
5: SCCSID(@(#)rnum.c 8.2 5/1/85)
6:
7:
8: /*
9: ** Internal numbers are used in decomp to
10: ** represent relation names. The numbers
11: ** from 0 to FIRSTNUM-1 refer to the names
12: ** stored in De.de_name_table[].
13: **
14: ** The number from FIRSTNUM to LASTNUM have
15: ** names which are computed from aa, ab, etc.
16: */
17:
18:
19:
20:
21: /*
22: ** Assign an internal number rnum to name.
23: */
24:
25: rnum_assign(name)
26: char *name;
27: {
28: register int i;
29:
30: for (i = 0; i < FIRSTNUM; i++)
31: if (De.de_num_used[i] == 0)
32: {
33: bmove(name, De.de_name_table[i], MAXNAME);
34: De.de_num_used[i]++;
35: return (i);
36: }
37: syserr("rnum_assign:no room");
38: return (-1);
39: }
40: /*
41: ** Find an existing rnum on a relation or add one.
42: */
43:
44: rnum_findadd(name)
45: char *name;
46: {
47: register int i;
48:
49: for (i = 0; i < FIRSTNUM; i++)
50: if (De.de_num_used[i]
51: && !bcmp(name, De.de_name_table[i], MAXNAME))
52: return(i);
53: return(rnum_assign(name));
54: }
55: /*
56: ** Allocate the next available name
57: */
58:
59: rnum_alloc()
60: {
61: register int i;
62: register char *cp;
63:
64: cp = &De.de_num_used[FIRSTNUM];
65: for (i = FIRSTNUM; i < LASTNUM; i++)
66: if (*cp++ == 0)
67: {
68: --cp;
69: (*cp)++;
70: return (i);
71: }
72: syserr("no free names");
73: return (-1);
74: }
75: /*
76: ** Convert internal relation number
77: ** to its real name. Guarantee '\0' at end.
78: */
79:
80: char *
81: rnum_convert(num)
82: int num;
83: {
84: register int i;
85: register char *ret, *cp;
86: static char temp[MAXNAME+1];
87: extern char *Fileset;
88: extern char *concat();
89:
90: i = num;
91: if (i > LASTNUM || De.de_num_used[i] == 0)
92: syserr("no name for %d", i);
93:
94: ret = temp;
95:
96: if (i < FIRSTNUM)
97: {
98: bmove(De.de_name_table[i], ret, MAXNAME);
99: }
100: else
101: {
102: /* compute temp name */
103: i -= FIRSTNUM;
104: strcpy(temp, "_SYS");
105: temp[4] = i%26 + 'a';
106: temp[5] = i/26 + 'a';
107: temp[6] = '\0';
108: concat(temp, Fileset, temp);
109: pad(temp, MAXNAME);
110: }
111: return (ret);
112: }
113: /*
114: ** Remove a num from the used list
115: */
116:
117: rnum_remove(num)
118: int num;
119: {
120: register char *cp;
121:
122: cp = &De.de_num_used[num];
123:
124: if (*cp == 0)
125: syserr("cant remove %d", num);
126: *cp = 0;
127: }
128: /*
129: ** returns number of largest assigned temp number.
130: ** zero if none
131: */
132:
133: rnum_last()
134: {
135: register int i;
136:
137: for (i = LASTNUM - 1; i >= FIRSTNUM; i--)
138: {
139: if (De.de_num_used[i])
140: {
141: return (i);
142: }
143: }
144:
145: return (0);
146: }
147: /*
148: ** Predicate to check whether rnum is a temporary relation or not
149: */
150:
151: rnum_temp(rnum)
152: int rnum;
153: {
154: register int i;
155:
156: i = rnum;
157:
158: return (i >= FIRSTNUM || bequal("_SYS", rnum_convert(i), 4));
159: }
160: /*
161: ** Clear tag fields from previous query
162: */
163:
164: rnum_init()
165: {
166: register char *cp;
167: register int i;
168:
169: cp = De.de_num_used;
170: i = FIRSTNUM;
171: while (--i)
172: *cp++ = 0;
173: }
Defined functions
rnum_convert
defined in line
80; used 24 times
- in line 158
- in /usr/ingres/source/decomp/byeval.c line
76,
92,
110,
239
- in /usr/ingres/source/decomp/call_ovqp.c line
57,
81
- in /usr/ingres/source/decomp/exec_sq.c line
196,
206
- in /usr/ingres/source/decomp/openrs.c line
163,
169,
176-177(2),
213,
318,
341,
377
- in /usr/ingres/source/decomp/rangetable.c line
144-146(2)
- in /usr/ingres/source/decomp/reformat.c line
375,
419
- in /usr/ingres/source/decomp/usubr.c line
112,
118,
149