0
|
1 /* Record indices of function doc strings stored in a file.
|
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30. */
|
|
23
|
|
24 /* This file has been Mule-ized except as noted. */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "buffer.h"
|
|
30 #include "bytecode.h"
|
|
31 #include "insdel.h"
|
|
32 #include "keymap.h"
|
|
33
|
|
34 #include "sysfile.h"
|
|
35
|
|
36
|
|
37 Lisp_Object Vdoc_file_name;
|
|
38
|
219
|
39 Lisp_Object QSsubstitute;
|
|
40
|
0
|
41 /* Read and return doc string from open file descriptor FD
|
|
42 at position POSITION. Does not close the file. Returns
|
|
43 string; or if error, returns a cons holding the error
|
|
44 data to pass to Fsignal. NAME_NONRELOC and NAME_RELOC
|
|
45 are only used for the error messages. */
|
|
46
|
|
47 Lisp_Object
|
|
48 unparesseuxify_doc_string (int fd, EMACS_INT position,
|
|
49 char *name_nonreloc, Lisp_Object name_reloc)
|
|
50 {
|
|
51 char buf[512 * 32 + 1];
|
|
52 char *buffer = buf;
|
|
53 int buffer_size = sizeof (buf);
|
|
54 char *from, *to;
|
|
55 REGISTER char *p = buffer;
|
|
56 Lisp_Object return_me;
|
|
57
|
|
58 if (0 > lseek (fd, position, 0))
|
|
59 {
|
|
60 if (name_nonreloc)
|
|
61 name_reloc = build_string (name_nonreloc);
|
|
62 return_me = list3 (build_string
|
|
63 ("Position out of range in doc string file"),
|
|
64 name_reloc, make_int (position));
|
|
65 goto done;
|
|
66 }
|
|
67
|
|
68 /* Read the doc string into a buffer.
|
|
69 Use the fixed buffer BUF if it is big enough; otherwise allocate one.
|
|
70 We store the buffer in use in BUFFER and its size in BUFFER_SIZE. */
|
|
71
|
|
72 while (1)
|
|
73 {
|
|
74 int space_left = buffer_size - (p - buffer);
|
|
75 int nread;
|
|
76
|
|
77 /* Switch to a bigger buffer if we need one. */
|
|
78 if (space_left == 0)
|
|
79 {
|
|
80 char * old_buffer = buffer;
|
|
81 if (buffer == buf) {
|
|
82 buffer = (char *) xmalloc (buffer_size *= 2);
|
|
83 memcpy (buffer, old_buffer, p - old_buffer);
|
|
84 } else {
|
|
85 buffer = (char *) xrealloc (buffer, buffer_size *= 2);
|
|
86 }
|
|
87 p += buffer - old_buffer;
|
|
88 space_left = buffer_size - (p - buffer);
|
|
89 }
|
|
90
|
2
|
91 /* Don't read too much at one go. */
|
0
|
92 if (space_left > 1024 * 8)
|
|
93 space_left = 1024 * 8;
|
|
94 nread = read (fd, p, space_left);
|
|
95 if (nread < 0)
|
|
96 {
|
185
|
97 return_me = list1 (build_string
|
0
|
98 ("Read error on documentation file"));
|
|
99 goto done;
|
|
100 }
|
|
101 p[nread] = 0;
|
|
102 if (!nread)
|
|
103 break;
|
|
104 {
|
|
105 char *p1 = strchr (p, '\037'); /* End of doc string marker */
|
|
106 if (p1)
|
|
107 {
|
|
108 *p1 = 0;
|
|
109 p = p1;
|
|
110 break;
|
|
111 }
|
|
112 }
|
|
113 p += nread;
|
|
114 }
|
|
115
|
|
116 /* Scan the text and remove quoting with ^A (char code 1).
|
|
117 ^A^A becomes ^A, ^A0 becomes a null char, and ^A_ becomes a ^_. */
|
|
118 from = to = buffer;
|
|
119 while (from < p)
|
|
120 {
|
|
121 if (*from != 1 /*^A*/)
|
|
122 *to++ = *from++;
|
|
123 else
|
|
124 {
|
|
125 int c = *(++from);
|
185
|
126
|
0
|
127 from++;
|
|
128 switch (c)
|
|
129 {
|
|
130 case 1: *to++ = c; break;
|
|
131 case '0': *to++ = '\0'; break;
|
|
132 case '_': *to++ = '\037'; break;
|
|
133 default:
|
|
134 return_me = list2 (build_string
|
80
|
135 ("Invalid data in documentation file -- ^A followed by weird code"),
|
0
|
136 make_int (c));
|
|
137 goto done;
|
|
138 }
|
|
139 }
|
|
140 }
|
|
141
|
|
142 /* #### mrb: following STILL completely broken */
|
|
143 return_me = make_ext_string ((Bufbyte *) buffer, to - buffer, FORMAT_BINARY);
|
|
144
|
|
145 done:
|
|
146 if (buffer != buf) /* We must have allocated buffer above */
|
|
147 xfree (buffer);
|
|
148 return return_me;
|
|
149 }
|
|
150
|
2
|
151 #define string_join(dest, s1, s2) \
|
14
|
152 memcpy ((void *) dest, (void *) XSTRING_DATA (s1), XSTRING_LENGTH (s1)); \
|
|
153 memcpy ((void *) ((Bufbyte *) dest + XSTRING_LENGTH (s1)), \
|
|
154 (void *) XSTRING_DATA (s2), XSTRING_LENGTH (s2)); \
|
|
155 dest[XSTRING_LENGTH (s1) + XSTRING_LENGTH (s2)] = '\0'
|
2
|
156
|
0
|
157 /* Extract a doc string from a file. FILEPOS says where to get it.
|
|
158 (This could actually be byte code instructions/constants instead
|
|
159 of a doc string.)
|
78
|
160 If it is an integer, use that position in the standard DOC file.
|
0
|
161 If it is (FILE . INTEGER), use FILE as the file name
|
|
162 and INTEGER as the position in that file.
|
|
163 But if INTEGER is negative, make it positive.
|
|
164 (A negative integer is used for user variables, so we can distinguish
|
|
165 them without actually fetching the doc string.) */
|
|
166
|
|
167 static Lisp_Object
|
|
168 get_doc_string (Lisp_Object filepos)
|
|
169 {
|
|
170 /* !!#### This function has not been Mule-ized */
|
|
171 REGISTER int fd;
|
|
172 REGISTER char *name_nonreloc = 0;
|
|
173 int minsize;
|
|
174 EMACS_INT position;
|
|
175 Lisp_Object file, tem;
|
173
|
176 Lisp_Object name_reloc = Qnil;
|
0
|
177
|
|
178 if (INTP (filepos))
|
|
179 {
|
|
180 file = Vdoc_file_name;
|
|
181 position = XINT (filepos);
|
|
182 }
|
|
183 else if (CONSP (filepos) && INTP (XCDR (filepos)))
|
|
184 {
|
|
185 file = XCAR (filepos);
|
|
186 position = XINT (XCDR (filepos));
|
|
187 if (position < 0)
|
|
188 position = - position;
|
|
189 }
|
|
190 else
|
|
191 return Qnil;
|
|
192
|
|
193 if (!STRINGP (file))
|
|
194 return Qnil;
|
185
|
195
|
0
|
196 /* Put the file name in NAME as a C string.
|
|
197 If it is relative, combine it with Vdoc_directory. */
|
|
198
|
|
199 tem = Ffile_name_absolute_p (file);
|
|
200 if (NILP (tem))
|
|
201 {
|
|
202 /* XEmacs: Move this check here. OK if called during loadup to
|
|
203 load byte code instructions. */
|
|
204 if (!STRINGP (Vdoc_directory))
|
|
205 return Qnil;
|
|
206
|
14
|
207 minsize = XSTRING_LENGTH (Vdoc_directory);
|
0
|
208 /* sizeof ("../lib-src/") == 12 */
|
|
209 if (minsize < 12)
|
|
210 minsize = 12;
|
14
|
211 name_nonreloc = (char *) alloca (minsize + XSTRING_LENGTH (file) + 8);
|
2
|
212 string_join (name_nonreloc, Vdoc_directory, file);
|
0
|
213 }
|
|
214 else
|
|
215 name_reloc = file;
|
|
216
|
|
217 fd = open (name_nonreloc ? name_nonreloc :
|
251
|
218 (char *) XSTRING_DATA (name_reloc), O_RDONLY | OPEN_BINARY, 0);
|
0
|
219 if (fd < 0)
|
|
220 {
|
|
221 #ifndef CANNOT_DUMP
|
|
222 if (purify_flag)
|
|
223 {
|
|
224 /* sizeof ("../lib-src/") == 12 */
|
14
|
225 name_nonreloc = (char *) alloca (12 + XSTRING_LENGTH (file) + 8);
|
0
|
226 /* Preparing to dump; DOC file is probably not installed.
|
|
227 So check in ../lib-src. */
|
|
228 strcpy (name_nonreloc, "../lib-src/");
|
14
|
229 strcat (name_nonreloc, (char *) XSTRING_DATA (file));
|
0
|
230
|
251
|
231 fd = open (name_nonreloc, O_RDONLY | OPEN_BINARY, 0);
|
0
|
232 }
|
80
|
233 #endif /* CANNOT_DUMP */
|
0
|
234
|
|
235 if (fd < 0)
|
|
236 error ("Cannot open doc string file \"%s\"",
|
|
237 name_nonreloc ? name_nonreloc :
|
14
|
238 (char *) XSTRING_DATA (name_reloc));
|
0
|
239 }
|
|
240
|
|
241 tem = unparesseuxify_doc_string (fd, position, name_nonreloc, name_reloc);
|
|
242 close (fd);
|
|
243
|
|
244 if (!STRINGP (tem))
|
|
245 signal_error (Qerror, tem);
|
|
246
|
|
247 return tem;
|
|
248 }
|
|
249
|
|
250 /* Get a string from position FILEPOS and pass it through the Lisp reader.
|
|
251 We use this for fetching the bytecode string and constants vector
|
|
252 of a compiled function from the .elc file. */
|
|
253
|
|
254 Lisp_Object
|
|
255 read_doc_string (Lisp_Object filepos)
|
|
256 {
|
|
257 Lisp_Object string = get_doc_string (filepos);
|
|
258
|
|
259 if (!STRINGP (string))
|
|
260 signal_simple_error ("loading bytecode failed to return string", string);
|
|
261 return Fread (string);
|
|
262 }
|
|
263
|
20
|
264 DEFUN ("documentation", Fdocumentation, 1, 2, 0, /*
|
0
|
265 Return the documentation string of FUNCTION.
|
|
266 Unless a non-nil second argument is given, the
|
|
267 string is passed through `substitute-command-keys'.
|
20
|
268 */
|
|
269 (function, raw))
|
0
|
270 {
|
|
271 /* This function can GC */
|
|
272 Lisp_Object fun;
|
|
273 Lisp_Object doc;
|
|
274
|
|
275 fun = Findirect_function (function);
|
|
276
|
|
277 if (SUBRP (fun))
|
|
278 {
|
|
279 if (XSUBR (fun)->doc == 0)
|
|
280 return Qnil;
|
|
281 if ((EMACS_INT) XSUBR (fun)->doc >= 0)
|
|
282 doc = build_string (XSUBR (fun)->doc);
|
|
283 else
|
|
284 doc = get_doc_string (make_int (- (EMACS_INT) XSUBR (fun)->doc));
|
|
285 }
|
|
286 else if (COMPILED_FUNCTIONP (fun))
|
|
287 {
|
|
288 Lisp_Object tem;
|
|
289 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
290 if (! (b->flags.documentationp))
|
|
291 return Qnil;
|
|
292 tem = compiled_function_documentation (b);
|
|
293 if (STRINGP (tem))
|
|
294 doc = tem;
|
|
295 else if (NATNUMP (tem) || CONSP (tem))
|
|
296 doc = get_doc_string (tem);
|
|
297 else
|
|
298 return Qnil;
|
|
299 }
|
|
300 else if (KEYMAPP (fun))
|
|
301 return build_translated_string ("Prefix command (definition is a keymap of subcommands).");
|
|
302 else if (STRINGP (fun) || VECTORP (fun))
|
|
303 return build_translated_string ("Keyboard macro.");
|
|
304 else if (CONSP (fun))
|
|
305 {
|
|
306 Lisp_Object funcar = Fcar (fun);
|
|
307
|
|
308 if (!SYMBOLP (funcar))
|
|
309 return Fsignal (Qinvalid_function, list1 (fun));
|
|
310 else if (EQ (funcar, Qlambda)
|
|
311 || EQ (funcar, Qautoload))
|
|
312 {
|
|
313 Lisp_Object tem, tem1;
|
|
314 tem1 = Fcdr (Fcdr (fun));
|
|
315 tem = Fcar (tem1);
|
|
316 if (STRINGP (tem))
|
|
317 doc = tem;
|
|
318 /* Handle a doc reference--but these never come last
|
|
319 in the function body, so reject them if they are last. */
|
|
320 else if ((NATNUMP (tem) || CONSP (tem))
|
|
321 && ! NILP (XCDR (tem1)))
|
|
322 doc = get_doc_string (tem);
|
|
323 else
|
|
324 return Qnil;
|
|
325 }
|
|
326 else if (EQ (funcar, Qmacro))
|
|
327 return Fdocumentation (Fcdr (fun), raw);
|
|
328 else
|
|
329 goto oops;
|
|
330 }
|
|
331 else
|
|
332 {
|
|
333 oops:
|
|
334 return Fsignal (Qinvalid_function, list1 (fun));
|
|
335 }
|
|
336
|
|
337 if (NILP (raw))
|
|
338 {
|
|
339 struct gcpro gcpro1;
|
|
340 #ifdef I18N3
|
|
341 Lisp_Object domain = Qnil;
|
|
342 if (COMPILED_FUNCTIONP (fun))
|
|
343 domain = Fcompiled_function_domain (fun);
|
|
344 if (NILP (domain))
|
|
345 doc = Fgettext (doc);
|
|
346 else
|
|
347 doc = Fdgettext (domain, doc);
|
|
348 #endif
|
|
349
|
|
350 GCPRO1 (doc);
|
|
351 doc = Fsubstitute_command_keys (doc);
|
|
352 UNGCPRO;
|
|
353 }
|
|
354 return doc;
|
|
355 }
|
|
356
|
20
|
357 DEFUN ("documentation-property", Fdocumentation_property, 2, 3, 0, /*
|
0
|
358 Return the documentation string that is SYMBOL's PROP property.
|
|
359 This is like `get', but it can refer to strings stored in the
|
|
360 `doc-directory/DOC' file; and if the value is a string, it is passed
|
|
361 through `substitute-command-keys'. A non-nil third argument avoids this
|
|
362 translation.
|
20
|
363 */
|
|
364 (sym, prop, raw))
|
0
|
365 {
|
|
366 /* This function can GC */
|
209
|
367 REGISTER Lisp_Object doc = Qnil;
|
0
|
368 #ifdef I18N3
|
|
369 REGISTER Lisp_Object domain;
|
|
370 #endif
|
209
|
371 struct gcpro gcpro1;
|
|
372
|
|
373 GCPRO1 (doc);
|
0
|
374
|
|
375 doc = Fget (sym, prop, Qnil);
|
|
376 if (INTP (doc))
|
|
377 doc = get_doc_string (XINT (doc) > 0 ? doc : make_int (- XINT (doc)));
|
|
378 else if (CONSP (doc))
|
|
379 doc = get_doc_string (doc);
|
|
380 #ifdef I18N3
|
|
381 if (!NILP (doc))
|
|
382 {
|
|
383 domain = Fget (sym, Qvariable_domain, Qnil);
|
|
384 if (NILP (domain))
|
|
385 doc = Fgettext (doc);
|
|
386 else
|
|
387 doc = Fdgettext (domain, doc);
|
|
388 }
|
185
|
389 #endif
|
0
|
390 if (NILP (raw) && STRINGP (doc))
|
|
391 doc = Fsubstitute_command_keys (doc);
|
209
|
392 UNGCPRO;
|
0
|
393 return doc;
|
|
394 }
|
|
395
|
|
396 static void
|
|
397 weird_doc (Lisp_Object sym, CONST char *weirdness, CONST char *type, int pos)
|
|
398 {
|
|
399 if (!strcmp (weirdness, GETTEXT ("duplicate"))) return;
|
|
400 message ("Note: Strange doc (%s) for %s %s @ %d",
|
|
401 weirdness, type, string_data (XSYMBOL (sym)->name), pos);
|
|
402 }
|
|
403
|
|
404
|
20
|
405 DEFUN ("Snarf-documentation", Fsnarf_documentation, 1, 1, 0, /*
|
0
|
406 Used during Emacs initialization, before dumping runnable Emacs,
|
|
407 to find pointers to doc strings stored in `.../lib-src/DOC' and
|
|
408 record them in function definitions.
|
|
409 One arg, FILENAME, a string which does not include a directory.
|
|
410 The file is written to `../lib-src', and later found in `exec-directory'
|
|
411 when doc strings are referred to in the dumped Emacs.
|
20
|
412 */
|
|
413 (filename))
|
0
|
414 {
|
|
415 /* !!#### This function has not been Mule-ized */
|
|
416 int fd;
|
|
417 char buf[1024 + 1];
|
|
418 REGISTER int filled;
|
|
419 REGISTER int pos;
|
|
420 REGISTER char *p, *end;
|
|
421 Lisp_Object sym, fun, tem;
|
|
422 char *name;
|
|
423
|
|
424 #ifndef CANNOT_DUMP
|
|
425 if (!purify_flag)
|
|
426 error ("Snarf-documentation can only be called in an undumped Emacs");
|
|
427 #endif
|
|
428
|
|
429 CHECK_STRING (filename);
|
|
430
|
239
|
431 #ifdef CANNOT_DUMP
|
|
432 if (!NILP(Vdoc_directory))
|
|
433 {
|
|
434 CHECK_STRING (Vdoc_directory);
|
|
435 name = (char *) alloca (XSTRING_LENGTH (filename)
|
|
436 + XSTRING_LENGTH (Vdoc_directory)
|
|
437 + 1);
|
|
438 strcpy (name, (char *) XSTRING_DATA (Vdoc_directory));
|
|
439 }
|
|
440 else
|
0
|
441 #endif /* CANNOT_DUMP */
|
239
|
442 {
|
|
443 name = (char *) alloca (XSTRING_LENGTH (filename) + 14);
|
|
444 strcpy (name, "../lib-src/");
|
|
445 }
|
|
446
|
14
|
447 strcat (name, (char *) XSTRING_DATA (filename));
|
0
|
448
|
251
|
449 fd = open (name, O_RDONLY | OPEN_BINARY, 0);
|
0
|
450 if (fd < 0)
|
|
451 report_file_error ("Opening doc string file",
|
|
452 Fcons (build_string (name), Qnil));
|
|
453 Vdoc_file_name = filename;
|
|
454 filled = 0;
|
|
455 pos = 0;
|
|
456 while (1)
|
|
457 {
|
|
458 if (filled < 512)
|
|
459 filled += read (fd, &buf[filled], sizeof buf - 1 - filled);
|
|
460 if (!filled)
|
|
461 break;
|
|
462
|
|
463 buf[filled] = 0;
|
|
464 p = buf;
|
|
465 end = buf + (filled < 512 ? filled : filled - 128);
|
|
466 while (p != end && *p != '\037') p++;
|
|
467 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
|
|
468 if (p != end)
|
|
469 {
|
|
470 end = strchr (p, '\n');
|
|
471 sym = oblookup (Vobarray, (Bufbyte *) p + 2, end - p - 2);
|
|
472 if (SYMBOLP (sym))
|
|
473 {
|
|
474 Lisp_Object offset = make_int (pos + end + 1 - buf);
|
|
475 /* Attach a docstring to a variable */
|
|
476 if (p[1] == 'V')
|
|
477 {
|
|
478 /* Install file-position as variable-documentation property
|
|
479 and make it negative for a user-variable
|
|
480 (doc starts with a `*'). */
|
|
481 Lisp_Object old = Fget (sym, Qvariable_documentation, Qzero);
|
|
482 if (!ZEROP (old))
|
|
483 {
|
|
484 weird_doc (sym, GETTEXT ("duplicate"),
|
|
485 GETTEXT ("variable"), pos);
|
|
486 /* In the case of duplicate doc file entries, always
|
|
487 take the later one. But if the doc is not an int
|
|
488 (a string, say) leave it alone. */
|
|
489 if (!INTP (old))
|
|
490 goto weird;
|
|
491 }
|
|
492 Fput (sym, Qvariable_documentation,
|
185
|
493 ((end[1] == '*')
|
0
|
494 ? make_int (- XINT (offset))
|
|
495 : offset));
|
|
496 }
|
|
497 /* Attach a docstring to a function.
|
|
498 The type determines where the docstring is stored. */
|
|
499 else if (p[1] == 'F')
|
|
500 {
|
189
|
501 fun = indirect_function (sym,0);
|
0
|
502
|
|
503 if (CONSP (fun) && EQ (XCAR (fun), Qmacro))
|
|
504 fun = XCDR (fun);
|
|
505
|
|
506 if (UNBOUNDP (fun))
|
|
507 {
|
|
508 /* May have been #if'ed out or something */
|
|
509 weird_doc (sym, GETTEXT ("not fboundp"),
|
|
510 GETTEXT ("function"), pos);
|
|
511 goto weird;
|
|
512 }
|
|
513 else if (SUBRP (fun))
|
|
514 {
|
|
515 /* Lisp_Subrs have a slot for it. */
|
|
516 if (XSUBR (fun)->doc)
|
|
517 {
|
|
518 weird_doc (sym, GETTEXT ("duplicate"),
|
|
519 GETTEXT ("subr"), pos);
|
|
520 goto weird;
|
|
521 }
|
|
522 XSUBR (fun)->doc = (char *) (- XINT (offset));
|
|
523 }
|
|
524 else if (CONSP (fun))
|
|
525 {
|
|
526 /* If it's a lisp form, stick it in the form. */
|
|
527 tem = XCAR (fun);
|
|
528 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
|
|
529 {
|
|
530 tem = Fcdr (Fcdr (fun));
|
|
531 if (CONSP (tem) &&
|
|
532 INTP (XCAR (tem)))
|
|
533 {
|
|
534 Lisp_Object old = XCAR (tem);
|
|
535 if (!ZEROP (old))
|
|
536 {
|
|
537 weird_doc (sym, GETTEXT ("duplicate"),
|
|
538 (EQ (tem, Qlambda)
|
|
539 ? GETTEXT ("lambda")
|
|
540 : GETTEXT ("autoload")),
|
|
541 pos);
|
|
542 /* In the case of duplicate doc file entries,
|
|
543 always take the later one. But if the doc
|
|
544 is not an int (a string, say) leave it
|
|
545 alone. */
|
|
546 if (!INTP (old))
|
|
547 goto weird;
|
|
548 }
|
|
549 XCAR (tem) = offset;
|
|
550 }
|
183
|
551 else if (!CONSP (tem))
|
|
552 {
|
|
553 weird_doc (sym, GETTEXT ("!CONSP(tem)"),
|
|
554 GETTEXT ("function"), pos);
|
|
555 goto cont;
|
|
556 }
|
|
557 else
|
|
558 {
|
|
559 /* DOC string is a string not integer 0 */
|
|
560 #if 0
|
|
561 weird_doc (sym, GETTEXT ("!INTP(XCAR(tem))"),
|
|
562 GETTEXT ("function"), pos);
|
|
563 #endif
|
|
564 goto cont;
|
|
565 }
|
0
|
566 }
|
183
|
567 else
|
|
568 {
|
|
569 weird_doc (sym, GETTEXT ("not lambda or autoload"),
|
|
570 GETTEXT ("function"), pos);
|
|
571 goto cont;
|
|
572 }
|
0
|
573 }
|
|
574 else if (COMPILED_FUNCTIONP (fun))
|
|
575 {
|
|
576 /* Compiled-Function objects sometimes have
|
|
577 slots for it. */
|
|
578 struct Lisp_Compiled_Function *b =
|
|
579 XCOMPILED_FUNCTION (fun);
|
|
580
|
|
581 /* This compiled-function object must have a
|
|
582 slot for the docstring, since we've found a
|
|
583 docstring for it. Unless there were multiple
|
|
584 definitions of it, and the latter one didn't
|
|
585 have any doc, which is a legal if slightly
|
|
586 bogus situation, so don't blow up. */
|
|
587
|
|
588 if (! (b->flags.documentationp))
|
|
589 {
|
|
590 weird_doc (sym, GETTEXT ("no doc slot"),
|
|
591 GETTEXT ("bytecode"), pos);
|
|
592 goto weird;
|
|
593 }
|
|
594 else
|
|
595 {
|
|
596 Lisp_Object old =
|
|
597 compiled_function_documentation (b);
|
|
598 if (!ZEROP (old))
|
|
599 {
|
|
600 weird_doc (sym, GETTEXT ("duplicate"),
|
|
601 GETTEXT ("bytecode"), pos);
|
|
602 /* In the case of duplicate doc file entries,
|
|
603 always take the later one. But if the doc is
|
|
604 not an int (a string, say) leave it alone. */
|
|
605 if (!INTP (old))
|
|
606 goto weird;
|
|
607 }
|
|
608 set_compiled_function_documentation (b, offset);
|
|
609 }
|
|
610 }
|
|
611 else
|
|
612 {
|
|
613 /* Otherwise the function is undefined or
|
|
614 otherwise weird. Ignore it. */
|
|
615 weird_doc (sym, GETTEXT ("weird function"),
|
|
616 GETTEXT ("function"), pos);
|
|
617 goto weird;
|
|
618 }
|
|
619 }
|
|
620 else
|
|
621 {
|
|
622 /* lose: */
|
|
623 error ("DOC file invalid at position %d", pos);
|
|
624 weird:
|
|
625 /* goto lose */;
|
|
626 }
|
|
627 }
|
|
628 }
|
183
|
629 cont:
|
0
|
630 pos += end - buf;
|
|
631 filled -= end - buf;
|
|
632 memmove (buf, end, filled);
|
|
633 }
|
|
634 close (fd);
|
|
635 return Qnil;
|
|
636 }
|
|
637
|
|
638
|
|
639 #if 1 /* Don't warn about functions whose doc was lost because they were
|
|
640 wrapped by advice-freeze.el... */
|
|
641 static int
|
|
642 kludgily_ignore_lost_doc_p (Lisp_Object sym)
|
|
643 {
|
|
644 # define kludge_prefix "ad-Orig-"
|
|
645 return (string_length (XSYMBOL (sym)->name) > sizeof (kludge_prefix) &&
|
|
646 !strncmp ((char *) string_data (XSYMBOL (sym)->name), kludge_prefix,
|
|
647 sizeof (kludge_prefix) - 1));
|
|
648 # undef kludge_prefix
|
|
649 }
|
|
650 #else
|
|
651 # define kludgily_ignore_lost_doc_p(sym) 0
|
|
652 #endif
|
|
653
|
|
654
|
227
|
655 static int
|
|
656 verify_doc_mapper (Lisp_Object sym, void *arg)
|
0
|
657 {
|
227
|
658 Lisp_Object closure = *(Lisp_Object *)arg;
|
|
659
|
0
|
660 if (!NILP (Ffboundp (sym)))
|
|
661 {
|
|
662 int doc = 0;
|
|
663 Lisp_Object fun = XSYMBOL (sym)->function;
|
|
664 if (CONSP (fun) &&
|
|
665 EQ (XCAR (fun), Qmacro))
|
|
666 fun = XCDR (fun);
|
|
667
|
|
668 if (SUBRP (fun))
|
|
669 doc = (EMACS_INT) XSUBR (fun)->doc;
|
|
670 else if (SYMBOLP (fun))
|
|
671 doc = -1;
|
|
672 else if (KEYMAPP (fun))
|
|
673 doc = -1;
|
|
674 else if (CONSP (fun))
|
|
675 {
|
|
676 Lisp_Object tem = XCAR (fun);
|
|
677 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
|
|
678 {
|
|
679 doc = -1;
|
|
680 tem = Fcdr (Fcdr (fun));
|
|
681 if (CONSP (tem) &&
|
185
|
682 INTP (XCAR (tem)))
|
0
|
683 doc = XINT (XCAR (tem));
|
|
684 }
|
|
685 }
|
|
686 else if (COMPILED_FUNCTIONP (fun))
|
|
687 {
|
|
688 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
689 if (! (b->flags.documentationp))
|
|
690 doc = -1;
|
|
691 else
|
|
692 {
|
|
693 Lisp_Object tem = compiled_function_documentation (b);
|
|
694 if (INTP (tem))
|
|
695 doc = XINT (tem);
|
|
696 }
|
|
697 }
|
|
698
|
|
699 if (doc == 0 && !kludgily_ignore_lost_doc_p (sym))
|
|
700 {
|
|
701 message ("Warning: doc lost for function %s.",
|
|
702 string_data (XSYMBOL (sym)->name));
|
|
703 XCDR (closure) = Qt;
|
|
704 }
|
|
705 }
|
|
706 if (!NILP (Fboundp (sym)))
|
|
707 {
|
|
708 Lisp_Object doc = Fget (sym, Qvariable_documentation, Qnil);
|
|
709 if (ZEROP (doc))
|
|
710 {
|
|
711 message ("Warning: doc lost for variable %s.",
|
|
712 string_data (XSYMBOL (sym)->name));
|
|
713 XCDR (closure) = Qt;
|
|
714 }
|
|
715 }
|
227
|
716 return 0; /* Never stop */
|
0
|
717 }
|
|
718
|
20
|
719 DEFUN ("Verify-documentation", Fverify_documentation, 0, 0, 0, /*
|
0
|
720 Used to make sure everything went well with Snarf-documentation.
|
|
721 Writes to stderr if not.
|
20
|
722 */
|
|
723 ())
|
0
|
724 {
|
|
725 Lisp_Object closure = Fcons (Qnil, Qnil);
|
|
726 struct gcpro gcpro1;
|
|
727 GCPRO1 (closure);
|
227
|
728 map_obarray (Vobarray, verify_doc_mapper, &closure);
|
0
|
729 if (!NILP (Fcdr (closure)))
|
|
730 message ("\n"
|
|
731 "This is usually because some files were preloaded by loaddefs.el or\n"
|
|
732 "site-load.el, but were not passed to make-docfile by Makefile.\n");
|
|
733 UNGCPRO;
|
173
|
734 return NILP (Fcdr (closure)) ? Qt : Qnil;
|
0
|
735 }
|
|
736
|
|
737
|
20
|
738 DEFUN ("substitute-command-keys", Fsubstitute_command_keys, 1, 1, 0, /*
|
0
|
739 Substitute key descriptions for command names in STRING.
|
|
740 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]
|
|
741 replaced by either: a keystroke sequence that will invoke COMMAND,
|
185
|
742 or "M-x COMMAND" if COMMAND is not on any keys.
|
0
|
743 Substrings of the form \\=\\{MAPVAR} are replaced by summaries
|
|
744 \(made by describe-bindings) of the value of MAPVAR, taken as a keymap.
|
|
745 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR
|
|
746 as the keymap for future \\=\\[COMMAND] substrings.
|
|
747 \\=\\= quotes the following character and is discarded;
|
|
748 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.
|
20
|
749 */
|
|
750 (str))
|
0
|
751 {
|
|
752 /* This function can GC */
|
|
753 Bufbyte *buf;
|
|
754 int changed = 0;
|
|
755 REGISTER Bufbyte *strdata;
|
|
756 REGISTER Bufbyte *bufp;
|
|
757 Bytecount strlength;
|
|
758 Bytecount idx;
|
|
759 Bytecount bsize;
|
|
760 Bufbyte *new;
|
|
761 Lisp_Object tem = Qnil;
|
|
762 Lisp_Object keymap;
|
|
763 Bufbyte *start;
|
|
764 Bytecount length;
|
|
765 Lisp_Object name;
|
|
766 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
767
|
|
768 if (NILP (str))
|
|
769 return Qnil;
|
|
770
|
|
771 CHECK_STRING (str);
|
|
772 tem = Qnil;
|
|
773 keymap = Qnil;
|
|
774 name = Qnil;
|
|
775 GCPRO4 (str, tem, keymap, name);
|
|
776
|
|
777 /* There is the possibility that the string is not destined for a
|
|
778 translating stream, and it could be argued that we should do the
|
|
779 same thing here as in Fformat(), but there are very few times
|
|
780 when this will be the case and many calls to this function
|
|
781 would have to have `gettext' calls added. (I18N3) */
|
|
782 str = LISP_GETTEXT (str);
|
|
783
|
|
784 /* KEYMAP is either nil (which means search all the active keymaps)
|
|
785 or a specified local map (which means search just that and the
|
|
786 global map). If non-nil, it might come from Voverriding_local_map,
|
|
787 or from a \\<mapname> construct in STR itself.. */
|
|
788 #if 0 /* FSFmacs */
|
|
789 /* This is really weird and garbagey. If keymap is nil and there's
|
|
790 an overriding-local-map, `where-is-internal' will correctly note
|
|
791 this, so there's no reason to do it here. Maybe FSFmacs
|
|
792 `where-is-internal' is broken. */
|
|
793 keymap = current_kboard->Voverriding_terminal_local_map;
|
|
794 if (NILP (keymap))
|
|
795 keymap = Voverriding_local_map;
|
|
796 #endif
|
|
797
|
14
|
798 strlength = XSTRING_LENGTH (str);
|
209
|
799 bsize = 1 + strlength;
|
0
|
800 buf = (Bufbyte *) xmalloc (bsize);
|
|
801 bufp = buf;
|
|
802
|
|
803 /* Have to reset strdata every time GC might be called */
|
14
|
804 strdata = XSTRING_DATA (str);
|
0
|
805 for (idx = 0; idx < strlength; )
|
|
806 {
|
|
807 Bufbyte *strp = strdata + idx;
|
185
|
808
|
0
|
809 if (strp[0] != '\\')
|
|
810 {
|
|
811 /* just copy other chars */
|
|
812 /* As it happens, this will work with Mule even if the
|
|
813 character quoted is multi-byte; the remaining multi-byte
|
|
814 characters will just be copied by this loop. */
|
|
815 *bufp++ = *strp;
|
|
816 idx++;
|
|
817 }
|
|
818 else switch (strp[1])
|
|
819 {
|
|
820 default:
|
|
821 {
|
|
822 /* just copy unknown escape sequences */
|
|
823 *bufp++ = *strp;
|
|
824 idx++;
|
|
825 break;
|
|
826 }
|
|
827 case '=':
|
|
828 {
|
|
829 /* \= quotes the next character;
|
|
830 thus, to put in \[ without its special meaning, use \=\[. */
|
|
831 /* As it happens, this will work with Mule even if the
|
|
832 character quoted is multi-byte; the remaining multi-byte
|
|
833 characters will just be copied by this loop. */
|
|
834 changed = 1;
|
|
835 *bufp++ = strp[2];
|
|
836 idx += 3;
|
|
837 break;
|
|
838 }
|
|
839 case '[':
|
|
840 {
|
|
841 changed = 1;
|
|
842 idx += 2; /* skip \[ */
|
|
843 strp += 2;
|
|
844 start = strp;
|
|
845
|
|
846 while ((idx < strlength)
|
|
847 && *strp != ']')
|
185
|
848 {
|
|
849 strp++;
|
|
850 idx++;
|
0
|
851 }
|
|
852 length = strp - start;
|
|
853 idx++; /* skip ] */
|
|
854
|
|
855 tem = Fintern (make_string (start, length), Qnil);
|
|
856 tem = Fwhere_is_internal (tem, keymap, Qt, Qnil, Qnil);
|
|
857
|
|
858 #if 0 /* FSFmacs */
|
|
859 /* Disregard menu bar bindings; it is positively annoying to
|
|
860 mention them when there's no menu bar, and it isn't terribly
|
|
861 useful even when there is a menu bar. */
|
|
862 if (!NILP (tem))
|
|
863 {
|
|
864 firstkey = Faref (tem, Qzero);
|
|
865 if (EQ (firstkey, Qmenu_bar))
|
|
866 tem = Qnil;
|
|
867 }
|
|
868 #endif
|
|
869
|
|
870 if (NILP (tem)) /* but not on any keys */
|
|
871 {
|
|
872 new = (Bufbyte *) xrealloc (buf, bsize += 4);
|
|
873 bufp += new - buf;
|
|
874 buf = new;
|
|
875 memcpy (bufp, "M-x ", 4);
|
|
876 bufp += 4;
|
|
877 goto subst;
|
|
878 }
|
|
879 else
|
|
880 { /* function is on a key */
|
|
881 tem = Fkey_description (tem);
|
|
882 goto subst_string;
|
|
883 }
|
|
884 }
|
|
885 case '{':
|
|
886 case '<':
|
|
887 {
|
219
|
888 Lisp_Object buffer = Fget_buffer_create (QSsubstitute);
|
|
889 struct buffer *buf_ = XBUFFER (buffer);
|
|
890
|
|
891 Fbuffer_disable_undo (buffer);
|
|
892 Ferase_buffer (buffer);
|
|
893
|
0
|
894 /* \{foo} is replaced with a summary of keymap (symbol-value foo).
|
|
895 \<foo> just sets the keymap used for \[cmd]. */
|
|
896 changed = 1;
|
|
897 idx += 2; /* skip \{ or \< */
|
|
898 strp += 2;
|
|
899 start = strp;
|
|
900
|
|
901 while ((idx < strlength)
|
|
902 && *strp != '}' && *strp != '>')
|
185
|
903 {
|
|
904 strp++;
|
|
905 idx++;
|
0
|
906 }
|
|
907 length = strp - start;
|
|
908 idx++; /* skip } or > */
|
|
909
|
|
910 /* Get the value of the keymap in TEM, or nil if undefined.
|
|
911 Do this while still in the user's current buffer
|
|
912 in case it is a local variable. */
|
|
913 name = Fintern (make_string (start, length), Qnil);
|
|
914 tem = Fboundp (name);
|
|
915 if (! NILP (tem))
|
|
916 {
|
|
917 tem = Fsymbol_value (name);
|
|
918 if (! NILP (tem))
|
|
919 tem = get_keymap (tem, 0, 1);
|
|
920 }
|
|
921
|
|
922 if (NILP (tem))
|
|
923 {
|
|
924 char boof[255], *b = boof;
|
|
925 *b++ = '\n';
|
267
|
926 /* #### This sprintf() is potentially dangerous! */
|
0
|
927 sprintf (b, GETTEXT (
|
|
928 "Uses keymap \"%s\", which is not currently defined."),
|
14
|
929 (char *) XSTRING_DATA (Fsymbol_name (name)));
|
0
|
930 b += strlen (b);
|
|
931 *b++ = '\n';
|
|
932 *b++ = 0;
|
219
|
933 buffer_insert_c_string (buf_, boof);
|
0
|
934
|
|
935 if (start[-1] == '<') keymap = Qnil;
|
|
936 }
|
|
937 else if (start[-1] == '<')
|
|
938 keymap = tem;
|
|
939 else
|
219
|
940 describe_map_tree (tem, 1, Qnil, Qnil, 0, buffer);
|
|
941
|
|
942 tem = make_string_from_buffer (buf_, BUF_BEG (buf_),
|
|
943 BUF_Z (buf_) - BUF_BEG (buf_));
|
|
944 Ferase_buffer (buffer);
|
0
|
945 goto subst_string;
|
|
946
|
|
947 subst_string:
|
14
|
948 start = XSTRING_DATA (tem);
|
|
949 length = XSTRING_LENGTH (tem);
|
0
|
950 subst:
|
|
951 bsize += length;
|
|
952 new = (Bufbyte *) xrealloc (buf, bsize);
|
|
953 bufp += new - buf;
|
|
954 buf = new;
|
|
955 memcpy (bufp, start, length);
|
|
956 bufp += length;
|
|
957
|
|
958 /* Reset STRDATA in case gc relocated it. */
|
14
|
959 strdata = XSTRING_DATA (str);
|
0
|
960
|
|
961 break;
|
|
962 }
|
|
963 }
|
|
964 }
|
|
965
|
|
966 if (changed) /* don't bother if nothing substituted */
|
|
967 tem = make_string (buf, bufp - buf);
|
|
968 else
|
|
969 tem = str;
|
|
970 xfree (buf);
|
|
971 UNGCPRO;
|
173
|
972 return tem;
|
0
|
973 }
|
|
974
|
|
975
|
|
976 /************************************************************************/
|
|
977 /* initialization */
|
|
978 /************************************************************************/
|
|
979
|
|
980 void
|
|
981 syms_of_doc (void)
|
|
982 {
|
20
|
983 DEFSUBR (Fdocumentation);
|
|
984 DEFSUBR (Fdocumentation_property);
|
|
985 DEFSUBR (Fsnarf_documentation);
|
|
986 DEFSUBR (Fverify_documentation);
|
|
987 DEFSUBR (Fsubstitute_command_keys);
|
0
|
988 }
|
|
989
|
|
990 void
|
|
991 vars_of_doc (void)
|
|
992 {
|
|
993 DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name /*
|
|
994 Name of file containing documentation strings of built-in symbols.
|
|
995 */ );
|
|
996 Vdoc_file_name = Qnil;
|
219
|
997
|
|
998 QSsubstitute = build_string (" *substitute*");
|
|
999 staticpro (&QSsubstitute);
|
0
|
1000 }
|