]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Work around the lack of %lld in msvcrt
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 2 Jun 2010 09:06:11 +0000 (09:06 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 2 Jun 2010 09:06:11 +0000 (09:06 +0000)
CMakeLists.txt
email.c
grepday.c
html.c
include/info.h
report.c
topsites.c
topuser.c
totday.c
totger.c

index 791381d43c2148e4efabbaed78ddee4c81162576..d6c70aa49bf220a9d87d65114babf89352f33206 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION "3-pre4")
 SET(sarg_BUILD "")
-SET(sarg_BUILDDATE "May-27-2010")
+SET(sarg_BUILDDATE "Jun-02-2010")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
diff --git a/email.c b/email.c
index e7227592e9cce78627a132e964d8896c96b72795..6e54850d8afc7e5343ed741eb1c2f59b4565af27 100644 (file)
--- a/email.c
+++ b/email.c
@@ -33,6 +33,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
    long long int ttnbytes=0, ttnacc=0, tnacc=0;
    long long int tnbytes=0, ttnelap=0, tnelap=0;
    long long int nacc, nbytes, elap;
+   long long int avgacc, avgelap;
    double perc=0.00;
    double perc2=0.00;
    int posicao=0;
@@ -82,7 +83,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #elif defined(__alpha) || __ALPHA
             fprintf(fp_top2,"%s\t%ld\t%ld\t%ld\n",olduser,tnbytes,tnacc,tnelap);
 #else
-            fprintf(fp_top2,"%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",olduser,tnbytes,tnacc,tnelap);
+            fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap);
 #endif
             ttnbytes+=tnbytes;
             ttnacc+=tnacc;
@@ -105,7 +106,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #elif defined(__alpha) || __ALPHA
       fprintf(fp_top2,"%s\t%ld\t%ld\t%ld\n",olduser,tnbytes,tnacc,tnelap);
 #else
-      fprintf(fp_top2,"%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",olduser,tnbytes,tnacc,tnelap);
+      fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap);
 #endif
       ttnbytes+=tnbytes;
       ttnacc+=tnacc;
@@ -134,7 +135,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #elif defined(__alpha) || __ALPHA
    fprintf(fp_top1,"TOTAL\t%ld\t%ld\t%ld\n",ttnbytes,ttnacc,ttnelap);
 #else
