12#include "EST_cutils.h"
15#include "siodeditline.h"
22 siod_docstrings = cons(cons(name,
doc),siod_docstrings);
25 cerr <<
"SIOD: duplicate builtin function: " <<
26 get_c_string(name) <<
endl;
27 cerr <<
"SIOD: probably an error" <<
endl;
39 if (TYPE(car(args)) != tc_symbol)
40 return rintern(
"No documentation available for non-symbol.");
41 tmp = envlookup(car(args),
penv);
45 val = VCELL(car(args));
46 if EQ(val,unbound_marker)
47 return rintern(
"Symbol is unbound.");
55 rintern(
"No documentation available for symbol.");
67 lpair = assq(car(args),siod_docstrings);
71 return rintern(
"No documentation available for builtin function.");
74 code = val->storage_as.closure.code;
75 if ((TYPE(cdr(code)) == tc_cons) &&
76 (TYPE(car(cdr(cdr(code)))) == tc_string))
77 return car(cdr(cdr(code)));
79 return rintern(
"No documentation available for user-defined function.");
81 return rintern(
"No documentation available for symbol.");
84 return rintern(
"No documentation available for symbol.");
87static LISP siod_all_function_docstrings(
void)
99 for(;CONSP(l);l=CDR(l))
101 if (VCELL(car(l)) == NIL)
continue;
102 switch(TYPE(VCELL(CAR(l))))
106 code = val->storage_as.closure.code;
108 (CONSP(cdr(code))) &&
109 (CONSP(cdr(cdr(code)))) &&
110 (TYPE(car(cdr(cdr(code)))) == tc_string))
111 docs = cons(cons(car(l),car(cdr(cdr(code)))),
docs);
120static int sort_compare_docstrings(
const void *
x,
const void *
y)
125 return EST_strcasecmp(get_c_string(car(a)),get_c_string(car(b)));
128static void siod_print_docstring(
const char *
symname,
139 if (
ds.contains(make_regex(
"\\[see .*\\]$")))
142 rest =
ds.before(make_regex(
"\\[see [^\n]*\\]$"));
144 ref = ref.
after(
"[see ");
152 for (state=0,i=0;
dsc[i] !=
'\0'; i++)
154 if (((
dsc[i] ==
'@') ||
160 if ((
dsc[i] ==
'\\') &&
161 ((
dsc[i+1] ==
'@') ||
188 if (streq(get_c_string(type),
"function"))
190 else if (streq(get_c_string(type),
"features"))
191 docstrings = symbol_value(rintern(
"ff_docstrings"),NIL);
193 docstrings = symbol_value(rintern(
"var-docstrings"),NIL);
202 siod_print_docstring(get_c_string(car(
array[i])),
203 get_c_string(cdr(
array[i])),
212const char *siod_docstring(
const char *symbol)
216 doc = siod_doc(cons(rintern(symbol),NIL),NIL);
218 return get_c_string(
doc);
221const char *siod_manual_sym(
const char *symbol)
226 info = leval(cons(rintern(
"manual-sym"),
227 cons(quote(rintern(symbol)),NIL)),NIL);
229 return get_c_string(info);
232void siod_saydocstring(
const char *symbol)
236 leval(cons(rintern(
"tts_text"),
237 cons(cons(rintern(
"doc"),cons(rintern(symbol),NIL)),
238 cons(NIL,NIL))),NIL);
242void init_subrs_doc(
void)
244 init_fsubr(
"doc",siod_doc,
246 Return documentation for SYMBOL.");
247 init_subr_2(
"sort-and-dump-docstrings",siod_sort_and_dump_docstrings,
248 "(sort-and-dump-docstrings DOCSTRINGS FILEFP)\n\
249 DOCSTRINGS is an assoc list of name and document string var-docstrings\n\
250 or func-docstrings. This very individual function sorts the list and \n\
251 prints out the documentation strings as texinfo list members to FILEFP.");
EST_String before(int pos, int len=0) const
Part before position.
EST_String after(int pos, int len=1) const
Part after pos+len.