]>
code.delx.au - gnu-emacs/blob - lib-src/make-docfile.c
1 /* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985, 1986 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* The arguments given to this program are all the C and Lisp source files
21 of GNU Emacs. .elc and .el and .c files are allowed.
22 A .o file can also be specified; the .c file it was made from is used.
23 This helps the makefile pass the correct list of files.
25 The results, which go to standard output or to a file
26 specified with -a or -o (-a to append, -o to start from nothing),
27 are entries containing function or variable names and their documentation.
28 Each entry starts with a ^_ character.
29 Then comes F for a function or V for a variable.
30 Then comes the function or variable name, terminated with a newline.
31 Then comes the documentation for that function or variable.
47 /* If first two args are -o FILE, output to FILE. */
49 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-o"))
51 outfile
= fopen (argv
[i
+ 1], "w");
54 if (argc
> i
+ 1 && !strcmp (argv
[i
], "-a"))
56 outfile
= fopen (argv
[i
+ 1], "a");
61 err_count
+= scan_file (argv
[i
]); /* err_count seems to be {mis,un}used */
63 exit (err_count
); /* see below - shane */
67 /* Read file FILENAME and output its doc strings to outfile. */
68 /* Return 1 if file is not found, 0 if it is found. */
73 int len
= strlen (filename
);
74 if (!strcmp (filename
+ len
- 4, ".elc"))
75 return scan_lisp_file (filename
);
76 else if (!strcmp (filename
+ len
- 3, ".el"))
77 return scan_lisp_file (filename
);
79 return scan_c_file (filename
);
84 /* Skip a C string from INFILE,
85 and return the character that follows the closing ".
86 If printflag is positive, output string contents to outfile.
87 If it is negative, store contents in buf.
88 Convert escape sequences \n and \t to newline and tab;
89 discard \ followed by newline. */
91 read_c_string (infile
, printflag
)
101 while (c
!= '"' && c
!= EOF
)
118 else if (printflag
< 0)
127 else if (printflag
< 0)
138 /* Write to file OUT the argument names of the function whose text is in BUF.
139 MINARGS and MAXARGS are the minimum and maximum number of arguments. */
141 write_c_args (out
, buf
, minargs
, maxargs
)
144 int minargs
, maxargs
;
147 register char *p
= buf
;
150 fprintf (out
, "arguments: ");
161 if (minargs
== 0 && maxargs
> 0)
162 fprintf (out
, "&optional ");
166 else if (c
== ' ' && space
)
174 /* Read through a c file. If a .o file is named,
175 the corresponding .c file is read instead.
176 Looks for DEFUN constructs such as are defined in ../src/lisp.h.
177 Accepts any word starting DEF... so it finds DEFSIMPLE and DEFPRED. */
179 scan_c_file (filename
)
185 register int defunflag
;
186 register int defvarflag
;
187 int minargs
, maxargs
;
189 if (filename
[strlen (filename
) - 1] == 'o')
190 filename
[strlen (filename
) - 1] = 'c';
192 infile
= fopen (filename
, "r");
194 /* No error if non-ex input file */
202 while (!feof (infile
))
238 defunflag
= c
== 'U';
253 c
= read_c_string (infile
, -1);
259 else /* For DEFSIMPLE and DEFPRED */
267 if (defunflag
&& (commas
== 1 || commas
== 2))
271 while (c
== ' ' || c
== '\n' || c
== '\t');
275 if (commas
== 2) /* pick up minargs */
276 fscanf (infile
, "%d", &minargs
);
277 else /* pick up maxargs */
278 if (c
== 'M' || c
== 'U') /* MANY || UNEVALLED */
281 fscanf (infile
, "%d", &maxargs
);
288 while (c
== ' ' || c
== '\n' || c
== '\t')
291 c
= read_c_string (infile
, 0);
295 while (c
== ' ' || c
== '\n' || c
== '\t')
301 putc (defvarflag
? 'V' : 'F', outfile
);
302 fprintf (outfile
, "%s\n", buf
);
303 c
= read_c_string (infile
, 1);
305 /* If this is a defun, find the arguments and print them. If
306 this function takes MANY or UNEVALLED args, then the C source
307 won't give the names of the arguments, so we shouldn't bother
308 trying to find them. */
309 if (defunflag
&& maxargs
!= -1)
311 char argbuf
[1024], *p
= argbuf
;
318 /* Skip into arguments. */
325 /* Copy arguments into ARGBUF. */
328 *p
++ = c
= getc (infile
);
332 fprintf (outfile
, "\n\n");
333 write_c_args (outfile
, argbuf
, minargs
, maxargs
);
342 /* Read a file of Lisp code, compiled or interpreted.
344 (defun NAME ARGS DOCSTRING ...)
345 (autoload 'NAME FILE DOCSTRING ...)
346 (defvar NAME VALUE DOCSTRING)
347 (defconst NAME VALUE DOCSTRING)
348 (fset (quote NAME) (make-byte-code (quote ARGS) ... "\
350 starting in column zero.
351 ARGS, FILE or VALUE is ignored. We do not know how to parse Lisp code
352 so we use a kludge to skip them:
353 In a function definition, the form of ARGS of FILE is known, and we
355 In a variable definition, we use a formatting convention:
356 the DOCSTRING, if present, must be followed by a closeparen and a newline,
357 and no newline must appear between the defvar or defconst and the docstring,
358 The only source file that must follow this convention is loaddefs.el;
359 aside from that, it is always the .elc file that we look at, and
360 they are no problem because byte-compiler output follows this convention.
361 The NAME and DOCSTRING are output.
362 NAME is preceded by `F' for a function or `V' for a variable.
363 An entry is output only if DOCSTRING has \ newline just after the opening "
366 scan_lisp_file (filename
)
375 infile
= fopen (filename
, "r");
379 return 0; /* No error */
383 while (!feof (infile
))
394 /* Handle an autoload. */
455 while (c
!= ' ' && c
!= ')')
472 c
= read_c_string (infile
, 0);
475 /* Handle def* clauses. */
486 /* Is this a defun? */
527 /* Now we have seen "defun" or "defvar" or "defconst". */
529 while (c
!= ' ' && c
!= '\n' && c
!= '\t')
532 while (c
== ' ' || c
== '\n' || c
== '\t')
535 /* Read and store name of function or variable being defined
536 Discard backslashes that are for quoting. */
538 while (c
!= ' ' && c
!= '\n' && c
!= '\t')
547 while (c
== ' ' || c
== '\n' || c
== '\t')
553 /* Skip the arguments: either "nil" or a list in parens */
556 while (c
!= ' ' && c
!= '\n' && c
!= '\t')
572 /* Skip until the first newline; remember
573 the two previous characters. */
576 while (c
!= '\n' && c
>= 0)
583 /* If two previous characters were " and \,
584 this is a doc string. Otherwise, there is none. */
585 if (c2
== '"' && c1
== '\\')
589 fprintf (outfile
, "%s\n", buf
);
590 read_c_string (infile
, 1);
596 /* Handle an fset clause. */
609 /* Skip white space */
612 while (c
== ' ' || c
== '\n' || c
== '\t');
614 /* Recognize "(quote". */
633 /* Skip white space */
636 while (c
== ' ' || c
== '\n' || c
== '\t');
638 /* Read and store name of function or variable being defined
639 Discard backslashes that are for quoting. */
641 while (c
!= ')' && c
!= ' ' && c
!= '\n' && c
!= '\t')
650 /* Skip white space */
653 while (c
== ' ' || c
== '\n' || c
== '\t');
655 /* Recognize "(make-byte-code". */
701 /* Scan for a \" followed by a newline, or for )) followed by
702 a newline. If we find the latter first, this function has
710 /* Find newlines, and remember the two previous characters. */
715 if (c
== '\n' || c
< 0)
722 /* If we've hit eof, quit. */
726 /* If the last two characters were \", this is a docstring. */
727 else if (c2
== '"' && c1
== '\\')
731 fprintf (outfile
, "%s\n", buf
);
732 read_c_string (infile
, 1);
736 /* If the last two characters were )), there is no
738 else if (c2
== ')' && c1
== ')')
747 /* Here for a function definition.
748 We have skipped the file name or arguments
749 and arrived at where the doc string is,
750 if there is a doc string. */
752 /* Skip whitespace */
754 while (c
== ' ' || c
== '\n' || c
== '\t')
757 /* " followed by \ and newline means a doc string we should gobble */
769 fprintf (outfile
, "%s\n", buf
);
770 read_c_string (infile
, 1);