annotate lib-src/make-docfile.c @ 102:a145efe76779 r20-1b3

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