emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117527: * make-docfile.c: Simplify a bit, to simpli


From: Paul Eggert
Subject: [Emacs-diffs] trunk r117527: * make-docfile.c: Simplify a bit, to simplify further refactoring.
Date: Mon, 14 Jul 2014 00:45:24 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117527
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sun 2014-07-13 17:45:19 -0700
message:
  * make-docfile.c: Simplify a bit, to simplify further refactoring.
  
  (outfile): Remove static var.  All uses changed to use stdout,
  since it's always stdout anyway.  While we're at it, prefer
  putchar/puts/fputs to printf when there are no format strings.
  (main): Use freopen rather than fopen, so that stdout is reused.
  Move O_BINARY stuff after the freopen, so it affects the
  reopened file.
  (write_c_args): Omit first arg, since it's always stdout now.
  All uses changed.
modified:
  lib-src/ChangeLog              changelog-20091113204419-o5vbwnq5f7feedwu-1608
  lib-src/make-docfile.c         
makedocfile.c-20091113204419-o5vbwnq5f7feedwu-33
=== modified file 'lib-src/ChangeLog'
--- a/lib-src/ChangeLog 2014-07-12 17:53:29 +0000
+++ b/lib-src/ChangeLog 2014-07-14 00:45:19 +0000
@@ -1,3 +1,15 @@
+2014-07-13  Paul Eggert  <address@hidden>
+
+       * make-docfile.c: Simplify a bit, to simplify further refactoring.
+       (outfile): Remove static var.  All uses changed to use stdout,
+       since it's always stdout anyway.  While we're at it, prefer
+       putchar/puts/fputs to printf when there are no format strings.
+       (main): Use freopen rather than fopen, so that stdout is reused.
+       Move O_BINARY stuff after the freopen, so it affects the
+       reopened file.
+       (write_c_args): Omit first arg, since it's always stdout now.
+       All uses changed.
+
 2014-07-12  Paul Eggert  <address@hidden>
 
        * etags.c (Lisp_functions): Also record cl-defun etc. (Bug#17965)

=== modified file 'lib-src/make-docfile.c'
--- a/lib-src/make-docfile.c    2014-06-17 16:09:19 +0000
+++ b/lib-src/make-docfile.c    2014-07-14 00:45:19 +0000
@@ -73,9 +73,6 @@
 
 #include <unistd.h>
 
-/* Stdio stream for output to the DOC file.  */
-FILE *outfile;
-
 /* Name this program was invoked with.  */
 char *progname;
 
@@ -135,33 +132,24 @@
 
   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 */
-
   /* If first two args are -o FILE, output to FILE.  */
   i = 1;
   if (argc > i + 1 && !strcmp (argv[i], "-o"))
     {
-      outfile = fopen (argv[i + 1], "w");
+      if (! freopen (argv[i + 1], "w", stdout))
+       {
+         perror (argv[i + 1]);
+         return EXIT_FAILURE;
+       }
       i += 2;
     }
   if (argc > i + 1 && !strcmp (argv[i], "-a"))
     {
-      outfile = fopen (argv[i + 1], "a");
+      if (! freopen (argv[i + 1], "a", stdout))
+       {
+         perror (argv[i + 1]);
+         return EXIT_FAILURE;
+       }
       i += 2;
     }
   if (argc > i + 1 && !strcmp (argv[i], "-d"))
@@ -179,8 +167,19 @@
       ++i;
     }
 
-  if (outfile == 0)
-    fatal ("No output file specified", "");
+  /* Don't put CRs in the output 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
+#endif /* MSDOS */
+#ifdef WINDOWSNT
+  _fmode = O_BINARY;
+  _setmode (fileno (stdout), O_BINARY);
+#endif /* WINDOWSNT */
 
   if (generate_globals)
     start_globals ();
@@ -215,13 +214,11 @@
        filename = tmp + 1;
     }
 
-  putc (037, outfile);
-  putc ('S', outfile);
-  fprintf (outfile, "%s\n", filename);
+  printf ("\037S%s\n", filename);
 }
 
-/* Read file FILENAME and output its doc strings to outfile.  */
-/* Return 1 if file is not found, 0 if it is found.  */
+/* Read file FILENAME and output its doc strings to stdout.
+   Return 1 if file is not found, 0 if it is found.  */
 
 static int
 scan_file (char *filename)
@@ -242,9 +239,9 @@
 static void
 start_globals (void)
 {
-  fprintf (outfile, "/* This file was auto-generated by make-docfile.  */\n");
-  fprintf (outfile, "/* DO NOT EDIT.  */\n");
-  fprintf (outfile, "struct emacs_globals {\n");
+  puts ("/* This file was auto-generated by make-docfile.  */");
+  puts ("/* DO NOT EDIT.  */");
+  puts ("struct emacs_globals {");
 }
 
 static char input_buffer[128];
@@ -373,7 +370,7 @@
 
 /* Skip a C string or C-style comment from INFILE, and return the
    character that follows.  COMMENT non-zero means skip a comment.  If
-   PRINTFLAG is positive, output string contents to outfile.  If it is
+   PRINTFLAG is positive, output string contents to stdout.  If it is
    negative, store contents in buf.  Convert escape sequences \n and
    \t to newline and tab; discard \ followed by newline.
    If SAW_USAGE is non-zero, then any occurrences of the string `usage:'
@@ -388,7 +385,7 @@
 
   state.in_file = infile;
   state.buf_ptr = (printflag < 0 ? input_buffer : 0);
-  state.out_file = (printflag > 0 ? outfile : 0);
+  state.out_file = (printflag > 0 ? stdout : 0);
   state.pending_spaces = 0;
   state.pending_newlines = 0;
   state.keyword = (saw_usage ? "usage:" : 0);
@@ -465,18 +462,18 @@
 
 
 
-/* Write to file OUT the argument names of function FUNC, whose text is in BUF.
+/* Write to stdout the argument names of function FUNC, whose text is in BUF.
    MINARGS and MAXARGS are the minimum and maximum number of arguments.  */
 
 static void
