--- output.c.orig 2001-06-15 10:34:24.000000000 +0200 +++ output.c 2004-07-03 14:32:01.000000000 +0200 @@ -140,6 +140,26 @@ FILE *out_fp; + +/*********************************************/ +/* FORMAT_NUM - output format of number */ +/*********************************************/ +char * format_num(double in) +{ + static char *jednotky[] = { + " B", " kB", " MB", " GB", " TB" + }; + char **jednotka, *tmp; + static char out[100]; + for (jednotka = jednotky; in > 1024 && jednotka < jednotky+4; in /= 1024, ++jednotka); + snprintf(out, 45, "%.2f", in); + for (tmp = out + strlen(out) - 1; tmp > out && *tmp == '0'; *tmp-- = 0); + if (*tmp == '.') *tmp = 0; + strcat(out, *jednotka); + return out; +} + + /*********************************************/ /* WRITE_HTML_HEAD - output top of HTML page */ /*********************************************/ @@ -544,8 +564,8 @@ "\n",msg_h_total, msg_h_visits, t_visit); /* Total XFer */ fprintf(out_fp,"%s\n" \ - "%.0f" \ - "\n",msg_mtot_tx,t_xfer/1024); + "%s" \ + "\n",msg_mtot_tx,format_num(t_xfer)); fprintf(out_fp,"\n"); /**********************************************/ /* Unique Sites */ @@ -620,10 +640,11 @@ /* Max/Avg KBytes per Day */ fprintf(out_fp,"" \ "%s\n" \ - "%.0f\n" \ - "%.0f" \ - "\n",msg_mtot_mkd, - (t_xfer/1024)/days_in_month,max_xfer/1024); + "%s\n", + msg_mtot_mkd,format_num(t_xfer/days_in_month)); + fprintf(out_fp,"%s" \ + "\n",format_num(max_xfer)); + fprintf(out_fp,"\n"); /**********************************************/ /* response code totals */ @@ -713,9 +734,9 @@ "%3.02f%%\n", tm_site[i],PCENT(tm_site[i],t_site)); fprintf(out_fp,"" \ - "%.0f\n" \ + "%s\n" \ "%3.02f%%\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,"\n"); fprintf(out_fp,"\n"); @@ -801,11 +822,13 @@ th_page[i]/days_in_month,th_page[i], PCENT(th_page[i],t_page)); fprintf(out_fp, - "%.0f\n" \ - "%.0f\n" \ + "%s\n", + format_num(th_xfer[i]/days_in_month)); + fprintf(out_fp, + "%s\n" \ "%3.02f%%\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 +907,15 @@ "%3.02f%%\n" \ "%lu\n" \ "%3.02f%%\n" \ - "%.0f\n" \ + "%s\n" \ "%3.02f%%\n" \ "%lu\n" \ "%3.02f%%\n" \ "", 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 +1090,12 @@ "%d\n" \ "%lu\n" \ "%3.02f%%\n" \ - "%.0f\n"\ + "%s\n"\ "%3.02f%%\n" \ "", 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 +2060,14 @@ "%3.02f%%\n" \ "%lu\n" \ "%3.02f%%\n" \ - "%.0f\n" \ + "%s\n" \ "%3.02f%%\n" \ "%s\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 +2426,9 @@ hist_visit[s_mth]/days_in_month); fprintf(out_fp,"%lu\n", hist_site[s_mth]); - fprintf(out_fp,"%.0f\n", - hist_xfer[s_mth]); + fprintf(out_fp,"%s\n", +/* hist_xfer[s_mth]);*/ + format_num(hist_xfer[s_mth]*1024)); fprintf(out_fp,"%lu\n", hist_visit[s_mth]); fprintf(out_fp,"%lu\n", @@ -2422,7 +2447,7 @@ fprintf(out_fp,"" \ "%s\n",GREY,msg_h_totals); fprintf(out_fp,"" \ - "%.0f\n",GREY,gt_xfer); + "%s\n",GREY,format_num(gt_xfer*1024)); fprintf(out_fp,"" \ "%.0f\n",GREY,gt_visits); fprintf(out_fp,"" \