Mercurial > emacs
annotate lib-src/make-docfile.c @ 9973:1d5a908f201e
(access_keymap): Use type test macros.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 16 Nov 1994 05:59:53 +0000 |
parents | 20652342eb9a |
children | 3e2571e22b61 |
rev | line source |
---|---|
24 | 1 /* Generate doc-string file for GNU Emacs from source files. |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. |
24 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
38 | 6 GNU Emacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | |
638 | 8 the Free Software Foundation; either version 2, or (at your option) |
38 | 9 any later version. |
24 | 10 |
38 | 11 GNU Emacs is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
24 | 19 |
20 /* The arguments given to this program are all the C and Lisp source files | |
21 of GNU Emacs. .elc and .el and .c files are allowed. | |
22 A .o file can also be specified; the .c file it was made from is used. | |
23 This helps the makefile pass the correct list of files. | |
24 | |
25 The results, which go to standard output or to a file | |
26 specified with -a or -o (-a to append, -o to start from nothing), | |
27 are entries containing function or variable names and their documentation. | |
28 Each entry starts with a ^_ character. | |
29 Then comes F for a function or V for a variable. | |
30 Then comes the function or variable name, terminated with a newline. | |
31 Then comes the documentation for that function or variable. | |
32 */ | |
33 | |
34 #include <stdio.h> | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
35 #ifdef MSDOS |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
36 #include <fcntl.h> |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
37 #endif /* MSDOS */ |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
38 #ifdef WINDOWSNT |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
39 #include <stdlib.h> |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
40 #include <fcntl.h> |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
41 #include <direct.h> |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
42 #endif /* WINDOWSNT */ |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
43 |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
44 #ifdef DOS_NT |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
45 #define READ_TEXT "rt" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
46 #define READ_BINARY "rb" |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
47 #else /* not DOS_NT */ |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
48 #define READ_TEXT "r" |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
49 #define READ_BINARY "r" |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
50 #endif /* not DOS_NT */ |
24 | 51 |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
52 int scan_file (); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
53 int scan_lisp_file (); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
54 int scan_c_file (); |
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
55 |
24 | 56 FILE *outfile; |
57 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
58 int |
24 | 59 main (argc, argv) |
60 int argc; | |
61 char **argv; | |
62 { | |
63 int i; | |
64 int err_count = 0; | |
9643
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
65 int first_infile; |
24 | 66 |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
67 /* Don't put CRs in the DOC file. */ |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
68 #ifdef MSDOS |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
69 _fmode = O_BINARY; |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
70 (stdout)->_flag &= ~_IOTEXT; |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
71 _setmode (fileno (stdout), O_BINARY); |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
72 #endif /* MSDOS */ |
9772
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
73 #ifdef WINDOWSNT |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
74 _fmode = O_BINARY; |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
75 _setmode (fileno (stdout), O_BINARY); |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
76 #endif /* WINDOWSNT */ |
20652342eb9a
(main) [WINDOWSNT]: Now sets _fmode and stdout to O_BINARY.
Richard M. Stallman <rms@gnu.org>
parents:
9643
diff
changeset
|
77 |
24 | 78 outfile = stdout; |
79 | |
80 /* If first two args are -o FILE, output to FILE. */ | |
81 i = 1; | |
82 if (argc > i + 1 && !strcmp (argv[i], "-o")) | |
83 { | |
84 outfile = fopen (argv[i + 1], "w"); | |
85 i += 2; | |
86 } | |
87 if (argc > i + 1 && !strcmp (argv[i], "-a")) | |
88 { | |
89 outfile = fopen (argv[i + 1], "a"); | |
90 i += 2; | |
91 } | |
2814
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
92 if (argc > i + 1 && !strcmp (argv[i], "-d")) |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
93 { |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
94 chdir (argv[i + 1]); |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
95 i += 2; |
0da5b58e98ed
Install patches from David J. Mackenzie to make the srcdir option
Jim Blandy <jimb@redhat.com>
parents:
2483
diff
changeset
|
96 } |
24 | 97 |
9643
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
98 first_infile = i; |
24 | 99 for (; i < argc; i++) |
9643
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
100 { |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
101 int j; |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
102 /* Don't process one file twice. */ |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
103 for (j = first_infile; j < i; j++) |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
104 if (! strcmp (argv[i], argv[j])) |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
105 break; |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
106 if (j == i) |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
107 err_count += scan_file (argv[i]); |
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
108 } |
24 | 109 #ifndef VMS |
9643
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
110 exit (err_count > 0); |
3028 | 111 #endif /* VMS */ |
9643
5d1e70b22a93
(main): Don't process one input file twice.
Richard M. Stallman <rms@gnu.org>
parents:
9491
diff
changeset
|
112 return err_count > 0; |
24 | 113 } |
114 | |
164 | 115 /* Read file FILENAME and output its doc strings to outfile. */ |
24 | 116 /* Return 1 if file is not found, 0 if it is found. */ |
117 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
118 int |
24 | 119 scan_file (filename) |
120 char *filename; | |
121 { | |
122 int len = strlen (filename); | |
123 if (!strcmp (filename + len - 4, ".elc")) | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
124 return scan_lisp_file (filename, READ_BINARY); |
24 | 125 else if (!strcmp (filename + len - 3, ".el")) |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
126 return scan_lisp_file (filename, READ_TEXT); |
24 | 127 else |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
128 return scan_c_file (filename, READ_TEXT); |
24 | 129 } |
130 | |
131 char buf[128]; | |
132 | |
133 /* Skip a C string from INFILE, | |
134 and return the character that follows the closing ". | |
164 | 135 If printflag is positive, output string contents to outfile. |
24 | 136 If it is negative, store contents in buf. |
137 Convert escape sequences \n and \t to newline and tab; | |
138 discard \ followed by newline. */ | |
139 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
140 int |
24 | 141 read_c_string (infile, printflag) |
142 FILE *infile; | |
143 int printflag; | |
144 { | |
145 register int c; | |
146 char *p = buf; | |
147 | |
148 c = getc (infile); | |
149 while (c != EOF) | |
150 { | |
151 while (c != '"' && c != EOF) | |
152 { | |
153 if (c == '\\') | |
154 { | |
155 c = getc (infile); | |
156 if (c == '\n') | |
157 { | |
158 c = getc (infile); | |
159 continue; | |
160 } | |
161 if (c == 'n') | |
162 c = '\n'; | |
163 if (c == 't') | |
164 c = '\t'; | |
165 } | |
166 if (printflag > 0) | |
167 putc (c, outfile); | |
168 else if (printflag < 0) | |
169 *p++ = c; | |
170 c = getc (infile); | |
171 } | |
172 c = getc (infile); | |
173 if (c != '"') | |
174 break; | |
4987
f052db139432
(read_c_string): For "", concatenate the two strings.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
175 /* If we had a "", concatenate the two strings. */ |
24 | 176 c = getc (infile); |
177 } | |
178 | |
179 if (printflag < 0) | |
180 *p = 0; | |
181 | |
182 return c; | |
183 } | |
184 | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
185 /* Write to file OUT the argument names of function FUNC, whose text is in BUF. |
24 | 186 MINARGS and MAXARGS are the minimum and maximum number of arguments. */ |
187 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
188 void |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
189 write_c_args (out, func, buf, minargs, maxargs) |
24 | 190 FILE *out; |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
191 char *func, *buf; |
24 | 192 int minargs, maxargs; |
193 { | |
1206 | 194 register char *p; |
1250 | 195 int in_ident = 0; |
196 int just_spaced = 0; | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
197 int need_space = 1; |
24 | 198 |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
199 fprintf (out, "(%s", func); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
200 |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
201 if (*buf == '(') |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
202 ++buf; |
24 | 203 |
1206 | 204 for (p = buf; *p; p++) |
24 | 205 { |
1250 | 206 char c = *p; |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
207 int ident_start = 0; |
1250 | 208 |
209 /* Notice when we start printing a new identifier. */ | |
210 if ((('A' <= c && c <= 'Z') | |
211 || ('a' <= c && c <= 'z') | |
212 || ('0' <= c && c <= '9') | |
213 || c == '_') | |
214 != in_ident) | |
24 | 215 { |
1250 | 216 if (!in_ident) |
217 { | |
218 in_ident = 1; | |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
219 ident_start = 1; |
1206 | 220 |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
221 if (need_space) |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
222 putc (' ', out); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
223 |
1250 | 224 if (minargs == 0 && maxargs > 0) |
225 fprintf (out, "&optional "); | |
226 just_spaced = 1; | |
1206 | 227 |
1250 | 228 minargs--; |
229 maxargs--; | |
230 } | |
231 else | |
232 in_ident = 0; | |
24 | 233 } |
638 | 234 |
1250 | 235 /* Print the C argument list as it would appear in lisp: |
236 print underscores as hyphens, and print commas as spaces. | |
237 Collapse adjacent spaces into one. */ | |
238 if (c == '_') c = '-'; | |
239 if (c == ',') c = ' '; | |
240 | |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
241 /* In C code, `default' is a reserved word, so we spell it |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
242 `defalt'; unmangle that here. */ |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
243 if (ident_start |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
244 && strncmp (p, "defalt", 6) == 0 |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
245 && ! (('A' <= p[6] && p[6] <= 'Z') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
246 || ('a' <= p[6] && p[6] <= 'z') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
247 || ('0' <= p[6] && p[6] <= '9') |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
248 || p[6] == '_')) |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
249 { |
7564
d5d803ffff27
(write_c_args): Put `default' in upper case.
Richard M. Stallman <rms@gnu.org>
parents:
5604
diff
changeset
|
250 fprintf (out, "DEFAULT"); |
2483
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
251 p += 5; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
252 in_ident = 0; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
253 just_spaced = 0; |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
254 } |
b4145a12422d
* make-docfile.c (write_c_args): Print an argument named "defalt"
Jim Blandy <jimb@redhat.com>
parents:
1676
diff
changeset
|
255 else if (c != ' ' || ! just_spaced) |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
256 { |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
257 if (c >= 'a' && c <= 'z') |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
258 /* Upcase the letter. */ |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
259 c += 'A' - 'a'; |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
260 putc (c, out); |
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
261 } |
1250 | 262 |
263 just_spaced = (c == ' '); | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
264 need_space = 0; |
24 | 265 } |
266 } | |
267 | |
268 /* Read through a c file. If a .o file is named, | |
269 the corresponding .c file is read instead. | |
270 Looks for DEFUN constructs such as are defined in ../src/lisp.h. | |
271 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */ | |
272 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
273 int |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
274 scan_c_file (filename, mode) |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
275 char *filename, *mode; |
24 | 276 { |
277 FILE *infile; | |
278 register int c; | |
279 register int commas; | |
280 register int defunflag; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
281 register int defvarperbufferflag; |
24 | 282 register int defvarflag; |
283 int minargs, maxargs; | |
284 | |
285 if (filename[strlen (filename) - 1] == 'o') | |
286 filename[strlen (filename) - 1] = 'c'; | |
287 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
288 infile = fopen (filename, mode); |
24 | 289 |
290 /* No error if non-ex input file */ | |
291 if (infile == NULL) | |
292 { | |
293 perror (filename); | |
294 return 0; | |
295 } | |
296 | |
297 c = '\n'; | |
298 while (!feof (infile)) | |
299 { | |
300 if (c != '\n') | |
301 { | |
302 c = getc (infile); | |
303 continue; | |
304 } | |
305 c = getc (infile); | |
306 if (c == ' ') | |
307 { | |
308 while (c == ' ') | |
309 c = getc (infile); | |
310 if (c != 'D') | |
311 continue; | |
312 c = getc (infile); | |
313 if (c != 'E') | |
314 continue; | |
315 c = getc (infile); | |
316 if (c != 'F') | |
317 continue; | |
318 c = getc (infile); | |
319 if (c != 'V') | |
320 continue; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
321 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
322 if (c != 'A') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
323 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
324 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
325 if (c != 'R') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
326 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
327 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
328 if (c != '_') |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
329 continue; |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
330 |
24 | 331 defvarflag = 1; |
332 defunflag = 0; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
333 |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
334 c = getc (infile); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
335 defvarperbufferflag = (c == 'P'); |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
336 |
24 | 337 c = getc (infile); |
338 } | |
339 else if (c == 'D') | |
340 { | |
341 c = getc (infile); | |
342 if (c != 'E') | |
343 continue; | |
344 c = getc (infile); | |
345 if (c != 'F') | |
346 continue; | |
347 c = getc (infile); | |
348 defunflag = c == 'U'; | |
349 defvarflag = 0; | |
350 } | |
351 else continue; | |
352 | |
353 while (c != '(') | |
354 { | |
355 if (c < 0) | |
356 goto eof; | |
357 c = getc (infile); | |
358 } | |
359 | |
360 c = getc (infile); | |
361 if (c != '"') | |
362 continue; | |
363 c = read_c_string (infile, -1); | |
364 | |
365 if (defunflag) | |
366 commas = 5; | |
1676
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
367 else if (defvarperbufferflag) |
e8b3c6b52c1e
* make-docfile.c (scan_c_file): Since DEFVAR_PER_BUFFER now takes
Jim Blandy <jimb@redhat.com>
parents:
1250
diff
changeset
|
368 commas = 2; |
24 | 369 else if (defvarflag) |
370 commas = 1; | |
371 else /* For DEFSIMPLE and DEFPRED */ | |
372 commas = 2; | |
373 | |
374 while (commas) | |
375 { | |
376 if (c == ',') | |
377 { | |
378 commas--; | |
379 if (defunflag && (commas == 1 || commas == 2)) | |
380 { | |
381 do | |
382 c = getc (infile); | |
383 while (c == ' ' || c == '\n' || c == '\t'); | |
384 if (c < 0) | |
385 goto eof; | |
386 ungetc (c, infile); | |
387 if (commas == 2) /* pick up minargs */ | |
388 fscanf (infile, "%d", &minargs); | |
389 else /* pick up maxargs */ | |
390 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ | |
391 maxargs = -1; | |
392 else | |
393 fscanf (infile, "%d", &maxargs); | |
394 } | |
395 } | |
396 if (c < 0) | |
397 goto eof; | |
398 c = getc (infile); | |
399 } | |
400 while (c == ' ' || c == '\n' || c == '\t') | |
401 c = getc (infile); | |
402 if (c == '"') | |
403 c = read_c_string (infile, 0); | |
404 while (c != ',') | |
405 c = getc (infile); | |
406 c = getc (infile); | |
407 while (c == ' ' || c == '\n' || c == '\t') | |
408 c = getc (infile); | |
409 | |
410 if (c == '"') | |
411 { | |
412 putc (037, outfile); | |
413 putc (defvarflag ? 'V' : 'F', outfile); | |
414 fprintf (outfile, "%s\n", buf); | |
168 | 415 c = read_c_string (infile, 1); |
416 | |
417 /* If this is a defun, find the arguments and print them. If | |
418 this function takes MANY or UNEVALLED args, then the C source | |
419 won't give the names of the arguments, so we shouldn't bother | |
420 trying to find them. */ | |
421 if (defunflag && maxargs != -1) | |
24 | 422 { |
423 char argbuf[1024], *p = argbuf; | |
424 while (c != ')') | |
425 { | |
426 if (c < 0) | |
427 goto eof; | |
428 c = getc (infile); | |
429 } | |
430 /* Skip into arguments. */ | |
431 while (c != '(') | |
432 { | |
433 if (c < 0) | |
434 goto eof; | |
435 c = getc (infile); | |
436 } | |
437 /* Copy arguments into ARGBUF. */ | |
438 *p++ = c; | |
439 do | |
440 *p++ = c = getc (infile); | |
441 while (c != ')'); | |
442 *p = '\0'; | |
443 /* Output them. */ | |
444 fprintf (outfile, "\n\n"); | |
5604
32ac07bd58ef
Make the argument list output look more like the Lisp docstrings do.
Roland McGrath <roland@gnu.org>
parents:
5449
diff
changeset
|
445 write_c_args (outfile, buf, argbuf, minargs, maxargs); |
24 | 446 } |
447 } | |
448 } | |
449 eof: | |
450 fclose (infile); | |
451 return 0; | |
452 } | |
453 | |
454 /* Read a file of Lisp code, compiled or interpreted. | |
455 Looks for | |
456 (defun NAME ARGS DOCSTRING ...) | |
753 | 457 (defmacro NAME ARGS DOCSTRING ...) |
458 (autoload (quote NAME) FILE DOCSTRING ...) | |
24 | 459 (defvar NAME VALUE DOCSTRING) |
460 (defconst NAME VALUE DOCSTRING) | |
753 | 461 (fset (quote NAME) (make-byte-code ... DOCSTRING ...)) |
462 (fset (quote NAME) #[... DOCSTRING ...]) | |
2966
e936d56c2354
(scan_lisp_file): Recognize defalias like fset.
Richard M. Stallman <rms@gnu.org>
parents:
2814
diff
changeset
|
463 (defalias (quote NAME) #[... DOCSTRING ...]) |
24 | 464 starting in column zero. |
753 | 465 (quote NAME) may appear as 'NAME as well. |
466 For defun, defmacro, and autoload, we know how to skip over the arglist. | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3028
diff
changeset
|
467 For defvar, defconst, and fset we skip to the docstring with a kludgy |
753 | 468 formatting convention: all docstrings must appear on the same line as the |
469 initial open-paren (the one in column zero) and must contain a backslash | |
470 and a double-quote immediately after the initial double-quote. No newlines | |
471 must appear between the beginning of the form and the first double-quote. | |
472 The only source file that must follow this convention is loaddefs.el; aside | |
473 from that, it is always the .elc file that we look at, and they are no | |
474 problem because byte-compiler output follows this convention. | |
24 | 475 The NAME and DOCSTRING are output. |
476 NAME is preceded by `F' for a function or `V' for a variable. | |
477 An entry is output only if DOCSTRING has \ newline just after the opening " | |
478 */ | |
479 | |
753 | 480 void |
481 skip_white (infile) | |
482 FILE *infile; | |
483 { | |
484 char c = ' '; | |
485 while (c == ' ' || c == '\t' || c == '\n') | |
486 c = getc (infile); | |
487 ungetc (c, infile); | |
488 } | |
489 | |
490 void | |
491 read_lisp_symbol (infile, buffer) | |
492 FILE *infile; | |
493 char *buffer; | |
494 { | |
495 char c; | |
496 char *fillp = buffer; | |
497 | |
498 skip_white (infile); | |
499 while (1) | |
500 { | |
501 c = getc (infile); | |
502 if (c == '\\') | |
503 *(++fillp) = getc (infile); | |
504 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')') | |
505 { | |
506 ungetc (c, infile); | |
507 *fillp = 0; | |
508 break; | |
509 } | |
510 else | |
511 *fillp++ = c; | |
512 } | |
513 | |
514 if (! buffer[0]) | |
515 fprintf (stderr, "## expected a symbol, got '%c'\n", c); | |
516 | |
517 skip_white (infile); | |
518 } | |
519 | |
9491
dd3b83e4ceb0
Eliminate some -Wall warnings.
David J. MacKenzie <djm@gnu.org>
parents:
7564
diff
changeset
|
520 int |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
521 scan_lisp_file (filename, mode) |
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
522 char *filename, *mode; |
24 | 523 { |
524 FILE *infile; | |
525 register int c; | |
526 | |
5449
296db649863d
[MSDOS]: Use text/binary mode as appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
5317
diff
changeset
|
527 infile = fopen (filename, mode); |
24 | 528 if (infile == NULL) |
529 { | |
530 perror (filename); | |
531 return 0; /* No error */ | |
532 } | |
533 | |
534 c = '\n'; | |
535 while (!feof (infile)) | |
536 { | |
753 | 537 char buffer [BUFSIZ]; |
538 char type; | |
539 | |
24 | 540 if (c != '\n') |
541 { | |
542 c = getc (infile); | |
543 continue; | |
544 } | |
545 c = getc (infile); | |
546 if (c != '(') | |
547 continue; | |
164 | 548 |
753 | 549 read_lisp_symbol (infile, buffer); |
550 | |
551 if (! strcmp (buffer, "defun") || | |
552 ! strcmp (buffer, "defmacro")) | |
24 | 553 { |
753 | 554 type = 'F'; |
555 read_lisp_symbol (infile, buffer); | |
556 | |
557 /* Skip the arguments: either "nil" or a list in parens */ | |
24 | 558 |
559 c = getc (infile); | |
753 | 560 if (c == 'n') /* nil */ |
561 { | |
562 if ((c = getc (infile)) != 'i' || | |
563 (c = getc (infile)) != 'l') | |
564 { | |
565 fprintf (stderr, "## unparsable arglist in %s (%s)\n", | |
566 buffer, filename); | |
567 continue; | |
568 } | |
569 } | |
570 else if (c != '(') | |
571 { | |
572 fprintf (stderr, "## unparsable arglist in %s (%s)\n", | |
573 buffer, filename); | |
574 continue; | |
575 } | |
576 else | |
577 while (c != ')') | |
578 c = getc (infile); | |
579 skip_white (infile); | |
24 | 580 |
753 | 581 /* If the next three characters aren't `dquote bslash newline' |
582 then we're not reading a docstring. | |
583 */ | |
584 if ((c = getc (infile)) != '"' || | |
585 (c = getc (infile)) != '\\' || | |
586 (c = getc (infile)) != '\n') | |
24 | 587 { |
753 | 588 #ifdef DEBUG |
589 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
590 buffer, filename); | |
591 #endif | |
592 continue; | |
593 } | |
594 } | |
595 | |
596 else if (! strcmp (buffer, "defvar") || | |
597 ! strcmp (buffer, "defconst")) | |
598 { | |
599 char c1 = 0, c2 = 0; | |
600 type = 'V'; | |
601 read_lisp_symbol (infile, buffer); | |
602 | |
603 /* Skip until the first newline; remember the two previous chars. */ | |
604 while (c != '\n' && c >= 0) | |
605 { | |
606 c2 = c1; | |
607 c1 = c; | |
24 | 608 c = getc (infile); |
609 } | |
753 | 610 |
611 /* If two previous characters were " and \, | |
612 this is a doc string. Otherwise, there is none. */ | |
613 if (c2 != '"' || c1 != '\\') | |
614 { | |
615 #ifdef DEBUG | |
616 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
617 buffer, filename); | |
618 #endif | |
619 continue; | |
620 } | |
621 } | |
622 | |
2966
e936d56c2354
(scan_lisp_file): Recognize defalias like fset.
Richard M. Stallman <rms@gnu.org>
parents:
2814
diff
changeset
|
623 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias")) |
753 | 624 { |
625 char c1 = 0, c2 = 0; | |
626 type = 'F'; | |
627 | |
628 c = getc (infile); | |
629 if (c == '\'') | |
630 read_lisp_symbol (infile, buffer); | |
24 | 631 else |
632 { | |
633 if (c != '(') | |
753 | 634 { |
635 fprintf (stderr, "## unparsable name in fset in %s\n", | |
636 filename); | |
637 continue; | |
638 } | |
639 read_lisp_symbol (infile, buffer); | |
640 if (strcmp (buffer, "quote")) | |
641 { | |
642 fprintf (stderr, "## unparsable name in fset in %s\n", | |
643 filename); | |
644 continue; | |
645 } | |
646 read_lisp_symbol (infile, buffer); | |
24 | 647 c = getc (infile); |
753 | 648 if (c != ')') |
649 { | |
650 fprintf (stderr, | |
651 "## unparsable quoted name in fset in %s\n", | |
652 filename); | |
653 continue; | |
654 } | |
24 | 655 } |
164 | 656 |
753 | 657 /* Skip until the first newline; remember the two previous chars. */ |
658 while (c != '\n' && c >= 0) | |
24 | 659 { |
753 | 660 c2 = c1; |
661 c1 = c; | |
24 | 662 c = getc (infile); |
663 } | |
753 | 664 |
665 /* If two previous characters were " and \, | |
666 this is a doc string. Otherwise, there is none. */ | |
667 if (c2 != '"' || c1 != '\\') | |
24 | 668 { |
753 | 669 #ifdef DEBUG |
670 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
671 buffer, filename); | |
672 #endif | |
24 | 673 continue; |
674 } | |
675 } | |
753 | 676 |
677 else if (! strcmp (buffer, "autoload")) | |
164 | 678 { |
753 | 679 type = 'F'; |
164 | 680 c = getc (infile); |
753 | 681 if (c == '\'') |
682 read_lisp_symbol (infile, buffer); | |
683 else | |
684 { | |
685 if (c != '(') | |
686 { | |
687 fprintf (stderr, "## unparsable name in autoload in %s\n", | |
688 filename); | |
689 continue; | |
690 } | |
691 read_lisp_symbol (infile, buffer); | |
692 if (strcmp (buffer, "quote")) | |
693 { | |
694 fprintf (stderr, "## unparsable name in autoload in %s\n", | |
695 filename); | |
696 continue; | |
697 } | |
698 read_lisp_symbol (infile, buffer); | |
699 c = getc (infile); | |
700 if (c != ')') | |
701 { | |
702 fprintf (stderr, | |
703 "## unparsable quoted name in autoload in %s\n", | |
704 filename); | |
705 continue; | |
706 } | |
707 } | |
708 skip_white (infile); | |
709 if ((c = getc (infile)) != '\"') | |
710 { | |
711 fprintf (stderr, "## autoload of %s unparsable (%s)\n", | |
712 buffer, filename); | |
713 continue; | |
714 } | |
715 read_c_string (infile, 0); | |
716 skip_white (infile); | |
164 | 717 |
753 | 718 /* If the next three characters aren't `dquote bslash newline' |
719 then we're not reading a docstring. | |
720 */ | |
721 if ((c = getc (infile)) != '"' || | |
722 (c = getc (infile)) != '\\' || | |
723 (c = getc (infile)) != '\n') | |
724 { | |
725 #ifdef DEBUG | |
726 fprintf (stderr, "## non-docstring in %s (%s)\n", | |
727 buffer, filename); | |
728 #endif | |
729 continue; | |
730 } | |
164 | 731 } |
24 | 732 |
753 | 733 #ifdef DEBUG |
734 else if (! strcmp (buffer, "if") || | |
735 ! strcmp (buffer, "byte-code")) | |
736 ; | |
737 #endif | |
24 | 738 |
753 | 739 else |
740 { | |
741 #ifdef DEBUG | |
742 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n", | |
743 buffer, filename); | |
744 #endif | |
745 continue; | |
746 } | |
24 | 747 |
753 | 748 /* At this point, there is a docstring that we should gobble. |
749 The opening quote (and leading backslash-newline) have already | |
750 been read. | |
751 */ | |
24 | 752 putc (037, outfile); |
753 | 753 putc (type, outfile); |
754 fprintf (outfile, "%s\n", buffer); | |
24 | 755 read_c_string (infile, 1); |
756 } | |
757 fclose (infile); | |
758 return 0; | |
759 } |