]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Use a global constant instead of the "index.html" file name in the code
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Tue, 30 Sep 2014 18:49:14 +0000 (20:49 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Tue, 30 Sep 2014 18:49:14 +0000 (20:49 +0200)
The name of the html index file is defined once in the source code as a
global constant instead of littering the source code with a hard coded
litteral string.

include/conf.h
index.c
indexonly.c
log.c
topuser.c

index 821ce85a924af528f6ae5dac7b0fdfe5f556f218..e5617e6b1ee10334215078236ba2492a20f9cc80 100755 (executable)
@@ -282,6 +282,9 @@ Sarg will complain that there are too many days in the files if this limit is ov
 //! Maximum number of limit files that can be stored.
 #define MAX_USER_LIMITS 16
 
+//! Name of the html file containing the index of a report file.
+#define INDEX_HTML_FILE "index.html"
+
 struct periodstruct
 {
    //! The first date of the period.
diff --git a/index.c b/index.c
index 64d9f646345efdbe1c0f87cbb35d1cc56b0ed504..c6065df4ea51f4e01256f092a3fa937784d01d6c 100644 (file)
--- a/index.c
+++ b/index.c
@@ -51,7 +51,10 @@ void make_index(void)
                return;
        }
 
-       if(debug) debuga(_("Making index.html\n"));
+       if(debug) {
+               // TRANSLATORS: The %s is the name of the html index file (index.html).
+               debuga(_("Making %s\n"),INDEX_HTML_FILE);
+       }
 
        // convert any old report hierarchy
        if ((dirp = opendir(outdir)) == NULL) {
@@ -156,7 +159,7 @@ static void make_date_index(void)
                else
                        year=yearsort[nyears-1-y];
                sprintf(yearnum,"%04d",year);
-               fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s</a></td>",yearnum,yearnum);
+               fprintf(fp_ou,"<tr><td class=\"data2\"><a href=\"%s/%s\">%s</a></td>",yearnum,INDEX_HTML_FILE,yearnum);
                if (IndexFields & INDEXFIELDS_DIRSIZE)
                        fprintf(fp_ou,"<td class=\"data2\">%s</td>",get_size(outdir,yearnum));
                fputs("</tr>\n",fp_ou);
@@ -190,7 +193,7 @@ static void make_date_index(void)
                        nmonths++;
                }
                closedir(dirp2);
-               sprintf(monthindex,"%s/index.html",yeardir);
+               sprintf(monthindex,"%s/"INDEX_HTML_FILE,yeardir);
                if((fp_ou2=fopen(monthindex,"w"))==NULL) {
                        debuga(_("(index) Cannot open file %s: %s\n"),monthindex,strerror(errno));
                        exit(EXIT_FAILURE);
@@ -219,7 +222,7 @@ static void make_date_index(void)
                                sprintf(monthnum,"%02d",m1);
                                name_month(nmonth,sizeof(nmonth));
                        }
-                       fprintf(fp_ou2,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s %s</a></td></tr>\n",monthnum,yearnum,nmonth);
+                       fprintf(fp_ou2,"<tr><td class=\"data2\"><a href=\"%s/%s\">%s %s</a></td></tr>\n",monthnum,INDEX_HTML_FILE,yearnum,nmonth);
 
                        sprintf(monthdir,"%s/%s",yeardir,monthnum);
                        // month dir
@@ -251,7 +254,7 @@ static void make_date_index(void)
                                ndays++;
                        }
                        closedir(dirp3);
-                       sprintf(dayindex,"%s/index.html",monthdir);
+                       sprintf(dayindex,"%s/"INDEX_HTML_FILE,monthdir);
                        if((fp_ou3=fopen(dayindex,"w"))==NULL) {
                                debuga(_("(index) Cannot open file %s: %s\n"),dayindex,strerror(errno));
                                exit(EXIT_FAILURE);
@@ -273,7 +276,7 @@ static void make_date_index(void)
                                } else {
                                        sprintf(daynum,"%02d",d1);
                                }
-                               fprintf(fp_ou3,"<tr><td class=\"data2\"><a href=\"%s/index.html\">%s %s %s</a></td></tr>\n",daynum,yearnum,nmonth,daynum);
+                               fprintf(fp_ou3,"<tr><td class=\"data2\"><a href=\"%s/%s\">%s %s %s</a></td></tr>\n",daynum,INDEX_HTML_FILE,yearnum,nmonth,daynum);
                        }
                        fputs("</table></div>\n",fp_ou3);
                        if (write_html_trailer(fp_ou3)<0)
index 5e45643653c175a9525c70f82df830ce50f81ca4..6eef6a3e98d5433233608aceec38382687750086 100644 (file)
@@ -39,7 +39,7 @@ void index_only(const char *dirname,int debug)
                exit(EXIT_FAILURE);
        }
        while ( (direntp = readdir( dirp )) != NULL ){
-               if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0 || strcmp(direntp->d_name, "index.html") == 0)
+               if(strcmp(direntp->d_name,".") == 0 || strcmp(direntp->d_name,"..") == 0 || strcmp(direntp->d_name, INDEX_HTML_FILE) == 0)
                        continue;
 
                if (snprintf(remove,sizeof(remove),"%s/%s",dirname,direntp->d_name)>=sizeof(remove)) {
diff --git a/log.c b/log.c
index 186e0148ee080508b0d336dd920922b4f61e7f67..7479d8b4711bb34f00854e6ac8d7f04211da532b 100644 (file)
--- a/log.c
+++ b/log.c
@@ -149,7 +149,7 @@ int main(int argc,char *argv[])
        DateFormat='u';
        OverwriteReport=false;
        RemoveTempFiles=true;
-       strcpy(ReplaceIndex,"index.html");
+       strcpy(ReplaceIndex,INDEX_HTML_FILE);
        Index=INDEX_YES;
        RecordsWithoutUser=RECORDWITHOUTUSER_IP;
        UseComma=0;
index 01015b5c1e54abae4321baf4c28256e962b6df65..83b3ef765ecc5db434dc0f860c7c2e84664ea51b 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -212,7 +212,7 @@ void topuser(void)
                exit(EXIT_FAILURE);
        }
 
-       snprintf(top3,sizeof(top3),"%s/index.html",outdirname);
+       snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname);
        if((fp_top3=fopen(top3,"w"))==NULL) {
                debuga(_("(topuser) Cannot open file %s: %s\n"),top3,strerror(errno));
                exit(EXIT_FAILURE);