annotate lib-src/make-docfile.c @ 20:859a2309aef8 r19-15b93

Import from CVS: tag r19-15b93
author cvs
date Mon, 13 Aug 2007 08:50:05 +0200
parents 376386a54a3c
children 441bb1e64a06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Generate doc-string file for XEmacs from source files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Board of Trustees, University of Illinois
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* The arguments given to this program are all the C and Lisp source files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 of XEmacs. .elc and .el and .c files are allowed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 A .o file can also be specified; the .c file it was made from is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 This helps the makefile pass the correct list of files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 The results, which go to standard output or to a file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 specified with -a or -o (-a to append, -o to start from nothing),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 are entries containing function or variable names and their documentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 Each entry starts with a ^_ character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 Then comes F for a function or V for a variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Then comes the function or variable name, terminated with a newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 Then comes the documentation for that function or variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #define NO_SHORTNAMES /* Tell config not to load remap.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #if __STDC__ || defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include <ctype.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <sys/param.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <direct.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #define READ_TEXT "rt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #define READ_BINARY "rb"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #else /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #define READ_TEXT "r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #define READ_BINARY "r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #endif /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 file where that function is defined. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #undef chdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 /* Stdio stream for output to the DOC file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 static FILE *outfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 el_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 elc_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 c_file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 } Current_file_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 static int scan_file (CONST char *filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 static int read_c_string (FILE *, int, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 static void write_c_args (FILE *out, CONST char *func, char *buf, int minargs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 int maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static int scan_c_file (CONST char *filename, CONST char *mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 static void skip_white (FILE *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 static void read_lisp_symbol (FILE *, char *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 static int scan_lisp_file (CONST char *filename, CONST char *mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
94 #define C_IDENTIFIER_CHAR_P(c) \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
95 (('A' <= c && c <= 'Z') || \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
96 ('a' <= c && c <= 'z') || \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
97 ('0' <= c && c <= '9') || \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
98 (c == '_'))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
99
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 /* Name this program was invoked with. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 error (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 fprintf (stderr, "%s: ", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 fprintf (stderr, s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 fatal (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 error (s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 static long *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 xmalloc (unsigned int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 long *result = (long *) malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 if (result == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 fatal ("virtual memory exhausted", 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 main (int argc, char **argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 int err_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 int first_infile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 progname = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 outfile = stdout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 /* Don't put CRs in the DOC file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 _fmode = O_BINARY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 #if 0 /* Suspicion is that this causes hanging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 So instead we require people to use -o on MSDOS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (stdout)->_flag &= ~_IOTEXT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 _setmode (fileno (stdout), O_BINARY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 outfile = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 _fmode = O_BINARY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 _setmode (fileno (stdout), O_BINARY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 /* If first two args are -o FILE, output to FILE. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 i = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (argc > i + 1 && !strcmp (argv[i], "-o"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 outfile = fopen (argv[i + 1], "w");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 i += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 if (argc > i + 1 && !strcmp (argv[i], "-a"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 outfile = fopen (argv[i + 1], "a");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 i += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 if (argc > i + 1 && !strcmp (argv[i], "-d"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 chdir (argv[i + 1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 i += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 if (outfile == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 fatal ("No output file specified", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 first_infile = i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 for (; i < argc; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 int j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 /* Don't process one file twice. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 for (j = first_infile; j < i; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 if (! strcmp (argv[i], argv[j]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 if (j == i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 /* err_count seems to be {mis,un}used */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 err_count += scan_file (argv[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 putc ('\n', outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 exit (err_count > 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 return err_count > 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 /* Read file FILENAME and output its doc strings to outfile. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 /* Return 1 if file is not found, 0 if it is found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 scan_file (CONST char *filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 int len = strlen (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (len > 4 && !strcmp (filename + len - 4, ".elc"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 Current_file_type = elc_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 return scan_lisp_file (filename, READ_BINARY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 else if (len > 3 && !strcmp (filename + len - 3, ".el"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Current_file_type = el_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 return scan_lisp_file (filename, READ_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 Current_file_type = c_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 return scan_c_file (filename, READ_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 char buf[128];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 /* Skip a C string from INFILE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 and return the character that follows the closing ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 If printflag is positive, output string contents to outfile.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 If it is negative, store contents in buf.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 Convert escape sequences \n and \t to newline and tab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 discard \ followed by newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 read_c_string (FILE *infile, int printflag, int c_docstring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 char *p = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 int start = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 while (c != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 while ((c_docstring || c != '"') && c != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 if (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 if (c == '*')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 int cc = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (cc == '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ungetc (cc, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 if (start != -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 if (printflag > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 putc ('\n', outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 else if (printflag < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 *p++ = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 if (c == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 if (c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 start = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (!c_docstring && c == 'n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 c = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 if (c == 't')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 c = '\t';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 if (c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 start = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 start = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if (printflag > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 putc (c, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 else if (printflag < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 *p++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 /* look for continuation of string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 if (Current_file_type == c_file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 while (isspace (c = getc (infile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (c != '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 if (c != '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 /* If we had a "", concatenate the two strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 if (printflag < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 *p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 return c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 write_c_args (FILE *out, CONST char *func, char *buff, int minargs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 int maxargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 register char *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 int in_ident = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 int just_spaced = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 int need_space = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 fprintf (out, "(%s", func);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 /* XEmacs - "arguments:" is for parsing the docstring. FSF's help system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 doesn't parse the docstring for arguments like we do, so we're also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 going to omit the function name to preserve compatibility with elisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 that parses the docstring. Finally, not prefixing the arglist with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 anything is asking for trouble because it's not uncommon to have an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 unescaped parenthesis at the beginning of a line. --Stig */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 fprintf (out, "arguments: (");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (*buff == '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ++buff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 for (p = buff; *p; p++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 char c = *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 int ident_start = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
347 /* Add support for ANSI prototypes. Hop over
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
348 "Lisp_Object" string (the only C type allowed in DEFUNs) */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
349 static char lo[] = "Lisp_Object";
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
350 if ((C_IDENTIFIER_CHAR_P (c) != in_ident) && !in_ident &&
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
351 (strncmp (p, lo, sizeof (lo) - 1) == 0) &&
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
352 isspace(*(p + sizeof (lo) - 1)))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
353 {
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
354 p += (sizeof (lo) - 1);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
355 while (isspace (*p))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
356 p++;
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
357 c = *p;
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
358 }
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
359
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 /* Notice when we start printing a new identifier. */
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
361 if (C_IDENTIFIER_CHAR_P (c) != in_ident)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 if (!in_ident)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 in_ident = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ident_start = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /* XEmacs - This goes along with the change above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 if (need_space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 putc (' ', out);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
371 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 if (minargs == 0 && maxargs > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 fprintf (out, "&optional ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 just_spaced = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 minargs--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 maxargs--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 in_ident = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* Print the C argument list as it would appear in lisp:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 print underscores as hyphens, and print commas as spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 Collapse adjacent spaces into one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (c == '_') c = '-';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 if (c == ',') c = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 /* In C code, `default' is a reserved word, so we spell it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 `defalt'; unmangle that here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (ident_start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 && strncmp (p, "defalt", 6) == 0
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
393 && ! C_IDENTIFIER_CHAR_P (p[6]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 fprintf (out, "DEFAULT");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 p += 5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 in_ident = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 just_spaced = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 else if (c != ' ' || ! just_spaced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 if (c >= 'a' && c <= 'z')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 /* Upcase the letter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 c += 'A' - 'a';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 putc (c, out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 just_spaced = (c == ' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 need_space = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 putc ('\n', out); /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 /* Read through a c file. If a .o file is named,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 the corresponding .c file is read instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 scan_c_file (CONST char *filename, CONST char *mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 FILE *infile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 register int commas;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 register int defunflag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 register int defvarperbufferflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 register int defvarflag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 int minargs, maxargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 int l = strlen (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 char f[MAXPATHLEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 if (l > sizeof (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 #ifdef ENAMETOOLONG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 errno = ENAMETOOLONG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 errno = EINVAL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 strcpy (f, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 if (f[l - 1] == 'o')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 f[l - 1] = 'c';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 infile = fopen (f, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 /* No error if non-ex input file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 if (infile == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 perror (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 c = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 while (!feof (infile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 if (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 if (c == ' ')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 while (c == ' ')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if (c != 'D')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 if (c != 'E')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 if (c != 'F')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 if (c != 'V')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 if (c != 'A')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 if (c != 'R')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 if (c != '_')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 defvarflag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 defunflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 /* Note that this business doesn't apply under XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 DEFVAR_BUFFER_LOCAL in XEmacs behaves normally. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 defvarperbufferflag = (c == 'P');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 else if (c == 'D')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 if (c != 'E')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 if (c != 'F')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 c = getc (infile);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
509 defunflag = (c == 'U');
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 defvarflag = 0;
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
511 c = getc (infile);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 else continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 while (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (c != '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 c = read_c_string (infile, -1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 if (defunflag)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
528 commas = 4;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 else if (defvarperbufferflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 commas = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 else if (defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 commas = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 else /* For DEFSIMPLE and DEFPRED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 commas = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 while (commas)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 if (c == ',')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 commas--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 if (defunflag && (commas == 1 || commas == 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 c = getc (infile);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
545 while (c == ' ' || c == '\n' || c == '\t')
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
546 ;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 if (commas == 2) /* pick up minargs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 fscanf (infile, "%d", &minargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 else /* pick up maxargs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 maxargs = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 fscanf (infile, "%d", &maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 while (c == ' ' || c == '\n' || c == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 if (c == '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 c = read_c_string (infile, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 if (defunflag | defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 while (c != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 while (c == '*')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 while (c != ',')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 while (c == ' ' || c == '\n' || c == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 if (defunflag | defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 if (defunflag || defvarflag || c == '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 putc (037, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 putc (defvarflag ? 'V' : 'F', outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 fprintf (outfile, "%s\n", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 c = read_c_string (infile, 1, (defunflag || defvarflag));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 /* If this is a defun, find the arguments and print them. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 this function takes MANY or UNEVALLED args, then the C source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 won't give the names of the arguments, so we shouldn't bother
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 trying to find them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 if (defunflag && maxargs != -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 char argbuf[1024], *p = argbuf;
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
600 #if 0 /* For old DEFUN's only */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 while (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
607 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 /* Skip into arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 while (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 /* Copy arguments into ARGBUF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 *p++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 *p++ = c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 while (c != ')');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 *p = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 /* Output them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 fprintf (outfile, "\n\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 write_c_args (outfile, buf, argbuf, minargs, maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 eof:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 fclose (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 /* Read a file of Lisp code, compiled or interpreted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 Looks for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (defun NAME ARGS DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (defmacro NAME ARGS DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (autoload (quote NAME) FILE DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (defvar NAME VALUE DOCSTRING)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (defconst NAME VALUE DOCSTRING)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (fset (quote NAME) #[... DOCSTRING ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (defalias (quote NAME) #[... DOCSTRING ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 starting in column zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (quote NAME) may appear as 'NAME as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 When we find that, we save it for the following defining-form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 and we use that instead of reading a doc string within that defining-form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 For defun, defmacro, and autoload, we know how to skip over the arglist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 For defvar, defconst, and fset we skip to the docstring with a kludgy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 formatting convention: all docstrings must appear on the same line as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 initial open-paren (the one in column zero) and must contain a backslash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 and a double-quote immediately after the initial double-quote. No newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 must appear between the beginning of the form and the first double-quote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 The only source file that must follow this convention is loaddefs.el; aside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 from that, it is always the .elc file that we look at, and they are no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 problem because byte-compiler output follows this convention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 The NAME and DOCSTRING are output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 NAME is preceded by `F' for a function or `V' for a variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 An entry is output only if DOCSTRING has \ newline just after the opening "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 skip_white (FILE *infile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 char c = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 while (c == ' ' || c == '\t' || c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 read_lisp_symbol (FILE *infile, char *buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 char c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 char *fillp = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 if (c == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 /* FSF has *(++fillp), which is wrong. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 *fillp++ = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 *fillp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 *fillp++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 if (! buffer[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 scan_lisp_file (CONST char *filename, CONST char *mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 FILE *infile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 char *saved_string = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 infile = fopen (filename, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 if (infile == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 perror (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 return 0; /* No error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 c = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 while (!feof (infile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 char buffer[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 char type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 if (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 /* Detect a dynamic doc string and save it for the next expression. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 if (c == '#')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 if (c == '@')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 int length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 /* Read the length. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 while ((c = getc (infile),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 c >= '0' && c <= '9'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 length *= 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 length += c - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 /* The next character is a space that is counted in the length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 but not part of the doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 We already read it, so just ignore it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 length--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 /* Read in the contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 if (saved_string != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 free (saved_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 saved_string = (char *) xmalloc (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 for (i = 0; i < length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 saved_string[i] = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 /* The last character is a ^_.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 That is needed in the .elc file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 but it is redundant in DOC. So get rid of it here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 saved_string[length - 1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 /* Skip the newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 while (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 if (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 if (! strcmp (buffer, "defun") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ! strcmp (buffer, "defmacro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 /* Skip the arguments: either "nil" or a list in parens */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 if (c == 'n') /* nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 if ((c = getc (infile)) != 'i' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (c = getc (infile)) != 'l')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 else if (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 while (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 /* If the next three characters aren't `dquote bslash newline'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 then we're not reading a docstring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 if ((c = getc (infile)) != '"' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (c = getc (infile)) != '\\' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (c = getc (infile)) != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 else if (! strcmp (buffer, "defvar") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ! strcmp (buffer, "defconst"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 char c1 = 0, c2 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 type = 'V';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 /* Skip until the first newline; remember the two previous chars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 while (c != '\n' && c >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
830 /* ### Kludge -- Ignore any ESC x x ISO2022 sequences */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
831 if (c == 27)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
832 {
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
833 getc (infile);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
834 getc (infile);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
835 goto nextchar;
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
836 }
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
837
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 c2 = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 c1 = c;
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
840 nextchar:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 /* If two previous characters were " and \,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 this is a doc string. Otherwise, there is none. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 if (c2 != '"' || c1 != '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 char c1 = 0, c2 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 if (c == '\'')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 if (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 fprintf (stderr, "## unparsable name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 if (strcmp (buffer, "quote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 fprintf (stderr, "## unparsable name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 if (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 "## unparsable quoted name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 /* Skip until the first newline; remember the two previous chars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 while (c != '\n' && c >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 c2 = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 c1 = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 /* If two previous characters were " and \,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 this is a doc string. Otherwise, there is none. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 if (c2 != '"' || c1 != '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 else if (! strcmp (buffer, "autoload"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 if (c == '\'')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 if (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 fprintf (stderr, "## unparsable name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 if (strcmp (buffer, "quote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 fprintf (stderr, "## unparsable name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 if (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 "## unparsable quoted name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 if ((c = getc (infile)) != '\"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 read_c_string (infile, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 /* If the next three characters aren't `dquote bslash newline'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 then we're not reading a docstring. */
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
959 if ((c = getc (infile)) != '"' ||
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (c = getc (infile)) != '\\' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (c = getc (infile)) != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
972 #if 0 /* causes crash */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 else if (! strcmp (buffer, "if") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ! strcmp (buffer, "byte-code"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 /* At this point, we should either use the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 dynamic doc string in saved_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 or gobble a doc string from the input file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 In the latter case, the opening quote (and leading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 backslash-newline) have already been read. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 putc ('\n', outfile); /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 putc (037, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 putc (type, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 fprintf (outfile, "%s\n", buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 if (saved_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 fputs (saved_string, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 /* Don't use one dynamic doc string twice. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 free (saved_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 saved_string = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 read_c_string (infile, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 fclose (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 }