#include #include #include #include #include #include #include #ifdef __cplusplus atlExamine::atlExamine(void){ type=0; status=0; strcpy(nick,"nick_nDef"); strcpy(level,"level_nDef"); ttl_day=ttl_hour=ttl_min=0; ll_day=ll_month=ll_year=0; } atlExamine::~atlExamine(void){ } inline void atlExamine::reset(void){ atlExamine(); } inline int atlExamine::isDefined(void){ return(status==3?1:0); } int atlExamine::writeToStream(FILE*f){ return(fprintf(f,"%s %s %d-%d-%d %d.%d.%d ", nick,level,ttl_day,ttl_hour,ttl_min,ll_day,ll_month,ll_year)); } int atlExamine::analyze(const char*orig_buf){ char*buf; buf=discolorcopy(orig_buf); if(buf==NULL){ #if DEBUG fprintf(stderr,"atlExamine::analyze() ERROR: discolorcopy() returns NULL.\n"); #endif return(-1); } switch(status){ case 0: if(strstr(buf,ATL_EXANOEXIST_STR)!=NULL){ strcpy(nick,"nick_N/A"); strcpy(level,"level_N/A"); status=3; } else if(strstr(buf,ATL_EXASIGN1_STR)!=NULL&& strstr(buf,ATL_EXASIGN2_STR)!=NULL&& strstr(buf,ATL_EXASIGN3_STR)!=NULL){ sscanf(buf,"%*s %s",nick); status++; } break; case 1:{ int type=0; if((strstr(buf,ATL_EXA1LOGGED_STR)!=NULL||strstr(buf,ATL_EXA1LASTLOG_STR)!=NULL)&& strstr(buf,ATL_EXA1LEVEL_STR)){ sscanf(strendstr(buf,ATL_EXA1LEVEL_STR),"%7s",level); type=1; } if(strstr(buf,ATL_EXA2LOGGED_STR)!=NULL||strstr(buf,ATL_EXA2LASTLOG_STR)!=NULL){ sscanf(buf,"%s",level); type=2; } if(type){ /* Zistime si kedy tu bol naposledy. */ if(strstr(buf,type==1?ATL_EXA1LASTLOG_STR:ATL_EXA2LASTLOG_STR)!=NULL){ atl_getdate(strendstr(buf,type==1?ATL_EXA1LASTLOG_STR:ATL_EXA2LASTLOG_STR)+1,&ll_day,&ll_month,&ll_year); } else{ /* Zapiseme aktualny datum. */ time_t t; struct tm ttm; time(&t); ttm=*localtime(&t); ll_day=ttm.tm_mday; ll_month=ttm.tm_mon; ll_year=ttm.tm_year+1900; } status++; } }break; case 2: if(strstr(buf,ATL_EXA1TTL_STR)!=NULL){ sscanf(strendstr(buf,ATL_EXA1TTL_STR)," %d %*s %d %*s %d",&ttl_day,&ttl_hour,&ttl_min); status++; } if(strstr(buf,ATL_EXA2TTL_STR)!=NULL){ sscanf(strendstr(buf,ATL_EXA2TTL_STR)," %d %*s %d %*s %d",&ttl_day,&ttl_hour,&ttl_min); status++; } break; case 3: break; default: #if DEBUG fprintf(stderr,"atlExamine::analyze() WARNING: Bad status value (%d) changed to initial.\n",status); #endif status=0; break; } if(buf!=NULL)free(buf); return(isDefined()); } #endif /* #ifdef __cplusplus */