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