This patch makes webalizer print byte counts in human readable format.
	Tomas Janousek <tomi@nomi.cz>, Ondrej Novy <onovy@nomi.cz>

--- output.c.old	2001-06-15 10:34:24.000000000 +0200
+++ output.c	2004-09-05 21:45:40.000000000 +0200
@@ -140,6 +140,30 @@
 
 FILE     *out_fp;
 
+
+/*********************************************/
+/* FORMAT_NUM - output format of number */
+/*********************************************/
+char * format_num(double in)
+{
+    static char *units[] = { "B", "KB", "MB", "GB", "TB" };
+    char **unit, *tmp;
+    static char out[50];
+
+    /* convert it to X Y, where X is less than 1024 and Y is the unit */
+    for (unit = units; in > 1024 && unit < units+sizeof(units)/sizeof(*units)-1;
+	    in /= 1024, ++unit);
+    snprintf(out, 40, "%.2f", in);
+
+    /* skip trailing zeros */
+    for (tmp = out + strlen(out) - 1; tmp > out && *tmp == '0'; *tmp-- = 0);
+    if (*tmp == '.') *tmp = 0;
+
+    strcat(out, "&nbsp;");
+    strcat(out, *unit);
+    return out;
+}
+
 /*********************************************/
 /* WRITE_HTML_HEAD - output top of HTML page */
 /*********************************************/
@@ -544,8 +568,8 @@
       "</FONT></TD></TR>\n",msg_h_total, msg_h_visits, t_visit);
    /* Total XFer */
    fprintf(out_fp,"<TR><TD WIDTH=380><FONT SIZE=\"-1\">%s</FONT></TD>\n"     \
-      "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%.0f</B>"              \
-      "</FONT></TD></TR>\n",msg_mtot_tx,t_xfer/1024);
+      "<TD ALIGN=right COLSPAN=2><FONT SIZE=\"-1\"><B>%s</B>"              \
+      "</FONT></TD></TR>\n",msg_mtot_tx,format_num(t_xfer));
    fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
    /**********************************************/
    /* Unique Sites */
@@ -620,10 +644,11 @@
    /* Max/Avg KBytes per Day */
    fprintf(out_fp,"<TR>"                                                     \
       "<TD><FONT SIZE=\"-1\">%s</FONT></TD>\n"                               \
-      "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
-      "<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%.0f</B>"                   \
-      "</FONT></TD></TR>\n",msg_mtot_mkd,
-      (t_xfer/1024)/days_in_month,max_xfer/1024);
+      "<TD ALIGN=right WIDTH=65><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n",
+      msg_mtot_mkd,format_num(t_xfer/days_in_month));
+   fprintf(out_fp,"<TD WIDTH=65 ALIGN=right><FONT SIZE=-1><B>%s</B>"         \
+      "</FONT></TD></TR>\n",format_num(max_xfer));
+
    fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
    /**********************************************/
    /* response code totals */
@@ -713,9 +738,9 @@
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n",
               tm_site[i],PCENT(tm_site[i],t_site));
       fprintf(out_fp,"<TD ALIGN=right>"                                      \
-              "<FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n"                  \
+              "<FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n"                  \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
-              tm_xfer[i]/1024,PCENT(tm_xfer[i],t_xfer));
+              format_num(tm_xfer[i]),PCENT(tm_xfer[i],t_xfer));
    }
    fprintf(out_fp,"<TR><TH HEIGHT=4></TH></TR>\n");
    fprintf(out_fp,"</TABLE>\n");
@@ -801,11 +826,13 @@
          th_page[i]/days_in_month,th_page[i],
          PCENT(th_page[i],t_page));
       fprintf(out_fp,
-         "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
-         "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
+         "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n",
+	 format_num(th_xfer[i]/days_in_month));
+      fprintf(out_fp,
+         "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n" \
          "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD></TR>\n",
-         (th_xfer[i]/days_in_month)/1024,th_xfer[i]/1024,
-         PCENT(th_xfer[i],t_xfer));
+         format_num(th_xfer[i]),
+	 PCENT(th_xfer[i],t_xfer));
       avg_file += th_file[i]/days_in_month;
       avg_xfer+= (th_xfer[i]/days_in_month)/1024;
    }