-   fprintf(fp_top1,"TOTAL\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",ttnbytes,ttnacc,ttnelap);
+   fprintf(fp_top1,"TOTAL\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)ttnbytes,(uint64_t)ttnacc,(uint64_t)ttnelap);
 #endif
    fclose(fp_top1);
 
@@ -210,7 +211,7 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #elif defined(__alpha) || __ALPHA
          fprintf(fp_top3,"%-7s %20s %8ld %15s %8s %9s %10ld\n",_("TOTAL")," ",ttnacc,fixnum(ttnbytes,1)," ",buildtime(ttnelap),ttnelap);
 #else
-         fprintf(fp_top3,"%-7s %20s %8"PRId64" %15s %8s %9s %10"PRId64"\n",_("TOTAL")," ",ttnacc,fixnum(ttnbytes,1)," ",buildtime(ttnelap),ttnelap);
+         fprintf(fp_top3,"%-7s %20s %8"PRIu64" %15s %8s %9s %10"PRIu64"\n",_("TOTAL")," ",(uint64_t)ttnacc,fixnum(ttnbytes,1)," ",buildtime(ttnelap),(uint64_t)ttnelap);
 #endif
       } else {
 #if defined(__FreeBSD__)
@@ -218,21 +219,29 @@ int geramail(const char *dirname, int debug, const char *outdir, const char *ema
 #elif defined(__alpha) || __ALPHA
          fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10ld %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
 #else
-         fprintf(fp_top3,"%7d %20s %8"PRId64" %15s %3.2lf%% %10s %10"PRId64" %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2);
+         fprintf(fp_top3,"%7d %20s %8"PRIu64" %15s %3.2lf%% %10s %10"PRIu64" %3.2lf%%\n",posicao,user,(uint64_t)nacc,fixnum(nbytes,1),perc,buildtime(elap),(uint64_t)elap,perc2);
 #endif
       }
    }
 
-   tnbytes=(totuser) ? ttnbytes / totuser : 0;
+   if (totuser>0) {
+      tnbytes=(totuser) ? ttnbytes / totuser : 0;
+      avgacc=ttnacc/totuser;
+      avgelap=ttnelap/totuser;
+   } else {
+      tnbytes=0;
+      avgacc=0;
+      avgelap=0;
+   }
 
    strcpy(strip1,_("AVERAGE"));
    strip_latin(strip1);
 #if defined(__FreeBSD__)
-   fprintf(fp_top3,"%-7s %20s %8qu %15s %8s %9s %10qu\n",strip1," ",ttnacc/totuser,fixnum(tnbytes,1)," ",buildtime(ttnelap/totuser),ttnelap/totuser);
+   fprintf(fp_top3,"%-7s %20s %8qu %15s %8s %9s %10qu\n",strip1," ",avgacc,fixnum(tnbytes,1)," ",buildtime(avgelap),avgelap);
 #elif defined(__alpha) || __ALPHA
-   fprintf(fp_top3,"%-7s %20s %8ld %15s %8s %9s %10ld\n",strip1," ",ttnacc/totuser,fixnum(tnbytes,1)," ",buildtime(ttnelap/totuser),ttnelap/totuser);
+   fprintf(fp_top3,"%-7s %20s %8ld %15s %8s %9s %10ld\n",strip1," ",avgacc,fixnum(tnbytes,1)," ",buildtime(avgelap),avgelap);
 #else
-   fprintf(fp_top3,"%-7s %20s %8"PRId64" %15s %8s %9s %10"PRId64"\n",strip1," ",ttnacc/totuser,fixnum(tnbytes,1)," ",buildtime(ttnelap/totuser),ttnelap/totuser);
+   fprintf(fp_top3,"%-7s %20s %8"PRIu64" %15s %8s %9s %10"PRIu64"\n",strip1," ",(uint64_t)avgacc,fixnum(tnbytes,1)," ",buildtime(avgelap),(uint64_t)avgelap);
 #endif
 
    fclose(fp_top1);
index 122fd7458e8324023ca8c089e0172a86dba9f0a8..ea0b437b811ff390d39bd3f9f64e04d928f56e4e 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -141,7 +141,7 @@ static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f
       if (sslen>gdata->string_size) {
          sstring = (char *)realloc(gdata->string,sslen);
          if (!sstring) {
-            debuga(_("realloc error (%"PRIu64" bytes required)\n"),(unsigned long long int)sslen);
+            debuga(_("realloc error (%"PRIu64" bytes required)\n"),(uint64_t)sslen);
             exit(EXIT_FAILURE);
          }
          gdata->string=(char *)sstring;
@@ -293,11 +293,11 @@ static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct
    double ymag;
 
    if (pdata->ymin<0.) {
-      debuga(_("Minimum for Y scale of the graph is out of range: %"PRId64"\n"),pdata->ymin);
+      debuga(_("Minimum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymin);
       return(-1);
    }
    if (pdata->ymax<=0.) {
-      debuga(_("Maximum for Y scale of the graph is out of range: %"PRId64"\n"),pdata->ymax);
+      debuga(_("Maximum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymax);
       return(-1);
    }
 
diff --git a/html.c b/html.c
index 22a94395ed8814d75c79e383c52af4e0d31cd7c4..a58d74f1d20afacc2bd859f03cc74e7a51071283 100644 (file)
--- a/html.c
+++ b/html.c
@@ -424,7 +424,11 @@ void htmlrel(void)
                }
                if(strcmp(user_ip,olduserip) != 0) {
                   sprintf(wwork1,"%s",fixnum(unbytes,1));
-                  fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRId64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
+                  /*
+                  This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+                  to print a long long int unless it is exactly 64-bits long.
+                  */
+                  fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRIu64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),(uint64_t)unelap);
 
                   strcpy(olduserip,user_ip);
                   unacc=0;
@@ -443,7 +447,11 @@ void htmlrel(void)
             unlink(tmp3);
 
             sprintf(wwork1,"%s",fixnum(unbytes,1));
-            fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRId64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),unelap);
+            /*
+            This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+            to print a long long int unless it is exactly 64-bits long.
+            */
+            fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%"PRIu64"</td></tr>\n",olduserip,wwork1,buildtime(unelap),(uint64_t)unelap);
          }
 
          unacc=0;
index 804e1433d5b9cd57346047728a9eb4a9e234a2ad..c9145fd3d6bfa55ff74afd8fb29613b9c8eaf133 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" May-27-2010"
+#define VERSION PACKAGE_VERSION" Jun-02-2010"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"
index b073154deaff7c070f3dd2248598a4677fb2ace0..3bf1b2bd66313a7ea0d91f8538f0208f5b2935c6 100644 (file)
--- a/report.c
+++ b/report.c
@@ -475,7 +475,11 @@ void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long
       exit(EXIT_FAILURE);
    }
 