-write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
+write_c_args (char *func, char *buf, int minargs, int maxargs)
 {
   register char *p;
   int in_ident = 0;
   char *ident_start IF_LINT (= NULL);
   size_t ident_length = 0;
 
-  fprintf (out, "(fn");
+  fputs ("(fn", stdout);
 
   if (*buf == '(')
     ++buf;
@@ -517,10 +514,10 @@
          if (strncmp (ident_start, "void", ident_length) == 0)
            continue;
 
-         putc (' ', out);
+         putchar (' ');
 
          if (minargs == 0 && maxargs > 0)
-           fprintf (out, "&optional ");
+           fputs ("&optional ", stdout);
 
          minargs--;
          maxargs--;
@@ -528,7 +525,7 @@
          /* In C code, `default' is a reserved word, so we spell it
             `defalt'; demangle that here.  */
          if (ident_length == 6 && memcmp (ident_start, "defalt", 6) == 0)
-           fprintf (out, "DEFAULT");
+           fputs ("DEFAULT", stdout);
          else
            while (ident_length-- > 0)
              {
@@ -539,12 +536,12 @@
                else if (c == '_')
                  /* Print underscore as hyphen.  */
                  c = '-';
-               putc (c, out);
+               putchar (c);
              }
        }
     }
 
-  putc (')', out);
+  putchar (')');
 }
 
 /* The types of globals.  These are sorted roughly in decreasing alignment
@@ -613,8 +610,8 @@
 static void
 close_emacs_globals (void)
 {
-  fprintf (outfile, "};\n");
-  fprintf (outfile, "extern struct emacs_globals globals;\n");
+  puts ("};");
+  puts ("extern struct emacs_globals globals;");
 }
 
 static void
@@ -641,7 +638,7 @@
          if (!seen_defun)
            {
              close_emacs_globals ();
-             fprintf (outfile, "\n");
+             putchar ('\n');
              seen_defun = 1;
            }
          break;
@@ -651,9 +648,9 @@
 
       if (type)
        {
-         fprintf (outfile, "  %s f_%s;\n", type, globals[i].name);
-         fprintf (outfile, "#define %s globals.f_%s\n",
-                  globals[i].name, globals[i].name);
+         printf ("  %s f_%s;\n", type, globals[i].name);
+         printf ("#define %s globals.f_%s\n",
+                 globals[i].name, globals[i].name);
        }
       else
        {
@@ -664,16 +661,16 @@
              || strcmp (globals[i].name, "Fkill_emacs") == 0
              || strcmp (globals[i].name, "Fexit_recursive_edit") == 0
              || strcmp (globals[i].name, "Fabort_recursive_edit") == 0)
-           fprintf (outfile, "_Noreturn ");
+           fputs ("_Noreturn ", stdout);
 
-         fprintf (outfile, "EXFUN (%s, ", globals[i].name);
+         printf ("EXFUN (%s, ", globals[i].name);
          if (globals[i].value == -1)
-           fprintf (outfile, "MANY");
+           fputs ("MANY", stdout);
          else if (globals[i].value == -2)
-           fprintf (outfile, "UNEVALLED");
+           fputs ("UNEVALLED", stdout);
          else
-           fprintf (outfile, "%d", globals[i].value);
-         fprintf (outfile, ")");
+           printf ("%d", globals[i].value);
+         putchar (')');
 
          /* It would be nice to have a cleaner way to deal with these
             special hacks, too.  */
@@ -681,9 +678,9 @@
              || strcmp (globals[i].name, "Ftool_bar_height") == 0
              || strcmp (globals[i].name, "Fmax_char") == 0
              || strcmp (globals[i].name, "Fidentity") == 0)
-           fprintf (outfile, " ATTRIBUTE_CONST");
+           fputs (" ATTRIBUTE_CONST", stdout);
 
-         fprintf (outfile, ";\n");
+         puts (";");
        }
 
       while (i + 1 < num_globals
@@ -952,9 +949,7 @@
          int comment = c != '"';
          int saw_usage;
 
-         putc (037, outfile);
-         putc (defvarflag ? 'V' : 'F', outfile);
-         fprintf (outfile, "%s\n", input_buffer);
+         printf ("\037%c%s\n", defvarflag ? 'V' : 'F', input_buffer);
 
          if (comment)
            getc (infile);      /* Skip past `*'.  */
@@ -996,8 +991,8 @@
              while (c != ')');
              *p = '\0';
              /* Output them.  */
-             fprintf (outfile, "\n\n");
-             write_c_args (outfile, input_buffer, argbuf, minargs, maxargs);
+             fputs ("\n\n", stdout);
+             write_c_args (input_buffer, argbuf, minargs, maxargs);
            }
          else if (defunflag && maxargs == -1 && !saw_usage)
            /* The DOC should provide the usage form.  */
@@ -1433,12 +1428,10 @@
         In the latter case, the opening quote (and leading backslash-newline)
         have already been read.  */
 
-      putc (037, outfile);
-      putc (type, outfile);
-      fprintf (outfile, "%s\n", buffer);
+      printf ("\037%c%s\n", type, buffer);
       if (saved_string)
        {
-         fputs (saved_string, outfile);
+         fputs (saved_string, stdout);
          /* Don't use one dynamic doc string twice.  */
          free (saved_string);
          saved_string = 0;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]