]> sjero.net Git - wget/blobdiff - src/log.c
[svn] Replace opt.no_flush with a function to disable/enable flushing.
[wget] / src / log.c
index c12ed225a73f350a5ccf7306beeff5b6d42c8cd4..f43351dc6a8c25a4b204efdb6191396a2fe79f7d 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1,20 +1,20 @@
 /* Messages logging.
    Copyright (C) 1998, 2000 Free Software Foundation, Inc.
 
-This file is part of Wget.
+This file is part of GNU Wget.
 
-This program is free software; you can redistribute it and/or modify
+GNU Wget is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
+GNU Wget is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
+along with Wget; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <config.h>
@@ -52,6 +52,10 @@ static FILE *logfp;
 /* Whether logging is saved at all.  */
 int save_log_p;
 
+/* Whether the log is flushed after each command. */
+int flush_log_p = 1;
+int needs_flushing;
+
 /* In the event of a hang-up, and if its output was on a TTY, Wget
    redirects its output to `wget-log'.
 
@@ -268,10 +272,13 @@ logputs (enum log_options o, const char *s)
   CANONICALIZE_LOGFP_OR_RETURN;
 
   fputs (s, logfp);
-  if (!opt.no_flush)
-    fflush (logfp);
   if (save_log_p)
     saved_append (s);
+
+  if (flush_log_p)
+    logflush ();
+  else
+    needs_flushing = 1;
 }
 
 /* Print a message to the log.  A copy of message will be saved to
@@ -348,16 +355,41 @@ logvprintf (enum log_options o, const char *fmt, va_list args)
       if (bigmsg)
        xfree (bigmsg);
     }
-  if (!opt.no_flush)
-    fflush (logfp);
+  if (flush_log_p)
+    logflush ();
+  else
+    needs_flushing = 1;
 }
 
-/* Flush LOGFP.  */
+/* Flush LOGFP.  Useful while flushing is disabled.  */
 void
 logflush (void)
 {
   CANONICALIZE_LOGFP_OR_RETURN;
   fflush (logfp);
+  needs_flushing = 0;
+}
+
+/* Enable or disable log flushing. */
+void
+log_set_flush (int flush)
+{
+  if (flush == flush_log_p)
+    return;
+
+  if (flush == 0)
+    {
+      /* Disable flushing by setting flush_log_p to 0. */
+      flush_log_p = 0;
+    }
+  else
+    {
+      /* Reenable flushing.  If anything was printed in no-flush mode,
+        flush the log now.  */
+      if (needs_flushing)
+       logflush ();
+      flush_log_p = 1;
+    }
 }
 
 /* Portability with pre-ANSI compilers makes these two functions look