#define TIME_FILENAME "~/TimeClock/TimeFile.DAT.Z" #define TET_EOF 0 #define TET_PUNCH_IN 1 #define TET_PUNCH_OUT 2 class TimeEntry { TimeEntry *next,*last; U8 type; CDate datetime; U8 *desc; }; U0 TimeFileRead(TimeEntry *header) { U8 *buf,*ptr; I64 type; TimeEntry *tempt; buf=FileRead(TIME_FILENAME); if (!buf) buf=CAlloc(1); QueInit(header); ptr=buf; while (type=*ptr++) { tempt=CAlloc(sizeof(TimeEntry)); tempt->type=type; tempt->datetime=*ptr(CDate *)++; tempt->desc=StrNew(ptr); ptr+=StrLen(ptr)+1; QueIns(tempt,header->last); } Free(buf); } U0 TimeFileWrite(TimeEntry *header) { U8 *buf,*ptr; TimeEntry *tempt; I64 size=1; //for EOF tempt=header->next; while (tempt!=header) { size+=sizeof(U8)+sizeof(CDate)+StrLen(tempt->desc)+1; tempt=tempt->next; } buf=MAlloc(size); ptr=buf; tempt=header->next; while (tempt!=header) { *ptr++=tempt->type; *ptr(CDate *)++=tempt->datetime; StrCpy(ptr,tempt->desc); ptr+=StrLen(tempt->desc)+1; tempt=tempt->next; } *ptr=TET_EOF; FileWrite(TIME_FILENAME,buf,size); Free(buf); } U0 TimeEntriesDel(TimeEntry *header) { TimeEntry *tempt=header->next,*tempt1; while (tempt!=header) { tempt1=tempt->next; Free(tempt->desc); Free(tempt); tempt=tempt1; } Free(header); } public Bool TimeRep(TimeEntry **_header=NULL) { Bool is_in=FALSE,first=TRUE; I64 week,cur_week=-1,week_total; TimeEntry *tempt,*header=MAlloc(sizeof(TimeEntry)); if (_header) *_header=header; TimeFileRead(header); tempt=header->next; while (tempt!=header) { week=tempt->datetime.date/7; //TODO if (week!=cur_week) { if (!first) { if (is_in) week_total+=Now; "Week Total:%T\n",week_total-local_time_offset; } else first=FALSE; cur_week=week; week_total=0; } if (tempt->type==TET_PUNCH_IN) { "$$RED$$IN "; if (!is_in) week_total-=tempt->datetime; is_in=TRUE; } else { "$$RED$$OUT"; if (is_in) week_total+=tempt->datetime; is_in=FALSE; } " %D %T:$$FG$$\n%s\n",tempt->datetime,tempt->datetime,tempt->desc; tempt=tempt->next; } if (is_in) week_total+=Now; "$$RED$$Week Total:%T$$FG$$\n",week_total-local_time_offset; if (!_header) TimeEntriesDel(header); return is_in; } public U0 PunchOut() { TimeEntry *tempt,*header; if (!TimeRep(&header)) "$$BK,1$$Already Punched-Out$$BK,0$$\n"; else { tempt=MAlloc(sizeof(TimeEntry)); tempt->type=TET_PUNCH_OUT; tempt->datetime=Now; "\nEnter Description.\nPress when done.\n"; if (!(tempt->desc=GetStr(,,GSF_WITH_NEW_LINE))) tempt->desc=CAlloc(1); QueIns(tempt,header->last); TimeFileWrite(header); } TimeEntriesDel(header); } public U0 PunchIn() { TimeEntry *tempt,*header; if (TimeRep(&header)) "$$BK,1$$Already Punched-In$$BK,0$$\n"; else { tempt=MAlloc(sizeof(TimeEntry)); tempt->type=TET_PUNCH_IN; tempt->datetime=Now; "\nEnter Description.\nPress when done.\n"; if (!(tempt->desc=GetStr(,,GSF_WITH_NEW_LINE))) tempt->desc=CAlloc(1); QueIns(tempt,header->last); TimeFileWrite(header); } TimeEntriesDel(header); }