1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9/*
10 * (c) Martin Kersten
11 * This module provides a wrapping of the help function in the .../mal/mal_modules.c
12 * and the list of all MAL functions for analysis using SQL.
13 */
14#include "monetdb_config.h"
15#include "manual.h"
16
17str
18MANUALcreateOverview(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
19{
20 BAT *mod, *fcn, *sig, *adr, *com;
21 bat *mx = getArgReference_bat(stk,pci,0);
22 bat *fx = getArgReference_bat(stk,pci,1);
23 bat *sx = getArgReference_bat(stk,pci,2);
24 bat *ax = getArgReference_bat(stk,pci,3);
25 bat *cx = getArgReference_bat(stk,pci,4);
26 Module s;
27 Module* moduleList;
28 int length;
29 int j, k, top = 0;
30 Symbol t;
31 Module list[256];
32 char buf[BUFSIZ], *tt;
33
34 mod = COLnew(0, TYPE_str, 0, TRANSIENT);
35 fcn = COLnew(0, TYPE_str, 0, TRANSIENT);
36 sig = COLnew(0, TYPE_str, 0, TRANSIENT);
37 adr = COLnew(0, TYPE_str, 0, TRANSIENT);
38 com = COLnew(0, TYPE_str, 0, TRANSIENT);
39 if (mod == NULL || fcn == NULL || sig == NULL || adr == NULL || com == NULL) {
40 BBPreclaim(mod);
41 BBPreclaim(fcn);
42 BBPreclaim(sig);
43 BBPreclaim(adr);
44 BBPreclaim(com);
45 throw(MAL, "manual.functions", SQLSTATE(HY001) MAL_MALLOC_FAIL);
46 }
47
48 list[top++] = cntxt->usermodule;
49 getModuleList(&moduleList, &length);
50 if (moduleList == NULL)
51 goto bailout;
52 while (top < 256 && top <= length) {
53 list[top] = moduleList[top - 1];
54 top++;
55 }
56 freeModuleList(moduleList);
57
58 for (k = 0; k < top; k++) {
59 s = list[k];
60 if (s->space) {
61 for (j = 0; j < MAXSCOPE; j++) {
62 if (s->space[j]) {
63 for (t = s->space[j]; t != NULL; t = t->peer) {
64 (void) fcnDefinition(t->def, getInstrPtr(t->def, 0), buf, TRUE, buf, sizeof(buf));
65 tt = strstr(buf, "address ");
66 if (tt) {
67 *tt = 0;
68 tt += 8;
69 }
70 if (BUNappend(mod, t->def->stmt[0]->modname, false) != GDK_SUCCEED ||
71 BUNappend(fcn, t->def->stmt[0]->fcnname, false) != GDK_SUCCEED ||
72 BUNappend(com, t->def->help ? t->def->help : "", false) != GDK_SUCCEED ||
73 BUNappend(sig,buf,false) != GDK_SUCCEED ||
74 BUNappend(adr, tt ? tt : "", false) != GDK_SUCCEED) {
75 goto bailout;
76 }
77 }
78 }
79 }
80 }
81 }
82
83 BBPkeepref( *mx = mod->batCacheid);
84 BBPkeepref( *fx = fcn->batCacheid);
85 BBPkeepref( *sx = sig->batCacheid);
86 BBPkeepref( *ax = adr->batCacheid);
87 BBPkeepref( *cx = com->batCacheid);
88 (void)mb;
89 return MAL_SUCCEED;
90
91 bailout:
92 BBPreclaim(mod);
93 BBPreclaim(fcn);
94 BBPreclaim(sig);
95 BBPreclaim(adr);
96 BBPreclaim(com);
97 throw(MAL, "manual.functions", GDK_EXCEPTION);
98}
99