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
|
70
|
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.)
|
70
|
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 }
|
70
|
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 #ifdef MOCKLISP_SUPPORT
|
|
352 else if (EQ (funcar, Qmocklisp))
|
|
353 return Qnil;
|
|
354 #endif
|
|
355 else if (EQ (funcar, Qmacro))
|
|
356 return Fdocumentation (Fcdr (fun), raw);
|
|
357 else
|
|
358 goto oops;
|
|
359 }
|
|
360 else
|
|
361 {
|
|
362 oops:
|
|
363 return Fsignal (Qinvalid_function, list1 (fun));
|
|
364 }
|
|
365
|
|
366 if (NILP (raw))
|
|
367 {
|
|
368 struct gcpro gcpro1;
|
|
369 #ifdef I18N3
|
|
370 Lisp_Object domain = Qnil;
|
|
371 if (COMPILED_FUNCTIONP (fun))
|
|
372 domain = Fcompiled_function_domain (fun);
|
|
373 if (NILP (domain))
|
|
374 doc = Fgettext (doc);
|
|
375 else
|
|
376 doc = Fdgettext (domain, doc);
|
|
377 #endif
|
|
378
|
|
379 GCPRO1 (doc);
|
|
380 doc = Fsubstitute_command_keys (doc);
|
|
381 UNGCPRO;
|
|
382 }
|
|
383 return doc;
|
|
384 }
|
|
385
|
20
|
386 DEFUN ("documentation-property", Fdocumentation_property, 2, 3, 0, /*
|
0
|
387 Return the documentation string that is SYMBOL's PROP property.
|
|
388 This is like `get', but it can refer to strings stored in the
|
|
389 `doc-directory/DOC' file; and if the value is a string, it is passed
|
|
390 through `substitute-command-keys'. A non-nil third argument avoids this
|
|
391 translation.
|
20
|
392 */
|
|
393 (sym, prop, raw))
|
0
|
394 {
|
|
395 /* This function can GC */
|
|
396 REGISTER Lisp_Object doc;
|
|
397 #ifdef I18N3
|
|
398 REGISTER Lisp_Object domain;
|
|
399 #endif
|
|
400
|
|
401 doc = Fget (sym, prop, Qnil);
|
|
402 if (INTP (doc))
|
|
403 doc = get_doc_string (XINT (doc) > 0 ? doc : make_int (- XINT (doc)));
|
|
404 else if (CONSP (doc))
|
|
405 doc = get_doc_string (doc);
|
|
406 #ifdef I18N3
|
|
407 if (!NILP (doc))
|
|
408 {
|
|
409 domain = Fget (sym, Qvariable_domain, Qnil);
|
|
410 if (NILP (domain))
|
|
411 doc = Fgettext (doc);
|
|
412 else
|
|
413 doc = Fdgettext (domain, doc);
|
|
414 }
|
|
415 #endif
|
|
416 if (NILP (raw) && STRINGP (doc))
|
|
417 doc = Fsubstitute_command_keys (doc);
|
|
418 return doc;
|
|
419 }
|
|
420
|
|
421 static void
|
|
422 weird_doc (Lisp_Object sym, CONST char *weirdness, CONST char *type, int pos)
|
|
423 {
|
70
|
424 #if defined(ENERGIZE) || defined(SUNPRO) /* hide kludgery... */
|
0
|
425 if (!strcmp (weirdness, GETTEXT ("duplicate"))) return;
|
70
|
426 #endif
|
0
|
427 message ("Note: Strange doc (%s) for %s %s @ %d",
|
|
428 weirdness, type, string_data (XSYMBOL (sym)->name), pos);
|
|
429 }
|
|
430
|
|
431
|
20
|
432 DEFUN ("Snarf-documentation", Fsnarf_documentation, 1, 1, 0, /*
|
0
|
433 Used during Emacs initialization, before dumping runnable Emacs,
|
|
434 to find pointers to doc strings stored in `.../lib-src/DOC' and
|
|
435 record them in function definitions.
|
|
436 One arg, FILENAME, a string which does not include a directory.
|
|
437 The file is written to `../lib-src', and later found in `exec-directory'
|
|
438 when doc strings are referred to in the dumped Emacs.
|
20
|
439 */
|
|
440 (filename))
|
0
|
441 {
|
|
442 /* !!#### This function has not been Mule-ized */
|
|
443 int fd;
|
|
444 char buf[1024 + 1];
|
|
445 REGISTER int filled;
|
|
446 REGISTER int pos;
|
|
447 REGISTER char *p, *end;
|
|
448 Lisp_Object sym, fun, tem;
|
|
449 char *name;
|
|
450
|
|
451 #ifndef CANNOT_DUMP
|
|
452 if (!purify_flag)
|
|
453 error ("Snarf-documentation can only be called in an undumped Emacs");
|
|
454 #endif
|
|
455
|
|
456 CHECK_STRING (filename);
|
|
457
|
|
458 #ifndef CANNOT_DUMP
|
14
|
459 name = (char *) alloca (XSTRING_LENGTH (filename) + 14);
|
0
|
460 strcpy (name, "../lib-src/");
|
|
461 #else /* CANNOT_DUMP */
|
|
462 CHECK_STRING (Vdoc_directory);
|
14
|
463 name = (char *) alloca (XSTRING_LENGTH (filename)
|
|
464 + XSTRING_LENGTH (Vdoc_directory)
|
0
|
465 + 1);
|
14
|
466 strcpy (name, (char *) XSTRING_DATA (Vdoc_directory));
|
0
|
467 #endif /* CANNOT_DUMP */
|
14
|
468 strcat (name, (char *) XSTRING_DATA (filename));
|
0
|
469 #ifdef VMS
|
|
470 #ifndef VMS4_4
|
|
471 /* For VMS versions with limited file name syntax,
|
|
472 convert the name to something VMS will allow. */
|
|
473 p = name;
|
|
474 while (*p)
|
|
475 {
|
|
476 if (*p == '-')
|
|
477 *p = '_';
|
|
478 p++;
|
|
479 }
|
|
480 #endif /* not VMS4_4 */
|
|
481 #ifdef VMS4_4
|
|
482 strcpy (name, sys_translate_unix (name));
|
|
483 #endif /* VMS4_4 */
|
|
484 #endif /* VMS */
|
|
485
|
|
486 fd = open (name, O_RDONLY, 0);
|
|
487 if (fd < 0)
|
|
488 report_file_error ("Opening doc string file",
|
|
489 Fcons (build_string (name), Qnil));
|
|
490 Vdoc_file_name = filename;
|
|
491 filled = 0;
|
|
492 pos = 0;
|
|
493 while (1)
|
|
494 {
|
|
495 if (filled < 512)
|
|
496 filled += read (fd, &buf[filled], sizeof buf - 1 - filled);
|
|
497 if (!filled)
|
|
498 break;
|
|
499
|
|
500 buf[filled] = 0;
|
|
501 p = buf;
|
|
502 end = buf + (filled < 512 ? filled : filled - 128);
|
|
503 while (p != end && *p != '\037') p++;
|
|
504 /* p points to ^_Ffunctionname\n or ^_Vvarname\n. */
|
|
505 if (p != end)
|
|
506 {
|
|
507 end = strchr (p, '\n');
|
|
508 sym = oblookup (Vobarray, (Bufbyte *) p + 2, end - p - 2);
|
|
509 if (SYMBOLP (sym))
|
|
510 {
|
|
511 Lisp_Object offset = make_int (pos + end + 1 - buf);
|
|
512 /* Attach a docstring to a variable */
|
|
513 if (p[1] == 'V')
|
|
514 {
|
|
515 /* Install file-position as variable-documentation property
|
|
516 and make it negative for a user-variable
|
|
517 (doc starts with a `*'). */
|
|
518 Lisp_Object old = Fget (sym, Qvariable_documentation, Qzero);
|
|
519 if (!ZEROP (old))
|
|
520 {
|
|
521 weird_doc (sym, GETTEXT ("duplicate"),
|
|
522 GETTEXT ("variable"), pos);
|
|
523 /* In the case of duplicate doc file entries, always
|
|
524 take the later one. But if the doc is not an int
|
|
525 (a string, say) leave it alone. */
|
|
526 if (!INTP (old))
|
|
527 goto weird;
|
|
528 }
|
|
529 Fput (sym, Qvariable_documentation,
|
|
530 ((end[1] == '*')
|
|
531 ? make_int (- XINT (offset))
|
|
532 : offset));
|
|
533 }
|
|
534 /* Attach a docstring to a function.
|
|
535 The type determines where the docstring is stored. */
|
|
536 else if (p[1] == 'F')
|
|
537 {
|
|
538 fun = XSYMBOL (sym)->function;/*indirect_function (sym,0);*/
|
|
539
|
|
540 if (CONSP (fun) && EQ (XCAR (fun), Qmacro))
|
|
541 fun = XCDR (fun);
|
|
542
|
|
543 if (UNBOUNDP (fun))
|
|
544 {
|
|
545 /* May have been #if'ed out or something */
|
|
546 weird_doc (sym, GETTEXT ("not fboundp"),
|
|
547 GETTEXT ("function"), pos);
|
|
548 goto weird;
|
|
549 }
|
|
550 else if (SUBRP (fun))
|
|
551 {
|
|
552 /* Lisp_Subrs have a slot for it. */
|
|
553 if (XSUBR (fun)->doc)
|
|
554 {
|
|
555 weird_doc (sym, GETTEXT ("duplicate"),
|
|
556 GETTEXT ("subr"), pos);
|
|
557 goto weird;
|
|
558 }
|
|
559 XSUBR (fun)->doc = (char *) (- XINT (offset));
|
|
560 }
|
|
561 else if (CONSP (fun))
|
|
562 {
|
|
563 /* If it's a lisp form, stick it in the form. */
|
|
564 tem = XCAR (fun);
|
|
565 if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
|
|
566 {
|
|
567 tem = Fcdr (Fcdr (fun));
|
|
568 if (CONSP (tem) &&
|
|
569 INTP (XCAR (tem)))
|
|
570 {
|
|
571 Lisp_Object old = XCAR (tem);
|
|
572 if (!ZEROP (old))
|
|
573 {
|
|
574 weird_doc (sym, GETTEXT ("duplicate"),
|
|
575 (EQ (tem, Qlambda)
|
|
576 ? GETTEXT ("lambda")
|
|
577 : GETTEXT ("autoload")),
|
|
578 pos);
|
|
579 /* In the case of duplicate doc file entries,
|
|
580 always take the later one. But if the doc
|
|
581 is not an int (a string, say) leave it
|
|
582 alone. */
|
|
583 if (!INTP (old))
|
|
584 goto weird;
|
|
585 }
|
|
586 XCAR (tem) = offset;
|
|
587 }
|
|
588 else goto weird_function;
|
|
589 }
|
|
590 else goto weird_function;
|
|
591 }
|
|
592 else if (COMPILED_FUNCTIONP (fun))
|
|
593 {
|
|
594 /* Compiled-Function objects sometimes have
|
|
595 slots for it. */
|
|
596 struct Lisp_Compiled_Function *b =
|
|
597 XCOMPILED_FUNCTION (fun);
|
|
598
|
|
599 /* This compiled-function object must have a
|
|
600 slot for the docstring, since we've found a
|
|
601 docstring for it. Unless there were multiple
|
|
602 definitions of it, and the latter one didn't
|
|
603 have any doc, which is a legal if slightly
|
|
604 bogus situation, so don't blow up. */
|
|
605
|
|
606 if (! (b->flags.documentationp))
|
|
607 {
|
|
608 weird_doc (sym, GETTEXT ("no doc slot"),
|
|
609 GETTEXT ("bytecode"), pos);
|
|
610 goto weird;
|
|
611 }
|
|
612 else
|
|
613 {
|
|
614 Lisp_Object old =
|
|
615 compiled_function_documentation (b);
|
|
616 if (!ZEROP (old))
|
|
617 {
|
|
618 weird_doc (sym, GETTEXT ("duplicate"),
|
|
619 GETTEXT ("bytecode"), pos);
|
|
620 /* In the case of duplicate doc file entries,
|
|
621 always take the later one. But if the doc is
|
|
622 not an int (a string, say) leave it alone. */
|
|
623 if (!INTP (old))
|
|
624 goto weird;
|
|
625 }
|
|
626 set_compiled_function_documentation (b, offset);
|
|
627 }
|
|
628 }
|
|
629 else
|
|
630 {
|
|
631 /* Otherwise the function is undefined or
|
|
632 otherwise weird. Ignore it. */
|
|
633 weird_function:
|
|
634 weird_doc (sym, GETTEXT ("weird function"),
|
|
635 GETTEXT ("function"), pos);
|
|
636 goto weird;
|
|
637 }
|
|
638 }
|
|
639 else
|
|
640 {
|
|
641 /* lose: */
|
|
642 error ("DOC file invalid at position %d", pos);
|
|
643 weird:
|
|
644 /* goto lose */;
|
|
645 }
|
|
646 }
|
|
647 }
|
|
648 pos += end - buf;
|
|
649 filled -= end - buf;
|
|
650 memmove (buf, end, filled);
|
|
651 }
|
|
652 close (fd);
|
|
653 return Qnil;
|
|
654 }
|
|
655
|
|
656
|
|
657 #if 1 /* Don't warn about functions whose doc was lost because they were
|
|
658 wrapped by advice-freeze.el... */
|
|
659 static int
|
|
660 kludgily_ignore_lost_doc_p (Lisp_Object sym)
|
|
661 {
|
|
662 # define kludge_prefix "ad-Orig-"
|
|
663 return (string_length (XSYMBOL (sym)->name) > sizeof (kludge_prefix) &&
|
|
664 !strncmp ((char *) string_data (XSYMBOL (sym)->name), kludge_prefix,
|
|
665 sizeof (kludge_prefix) - 1));
|
|
666 # undef kludge_prefix
|
|
667 }
|
|
668 #else
|
|
669 # define kludgily_ignore_lost_doc_p(sym) 0
|
|
670 #endif
|
|
671
|
|
672
|
|
673 static void
|
|
674 verify_doc_mapper (Lisp_Object sym, Lisp_Object closure)
|
|
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 {
|
|
704 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
705 if (! (b->flags.documentationp))
|
|
706 doc = -1;
|
|
707 else
|
|
708 {
|
|
709 Lisp_Object tem = compiled_function_documentation (b);
|
|
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.",
|
|
718 string_data (XSYMBOL (sym)->name));
|
|
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.",
|
|
728 string_data (XSYMBOL (sym)->name));
|
|
729 XCDR (closure) = Qt;
|
|
730 }
|
|
731 }
|
|
732 }
|
|
733
|
20
|
734 DEFUN ("Verify-documentation", Fverify_documentation, 0, 0, 0, /*
|
0
|
735 Used to make sure everything went well with Snarf-documentation.
|
|
736 Writes to stderr if not.
|
20
|
737 */
|
|
738 ())
|
0
|
739 {
|
|
740 Lisp_Object closure = Fcons (Qnil, Qnil);
|
|
741 struct gcpro gcpro1;
|
|
742 GCPRO1 (closure);
|
|
743 map_obarray (Vobarray, verify_doc_mapper, closure);
|
|
744 if (!NILP (Fcdr (closure)))
|
|
745 message ("\n"
|
|
746 "This is usually because some files were preloaded by loaddefs.el or\n"
|
|
747 "site-load.el, but were not passed to make-docfile by Makefile.\n");
|
|
748 UNGCPRO;
|
|
749 return (NILP (Fcdr (closure)) ? Qt : Qnil);
|
|
750 }
|
|
751
|
|
752
|
20
|
753 DEFUN ("substitute-command-keys", Fsubstitute_command_keys, 1, 1, 0, /*
|
0
|
754 Substitute key descriptions for command names in STRING.
|
|
755 Return a new string which is STRING with substrings of the form \\=\\[COMMAND]
|
|
756 replaced by either: a keystroke sequence that will invoke COMMAND,
|
|
757 or \"M-x COMMAND\" if COMMAND is not on any keys.
|
|
758 Substrings of the form \\=\\{MAPVAR} are replaced by summaries
|
|
759 \(made by describe-bindings) of the value of MAPVAR, taken as a keymap.
|
|
760 Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR
|
|
761 as the keymap for future \\=\\[COMMAND] substrings.
|
|
762 \\=\\= quotes the following character and is discarded;
|
|
763 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.
|
20
|
764 */
|
|
765 (str))
|
0
|
766 {
|
|
767 /* This function can GC */
|
|
768 Bufbyte *buf;
|
|
769 int changed = 0;
|
|
770 REGISTER Bufbyte *strdata;
|
|
771 REGISTER Bufbyte *bufp;
|
|
772 Bytecount strlength;
|
|
773 Bytecount idx;
|
|
774 Bytecount bsize;
|
|
775 Bufbyte *new;
|
|
776 Lisp_Object tem = Qnil;
|
|
777 Lisp_Object keymap;
|
|
778 Bufbyte *start;
|
|
779 Bytecount length;
|
|
780 Lisp_Object name;
|
|
781 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
782
|
|
783 if (NILP (str))
|
|
784 return Qnil;
|
|
785
|
|
786 CHECK_STRING (str);
|
|
787 tem = Qnil;
|
|
788 keymap = Qnil;
|
|
789 name = Qnil;
|
|
790 GCPRO4 (str, tem, keymap, name);
|
|
791
|
|
792 /* There is the possibility that the string is not destined for a
|
|
793 translating stream, and it could be argued that we should do the
|
|
794 same thing here as in Fformat(), but there are very few times
|
|
795 when this will be the case and many calls to this function
|
|
796 would have to have `gettext' calls added. (I18N3) */
|
|
797 str = LISP_GETTEXT (str);
|
|
798
|
|
799 /* KEYMAP is either nil (which means search all the active keymaps)
|
|
800 or a specified local map (which means search just that and the
|
|
801 global map). If non-nil, it might come from Voverriding_local_map,
|
|
802 or from a \\<mapname> construct in STR itself.. */
|
|
803 #if 0 /* FSFmacs */
|
|
804 /* This is really weird and garbagey. If keymap is nil and there's
|
|
805 an overriding-local-map, `where-is-internal' will correctly note
|
|
806 this, so there's no reason to do it here. Maybe FSFmacs
|
|
807 `where-is-internal' is broken. */
|
|
808 keymap = current_kboard->Voverriding_terminal_local_map;
|
|
809 if (NILP (keymap))
|
|
810 keymap = Voverriding_local_map;
|
|
811 #endif
|
|
812
|
14
|
813 strlength = XSTRING_LENGTH (str);
|
0
|
814 bsize = strlength;
|
|
815 buf = (Bufbyte *) xmalloc (bsize);
|
|
816 bufp = buf;
|
|
817
|
|
818 /* Have to reset strdata every time GC might be called */
|
14
|
819 strdata = XSTRING_DATA (str);
|
0
|
820 for (idx = 0; idx < strlength; )
|
|
821 {
|
|
822 Bufbyte *strp = strdata + idx;
|
|
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 */
|
|
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 }
|
|
883 #endif
|
|
884
|
|
885 if (NILP (tem)) /* but not on any keys */
|
|
886 {
|
|
887 new = (Bufbyte *) xrealloc (buf, bsize += 4);
|
|
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 {
|
|
903 /* \{foo} is replaced with a summary of keymap (symbol-value foo).
|
|
904 \<foo> just sets the keymap used for \[cmd]. */
|
|
905 struct buffer *oldbuf;
|
|
906
|
|
907 changed = 1;
|
|
908 idx += 2; /* skip \{ or \< */
|
|
909 strp += 2;
|
|
910 start = strp;
|
|
911
|
|
912 while ((idx < strlength)
|
|
913 && *strp != '}' && *strp != '>')
|
|
914 {
|
|
915 strp++;
|
|
916 idx++;
|
|
917 }
|
|
918 length = strp - start;
|
|
919 idx++; /* skip } or > */
|
|
920
|
|
921 /* Get the value of the keymap in TEM, or nil if undefined.
|
|
922 Do this while still in the user's current buffer
|
|
923 in case it is a local variable. */
|
|
924 name = Fintern (make_string (start, length), Qnil);
|
|
925 tem = Fboundp (name);
|
|
926 if (! NILP (tem))
|
|
927 {
|
|
928 tem = Fsymbol_value (name);
|
|
929 if (! NILP (tem))
|
|
930 tem = get_keymap (tem, 0, 1);
|
|
931 }
|
|
932
|
|
933 /* Now switch to a temp buffer. */
|
|
934 oldbuf = current_buffer;
|
|
935 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
|
|
936
|
|
937 if (NILP (tem))
|
|
938 {
|
|
939 char boof[255], *b = boof;
|
|
940 *b++ = '\n';
|
|
941 sprintf (b, GETTEXT (
|
|
942 "Uses keymap \"%s\", which is not currently defined."),
|
14
|
943 (char *) XSTRING_DATA (Fsymbol_name (name)));
|
0
|
944 b += strlen (b);
|
|
945 *b++ = '\n';
|
|
946 *b++ = 0;
|
|
947 buffer_insert_c_string (current_buffer, boof);
|
|
948
|
|
949 if (start[-1] == '<') keymap = Qnil;
|
|
950 }
|
|
951 else if (start[-1] == '<')
|
|
952 keymap = tem;
|
|
953 else
|
|
954 describe_map_tree (tem, 1, Qnil, Qnil, 0);
|
|
955 tem = Fbuffer_substring (Qnil, Qnil, Fcurrent_buffer ());
|
|
956 Ferase_buffer (Fcurrent_buffer ());
|
|
957 set_buffer_internal (oldbuf);
|
|
958 goto subst_string;
|
|
959
|
|
960 subst_string:
|
14
|
961 start = XSTRING_DATA (tem);
|
|
962 length = XSTRING_LENGTH (tem);
|
0
|
963 subst:
|
|
964 bsize += length;
|
|
965 new = (Bufbyte *) xrealloc (buf, bsize);
|
|
966 bufp += new - buf;
|
|
967 buf = new;
|
|
968 memcpy (bufp, start, length);
|
|
969 bufp += length;
|
|
970
|
|
971 /* Reset STRDATA in case gc relocated it. */
|
14
|
972 strdata = XSTRING_DATA (str);
|
0
|
973
|
|
974 break;
|
|
975 }
|
|
976 }
|
|
977 }
|
|
978
|
|
979 if (changed) /* don't bother if nothing substituted */
|
|
980 tem = make_string (buf, bufp - buf);
|
|
981 else
|
|
982 tem = str;
|
|
983 xfree (buf);
|
|
984 UNGCPRO;
|
|
985 return (tem);
|
|
986 }
|
|
987
|
|
988
|
|
989 /************************************************************************/
|
|
990 /* initialization */
|
|
991 /************************************************************************/
|
|
992
|
|
993 void
|
|
994 syms_of_doc (void)
|
|
995 {
|
20
|
996 DEFSUBR (Fdocumentation);
|
|
997 DEFSUBR (Fdocumentation_property);
|
|
998 DEFSUBR (Fsnarf_documentation);
|
|
999 DEFSUBR (Fverify_documentation);
|
|
1000 DEFSUBR (Fsubstitute_command_keys);
|
0
|
1001 }
|
|
1002
|
|
1003 void
|
|
1004 vars_of_doc (void)
|
|
1005 {
|
|
1006 DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name /*
|
|
1007 Name of file containing documentation strings of built-in symbols.
|
|
1008 */ );
|
|
1009 Vdoc_file_name = Qnil;
|
|
1010 }
|