12 #include "EST_cutils.h"
15 #include "siodeditline.h"
17 void setdoc(LISP name,LISP doc)
20 LISP lpair = assq(name,siod_docstrings);
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;
32 static LISP siod_doc(LISP args,LISP penv)
36 LISP lpair,val,tmp,code;
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.");
50 var_docstrings = symbol_value(rintern(
"var-docstrings"),penv);
51 lpair = assq(car(args),var_docstrings);
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.");
87 static LISP siod_all_function_docstrings(
void)
91 LISP docs = siod_docstrings;
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);
120 static int sort_compare_docstrings(
const void *x,
const void *y)
125 return EST_strcasecmp(get_c_string(car(a)),get_c_string(car(b)));
128 static void siod_print_docstring(
const char *symname,
129 const char *docstring, FILE *fp)
139 if (ds.
contains(make_regex(
"\\[see .*\\]$")))
142 rest = ds.
before(make_regex(
"\\[see [^\n]*\\]$"));
143 ref = ds.
after(rest);
144 ref = ref.
after(
"[see ");
151 fprintf(fp,
"@item ");
152 for (state=0,i=0; dsc[i] !=
'\0'; i++)
154 if (((dsc[i] ==
'@') ||
160 if ((dsc[i] ==
'\\') &&
161 ((dsc[i+1] ==
'@') ||
181 static LISP siod_sort_and_dump_docstrings(LISP type,LISP filefp)
184 LISP *array,l,docstrings;
188 if (streq(get_c_string(type),
"function"))
189 docstrings = siod_all_function_docstrings();
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);
195 num_strings = siod_llength(docstrings);
196 array = walloc(LISP,num_strings);
197 for (l=docstrings,i=0; i < num_strings; i++,l=cdr(l))
199 qsort(array,num_strings,
sizeof(LISP),sort_compare_docstrings);
201 for (i=0; i < num_strings; i++)
202 siod_print_docstring(get_c_string(car(array[i])),
203 get_c_string(cdr(array[i])),
204 get_c_file(filefp,stdout));
212 const char *siod_docstring(
const char *symbol)
216 doc = siod_doc(cons(rintern(symbol),NIL),NIL);
218 return get_c_string(doc);
221 const 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);
232 void 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);
242 void 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.");