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