* textmodes/picture.el (picture-mouse-set-point): New command.
[emacs.git] / lib-src / make-docfile.c
bloba4828d53361f0fc89a79d258d6aa1c75addd0f5f
1 /* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985, 86, 92, 93, 94, 97, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* The arguments given to this program are all the C and Lisp source files
23 of GNU Emacs. .elc and .el and .c files are allowed.
24 A .o file can also be specified; the .c file it was made from is used.
25 This helps the makefile pass the correct list of files.
27 The results, which go to standard output or to a file
28 specified with -a or -o (-a to append, -o to start from nothing),
29 are entries containing function or variable names and their documentation.
30 Each entry starts with a ^_ character.
31 Then comes F for a function or V for a variable.
32 Then comes the function or variable name, terminated with a newline.
33 Then comes the documentation for that function or variable.
36 #define NO_SHORTNAMES /* Tell config not to load remap.h */
37 #include <config.h>
39 /* defined to be emacs_main, sys_fopen, etc. in config.h */
40 #undef main
41 #undef fopen
42 #undef chdir
44 #include <stdio.h>
45 #ifdef MSDOS
46 #include <fcntl.h>
47 #endif /* MSDOS */
48 #ifdef WINDOWSNT
49 #include <stdlib.h>
50 #include <fcntl.h>
51 #include <direct.h>
52 #endif /* WINDOWSNT */
54 #ifdef DOS_NT
55 #define READ_TEXT "rt"
56 #define READ_BINARY "rb"
57 #else /* not DOS_NT */
58 #define READ_TEXT "r"
59 #define READ_BINARY "r"
60 #endif /* not DOS_NT */
62 int scan_file ();
63 int scan_lisp_file ();
64 int scan_c_file ();
66 #ifdef MSDOS
67 /* s/msdos.h defines this as sys_chdir, but we're not linking with the
68 file where that function is defined. */
69 #undef chdir
70 #endif
72 #ifdef HAVE_UNISTD_H
73 #include <unistd.h>
74 #endif
76 /* Stdio stream for output to the DOC file. */
77 FILE *outfile;
79 /* Name this program was invoked with. */
80 char *progname;
82 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
84 /* VARARGS1 */
85 void
86 error (s1, s2)
87 char *s1, *s2;
89 fprintf (stderr, "%s: ", progname);
90 fprintf (stderr, s1, s2);
91 fprintf (stderr, "\n");
94 /* Print error message and exit. */
96 /* VARARGS1 */
97 void
98 fatal (s1, s2)
99 char *s1, *s2;
101 error (s1, s2);
102 exit (1);
105 /* Like malloc but get fatal error if memory is exhausted. */
107 long *
108 xmalloc (size)
109 unsigned int size;
111 long *result = (long *) malloc (size);
112 if (result == NULL)
113 fatal ("virtual memory exhausted", 0);
114 return result;
118 main (argc, argv)
119 int argc;
120 char **argv;
122 int i;
123 int err_count = 0;
124 int first_infile;
126 progname = argv[0];
128 outfile = stdout;
130 /* Don't put CRs in the DOC file. */
131 #ifdef MSDOS
132 _fmode = O_BINARY;
133 #if 0 /* Suspicion is that this causes hanging.
134 So instead we require people to use -o on MSDOS. */
135 (stdout)->_flag &= ~_IOTEXT;
136 _setmode (fileno (stdout), O_BINARY);
137 #endif
138 outfile = 0;
139 #endif /* MSDOS */
140 #ifdef WINDOWSNT
141 _fmode = O_BINARY;
142 _setmode (fileno (stdout), O_BINARY);
143 #endif /* WINDOWSNT */
145 /* If first two args are -o FILE, output to FILE. */
146 i = 1;
147 if (argc > i + 1 && !strcmp (argv[i], "-o"))
149 outfile = fopen (argv[i + 1], "w");
150 i += 2;
152 if (argc > i + 1 && !strcmp (argv[i], "-a"))
154 outfile = fopen (argv[i + 1], "a");
155 i += 2;
157 if (argc > i + 1 && !strcmp (argv[i], "-d"))
159 chdir (argv[i + 1]);
160 i += 2;
163 if (outfile == 0)
164 fatal ("No output file specified", "");
166 first_infile = i;
167 for (; i < argc; i++)
169 int j;
170 /* Don't process one file twice. */
171 for (j = first_infile; j < i; j++)
172 if (! strcmp (argv[i], argv[j]))
173 break;
174 if (j == i)
175 err_count += scan_file (argv[i]);
177 #ifndef VMS
178 exit (err_count > 0);
179 #endif /* VMS */
180 return err_count > 0;
183 /* Read file FILENAME and output its doc strings to outfile. */
184 /* Return 1 if file is not found, 0 if it is found. */
187 scan_file (filename)
188 char *filename;
190 int len = strlen (filename);
191 if (len > 4 && !strcmp (filename + len - 4, ".elc"))
192 return scan_lisp_file (filename, READ_BINARY);
193 else if (len > 3 && !strcmp (filename + len - 3, ".el"))
194 return scan_lisp_file (filename, READ_TEXT);
195 else
196 return scan_c_file (filename, READ_TEXT);
199 char buf[128];
201 /* Some state during the execution of `read_c_string_or_comment'. */
202 struct rcsoc_state
204 /* A count of spaces and newlines that have been read, but not output. */
205 unsigned pending_spaces, pending_newlines;
207 /* Where we're reading from. */
208 FILE *in_file;
210 /* If non-zero, a buffer into which to copy characters. */
211 char *buf_ptr;
212 /* If non-zero, a file into which to copy characters. */
213 FILE *out_file;
215 /* A keyword we look for at the beginning of lines. If found, it is
216 not copied, and SAW_KEYWORD is set to true. */
217 char *keyword;
218 /* The current point we've reached in an occurance of KEYWORD in
219 the input stream. */
220 char *cur_keyword_ptr;
221 /* Set to true if we saw an occurance of KEYWORD. */
222 int saw_keyword;
225 /* Output CH to the file or buffer in STATE. Any pending newlines or
226 spaces are output first. */
228 static INLINE void
229 put_char (ch, state)
230 int ch;
231 struct rcsoc_state *state;
233 int out_ch;
236 if (state->pending_newlines > 0)
238 state->pending_newlines--;
239 out_ch = '\n';
241 else if (state->pending_spaces > 0)
243 state->pending_spaces--;
244 out_ch = ' ';
246 else
247 out_ch = ch;
249 if (state->out_file)
250 putc (out_ch, state->out_file);
251 if (state->buf_ptr)
252 *state->buf_ptr++ = out_ch;
254 while (out_ch != ch);
257 /* If in the middle of scanning a keyword, continue scanning with
258 character CH, otherwise output CH to the file or buffer in STATE.
259 Any pending newlines or spaces are output first, as well as any
260 previously scanned characters that were thought to be part of a
261 keyword, but were in fact not. */
263 static void
264 scan_keyword_or_put_char (ch, state)
265 int ch;
266 struct rcsoc_state *state;
268 if (state->keyword
269 && *state->cur_keyword_ptr == ch
270 && (state->cur_keyword_ptr > state->keyword
271 || state->pending_newlines > 0))
272 /* We might be looking at STATE->keyword at some point.
273 Keep looking until we know for sure. */
275 if (*++state->cur_keyword_ptr == '\0')
276 /* Saw the whole keyword. Set SAW_KEYWORD flag to true. */
278 state->saw_keyword = 1;
280 /* Reset the scanning pointer. */
281 state->cur_keyword_ptr = state->keyword;
283 /* Canonicalize whitespace preceding a usage string. */
284 state->pending_newlines = 2;
285 state->pending_spaces = 0;
287 /* Skip any whitespace between the keyword and the
288 usage string. */
290 ch = getc (state->in_file);
291 while (ch == ' ' || ch == '\n');
293 /* Output the open-paren we just read. */
294 put_char (ch, state);
296 /* Skip the function name and replace it with `fn'. */
298 ch = getc (state->in_file);
299 while (ch != ' ' && ch != ')');
300 put_char ('f', state);
301 put_char ('n', state);
303 /* Put back the last character. */
304 ungetc (ch, state->in_file);
307 else
309 if (state->keyword && state->cur_keyword_ptr > state->keyword)
310 /* We scanned the beginning of a potential usage
311 keyword, but it was a false alarm. Output the
312 part we scanned. */
314 char *p;
316 for (p = state->keyword; p < state->cur_keyword_ptr; p++)
317 put_char (*p, state);
319 state->cur_keyword_ptr = state->keyword;
322 put_char (ch, state);
327 /* Skip a C string or C-style comment from INFILE, and return the
328 character that follows. COMMENT non-zero means skip a comment. If
329 PRINTFLAG is positive, output string contents to outfile. If it is
330 negative, store contents in buf. Convert escape sequences \n and
331 \t to newline and tab; discard \ followed by newline.
332 If SAW_USAGE is non-zero, then any occurances of the string `usage:'
333 at the beginning of a line will be removed, and *SAW_USAGE set to
334 true if any were encountered. */
337 read_c_string_or_comment (infile, printflag, comment, saw_usage)
338 FILE *infile;
339 int printflag;
340 int *saw_usage;
342 register int c;
343 struct rcsoc_state state;
345 state.in_file = infile;
346 state.buf_ptr = (printflag < 0 ? buf : 0);
347 state.out_file = (printflag > 0 ? outfile : 0);
348 state.pending_spaces = 0;
349 state.pending_newlines = 0;
350 state.keyword = (saw_usage ? "usage:" : 0);
351 state.cur_keyword_ptr = state.keyword;
352 state.saw_keyword = 0;
354 c = getc (infile);
355 if (comment)
356 while (c == '\n' || c == '\r' || c == '\t' || c == ' ')
357 c = getc (infile);
359 while (c != EOF)
361 while (c != EOF && (comment ? c != '*' : c != '"'))
363 if (c == '\\')
365 c = getc (infile);
366 if (c == '\n' || c == '\r')
368 c = getc (infile);
369 continue;
371 if (c == 'n')
372 c = '\n';
373 if (c == 't')
374 c = '\t';
377 if (c == ' ')
378 state.pending_spaces++;
379 else if (c == '\n')
381 state.pending_newlines++;
382 state.pending_spaces = 0;
384 else
385 scan_keyword_or_put_char (c, &state);
387 c = getc (infile);
390 if (c != EOF)
391 c = getc (infile);
393 if (comment)
395 if (c == '/')
397 c = getc (infile);
398 break;
401 scan_keyword_or_put_char ('*', &state);
403 else
405 if (c != '"')
406 break;
408 /* If we had a "", concatenate the two strings. */
409 c = getc (infile);
413 if (printflag < 0)
414 *state.buf_ptr = 0;
416 if (saw_usage)
417 *saw_usage = state.saw_keyword;
419 return c;
424 /* Write to file OUT the argument names of function FUNC, whose text is in BUF.
425 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
427 void
428 write_c_args (out, func, buf, minargs, maxargs)
429 FILE *out;
430 char *func, *buf;
431 int minargs, maxargs;
433 register char *p;
434 int in_ident = 0;
435 int just_spaced = 0;
436 int need_space = 1;
438 fprintf (out, "(fn");
440 if (*buf == '(')
441 ++buf;
443 for (p = buf; *p; p++)
445 char c = *p;
446 int ident_start = 0;
448 /* Notice when we start printing a new identifier. */
449 if ((('A' <= c && c <= 'Z')
450 || ('a' <= c && c <= 'z')
451 || ('0' <= c && c <= '9')
452 || c == '_')
453 != in_ident)
455 if (!in_ident)
457 in_ident = 1;
458 ident_start = 1;
460 if (need_space)
461 putc (' ', out);
463 if (minargs == 0 && maxargs > 0)
464 fprintf (out, "&optional ");
465 just_spaced = 1;
467 minargs--;
468 maxargs--;
470 else
471 in_ident = 0;
474 /* Print the C argument list as it would appear in lisp:
475 print underscores as hyphens, and print commas and newlines
476 as spaces. Collapse adjacent spaces into one. */
477 if (c == '_')
478 c = '-';
479 else if (c == ',' || c == '\n')
480 c = ' ';
482 /* In C code, `default' is a reserved word, so we spell it
483 `defalt'; unmangle that here. */
484 if (ident_start
485 && strncmp (p, "defalt", 6) == 0
486 && ! (('A' <= p[6] && p[6] <= 'Z')
487 || ('a' <= p[6] && p[6] <= 'z')
488 || ('0' <= p[6] && p[6] <= '9')
489 || p[6] == '_'))
491 fprintf (out, "DEFAULT");
492 p += 5;
493 in_ident = 0;
494 just_spaced = 0;
496 else if (c != ' ' || !just_spaced)
498 if (c >= 'a' && c <= 'z')
499 /* Upcase the letter. */
500 c += 'A' - 'a';
501 putc (c, out);
504 just_spaced = c == ' ';
505 need_space = 0;
509 /* Read through a c file. If a .o file is named,
510 the corresponding .c file is read instead.
511 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
512 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
515 scan_c_file (filename, mode)
516 char *filename, *mode;
518 FILE *infile;
519 register int c;
520 register int commas;
521 register int defunflag;
522 register int defvarperbufferflag;
523 register int defvarflag;
524 int minargs, maxargs;
525 int extension = filename[strlen (filename) - 1];
527 if (extension == 'o')
528 filename[strlen (filename) - 1] = 'c';
530 infile = fopen (filename, mode);
532 /* No error if non-ex input file */
533 if (infile == NULL)
535 perror (filename);
536 return 0;
539 /* Reset extension to be able to detect duplicate files. */
540 filename[strlen (filename) - 1] = extension;
542 c = '\n';
543 while (!feof (infile))
545 int doc_keyword = 0;
547 if (c != '\n' && c != '\r')
549 c = getc (infile);
550 continue;
552 c = getc (infile);
553 if (c == ' ')
555 while (c == ' ')
556 c = getc (infile);
557 if (c != 'D')
558 continue;
559 c = getc (infile);
560 if (c != 'E')
561 continue;
562 c = getc (infile);
563 if (c != 'F')
564 continue;
565 c = getc (infile);
566 if (c != 'V')
567 continue;
568 c = getc (infile);
569 if (c != 'A')
570 continue;
571 c = getc (infile);
572 if (c != 'R')
573 continue;
574 c = getc (infile);
575 if (c != '_')
576 continue;
578 defvarflag = 1;
579 defunflag = 0;
581 c = getc (infile);
582 defvarperbufferflag = (c == 'P');
584 c = getc (infile);
586 else if (c == 'D')
588 c = getc (infile);
589 if (c != 'E')
590 continue;
591 c = getc (infile);
592 if (c != 'F')
593 continue;
594 c = getc (infile);
595 defunflag = c == 'U';
596 defvarflag = 0;
598 else continue;
600 while (c != '(')
602 if (c < 0)
603 goto eof;
604 c = getc (infile);
607 /* Lisp variable or function name. */
608 c = getc (infile);
609 if (c != '"')
610 continue;
611 c = read_c_string_or_comment (infile, -1, 0, 0);
613 /* DEFVAR_LISP ("name", addr, "doc")
614 DEFVAR_LISP ("name", addr /\* doc *\/)
615 DEFVAR_LISP ("name", addr, doc: /\* doc *\/) */
617 if (defunflag)
618 commas = 5;
619 else if (defvarperbufferflag)
620 commas = 2;
621 else if (defvarflag)
622 commas = 1;
623 else /* For DEFSIMPLE and DEFPRED */
624 commas = 2;
626 while (commas)
628 if (c == ',')
630 commas--;
632 if (defunflag && (commas == 1 || commas == 2))
635 c = getc (infile);
636 while (c == ' ' || c == '\n' || c == '\r' || c == '\t');
637 if (c < 0)
638 goto eof;
639 ungetc (c, infile);
640 if (commas == 2) /* pick up minargs */
641 fscanf (infile, "%d", &minargs);
642 else /* pick up maxargs */
643 if (c == 'M' || c == 'U') /* MANY || UNEVALLED */
644 maxargs = -1;
645 else
646 fscanf (infile, "%d", &maxargs);
650 if (c == EOF)
651 goto eof;
652 c = getc (infile);
655 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
656 c = getc (infile);
658 if (c == '"')
659 c = read_c_string_or_comment (infile, 0, 0, 0);
661 while (c != EOF && c != ',' && c != '/')
662 c = getc (infile);
663 if (c == ',')
665 c = getc (infile);
666 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
667 c = getc (infile);
668 while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z'))
669 c = getc (infile);
670 if (c == ':')
672 doc_keyword = 1;
673 c = getc (infile);
674 while (c == ' ' || c == '\n' || c == '\r' || c == '\t')
675 c = getc (infile);
679 if (c == '"'
680 || (c == '/'
681 && (c = getc (infile),
682 ungetc (c, infile),
683 c == '*')))
685 int comment = c != '"';
686 int saw_usage;
688 putc (037, outfile);
689 putc (defvarflag ? 'V' : 'F', outfile);
690 fprintf (outfile, "%s\n", buf);
692 if (comment)
693 getc (infile); /* Skip past `*' */
694 c = read_c_string_or_comment (infile, 1, comment, &saw_usage);
696 /* If this is a defun, find the arguments and print them. If
697 this function takes MANY or UNEVALLED args, then the C source
698 won't give the names of the arguments, so we shouldn't bother
699 trying to find them.
701 Various doc-string styles:
702 0: DEFUN (..., "DOC") (args) [!comment]
703 1: DEFUN (..., /\* DOC *\/ (args)) [comment && !doc_keyword]
704 2: DEFUN (..., doc: /\* DOC *\/) (args) [comment && doc_keyword]
706 if (defunflag && maxargs != -1 && !saw_usage)
708 char argbuf[1024], *p = argbuf;
710 if (!comment || doc_keyword)
711 while (c != ')')
713 if (c < 0)
714 goto eof;
715 c = getc (infile);
718 /* Skip into arguments. */
719 while (c != '(')
721 if (c < 0)
722 goto eof;
723 c = getc (infile);
725 /* Copy arguments into ARGBUF. */
726 *p++ = c;
728 *p++ = c = getc (infile);
729 while (c != ')');
730 *p = '\0';
731 /* Output them. */
732 fprintf (outfile, "\n\n");
733 write_c_args (outfile, buf, argbuf, minargs, maxargs);
735 else if (defunflag && maxargs == -1 && !saw_usage)
736 /* The DOC should provide the usage form. */
737 fprintf (stderr, "Missing `usage' for function `%s'.\n", buf);
740 eof:
741 fclose (infile);
742 return 0;
745 /* Read a file of Lisp code, compiled or interpreted.
746 Looks for
747 (defun NAME ARGS DOCSTRING ...)
748 (defmacro NAME ARGS DOCSTRING ...)
749 (defsubst NAME ARGS DOCSTRING ...)
750 (autoload (quote NAME) FILE DOCSTRING ...)
751 (defvar NAME VALUE DOCSTRING)
752 (defconst NAME VALUE DOCSTRING)
753 (fset (quote NAME) (make-byte-code ... DOCSTRING ...))
754 (fset (quote NAME) #[... DOCSTRING ...])
755 (defalias (quote NAME) #[... DOCSTRING ...])
756 (custom-declare-variable (quote NAME) VALUE DOCSTRING ...)
757 starting in column zero.
758 (quote NAME) may appear as 'NAME as well.
760 We also look for #@LENGTH CONTENTS^_ at the beginning of the line.
761 When we find that, we save it for the following defining-form,
762 and we use that instead of reading a doc string within that defining-form.
764 For defvar, defconst, and fset we skip to the docstring with a kludgy
765 formatting convention: all docstrings must appear on the same line as the
766 initial open-paren (the one in column zero) and must contain a backslash
767 and a newline immediately after the initial double-quote. No newlines
768 must appear between the beginning of the form and the first double-quote.
769 For defun, defmacro, and autoload, we know how to skip over the
770 arglist, but the doc string must still have a backslash and newline
771 immediately after the double quote.
772 The only source files that must follow this convention are preloaded
773 uncompiled ones like loaddefs.el and bindings.el; aside
774 from that, it is always the .elc file that we look at, and they are no
775 problem because byte-compiler output follows this convention.
776 The NAME and DOCSTRING are output.
777 NAME is preceded by `F' for a function or `V' for a variable.
778 An entry is output only if DOCSTRING has \ newline just after the opening "
781 void
782 skip_white (infile)
783 FILE *infile;
785 char c = ' ';
786 while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
787 c = getc (infile);
788 ungetc (c, infile);
791 void
792 read_lisp_symbol (infile, buffer)
793 FILE *infile;
794 char *buffer;
796 char c;
797 char *fillp = buffer;
799 skip_white (infile);
800 while (1)
802 c = getc (infile);
803 if (c == '\\')
804 *(++fillp) = getc (infile);
805 else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')')
807 ungetc (c, infile);
808 *fillp = 0;
809 break;
811 else
812 *fillp++ = c;
815 if (! buffer[0])
816 fprintf (stderr, "## expected a symbol, got '%c'\n", c);
818 skip_white (infile);
822 scan_lisp_file (filename, mode)
823 char *filename, *mode;
825 FILE *infile;
826 register int c;
827 char *saved_string = 0;
829 infile = fopen (filename, mode);
830 if (infile == NULL)
832 perror (filename);
833 return 0; /* No error */
836 c = '\n';
837 while (!feof (infile))
839 char buffer[BUFSIZ];
840 char type;
842 /* If not at end of line, skip till we get to one. */
843 if (c != '\n' && c != '\r')
845 c = getc (infile);
846 continue;
848 /* Skip the line break. */
849 while (c == '\n' || c == '\r')
850 c = getc (infile);
851 /* Detect a dynamic doc string and save it for the next expression. */
852 if (c == '#')
854 c = getc (infile);
855 if (c == '@')
857 int length = 0;
858 int i;
860 /* Read the length. */
861 while ((c = getc (infile),
862 c >= '0' && c <= '9'))
864 length *= 10;
865 length += c - '0';
868 /* The next character is a space that is counted in the length
869 but not part of the doc string.
870 We already read it, so just ignore it. */
871 length--;
873 /* Read in the contents. */
874 if (saved_string != 0)
875 free (saved_string);
876 saved_string = (char *) malloc (length);
877 for (i = 0; i < length; i++)
878 saved_string[i] = getc (infile);
879 /* The last character is a ^_.
880 That is needed in the .elc file
881 but it is redundant in DOC. So get rid of it here. */
882 saved_string[length - 1] = 0;
883 /* Skip the line break. */
884 while (c == '\n' && c == '\r')
885 c = getc (infile);
886 /* Skip the following line. */
887 while (c != '\n' && c != '\r')
888 c = getc (infile);
890 continue;
893 if (c != '(')
894 continue;
896 read_lisp_symbol (infile, buffer);
898 if (! strcmp (buffer, "defun")
899 || ! strcmp (buffer, "defmacro")
900 || ! strcmp (buffer, "defsubst"))
902 type = 'F';
903 read_lisp_symbol (infile, buffer);
905 /* Skip the arguments: either "nil" or a list in parens */
907 c = getc (infile);
908 if (c == 'n') /* nil */
910 if ((c = getc (infile)) != 'i'
911 || (c = getc (infile)) != 'l')
913 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
914 buffer, filename);
915 continue;
918 else if (c != '(')
920 fprintf (stderr, "## unparsable arglist in %s (%s)\n",
921 buffer, filename);
922 continue;
924 else
925 while (c != ')')
926 c = getc (infile);
927 skip_white (infile);
929 /* If the next three characters aren't `dquote bslash newline'
930 then we're not reading a docstring.
932 if ((c = getc (infile)) != '"'
933 || (c = getc (infile)) != '\\'
934 || ((c = getc (infile)) != '\n' && c != '\r'))
936 #ifdef DEBUG
937 fprintf (stderr, "## non-docstring in %s (%s)\n",
938 buffer, filename);
939 #endif
940 continue;
944 else if (! strcmp (buffer, "defvar")
945 || ! strcmp (buffer, "defconst"))
947 char c1 = 0, c2 = 0;
948 type = 'V';
949 read_lisp_symbol (infile, buffer);
951 if (saved_string == 0)
954 /* Skip until the end of line; remember two previous chars. */
955 while (c != '\n' && c != '\r' && c >= 0)
957 c2 = c1;
958 c1 = c;
959 c = getc (infile);
962 /* If two previous characters were " and \,
963 this is a doc string. Otherwise, there is none. */
964 if (c2 != '"' || c1 != '\\')
966 #ifdef DEBUG
967 fprintf (stderr, "## non-docstring in %s (%s)\n",
968 buffer, filename);
969 #endif
970 continue;
975 else if (! strcmp (buffer, "custom-declare-variable"))
977 char c1 = 0, c2 = 0;
978 type = 'V';
980 c = getc (infile);
981 if (c == '\'')
982 read_lisp_symbol (infile, buffer);
983 else
985 if (c != '(')
987 fprintf (stderr,
988 "## unparsable name in custom-declare-variable in %s\n",
989 filename);
990 continue;
992 read_lisp_symbol (infile, buffer);
993 if (strcmp (buffer, "quote"))
995 fprintf (stderr,
996 "## unparsable name in custom-declare-variable in %s\n",
997 filename);
998 continue;
1000 read_lisp_symbol (infile, buffer);
1001 c = getc (infile);
1002 if (c != ')')
1004 fprintf (stderr,
1005 "## unparsable quoted name in custom-declare-variable in %s\n",
1006 filename);
1007 continue;
1011 if (saved_string == 0)
1013 /* Skip to end of line; remember the two previous chars. */
1014 while (c != '\n' && c != '\r' && c >= 0)
1016 c2 = c1;
1017 c1 = c;
1018 c = getc (infile);
1021 /* If two previous characters were " and \,
1022 this is a doc string. Otherwise, there is none. */
1023 if (c2 != '"' || c1 != '\\')
1025 #ifdef DEBUG
1026 fprintf (stderr, "## non-docstring in %s (%s)\n",
1027 buffer, filename);
1028 #endif
1029 continue;
1034 else if (! strcmp (buffer, "fset") || ! strcmp (buffer, "defalias"))
1036 char c1 = 0, c2 = 0;
1037 type = 'F';
1039 c = getc (infile);
1040 if (c == '\'')
1041 read_lisp_symbol (infile, buffer);
1042 else
1044 if (c != '(')
1046 fprintf (stderr, "## unparsable name in fset in %s\n",
1047 filename);
1048 continue;
1050 read_lisp_symbol (infile, buffer);
1051 if (strcmp (buffer, "quote"))
1053 fprintf (stderr, "## unparsable name in fset in %s\n",
1054 filename);
1055 continue;
1057 read_lisp_symbol (infile, buffer);
1058 c = getc (infile);
1059 if (c != ')')
1061 fprintf (stderr,
1062 "## unparsable quoted name in fset in %s\n",
1063 filename);
1064 continue;
1068 if (saved_string == 0)
1070 /* Skip to end of line; remember the two previous chars. */
1071 while (c != '\n' && c != '\r' && c >= 0)
1073 c2 = c1;
1074 c1 = c;
1075 c = getc (infile);
1078 /* If two previous characters were " and \,
1079 this is a doc string. Otherwise, there is none. */
1080 if (c2 != '"' || c1 != '\\')
1082 #ifdef DEBUG
1083 fprintf (stderr, "## non-docstring in %s (%s)\n",
1084 buffer, filename);
1085 #endif
1086 continue;
1091 else if (! strcmp (buffer, "autoload"))
1093 type = 'F';
1094 c = getc (infile);
1095 if (c == '\'')
1096 read_lisp_symbol (infile, buffer);
1097 else
1099 if (c != '(')
1101 fprintf (stderr, "## unparsable name in autoload in %s\n",
1102 filename);
1103 continue;
1105 read_lisp_symbol (infile, buffer);
1106 if (strcmp (buffer, "quote"))
1108 fprintf (stderr, "## unparsable name in autoload in %s\n",
1109 filename);
1110 continue;
1112 read_lisp_symbol (infile, buffer);
1113 c = getc (infile);
1114 if (c != ')')
1116 fprintf (stderr,
1117 "## unparsable quoted name in autoload in %s\n",
1118 filename);
1119 continue;
1122 skip_white (infile);
1123 if ((c = getc (infile)) != '\"')
1125 fprintf (stderr, "## autoload of %s unparsable (%s)\n",
1126 buffer, filename);
1127 continue;
1129 read_c_string_or_comment (infile, 0, 0, 0);
1130 skip_white (infile);
1132 if (saved_string == 0)
1134 /* If the next three characters aren't `dquote bslash newline'
1135 then we're not reading a docstring. */
1136 if ((c = getc (infile)) != '"'
1137 || (c = getc (infile)) != '\\'
1138 || ((c = getc (infile)) != '\n' && c != '\r'))
1140 #ifdef DEBUG
1141 fprintf (stderr, "## non-docstring in %s (%s)\n",
1142 buffer, filename);
1143 #endif
1144 continue;
1149 #ifdef DEBUG
1150 else if (! strcmp (buffer, "if")
1151 || ! strcmp (buffer, "byte-code"))
1153 #endif
1155 else
1157 #ifdef DEBUG
1158 fprintf (stderr, "## unrecognised top-level form, %s (%s)\n",
1159 buffer, filename);
1160 #endif
1161 continue;
1164 /* At this point, we should either use the previous
1165 dynamic doc string in saved_string
1166 or gobble a doc string from the input file.
1168 In the latter case, the opening quote (and leading
1169 backslash-newline) have already been read. */
1171 putc (037, outfile);
1172 putc (type, outfile);
1173 fprintf (outfile, "%s\n", buffer);
1174 if (saved_string)
1176 fputs (saved_string, outfile);
1177 /* Don't use one dynamic doc string twice. */
1178 free (saved_string);
1179 saved_string = 0;
1181 else
1182 read_c_string_or_comment (infile, 1, 0, 0);
1184 fclose (infile);
1185 return 0;