From c5d6ef4b904b4797688534abbc36fd50ac01cfc8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Tue, 3 Jul 2012 12:12:44 +0200 Subject: [PATCH] Store the date and time in a structure The purpose is to store all the fields in a structure that will be exchanged with modules to read many more type of log files. --- readlog.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/readlog.c b/readlog.c index 8b7fb96..aa14807 100644 --- a/readlog.c +++ b/readlog.c @@ -89,7 +89,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) char hora[30]; char mes[30]; char tbuf2[128]; - char dia[128]; + char dia[128]=""; char wuser[MAXLEN]; char tmp3[MAXLEN]; char sz_Download_Unsort[20000]; @@ -131,13 +131,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) bool totper=false; struct stat logstat; struct getwordstruct gwarea; - struct tm *t; struct tm tt; struct userfilestruct *prev_ufile; struct userinfostruct *uinfo; struct userfilestruct *first_user_file=NULL; struct userfilestruct *ufile; struct userfilestruct *ufile1; + struct ReadLogStruct log_entry; time_t tnum; for (ilf=0 ; ilftm_year+1900)*10000+(t->tm_mon+1)*100+t->tm_mday; + idata=(log_entry.EntryTime->tm_year+1900)*10000+(log_entry.EntryTime->tm_mon+1)*100+log_entry.EntryTime->tm_mday; } } if (ilf==ILF_Sarg) { @@ -508,7 +508,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Invalid time found in %s\n"),arq); exit(EXIT_FAILURE); } - t=&tt; + log_entry.EntryTime=&tt; } if (ilf==ILF_Isa) { if (linebuf[0] == '#') { @@ -626,16 +626,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) exit(EXIT_FAILURE); } } - t=&tt; + log_entry.EntryTime=&tt; } - if (t==NULL) { + if (log_entry.EntryTime==NULL) { debuga(_("Unknown input log file format\n")); break; } - strftime(dia, sizeof(dia), "%d/%m/%Y", t); - snprintf(hora,sizeof(hora),"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec); - if(debugm) printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",Filter->DateRange,idata,dfrom,duntil); @@ -644,13 +641,11 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } // Record only hours usage which is required - if (t) { - if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL ) - continue; + if( bsearch( &( log_entry.EntryTime->tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL ) + continue; - if( bsearch( &( t -> tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL ) - continue; - } + if( bsearch( &( log_entry.EntryTime->tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL ) + continue; if(strlen(user) > MAX_USER_LEN) { @@ -734,7 +729,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } if(Filter->StartTime >= 0 && Filter->EndTime >= 0) { - hmr=t->tm_hour*100+t->tm_min; + hmr=log_entry.EntryTime->tm_hour*100+log_entry.EntryTime->tm_min; if(hmr < Filter->StartTime || hmr > Filter->EndTime) continue; } @@ -862,6 +857,9 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } } + strftime(dia, sizeof(dia), "%d/%m/%Y", log_entry.EntryTime); + strftime(hora,sizeof(hora),"%H:%M:%S",log_entry.EntryTime); + /*if ( strcmp ( user , sz_Last_User ) != 0 ) { if ( fp_Write_User ) fclose( fp_Write_User ) ; @@ -909,12 +907,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) if (ilf!=ILF_Sarg) { if(!totper || idatamaxdate) { maxdate=idata; - memcpy(&period.end,t,sizeof(*t)); + memcpy(&period.end,log_entry.EntryTime,sizeof(*log_entry.EntryTime)); } totper=true; } -- 2.47.3