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