|
|
1.1 root 1: # include <pv.h>
2: # include <ingres.h>
3: # include <aux.h>
4: # include <catalog.h>
5: # include <access.h>
6: # include <func.h>
7: # include <signal.h>
8: # include <sccs.h>
9:
10: SCCSID(@(#)help.c 7.4 9/26/83)
11:
12: extern short tTdbu[100];
13: extern int help();
14: extern int null_fn();
15:
16: struct fn_def HelpFn =
17: {
18: "HELP",
19: help,
20: null_fn, /* initialization function */
21: null_fn,
22: NULL,
23: 0,
24: tTdbu,
25: 100,
26: 'Z',
27: 0
28: };
29:
30:
31: /*
32: ** HELP - Provide Information to User
33: **
34: ** Arguments:
35: ** pv[i] - code
36: ** 0 - print relation information
37: ** 1 - print manual section
38: ** 2 - print relation list
39: ** 3 - print relation info for all accessible relations
40: ** pv[i+1] - name of entity for modes 0 or 1
41: **
42: ** Trace Flags:
43: ** 44
44: */
45:
46: help(parmc, parmv)
47: int parmc;
48: PARM parmv[];
49: {
50: DESC des;
51: int mode;
52: register PARM *pv;
53: register int ret;
54:
55: # ifdef xZTR1
56: if (tTf(44, -1))
57: {
58: printf(">>help\n");
59: if (tTf(44, 0))
60: prvect(parmc, parmv);
61: }
62: # endif
63:
64: ret = 0;
65: pv = parmv;
66: getuser(-1); /* init getuser for modes 1 & 2 */
67: while (pv->pv_type != PV_EOF)
68: {
69: mode = atoi((pv++)->pv_val.pv_str);
70: if (mode < 2 && pv->pv_type == PV_EOF)
71: syserr("help: mode %d no val", mode);
72:
73: # ifdef xZTR1
74: if (tTf(44, -1))
75: {
76: printf("help %d", mode);
77: if (mode != 2)
78: printf(" %s", pv->pv_val.pv_str);
79: putchar('\n');
80: }
81: # endif
82: switch (mode)
83: {
84:
85: case 0: /* help relation */
86: if (!openr(&des, -1, pv->pv_val.pv_str))
87: {
88: rel_fmt(&des);
89: pv->pv_val.pv_str = NULL;
90: }
91: pv++;
92: break;
93:
94: case 1: /* help manual section */
95: if (man(pv->pv_val.pv_str))
96: pv->pv_val.pv_str = NULL;
97: pv++;
98: break;
99:
100: case 2:
101: case 3:
102: relpr(mode);
103: break;
104:
105: default:
106: syserr("HELP: mode %d", mode);
107: }
108: }
109: getuser(0); /* close getuser in case mode 1 or 2 */
110:
111: /* now rescan for error messages */
112: pv = parmv;
113: while (pv->pv_type != PV_EOF)
114: {
115: mode = atoi((pv++)->pv_val.pv_str);
116:
117: if (mode < 2)
118: {
119: if (pv->pv_val.pv_str != NULL)
120: ret = nferror(5401 + mode, pv->pv_val.pv_str, 0);
121: pv++;
122: }
123: }
124: return (ret);
125: }
126:
127:
128: /*
129: ** Nroff Manual Section
130: **
131: ** The manual section given by 'name' is nroff'ed. Returns one
132: ** on success, zero if the manual section is not found.
133: **
134: ** Uses trace flag 11
135: */
136:
137: int
138: man(name)
139: char *name;
140: {
141: char manual[100];
142: register int i;
143: int stat;
144: char name_nr[18];
145: register char *naa;
146: extern char *ztack();
147:
148: if (length(name) > 14)
149: return (0);
150:
151: /* a null manual name gives table of contents */
152: if (name[0] == 0)
153: smove("../toc.nr", name_nr);
154: else
155: concat(name, ".nr", name_nr);
156:
157: concat(ztack(Pathname, "/doc/quel/"), name_nr, manual);
158: if ((i = open(manual, 0)) < 0)
159: {
160: /* try a unix command instead */
161: concat(ztack(Pathname, "/doc/unix/"), name_nr, manual);
162: if ((i = open(manual, 0)) < 0)
163: return (0);
164: }
165: if (close(i))
166: syserr("cannot close %s", manual);
167: ruboff(0); /* wait for child's death if rubout occures */
168: i = fork();
169: if (i == 0)
170: {
171: signal(SIGINT, SIG_DFL); /* die on rubout */
172: setuid(getuid());
173: # ifndef xB_UNIX
174: setgid(getgid());
175: # endif
176: naa = ztack(Pathname, "/doc/iaa");
177: execl("/bin/nroff", "nroff", naa, manual, 0);
178: execl("/usr/bin/nroff", "nroff", naa, manual, 0);
179: syserr("help: exec: nroff");
180: }
181: /* wait for nroff if fork succeeded */
182: if (i > 0)
183: fullwait(i, "help: nroff");
184: rubon();
185: return (1);
186: }
187:
188:
189: /*
190: ** PRINT DATABASE INFORMATION
191: **
192: ** Prints a list of all the relations in the database, together
193: ** with their owner.
194: **
195: ** Uses trace flag 12
196: */
197:
198: relpr(mode)
199: int mode;
200: {
201: extern DESC Reldes;
202: register DESC *d;
203: register int i;
204: register char *cp;
205: struct tup_id limtid, tid;
206: char buf[MAXLINE + 1];
207: char lastuser[2];
208: struct relation rel;
209:
210: opencatalog("relation", 0);
211: d = &Reldes;
212: if (i = find(d, NOKEY, &tid, &limtid))
213: syserr("help: relpr: find %d", i);
214:
215: lastuser[0] = '\0';
216:
217: if (mode == 2)
218: printf("\n relation name relation owner\n\n");
219:
220: while ((i = get(d, &tid, &limtid, &rel, 1)) == 0)
221: {
222: if (mode == 2)
223: {
224: if (!bequal(lastuser, rel.relowner, 2))
225: {
226: if (getuser(rel.relowner, buf))
227: {
228: /* cant find user code */
229: bmove(" ", buf, 2);
230: cp = &buf[2];
231: bmove(rel.relowner, cp, 2);
232: cp = &cp[2];
233: *cp = '\0';
234: }
235: else
236: {
237: for (cp = buf; *cp != ':'; cp++)
238: ;
239: *cp = '\0';
240: }
241: bmove(rel.relowner, lastuser, 2);
242: }
243: printf(" %.12s %s\n", rel.relid, buf);
244: }
245: else
246: {
247: if ((rel.relstat & S_CATALOG) || bequal("_SYS", rel.relid, 4))
248: continue;
249: if (bequal(Usercode, rel.relowner, 2) || bequal(Admin.adhdr.adowner, rel.relowner, 2))
250: rel_fmt(&rel);
251: }
252: }
253:
254: if (i < 0)
255: syserr("help: relpr: get %d", i);
256: if (mode == 2)
257: printf("\n");
258: return (0);
259: }
260:
261:
262:
263: /*
264: ** Print Relation Information
265: **
266: ** Prints detailed information regarding the relation.
267: **
268: ** Uses trace flag 13
269: */
270:
271: rel_fmt(r)
272: register struct relation *r;
273: {
274: struct tup_id limtid, tid;
275: char buf[MAXLINE + 1];
276: struct attribute att;
277: struct index indkey, ind;
278: register int i;
279: int j;
280: extern DESC Attdes, Inddes;
281: char *trim_relname();
282:
283: printf("\nRelation:\t\t%s\n", trim_relname(r->relid));
284: i = getuser(r->relowner, buf);
285: if (i)
286: {
287: smove("(xx)", buf);
288: bmove(r->relowner, &buf[1], 2);
289: }
290: else
291: {
292: for (i = 0; buf[i] != ':'; i++)
293: continue;
294: buf[i] = 0;
295: }
296: printf("Owner:\t\t\t%s\n", buf);
297: printf("Tuple width:\t\t%d\n", r->relwid);
298: if (r->relsave != 0)
299: {
300: printf("Saved until:\t\t%s", ctime(&r->relsave));
301: }
302: if ((r->relstat & S_VIEW) == 0)
303: {
304: printf("Number of tuples:\t%ld\n", r->reltups);
305: printf("Storage structure:\t");
306: i = r->relspec;
307: if (i < 0)
308: {
309: printf("compressed ");
310: i = -i;
311: }
312: switch (i)
313: {
314:
315: case M_HEAP:
316: printf("paged heap\n");
317: break;
318:
319: case M_ISAM:
320: printf("ISAM file\n");
321: break;
322:
323: case M_HASH:
324: printf("random hash\n");
325: break;
326:
327: default:
328: printf("unknown structure %d\n", i);
329: break;
330:
331: }
332: }
333:
334: printf("Relation type:\t\t");
335: if (r->relstat & S_CATALOG)
336: printf("system catalog\n");
337: else if (r->relstat & S_VIEW)
338: printf("view\n");
339: else
340: if (r->relindxd < 0)
341: {
342: printf("secondary index on ");
343: opencatalog("indexes", 0);
344: setkey(&Inddes, &indkey, r->relowner, IOWNERP);
345: setkey(&Inddes, &indkey, r->relid, IRELIDI);
346: if (!getequal(&Inddes, &indkey, &ind, &tid))
347: printf("%s\n", trim_relname(ind.irelidp));
348: else
349: printf("unknown relation\n");
350: }
351: else
352: {
353: if (r->relstat & S_DISTRIBUTED)
354: printf("distributed ");
355: printf("user relation\n");
356: }
357: if (r->relindxd > 0)
358: {
359: printf("Secondary Indices:\t");
360: opencatalog("indexes", 0);
361: setkey(&Inddes, &indkey, r->relid, IRELIDP);
362: setkey(&Inddes, &indkey, r->relowner, IOWNERP);
363: if (i = find(&Inddes, EXACTKEY, &tid, &limtid, &indkey))
364: syserr("help: find %d indexes", i);
365: j = FALSE;
366: while ((i = get(&Inddes, &tid, &limtid, &ind, 1)) == 0)
367: {
368: if (!bequal(&indkey, &ind, MAXNAME + 2))
369: continue;
370: if (j)
371: printf(", ");
372: j =TRUE;
373: printf("%s", trim_relname(ind.irelidi));
374: }
375: if (i < 0)
376: syserr("help:get indexes %d", i);
377: if (!j)
378: printf("unknown");
379: }
380: printf("\n");
381:
382: opencatalog("attribute", 0);
383: printf("\n attribute name type length keyno.\n\n");
384: seq_init(&Attdes, r);
385: while (seq_attributes(&Attdes, r, &att))
386: {
387: printf(" %.12s %c%8d",
388: att.attname, att.attfrmt, att.attfrml & 0377);
389: if (att.attxtra)
390: printf("%7d", att.attxtra);
391: printf("\n");
392: }
393:
394: printf("\n");
395: return (0);
396: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.