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