From 56b97279b03d9ff758528f6f2d6eeeff4cd3f09e Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Tue, 30 Sep 2014 20:49:14 +0200 Subject: [PATCH] Use a global constant instead of the "index.html" file name in the code 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 | 3 +++ index.c | 15 +++++++++------ indexonly.c | 2 +- log.c | 2 +- topuser.c | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/conf.h b/include/conf.h index 821ce85..e5617e6 100755 --- a/include/conf.h +++ b/include/conf.h @@ -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 64d9f64..c6065df 100644 --- 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,"%s",yearnum,yearnum); + fprintf(fp_ou,"%s",yearnum,INDEX_HTML_FILE,yearnum); if (IndexFields & INDEXFIELDS_DIRSIZE) fprintf(fp_ou,"%s",get_size(outdir,yearnum)); fputs("\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,"%s %s\n",monthnum,yearnum,nmonth); + fprintf(fp_ou2,"%s %s\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,"%s %s %s\n",daynum,yearnum,nmonth,daynum); + fprintf(fp_ou3,"%s %s %s\n",daynum,INDEX_HTML_FILE,yearnum,nmonth,daynum); } fputs("\n",fp_ou3); if (write_html_trailer(fp_ou3)<0) diff --git a/indexonly.c b/indexonly.c index 5e45643..6eef6a3 100644 --- a/indexonly.c +++ b/indexonly.c @@ -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 186e014..7479d8b 100644 --- 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; diff --git a/topuser.c b/topuser.c index 01015b5..83b3ef7 100644 --- 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); -- 2.39.2