Index: src/main.c
===================================================================
RCS file: /cvsroot/curl/curl/src/main.c,v
retrieving revision 1.319
diff -u -r1.319 main.c
--- src/main.c	27 Apr 2005 21:24:58 -0000	1.319
+++ src/main.c	30 Apr 2005 22:58:37 -0000
@@ -307,6 +307,11 @@
 #define GETOUT_UPLOAD  (1<<3)   /* if set, -T has been used */
 #define GETOUT_NOUPLOAD  (1<<4) /* if set, -T "" has been used */
 
+typedef enum {
+    TRACE_BIN,   /* tcpdump inspired look */
+    TRACE_ASCII, /* like *BIN but without the hex output */
+    TRACE_PLAIN  /* -v/--verbose type */
+} trace;
 
 static void help(void)
 {
@@ -501,7 +506,7 @@
   char *trace_dump; /* file to dump the network trace to, or NULL */
   FILE *trace_stream;
   bool trace_fopened;
-  bool trace_ascii;
+  trace tracetype;
   long httpversion;
   bool progressmode;
   bool nobuffer;
@@ -1433,10 +1438,11 @@
 #endif
       case 'g': /* --trace */
         GetStr(&config->trace_dump, nextarg);
+        config->tracetype = TRACE_BIN;
         break;
       case 'h': /* --trace-ascii */
         GetStr(&config->trace_dump, nextarg);
-        config->trace_ascii = TRUE;
+        config->tracetype = TRACE_ASCII;
         break;
       case 'i': /* --limit-rate */
         {
@@ -2083,7 +2089,8 @@
       checkpasswd("proxy", &config->proxyuserpwd);
       break;
     case 'v':
-      config->conf ^= CONF_VERBOSE; /* talk a lot */
+      GetStr(&config->trace_dump, (char *)"%");
+      config->tracetype = TRACE_PLAIN;
       break;
     case 'V':
     {
@@ -2744,14 +2751,14 @@
 static
 void dump(const char *text,
           FILE *stream, unsigned char *ptr, size_t size,
-          bool nohex)
+          trace tracetype)
 {
   size_t i;
   size_t c;
 
   unsigned int width=0x10;
 
-  if(nohex)
+  if(tracetype == TRACE_ASCII)
     /* without the hex output, we can fit more on screen */
     width = 0x40;
 
@@ -2761,7 +2768,7 @@
 
     fprintf(stream, "%04zx: ", i);
 
-    if(!nohex) {
+    if(tracetype == TRACE_BIN) {
       /* hex not disabled, show it */
       for(c = 0; c < width; c++)
         if(i+c < size)
@@ -2772,14 +2779,16 @@
 
     for(c = 0; (c < width) && (i+c < size); c++) {
       /* check for 0D0A; if found, skip past and start a new line of output */
-      if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
+      if ((tracetype == TRACE_ASCII) &&
+          (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
         i+=(c+2-width);
         break;
       }
       fprintf(stream, "%c",
               (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
       /* check again for 0D0A, to avoid an extra \n if it's at width */
-      if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
+      if ((tracetype == TRACE_ASCII) &&
+          (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
         i+=(c+3-width);
         break;
       }
@@ -2803,6 +2812,9 @@
     /* open for append */
     if(curlx_strequal("-", config->trace_dump))
       config->trace_stream = stdout;
+    else if(curlx_strequal("%", config->trace_dump))
+      /* Ok, this is somewhat hackish but we do it undocumented for now */
+      config->trace_stream = stderr;
     else {
       config->trace_stream = fopen(config->trace_dump, "w");
       config->trace_fopened = TRUE;
@@ -2812,6 +2824,58 @@
   if(config->trace_stream)
     output = config->trace_stream;
 
+  if(config->tracetype == TRACE_PLAIN) {
+    /*
+     * This is the trace look that is similar to what libcurl makes on its
+     * own, but we prepend the current time.
+     */
+    static const char * const s_infotype[CURLINFO_END] = {
+      "*", "<", ">"
+    };
+    struct timeval tv = curlx_tvnow();
+    struct tm *now =
+      localtime(&tv.tv_sec); /* not multithread safe but we don't care */
+    size_t i;
+    int st=0;
+    static bool newl = FALSE;
+    char timebuf[12];
+    snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%02d",
+             now->tm_hour, now->tm_min, now->tm_sec,
+             tv.tv_usec/10000);
+
+    switch(type) {
+    case CURLINFO_HEADER_OUT:
+      for(i=0; i<size-1; i++) {
+        if(data[i] == '\n') { /* LF */
+          if(!newl) {
+            fprintf(config->trace_stream, "%s %s ",
+                    timebuf, s_infotype[type]);
+          }
+          fwrite(data+st, i-st+1, 1, config->trace_stream);
+          st = i+1;
+          newl = FALSE;
+        }
+      }
+      if(!newl)
+        fprintf(config->trace_stream, "%s %s ", timebuf, s_infotype[type]);
+      fwrite(data+st, i-st+1, 1, config->trace_stream);
+      break;
+    case CURLINFO_TEXT:
+    case CURLINFO_HEADER_IN:
+      if(!newl)
+        fprintf(config->trace_stream, "%s %s ", timebuf, s_infotype[type]);
+      fwrite(data, size, 1, config->trace_stream);
+      break;
+    default: /* nada */
+      break;
+    }
+
+    newl = (size && (data[size-1] != '\n'));
+
+    return 0;
+  }
+
+
   switch (type) {
   case CURLINFO_TEXT:
     fprintf(output, "== Info: %s", data);
@@ -2838,7 +2902,7 @@
     break;
   }
 
-  dump(text, output, data, size, config->trace_ascii);
+  dump(text, output, data, size, config->tracetype);
   return 0;
 }
 
@@ -3685,9 +3749,8 @@
         if(config->trace_dump) {
           curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
           curl_easy_setopt(curl, CURLOPT_DEBUGDATA, config);
-          config->conf |= CONF_VERBOSE; /* force verbose */
+          curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
         }
-        curl_easy_setopt(curl, CURLOPT_VERBOSE, config->conf&CONF_VERBOSE);
 
         res = CURLE_OK;
 
