annotate src/doc.c @ 436:080151679be2 r21-2-26

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