From: Frederic Marchal Date: Tue, 9 Jun 2015 17:45:21 +0000 (+0200) Subject: Don't display the period covered by the logs if it is empty X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6fb8c79cdd27cfdc34a9fb0212e58854437c04c;p=thirdparty%2Fsarg.git Don't display the period covered by the logs if it is empty Sarg outputs a line with the earliest and latest dates found if the logs but it displays 00/01/00 if no log was found. It is best not to display anything in that case. --- diff --git a/include/defs.h b/include/defs.h index 369b56a..012a801 100644 --- a/include/defs.h +++ b/include/defs.h @@ -262,7 +262,7 @@ void make_index(void); // readlog.c int ReadLogFile(struct ReadLogDataStruct *Filter); -void GetLogPeriod(struct tm *Start,struct tm *End); +bool GetLogPeriod(struct tm *Start,struct tm *End); // realtime.c void realtime(void); diff --git a/log.c b/log.c index 30561a0..027a963 100644 --- a/log.c +++ b/log.c @@ -682,11 +682,12 @@ int main(int argc,char *argv[]) char date0[30], date1[30]; struct tm Start,End; - GetLogPeriod(&Start,&End); - strftime(date0,sizeof(date0),"%x",&Start); - strftime(date1,sizeof(date1),"%x",&End); - // TRANSLATORS: The %s are the start and end dates in locale format. - debuga(__FILE__,__LINE__,_("Period covered by log files: %s-%s\n"),date0,date1); + if (GetLogPeriod(&Start,&End)) { + strftime(date0,sizeof(date0),"%x",&Start); + strftime(date1,sizeof(date1),"%x",&End); + // TRANSLATORS: The %s are the start and end dates in locale format. + debuga(__FILE__,__LINE__,_("Period covered by log files: %s-%s\n"),date0,date1); + } } if (!LogStatus){ diff --git a/readlog.c b/readlog.c index dcbd220..31e307b 100644 --- a/readlog.c +++ b/readlog.c @@ -896,16 +896,21 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) /*! * Get the start and end date of the period covered by the log files. */ -void GetLogPeriod(struct tm *Start,struct tm *End) +bool GetLogPeriod(struct tm *Start,struct tm *End) { + bool Valid=false; + if (EarliestDate>=0) { memcpy(Start,&EarliestDateTime,sizeof(struct tm)); + Valid=true; } else { memset(Start,0,sizeof(struct tm)); } if (LatestDate>=0) { memcpy(End,&LatestDateTime,sizeof(struct tm)); + Valid=true; } else { memset(End,0,sizeof(struct tm)); } + return(Valid); }