#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FNAME "./xeyez.txt"
#define MAXSIZE 1024
int iCaltall;
int icount;
int savetokey(char *buf, char *buftime, char *bufindex)
{
//printf(".......222222\n");
int i = 0;
int count = 0;
char buftmp[50];
//printf("buf:%s\n", buf);
while(buf[i] != '\0')
{
if (buf[i] == 't' && buf[i+1] == 'i')
{
//printf("entry time\n");
//buftime = buf + i + 4;
strcpy(buftmp , buf+i+5);
while(buftmp[count] != ',')
{
count++;
}
//printf("count:%d\n", count);
//buftmp[count] = '\0';
strncpy(buftime, buftmp, count);
buftime[count] = '\0';
printf("buftime:%s\n", buftime);
}
if (buf[i] == 'i' && buf[i + 1] == 'n')
{
//printf("entry index\n");
//bufindex = buf + i + 5;
strcpy(bufindex, buf+i+6);
printf("bufindex:%s\n", bufindex);
}
i++;
}
return 0;
}
int readline()
{
FILE *fp;
long timeA, timeB;
int dTime = 0;
char bufA[MAXSIZE];
char buf[MAXSIZE];
char bufB[MAXSIZE];
char buftimeA[50];
char buftimeB[50];
char bufindexA[20];
char bufindexB[20];
char buftime[50];
char bufindex[20];
if ((fp = fopen(FNAME, "r")) == NULL)
{
printf("fopen err!\n");
}
while(fgets(bufA, MAXSIZE, fp) != NULL)
{
//savetokey(bufA, buftimeA, bufindexA);
//fgets(bufA, MAXSIZE, fp);
//strcpy(bufA, buf);
//savetokey(bufA, buftimeA, bufindexA);
//fgets(bufB, MAXSIZE, fp);
//savetokey(bufA, buftimeB, bufindexB);
savetokey(bufA, buftime, bufindex);
if(!strcmp(bufindexA, bufindex))
{
timeA = atol(buftimeA);
timeB = atol(buftime);
dTime = timeB - timeA;
iCaltall += dTime;
printf("dTime:%d, count:%d\n", dTime, icount);
}
strcpy(buftimeA , buftime);
strcpy(bufindexA, bufindex);
//iCaltall += dTime;
icount++;
}
//iCaltall = iCaltall - dTime;
printf("tall: icaltall:%d, statical:%d, icount:%d\n", iCaltall, (iCaltall/icount), icount);
return 0;
}
int main(int argc, char *argv[])
{
iCaltall = 0;
icount = 0;
//printf(".......1111111\n");
readline();
return 0;
}