@@ -884,14 +911,15 @@
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"    \
               "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%lu</B></FONT></TD>\n"  \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"    \
-              "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
+              "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n" \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"    \
               "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%lu</B></FONT></TD>\n"  \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"    \
               "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
               i+1,hptr->count,
               (t_hit==0)?0:((float)hptr->count/t_hit)*100.0,hptr->files,
-              (t_file==0)?0:((float)hptr->files/t_file)*100.0,hptr->xfer/1024,
+              (t_file==0)?0:((float)hptr->files/t_file)*100.0,
+	      format_num(hptr->xfer),
               (t_xfer==0)?0:((float)hptr->xfer/t_xfer)*100.0,hptr->visit,
               (t_visit==0)?0:((float)hptr->visit/t_visit)*100.0);
 
@@ -1066,12 +1094,12 @@
             "<TD ALIGN=center><FONT SIZE=\"-1\"><B>%d</B></FONT></TD>\n" \
             "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%lu</B></FONT></TD>\n" \
             "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"   \
-            "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n"\
+            "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n"\
             "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"   \
             "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">",
             i+1,uptr->count,
             (t_hit==0)?0:((float)uptr->count/t_hit)*100.0,
-            uptr->xfer/1024,
+            format_num(uptr->xfer),
             (t_xfer==0)?0:((float)uptr->xfer/t_xfer)*100.0);
 
          if (uptr->flag==OBJ_GRP)
@@ -2036,14 +2064,14 @@
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"   \
               "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%lu</B></FONT></TD>\n" \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"   \
-              "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%.0f</B></FONT></TD>\n" \
+              "<TD ALIGN=right><FONT SIZE=\"-1\"><B>%s</B></FONT></TD>\n" \
               "<TD ALIGN=right><FONT SIZE=\"-2\">%3.02f%%</FONT></TD>\n"   \
               "<TD ALIGN=left NOWRAP><FONT SIZE=\"-1\">%s</FONT></TD></TR>\n",
               i+1,top_ctrys[i]->count,
               (t_hit==0)?0:((float)top_ctrys[i]->count/t_hit)*100.0,
               top_ctrys[i]->files,
               (t_file==0)?0:((float)top_ctrys[i]->files/t_file)*100.0,
-              top_ctrys[i]->xfer/1024,
+              format_num(top_ctrys[i]->xfer),
               (t_xfer==0)?0:((float)top_ctrys[i]->xfer/t_xfer)*100.0,
               top_ctrys[i]->desc);
    }
@@ -2402,8 +2430,9 @@
                       hist_visit[s_mth]/days_in_month);
       fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%lu</FONT></TD>\n",
                       hist_site[s_mth]);
-      fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%.0f</FONT></TD>\n",
-                      hist_xfer[s_mth]);
+      fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%s</FONT></TD>\n",
+/*                      hist_xfer[s_mth]);*/
+                      format_num(hist_xfer[s_mth]*1024));
       fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%lu</FONT></TD>\n",
                       hist_visit[s_mth]);
       fprintf(out_fp,"<TD ALIGN=right><FONT SIZE=\"-1\">%lu</FONT></TD>\n",
@@ -2422,7 +2451,7 @@
    fprintf(out_fp,"<TR><TH BGCOLOR=\"%s\" COLSPAN=6 ALIGN=left>"          \
           "<FONT SIZE=\"-1\">%s</FONT></TH>\n",GREY,msg_h_totals);
    fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>"                       \
-          "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_xfer);
+          "<FONT SIZE=\"-1\">%s</FONT></TH>\n",GREY,format_num(gt_xfer*1024));
    fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>"                       \
           "<FONT SIZE=\"-1\">%.0f</FONT></TH>\n",GREY,gt_visits);
    fprintf(out_fp,"<TH BGCOLOR=\"%s\" ALIGN=right>"                       \
