]> code.delx.au - gnu-emacs/blobdiff - lib-src/make-docfile.c
[WINDOWSNT]: Include io.h.
[gnu-emacs] / lib-src / make-docfile.c
index df9c6e069f5d946e261e47ca617037b9b8dd0230..b0072672114837de310a26953376514177a1af88 100644 (file)
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* The arguments given to this program are all the C and Lisp source files
  of GNU Emacs.  .elc and .el and .c files are allowed.
@@ -31,6 +32,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  Then comes the documentation for that function or variable.
  */
 
+#define NO_SHORTNAMES   /* Tell config not to load remap.h */
+#include <../src/config.h>
+
 #include <stdio.h>
 #ifdef MSDOS
 #include <fcntl.h>
@@ -53,6 +57,12 @@ int scan_file ();
 int scan_lisp_file ();
 int scan_c_file ();
 
+#ifdef MSDOS
+/* s/msdos.h defines this as sys_chdir, but we're not linking with the
+   file where that function is defined.  */
+#undef chdir
+#endif
+
 /* Stdio stream for output to the DOC file.  */
 FILE *outfile;
 
@@ -84,11 +94,11 @@ fatal (s1, s2)
 
 /* Like malloc but get fatal error if memory is exhausted.  */
 
-char *
+long *
 xmalloc (size)
      unsigned int size;
 {
-  char *result = (char *) malloc (size);
+  long *result = (long *) malloc (size);
   if (result == NULL)
     fatal ("virtual memory exhausted", 0);
   return result;
@@ -105,19 +115,23 @@ main (argc, argv)
 
   progname = argv[0];
 
+  outfile = stdout;
+
   /* Don't put CRs in the DOC file.  */
 #ifdef MSDOS
   _fmode = O_BINARY;
+#if 0  /* Suspicion is that this causes hanging.
+         So instead we require people to use -o on MSDOS.  */
   (stdout)->_flag &= ~_IOTEXT;
   _setmode (fileno (stdout), O_BINARY);
+#endif
+  outfile = 0;
 #endif /* MSDOS */
 #ifdef WINDOWSNT
   _fmode = O_BINARY;
   _setmode (fileno (stdout), O_BINARY);
 #endif /* WINDOWSNT */
 
-  outfile = stdout;
-
   /* If first two args are -o FILE, output to FILE.  */
   i = 1;
   if (argc > i + 1 && !strcmp (argv[i], "-o"))
@@ -136,6 +150,9 @@ main (argc, argv)
       i += 2;
     }
 
+  if (outfile == 0)
+    fatal ("No output file specified", "");
+
   first_infile = i;
   for (; i < argc; i++)
     {
@@ -161,9 +178,9 @@ scan_file (filename)
      char *filename;
 {
   int len = strlen (filename);
-  if (!strcmp (filename + len - 4, ".elc"))
+  if (len > 4 && !strcmp (filename + len - 4, ".elc"))
     return scan_lisp_file (filename, READ_BINARY);
-  else if (!strcmp (filename + len - 3, ".el"))
+  else if (len > 3 && !strcmp (filename + len - 3, ".el"))
     return scan_lisp_file (filename, READ_TEXT);
   else
     return scan_c_file (filename, READ_TEXT);
@@ -322,8 +339,9 @@ scan_c_file (filename, mode)
   register int defvarperbufferflag;
   register int defvarflag;
   int minargs, maxargs;
+  int extension = filename[strlen (filename) - 1];
 
-  if (filename[strlen (filename) - 1] == 'o')
+  if (extension == 'o')
     filename[strlen (filename) - 1] = 'c';
 
   infile = fopen (filename, mode);
@@ -335,6 +353,9 @@ scan_c_file (filename, mode)
       return 0;
     }
 
+  /* Reset extension to be able to detect duplicate files. */
+  filename[strlen (filename) - 1] = extension;
+
   c = '\n';
   while (!feof (infile))
     {