annotate lib-src/make-docfile.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents a145efe76779
children 677f6a0ee643
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;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 el_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 elc_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 c_file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 } Current_file_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 static int scan_file (CONST char *filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static int read_c_string (FILE *, int, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 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
91 int maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 static int scan_c_file (CONST char *filename, CONST char *mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 static void skip_white (FILE *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 static void read_lisp_symbol (FILE *, char *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 static int scan_lisp_file (CONST char *filename, CONST char *mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
97 #define C_IDENTIFIER_CHAR_P(c) \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
98 (('A' <= c && c <= 'Z') || \
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 ('0' <= c && c <= '9') || \
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
101 (c == '_'))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
102
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 /* Name this program was invoked with. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 error (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 fprintf (stderr, "%s: ", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 fprintf (stderr, s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 fprintf (stderr, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 fatal (CONST char *s1, CONST char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 error (s1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 static long *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 xmalloc (unsigned int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 long *result = (long *) malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (result == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 fatal ("virtual memory exhausted", 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
136 static char *
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
137 next_extra_elc(char *extra_elcs)
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
138 {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
139 static FILE *fp = NULL;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
140 static char line_buf[BUFSIZ];
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
141 char *p = line_buf+1;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
142
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
143 if (!fp) {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
144 if (!extra_elcs) {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
145 return NULL;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
146 } else if (!(fp = fopen(extra_elcs, "r"))) {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
147 /* It is not an error if this file doesn't exist. */
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
148 /*fatal("error opening site package file list", 0);*/
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
149 return NULL;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
150 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
151 fgets(line_buf, BUFSIZ, fp);
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
152 }
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 again:
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
155 if (!fgets(line_buf, BUFSIZ, fp)) {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
156 fclose(fp);
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
157 fp = NULL;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
158 return NULL;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
159 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
160 line_buf[0] = '\0';
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
161 if (strlen(p) <= 2 || strlen(p) >= (BUFSIZ - 5)) {
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
162 /* reject too short or too long lines */
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
163 goto again;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
164 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
165 p[strlen(p) - 2] = '\0';
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
166 strcat(p, ".elc");
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
167
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
168 return p;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
169 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
170
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 main (int argc, char **argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 int err_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 int first_infile;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
178 char *extra_elcs = NULL;
0
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
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
381 fprintf (out, "(%s", func);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
382 #else
0
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 */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
389 fprintf (out, "arguments: (");
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
390 #endif
0
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 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
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.
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
438 Collapse adjacent spaces into one. */
0
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
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
442 /* If the C argument name ends with `_', change it to ' ',
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
443 to allow use of C reserved words or global symbols as Lisp args. */
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
444 if (c == '-' && ! C_IDENTIFIER_CHAR_P (p[1]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 in_ident = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 just_spaced = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 else if (c != ' ' || ! just_spaced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 if (c >= 'a' && c <= 'z')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 /* Upcase the letter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 c += 'A' - 'a';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 putc (c, out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 just_spaced = (c == ' ');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 need_space = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 putc ('\n', out); /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 /* Read through a c file. If a .o file is named,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 the corresponding .c file is read instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 scan_c_file (CONST char *filename, CONST char *mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 FILE *infile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 register int commas;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 register int defunflag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 register int defvarperbufferflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 register int defvarflag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 int minargs, maxargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 int l = strlen (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 char f[MAXPATHLEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 if (l > sizeof (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 #ifdef ENAMETOOLONG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 errno = ENAMETOOLONG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 errno = EINVAL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 strcpy (f, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 if (f[l - 1] == 'o')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 f[l - 1] = 'c';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 infile = fopen (f, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 /* No error if non-ex input file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 if (infile == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 perror (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 c = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 while (!feof (infile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 if (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 if (c == ' ')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 while (c == ' ')
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 != 'D')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (c != 'E')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 if (c != 'F')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 if (c != 'V')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 if (c != 'A')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 if (c != 'R')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 if (c != '_')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 defvarflag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 defunflag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 /* Note that this business doesn't apply under XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 DEFVAR_BUFFER_LOCAL in XEmacs behaves normally. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 defvarperbufferflag = (c == 'P');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 else if (c == 'D')
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 if (c != 'E')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 if (c != 'F')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 c = getc (infile);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
558 defunflag = (c == 'U');
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 defvarflag = 0;
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
560 c = getc (infile);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 else continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 while (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 if (c != '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 c = read_c_string (infile, -1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 if (defunflag)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
577 commas = 4;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 else if (defvarperbufferflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 commas = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 else if (defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 commas = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 else /* For DEFSIMPLE and DEFPRED */
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 while (commas)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 if (c == ',')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 commas--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 if (defunflag && (commas == 1 || commas == 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 c = getc (infile);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
594 while (c == ' ' || c == '\n' || c == '\t')
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
595 ;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 if (commas == 2) /* pick up minargs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 fscanf (infile, "%d", &minargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 else /* pick up maxargs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 maxargs = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 fscanf (infile, "%d", &maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 while (c == ' ' || c == '\n' || c == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 if (c == '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 c = read_c_string (infile, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 if (defunflag | defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 while (c != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 while (c == '*')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 while (c != ',')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 c = getc (infile);
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 == ' ' || c == '\n' || c == '\t')
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 if (defunflag | defvarflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 if (defunflag || defvarflag || c == '"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 putc (037, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 putc (defvarflag ? 'V' : 'F', outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 fprintf (outfile, "%s\n", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 c = read_c_string (infile, 1, (defunflag || defvarflag));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 /* If this is a defun, find the arguments and print them. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 this function takes MANY or UNEVALLED args, then the C source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 won't give the names of the arguments, so we shouldn't bother
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 trying to find them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 if (defunflag && maxargs != -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 char argbuf[1024], *p = argbuf;
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
649 #if 0 /* For old DEFUN's only */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 while (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 }
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
656 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 /* Skip into arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 while (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 if (c < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 goto eof;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 /* Copy arguments into ARGBUF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 *p++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 *p++ = c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 while (c != ')');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 *p = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 /* Output them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 fprintf (outfile, "\n\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 write_c_args (outfile, buf, argbuf, minargs, maxargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 eof:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 fclose (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 /* Read a file of Lisp code, compiled or interpreted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 Looks for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (defun NAME ARGS DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (defmacro NAME ARGS DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (autoload (quote NAME) FILE DOCSTRING ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (defvar NAME VALUE DOCSTRING)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (defconst NAME VALUE DOCSTRING)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (fset (quote NAME) #[... DOCSTRING ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (defalias (quote NAME) #[... DOCSTRING ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 starting in column zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (quote NAME) may appear as 'NAME as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 When we find that, we save it for the following defining-form,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 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
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 For defun, defmacro, and autoload, we know how to skip over the arglist.
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
699 For defvar, defconst, and fset we skip to the docstring with a kludgy
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 formatting convention: all docstrings must appear on the same line as the
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
701 initial open-paren (the one in column zero) and must contain a backslash
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 and a double-quote immediately after the initial double-quote. No newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 must appear between the beginning of the form and the first double-quote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 The only source file that must follow this convention is loaddefs.el; aside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 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
706 problem because byte-compiler output follows this convention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 The NAME and DOCSTRING are output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 NAME is preceded by `F' for a function or `V' for a variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 An entry is output only if DOCSTRING has \ newline just after the opening "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 skip_white (FILE *infile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 char c = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 while (c == ' ' || c == '\t' || c == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 read_lisp_symbol (FILE *infile, char *buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 char c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 char *fillp = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 if (c == '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 /* FSF has *(++fillp), which is wrong. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 *fillp++ = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 else if (c == ' ' || c == '\t' || c == '\n' || c == '(' || c == ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ungetc (c, infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 *fillp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 *fillp++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 if (! buffer[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
746
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 scan_lisp_file (CONST char *filename, CONST char *mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 FILE *infile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 register int c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 char *saved_string = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 infile = fopen (filename, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 if (infile == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 perror (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 return 0; /* No error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 c = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 while (!feof (infile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 char buffer[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 char type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 if (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 /* Detect a dynamic doc string and save it for the next expression. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 if (c == '#')
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 if (c == '@')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 int length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 /* Read the length. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 while ((c = getc (infile),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 c >= '0' && c <= '9'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 length *= 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 length += c - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 /* The next character is a space that is counted in the length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 but not part of the doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 We already read it, so just ignore it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 length--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 /* Read in the contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 if (saved_string != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 free (saved_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 saved_string = (char *) xmalloc (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 for (i = 0; i < length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 saved_string[i] = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 /* The last character is a ^_.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 That is needed in the .elc file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 but it is redundant in DOC. So get rid of it here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 saved_string[length - 1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 /* Skip the newline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 while (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 if (c != '(')
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 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 if (! strcmp (buffer, "defun") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ! strcmp (buffer, "defmacro"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 /* Skip the arguments: either "nil" or a list in parens */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 if (c == 'n') /* nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 if ((c = getc (infile)) != 'i' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (c = getc (infile)) != 'l')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 else if (c != '(')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 while (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 /* If the next three characters aren't `dquote bslash newline'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 then we're not reading a docstring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 if ((c = getc (infile)) != '"' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (c = getc (infile)) != '\\' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (c = getc (infile)) != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 else if (! strcmp (buffer, "defvar") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 ! strcmp (buffer, "defconst"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 char c1 = 0, c2 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 type = 'V';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 /* Skip until the first newline; remember the two previous chars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 while (c != '\n' && c >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 {
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
879 /* ### Kludge -- Ignore any ESC x x ISO2022 sequences */
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
880 if (c == 27)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
881 {
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
882 getc (infile);
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
883 getc (infile);
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
884 goto nextchar;
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
885 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
886
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 c2 = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 c1 = c;
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
889 nextchar:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
892
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 /* If two previous characters were " and \,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 this is a doc string. Otherwise, there is none. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 if (c2 != '"' || c1 != '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 char c1 = 0, c2 = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 if (c == '\'')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 {
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 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 fprintf (stderr, "## unparsable name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 if (strcmp (buffer, "quote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 fprintf (stderr, "## unparsable name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 if (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 "## unparsable quoted name in fset in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 /* Skip until the first newline; remember the two previous chars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 while (c != '\n' && c >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 c2 = c1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 c1 = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 102
diff changeset
949
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 /* If two previous characters were " and \,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 this is a doc string. Otherwise, there is none. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 if (c2 != '"' || c1 != '\\')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 else if (! strcmp (buffer, "autoload"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 type = 'F';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 if (c == '\'')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 {
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 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 fprintf (stderr, "## unparsable name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 if (strcmp (buffer, "quote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 fprintf (stderr, "## unparsable name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 read_lisp_symbol (infile, buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 c = getc (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 if (c != ')')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 "## unparsable quoted name in autoload in %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 if ((c = getc (infile)) != '\"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 read_c_string (infile, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 skip_white (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 if (saved_string == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 /* If the next three characters aren't `dquote bslash newline'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 then we're not reading a docstring. */
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
1008 if ((c = getc (infile)) != '"' ||
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (c = getc (infile)) != '\\' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (c = getc (infile)) != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 fprintf (stderr, "## non-docstring in %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
1021 #if 0 /* causes crash */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 else if (! strcmp (buffer, "if") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ! strcmp (buffer, "byte-code"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 #ifdef DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 buffer, filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 /* At this point, we should either use the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 dynamic doc string in saved_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 or gobble a doc string from the input file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 In the latter case, the opening quote (and leading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 backslash-newline) have already been read. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 putc ('\n', outfile); /* XEmacs addition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 putc (037, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 putc (type, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 fprintf (outfile, "%s\n", buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 if (saved_string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 fputs (saved_string, outfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 /* Don't use one dynamic doc string twice. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 free (saved_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 saved_string = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 read_c_string (infile, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 fclose (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 }