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