]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - splitlog.c
Indent the configure script for more readability.
[thirdparty/sarg.git] / splitlog.c
index 82e5a2a015cf6a56378e6404b6db9d6bce2aad28..0816e03fdf381ebf13eca0842b9ee6241c115f53 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -44,9 +44,9 @@ US date format.
 \param splitprefix If not empty, the output file is written in separate files (one for each day) and
 the files are named after the day they contain prefixed with the string contained in this variable.
 */
-void splitlog(const char *arq, const char *df, int dfrom, int duntil, int convert, const char *splitprefix)
+void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix)
 {
-       FILE *fp_in;
+       FileObject *fp_in;
        FILE *fp_ou=NULL;
        char *buf;
        char data[30];
@@ -67,7 +67,8 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
                // '/' + '-YYYY-mm-dd' + '\0' == 13
                output_prefix_len=snprintf(output_file,sizeof(output_file)-12,"%s%s",outdir,splitprefix);
                if (output_prefix_len>=sizeof(output_file)-12) {
-                       debuga(_("(splitlog) Output path is too long: %s%s-YYYY-mm-dd\n"),outdir,splitprefix);
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
+                       debuga_more("%s%s-YYYY-mm-dd\n",outdir,splitprefix);
                        exit(EXIT_FAILURE);
                }
                autosplit=1;
@@ -78,13 +79,13 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
        if(arq[0] == '\0')
                arq="/var/log/squid/access.log";
 
-       if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
-               debuga(_("(splitlog) Cannot open log file %s - %s\n"),arq,strerror(errno));
+       if((fp_in=FileObject_Open(arq))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arq,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the log file %s\n"),arq);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),arq);
                exit(EXIT_FAILURE);
        }
        time(&min_tt);
@@ -92,7 +93,7 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
        while((buf=longline_read(fp_in,line))!=NULL) {
                getword_start(&gwarea,buf);
                if (getword(data,sizeof(data),&gwarea,' ')<0) {
-                       debuga(_("Invalid date found in file %s\n"),arq);
+                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),arq);
                        exit(EXIT_FAILURE);
                }
                tt=atoi(data);
@@ -109,7 +110,7 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
                        prev_month=t->tm_mon;
                        prev_day=t->tm_mday;
                        if (fp_ou && fclose(fp_ou)==EOF) {
-                               debuga(_("Failed to close file %s - %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        strftime(output_file+output_prefix_len, sizeof(output_file)-output_prefix_len, "-%Y-%m-%d", t);
@@ -119,7 +120,7 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
                        a second time.
                        */
                        if ((fp_ou=MY_FOPEN(output_file,(tt>=min_tt && tt<=max_tt) ? "a" : "w"))==NULL) {
-                               debuga(_("(splitlog) Cannot open output log file %s - %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        if (tt<min_tt) min_tt=tt;
@@ -129,7 +130,7 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
                if(!convert) {
                        fprintf(fp_ou,"%s %s\n",data,gwarea.current);
                } else {
-                       if(df[0]=='e')
+                       if (df=='e')
                                strftime(dia, sizeof(dia), "%d/%m/%Y", t);
                        else
                                strftime(dia, sizeof(dia), "%m/%d/%Y", t);
@@ -139,12 +140,13 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver
        }
 
        longline_destroy(&line);
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Failed to close file %s - %s\n"),arq,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
        }
        if (autosplit && fp_ou) {
                if (fclose(fp_ou)==EOF) {
-                       debuga(_("Failed to close file %s - %s\n"),output_file,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }