]> sjero.net Git - wget/commitdiff
[svn] Replace opt.no_flush with a function to disable/enable flushing.
authorhniksic <devnull@localhost>
Thu, 22 Nov 2001 20:13:13 +0000 (12:13 -0800)
committerhniksic <devnull@localhost>
Thu, 22 Nov 2001 20:13:13 +0000 (12:13 -0800)
Published in <sxssnb6imyz.fsf@florida.arsdigita.de>.

src/ChangeLog
src/log.c
src/options.h
src/retr.c
src/wget.h

index 36377658186984ea6e0836531ceca420db6b3deb..8c799ddafbef8d71b3d2a59e7ca8e31e2c01d91d 100644 (file)
@@ -1,3 +1,9 @@
+2001-11-22  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * retr.c (show_progress): Use it.
+
+       * log.c (log_set_flush): New function.
+
 2001-11-22  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * utils.c (path_simplify): Don't remove trailing slashes.
index 61766f9036923dbfc91175f39c0d2b560fc76798..f43351dc6a8c25a4b204efdb6191396a2fe79f7d 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -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
index c6f21b5ba6b2efa6b71e14030b388b7c22a94119..f0d61505b4e6d1a342cb0a6be7a16fc022570e61 100644 (file)
@@ -49,7 +49,6 @@ struct options
                                   data. */
   char *dir_prefix;            /* The top of directory tree */
   char *lfilename;             /* Log filename */
-  int no_flush;                        /* If non-zero, inhibit flushing log. */
   char *input_filename;                /* Input filename */
   int force_html;              /* Is the input file an HTML file? */
 
index 398bc52cb0f79e503a56290a853b80abed88cf50..75ae3252d1911a1ea97c8dff19701fcefdcac1f7 100644 (file)
@@ -50,7 +50,6 @@ extern int errno;
 /* See the comment in gethttp() why this is needed. */
 int global_download_count;
 
-void logflush PARAMS ((void));
 \f
 /* Flags for show_progress().  */
 enum spflags { SP_NONE, SP_INIT, SP_FINISH };
@@ -198,7 +197,8 @@ show_progress (long res, long expected, enum spflags flags)
     }
 
   /* Temporarily disable flushing.  */
-  opt.no_flush = 1;
+  log_set_flush (0);
+
   /* init set means initialization.  If res is set, it also means that
      the retrieval is *not* done from the beginning.  The part that
      was already retrieved is not shown again.  */
@@ -255,11 +255,10 @@ show_progress (long res, long expected, enum spflags flags)
          logprintf (LOG_VERBOSE, "\n%5ldK", nrow * line_bytes / 1024);
        }
     }
+
   /* Reenable flushing.  */
-  opt.no_flush = 0;
-  if (any_output)
-    /* Force flush.  */
-    logflush ();
+  log_set_flush (1);
+
   return any_output;
 }
 \f
index f5eff47e4f46e2d37e0db28c68902fb7d24851c6..f0cabd16c4e4c614d0d1b6f5094a398a5399ae66 100644 (file)
@@ -98,6 +98,8 @@ void logprintf ();
 void debug_logprintf ();
 #endif /* not HAVE_STDARG_H */
 void logputs PARAMS ((enum log_options, const char *));
+void logflush PARAMS ((void));
+void log_set_flush PARAMS ((int));
 
 /* Defined in `utils.c', but used literally everywhere.  */
 #ifndef DEBUG_MALLOC