[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123.c status.c

Kenneth C. Arnold kcarnold at xiph.org
Mon Aug 13 13:07:05 PDT 2001



kcarnold    01/08/13 13:07:05

  Modified:    ogg123   Tag: kcarnold_work ogg123.c status.c
  Log:
  Status reworking -- cursor shouldn't dance around nearly as much.

Revision  Changes    Path
No                   revision

No                   revision

1.39.2.19 +5 -2      vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.18
retrieving revision 1.39.2.19
diff -u -r1.39.2.18 -r1.39.2.19
--- ogg123.c	2001/08/13 17:31:46	1.39.2.18
+++ ogg123.c	2001/08/13 20:07:03	1.39.2.19
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.18 2001/08/13 17:31:46 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.19 2001/08/13 20:07:03 kcarnold Exp $
 
  ********************************************************************/
 
@@ -732,8 +732,11 @@
 
           do {
             if (nthc-- == 0) {
-	      if (Options.outputOpts.buffer)
+	      if (Options.outputOpts.buffer) {
                 SubmitData (Options.outputOpts.buffer, convbuffer, ret, 1);
+		SetBuffersStats ();
+		UpdateStats (Options.statOpts.stats);
+	      }
               else
                 OutBufferWrite (convbuffer, ret, 1, &Options, 0);
               nthc = Options.playOpts.nth - 1;

1.1.2.4   +49 -10    vorbis-tools/ogg123/Attic/status.c

Index: status.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/status.c,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- status.c	2001/08/13 00:59:43	1.1.2.3
+++ status.c	2001/08/13 20:07:04	1.1.2.4
@@ -11,16 +11,22 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: status.c,v 1.1.2.3 2001/08/13 00:59:43 kcarnold Exp $
+ last mod: $Id: status.c,v 1.1.2.4 2001/08/13 20:07:04 kcarnold Exp $
 
  ********************************************************************/
 
 /* status interface */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
 #include "status.h"
 
 /* a few globals */
+/* stderr is thread-global, so status vars should be also; caller must
+ * ensure that status functions are not called concurrently */
+int buflen = 100; /* guess max length to be 100 */
+char *tmpbuf = NULL; /* global so updating quick after size determined */
 int LastLineLen = 0;
 int MaxPrio = 0;
 
@@ -33,10 +39,43 @@
   fputc ('\r', stderr);
 }
 
+int AppendString (int len, char *fmt, ...) {
+  va_list ap;
+  int n = -1, size;
+
+  while (n == -1) {
+    size = buflen - len - 1;
+    va_start (ap, fmt);
+    n = vsnprintf (tmpbuf + len, size, fmt, ap);
+    va_end (ap);
+
+    if (n > -1 && n < size)
+      return n;
+    /* otherwise, double the size (likely more efficient) */
+    buflen *= 2;
+    if (!(tmpbuf = realloc (tmpbuf, buflen))) {
+      ClearLine();
+      perror ("malloc");
+      exit (1);
+    }
+    n = -1;
+  }
+  return 0; /* makes dumb compilers happy */
+}
+
 void UpdateStats (Stat_t stats[])
 {
   int len = 0, left;
-
+  
+  if (tmpbuf == NULL) {
+    tmpbuf = malloc (buflen);
+    if (!tmpbuf) {
+      ClearLine();
+      perror ("malloc");
+      exit (1);
+    }
+  }
+  
   while (stats->formatstr != NULL)
     {
       if (stats->prio > MaxPrio || !stats->enabled) {
@@ -44,33 +83,33 @@
         continue;
       }
       if (len != 0)
-	len += fprintf (stderr, " ");
+	len += AppendString(len, " ");
       else
         fputc ('\r', stderr);
       switch (stats->type) {
       case stat_noarg:
-	len += fprintf (stderr, stats->formatstr);
+	len += AppendString (len, stats->formatstr);
         break;
       case stat_intarg:
-	len += fprintf (stderr, stats->formatstr, stats->arg.intarg);
+	len += AppendString (len, stats->formatstr, stats->arg.intarg);
         break;
       case stat_stringarg:
-	len += fprintf (stderr, stats->formatstr, stats->arg.stringarg);
+	len += AppendString (len, stats->formatstr, stats->arg.stringarg);
         break;
       case stat_floatarg:
-	len += fprintf (stderr, stats->formatstr, stats->arg.floatarg);
+	len += AppendString (len, stats->formatstr, stats->arg.floatarg);
         break;
       case stat_doublearg:
-	len += fprintf (stderr, stats->formatstr, stats->arg.doublearg);
+	len += AppendString (len, stats->formatstr, stats->arg.doublearg);
         break;
       }
       stats++;
     }
-  left = LastLineLen - len;
+  left = LastLineLen - fprintf (stderr, "%s", tmpbuf);
   while (left-- > 0)
     fputc (' ', stderr);
-  LastLineLen = len;
   fputc ('\r', stderr);
+  LastLineLen = len;
 }
 
 /* msg has no final \n and no formatting */

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list