-   fprintf(fp_ou,"%"PRId64"\t%"PRId64"\t%s\t%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
+   /*
+   This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+   to print a long long int unless it is exactly 64-bits long.
+   */
+   fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)nacc,(uint64_t)nbytes,oldurl,oldmsg,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache);
 
    fclose(fp_ou);
    ttopen=0;
@@ -507,7 +511,11 @@ static void gravatmpf(const struct userinfostruct *uinfo,const char *oldurl, lon
       exit(EXIT_FAILURE);
    }
 
-   fprintf(fp_ou,"%"PRId64"\t%"PRId64"\t%s\t%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache);
+   /*
+   This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+   to print a long long int unless it is exactly 64-bits long.
+   */
+   fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)nacc,(uint64_t)nbytes,oldurl,oldmsg,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache);
 
    if (fclose(fp_ou)==EOF) {
       debuga(_("Failed to close file %s - %s\n"),wdirname,strerror(errno));
@@ -547,8 +555,8 @@ static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinf
 
    hour=atoi(hora);
    fprintf(fp_ou,"%s\t%d",data,hour);
-   if((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRId64,bytes);
-   if((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRId64,elap);
+   if((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64,(uint64_t)bytes);
+   if((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64,(uint64_t)elap);
    fputs("\n",fp_ou);
 
    if (fclose(fp_ou)==EOF) {
@@ -578,7 +586,11 @@ static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname
       exit(EXIT_FAILURE);
    }
 
-   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%"PRId64"\t%"PRId64"\n",ip,url,data,hora,tam,elap);
+   /*
+   This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+   to print a long long int unless it is exactly 64-bits long.
+   */
+   fprintf(fp_ou,"%s\t%s\t%s\t%s\t%"PRIu64"\t%"PRIu64"\n",ip,url,data,hora,(uint64_t)tam,(uint64_t)elap);
 
    fclose(fp_ou);
 
@@ -589,7 +601,11 @@ static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname
 
 static void gravager(FILE *fp_gen, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache)
 {
-   fprintf(fp_gen,"%s\t%"PRId64"\t%"PRId64"\t%s\t%s\t%s\t%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",uinfo->id,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache);
+   /*
+   This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+   to print a long long int unless it is exactly 64-bits long.
+   */
+   fprintf(fp_gen,"%s\t%"PRIu64"\t%"PRIu64"\t%s\t%s\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",uinfo->id,(uint64_t)nacc,(uint64_t)nbytes,url,ip,hora,dia,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache);
    return;
 }
 
index 3742825ab6b0d71a693e419112cf28f42e284029..7e1c202975119c4547c860b6b734be9a9d7cea02 100644 (file)
@@ -114,7 +114,11 @@ void topsites(void)
       }
 
       if(strcmp(item.url,ourl) != 0) {
-         fprintf(fp_ou,"%"PRId64"\t%"PRId64"\t%"PRId64"\t%s\n",tnacc,tnbytes,tntime,ourl);
+         /*
+         This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+         to print a long long int unless it is exactly 64-bits long.
+         */
+         fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%s\n",(uint64_t)tnacc,(uint64_t)tnbytes,(uint64_t)tntime,ourl);
          url_len=strlen(item.url);
          if (url_len>=ourl_size) {
             ourl_size=url_len+1;
@@ -139,7 +143,11 @@ void topsites(void)
    longline_destroy(&line);
 
    if (ourl) {
-      fprintf(fp_ou,"%"PRId64"\t%"PRId64"\t%"PRId64"\t%s\n",tnacc,tnbytes,tntime,ourl);
+      /*
+      This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+      to print a long long int unless it is exactly 64-bits long.
+      */
+      fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%s\n",(uint64_t)tnacc,(uint64_t)tnbytes,(uint64_t)tntime,ourl);
       free(ourl);
    }
 
index 8913863421bde87fcfdb14fe5ff04e7bcd65e5ae..f63885a18bb10b54c299e57d38295b0d45ebb8ae 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -88,7 +88,11 @@ void topuser(void)
          totuser++;
 
          if (olduser[0] != '\0') {
-            fprintf(fp_top2,"%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
+            /*
+            This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+            to print a long long int unless it is exactly 64-bits long.
+            */
+            fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache);
 
             ttnbytes+=tnbytes;
             ttnacc+=tnacc;
@@ -114,7 +118,11 @@ void topuser(void)
    longline_destroy(&line);
 
    if (olduser[0] != '\0') {
-      fprintf(fp_top2,"%s\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache);
+      /*
+      This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+      to print a long long int unless it is exactly 64-bits long.
+      */
+      fprintf(fp_top2,"%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",olduser,(uint64_t)tnbytes,(uint64_t)tnacc,(uint64_t)tnelap,(uint64_t)tnincache,(uint64_t)tnoucache);
 
       ttnbytes+=tnbytes;
       ttnacc+=tnacc;
index 36ff220de32b7ff51793416139b0d3429f3a633a..38adc11f4713bd36267d2b033916cd3f1e0133e2 100644 (file)
--- a/totday.c
+++ b/totday.c
@@ -124,9 +124,9 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int index
       day=daynum%100;
       month=(daynum/100)%100;
       year=daynum/10000;
-      fprintf(fp_ou,"%d/%d/%d\t%"PRId64"",day,month,year,hour);
-      if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRId64"",tbytes[i]);
-      if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRId64"",telap[i]);
+      fprintf(fp_ou,"%d/%d/%d\t%d",day,month,year,(int)hour);
+      if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)tbytes[i]);
+      if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64"",(uint64_t)telap[i]);
       fputs("\n",fp_ou);
    }
 
index 77422398b416915130dd9ca38de92e994f94006b..a521b774fbf046ecc798b2ea7f25f2e6dc46bdc8 100644 (file)
--- a/totger.c
+++ b/totger.c
@@ -67,7 +67,11 @@ int totalger(const char *dirname, int debug, const char *outdir)
       exit(EXIT_FAILURE);
    }
 
-   if (fprintf(fp_in,"TOTAL\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\t%"PRId64"\n",tnacc,tnbytes,telap,tincache,toucache)<0) {
+   /*
+   This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable
+   to print a long long int unless it is exactly 64-bits long.
+   */
+   if (fprintf(fp_in,"TOTAL\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)tnacc,(uint64_t)tnbytes,(uint64_t)telap,(uint64_t)tincache,(uint64_t)toucache)<0) {
       debuga(_("Failed to write the total line in %s\n"),wger);
       exit(EXIT_FAILURE);
    }