home *** CD-ROM | disk | FTP | other *** search
- Program Log;
- (****************************************************************************)
- (* *)
- (* LOG *)
- (* Revision 2.0 *)
- (* Written by Don Gancsos and Robert Wilcox *)
- (* *)
- (* A program which logs computer operation and calculates *)
- (* the elapsed time between log entries. *)
- (* Logs date, time, elapsed time and comment to the *)
- (* file "TIME.LOG" *)
- (* *)
- (* Use: LOG comment *)
- (* *)
- (* Modified by R. Wilcox 3-14-86 *)
- (* - Now puts log file in root directory of drive A *)
- (* rather than in the logged-in directory. *)
- (* - Uses command line (up to 50 characters) as comment. *)
- (* - Log file changed to 'TIME.LOG' (3-23-86) *)
- (* Rev 2.0 modifications 4-9-86 *)
- (* - Uses random file allowing a "SHOW" program to *)
- (* display start and end log entries with the *)
- (* calculated elapsed time. *)
- (* - Log file changed to 'NEWTIME.LOG'. *)
- (* *)
- (* Rev 3.0 modifications 5-10-87 by Rick Johnson *)
- (* *)
- (* Use: LOG <off|[comment] /a|/*> *)
- (* *)
- (* - Keeps log in random file 'TIME.LOG' in path *)
- (* C:\UTILITY. *)
- (* - Random file records now store: *)
- (* 1) Time category, e.g. 'B' for business. *)
- (* 2) Start date. *)
- (* 3) Start time. *)
- (* 4) End time. *)
- (* 5) Elapsed time (string). *)
- (* 6) Elapsed time (real no.). *)
- (* 8) Comment (up to 12 characters). *)
- (* - Session terminated and elapsed time calculated *)
- (* with 'LOG OFF' command. *)
- (* - Time category invoked with '/a' parameter where *)
- (* 'a' is any alpha character a through z. *)
- (* - Time categories 'B' and 'P' noted as 'Business' *)
- (* or 'Personal' use in program's screen messages *)
- (* - Times displayed and totaled with '/*' parameter *)
- (* and optionally written to disk file: *)
- (* 1) Text format for word processor or *)
- (* 2) Comma-delimited for spreadsheet. *)
- (* SHOW.COM no longer needed. *)
- (* *)
- (* *)
- (****************************************************************************)
-
-
- Type
- Datestring = string[8];
- CommandString = string[50];
- CommentString = string[12];
- Filename = string[24];
- Registers = record
- AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer;
- End;
-
- LogRec = Record
- usage: char; {usage type, i.e. business/personal}
- start_date_log : Datestring; {start date}
- start_time_log : Datestring; {start time}
- end_time_log : Datestring; {end time}
- elapsed_log : Datestring; {elapsed time}
- comment : CommentString; {comment}
- elapsed_real : Real; {elapsed time stored as real no.}
- end;
-
- Var
- Mon, Day, Year : string[2];
- logfile : file of LogRec;
- realtime : Real;
- Buffer : CommandString;
- CL : CommandString absolute cseg:$80;
- log_data : logrec;
- logoff : boolean;
-
- Const
- logfilename : filename = 'C:\UTILITY\TIME.LOG';
-
- Function Date: Datestring;
- var
- RSet : Registers;
- tempstring: Datestring;
- i: Integer;
- Begin
- With Rset do
- Begin
- AX := $2A00; { DOS get date function }
- MSDos(RSet);
- CX := cx mod 100;
- str(CX:2,year);
- str(Hi(DX):2,mon);
- str(Lo(DX):2,day);
- End;
- tempstring := mon + '/' + day + '/' + year;
- for i := 1 to 8 do
- if tempstring[i] = ' ' then
- tempstring[i] := '0';
- Date := tempstring;
- End;
-
- Function Time: Datestring;
- var
- RSet : registers;
- hour, minute, second : string[2];
- i : integer;
- tempstring : Datestring;
- Begin
- rset.ax := $2C * 256;
- MsDos(rset);
- str((rset.cx div 256):2,hour);
- str((rset.cx mod 256):2,minute);
- str((rset.dx div 256):2,second);
- tempstring := hour + ':' + minute + ':' + second;
- for i := 1 to 8 do
- if tempstring[i] = ' ' then
- tempstring[i] := '0';
- Time := tempstring;
- End; {Time}
-
- Function SecToString(secs: integer): Datestring;
- var
- t: integer;
- result: Datestring;
- tempresult: Datestring;
- Begin
- Str(secs div 3600:2,tempresult);
- result := tempresult + ':';
- t:= secs mod 3600;
- Str(t div 60:2,tempresult);
- result := result +tempresult + ':';
- Str(t mod 60:2,tempresult);
- result := result + tempresult;
- For t := 1 to 8 do if result[t] = ' ' then result[t] := '0';
- SecToString := result;
- end;
-
- Function elapsed_time(start_str, end_str: Datestring): Datestring;
- var
- i,j,k,starttime,endtime: integer;
- begin
- val(copy(end_str,1,2),i,j);
- endtime := i * 3600;
- val(copy(end_str,4,2),i,j);
- endtime := endtime + (i * 60);
- val(copy(end_str,7,2),i,j);
- endtime := endtime + i;
- val(copy(start_str,1,2),i,j);
- starttime := i * 3600;
- val(copy(start_str,4,2),i,j);
- starttime := starttime + (i * 60);
- val(copy(start_str,7,2),i,j);
- starttime := starttime + i;
- k := endtime - starttime;
- elapsed_time := SecToString(k);
- end;
-
- Function elapsed_real_time(tempstring: Datestring): real;
- var
- temp, temptime : real;
- err : integer;
- begin
- val(copy(tempstring,1,2),temptime,err); {get hours}
- val(copy(tempstring,4,2),temp,err);
- temptime := temptime + (temp/60); {get fraction of hours from minutes}
- val(copy(tempstring,7,2),temp,err);
- temptime := temptime + (temp/3600); {get fraction of hours from seconds}
- elapsed_real_time := temptime;
- end;
-
- Procedure initialize_variables;
- begin
- logoff:=false;
- log_data.usage := '@';
- log_data.start_date_log:= Date;
- log_data.start_time_log:= Time;
- log_data.end_time_log:= Time;
- log_data.elapsed_log:= '00:00:00';
- log_data.comment:= '';
- log_data.elapsed_real:=0;
- end;
-
- Function uppercase(tempstring: CommandString; startpos, number: integer): CommandString;
- var temp : CommandString;
- i : integer;
- begin
- if length(tempstring) >= startpos then
- begin
- tempstring:=copy(tempstring,startpos,number);
- for i := 1 to length(tempstring) do
- tempstring[i] := upcase(tempstring[i]);
- end
- else tempstring:='';
- uppercase:=tempstring;
- end; {procedure uppercase}
-
- procedure summarize;
- var
- total_time : real;
- category_total : array [64..90] of real;
- i, counter : integer;
- ch : char;
- disk_file,
- delimited : boolean;
- textfile : text;
- const
- textfilename : filename = 'C:\UTILITY\TIME.TXT';
- begin
- for i:=ord('A') to ord('Z') do
- category_total[i]:=0;
- total_time:=0;
- lowvideo; writeln; writeln;
- writeln('LOG''s summary function requested. This function will list the contents');
- writeln('of the TIME.LOG file to the screen. You may also have a copy written');
- writeln('to a disk file named TIME.TXT, which can be viewed by a word processor');
- writeln('or read into a spreadsheet.'); writeln; writeln;
- write('Would you like a disk file record of your logon/logoff file? (Y/N) ');
- read(kbd,ch); writeln(upcase(ch));
- writeln;
- if upcase(ch)='Y' then disk_file:=true else disk_file:=false;
- if disk_file then
- begin {get file specs}
- write('Would you like the file comma-delimited for spreadsheet use? (Y/N) ');
- read(kbd,ch); writeln(upcase(ch));
- if upcase(ch)='Y' then delimited:=true else delimited:=false;
- writeln;
- write('Would you like the file written to ',textfilename,'? (Y/N) ');
- read(kbd,ch); writeln(upcase(ch));
- if upcase(ch)='N' then
- begin {get new output filename}
- writeln;
- write('New drive/path/filename (max. 24 characters): ________________________');
- gotoXY(47,whereY);
- readln(textfilename);
- end;
- Assign(textfile,textfilename);
- rewrite(textfile);
- if delimited then
- begin
- write(textfile,'"USAGE","DATE","START TIME","END TIME",');
- writeln(textfile,'"RECORDED TIME","CALCULATED TIME","COMMENT"');
- end
- else
- begin
- writeln;
- writeln(textfile,' DATE START END ELAPSED COMMENT');
- end;
- end; {get file specs}
- counter:=22;
- for i:=0 to filesize(logfile)-1 do
- begin {read file loop}
- counter:=counter+1;
- if counter=23 then
- begin
- write('Press any key to continue... ');
- read(kbd,ch); writeln; writeln;
- writeln(' DATE START END ELAPSED COMMENT');
- counter:=0;
- end;
- seek(logfile,i);
- read(logfile,log_data);
- with log_data do
- begin
- write(usage,' ',start_date_log,' ',start_time_log,' ');
- writeln(end_time_log,' ',elapsed_log,' ',comment);
- if disk_file then
- begin
- if delimited then
- begin
- write(textfile,'"',usage,'","',start_date_log,'","',start_time_log,'","');
- write(textfile,end_time_log,'","',elapsed_log,'",');
- writeln(textfile,elapsed_real:6:2,',"',comment,'"');
- end {if delimited}
- else
- begin
- write(textfile,usage,' ',start_date_log,' ',start_time_log,' ');
- write(textfile,end_time_log,' ',elapsed_log,' ');
- writeln(textfile,elapsed_real:6:2,' hours, ',comment);
- end;
- end; {if disk file}
- end; {with log_data}
- if not (log_data.usage in ['A'..'Z']) then
- log_data.usage:='@';
- category_total[ord(log_data.usage)]:=
- category_total[ord(log_data.usage)]+log_data.elapsed_real;
- total_time:=total_time+log_data.elapsed_real;
- end; {read file loop}
- close(logfile);
- writeln; writeln; writeln('TOTAL LOGGED TIME: ',total_time:6:2,' Hours'); writeln;
- if disk_file then
- begin
- if delimited then
- begin
- writeln(textfile); writeln(textfile);
- writeln(textfile,'"TOTAL LOGGED TIME",',total_time:6:2); writeln(textfile);
- end
- else
- begin
- writeln(textfile); writeln(textfile);
- writeln(textfile,'TOTAL LOGGED TIME: ',total_time:6:2,' Hours');
- writeln(textfile);
- end;
- end; {if disk file}{header}
- for i:= 64 to 90 do
- begin {total time by category}
- if category_total[i]>0 then
- begin
- writeln(chr(i),': ',category_total[i]:6:2,' Hours (',
- category_total[i]/total_time:4:2,'% of total)');
- if disk_file and (not delimited) then writeln(textfile,chr(i),': ',category_total[i]:6:2,
- ' Hours (',category_total[i]/total_time:4:2,'% of total)');
- if disk_file and delimited then writeln(textfile,'"',chr(i),'",',category_total[i]:6:2,
- category_total[i]/total_time:4:2);
- end;
- end; {total time by category}
- if disk_file then close(textfile);
- writeln;
- halt;
- end; {subroutine}
-
- procedure give_instructions;
- begin
- writeln;
- writeln('LOG Time tracking utility');
- writeln;
- writeln('Usage:');
- writeln(' "LOG APPLICATION /X" to begin time tracking, where "APPLICATION"');
- writeln(' is the name of your project (up to 12');
- writeln(' characters) and the optional switch "X" can');
- writeln(' be any character A through Z (LOG assumes');
- writeln(' "B" is for business, "P" is for personal).');
- writeln;
- writeln(' "LOG OFF" to end time tracking on current project');
- writeln;
- writeln(' "LOG /*" to view log file and optionally write it');
- writeln(' to disk for use in an application program.');
- writeln;
- halt;
- end;
-
- Begin {program}
- lowvideo;
- initialize_variables;
- Buffer := CL; {move command line into buffer}
- if length(buffer)=0 then give_instructions;
- if length(buffer)>0 then
- begin {check for logoff flag}
- if uppercase(buffer,2,length(buffer))='OFF' then
- begin
- logoff:=true;
- delete(buffer,1,4);
- end; {if uppercase... }
- if (pos('/',buffer)>0) and (length(buffer)>pos('/',buffer)) then
- begin {set business/personal flag}
- log_data.Usage:=upcase(buffer[pos('/',buffer)+1]);
- Delete(buffer,pos('/',buffer),2);
- end;
- while (length(buffer)>0) and (buffer[1]=' ') do delete(buffer,1,1);
- while (length(buffer)>0) and (buffer[length(buffer)]=' ') do delete(buffer,length(buffer),1);
- end; {if length...}
-
- Assign(logfile,logfilename);
- {$I-}
- Reset(logfile);
- {$I+}
- If (ioresult = 1) then
- begin
- rewrite(logfile);
- write(logfile,log_data);
- writeln('Can''t find ',logfilename,',--creating new file.');
- delay(200);
- end;
-
- if log_data.usage='*' then summarize;
-
- if logoff then
- begin
- seek(logfile,filesize(logfile)-1);
- read(logfile,log_data);
- with log_data do
- begin
- end_time_log:= Time;
- elapsed_log:= elapsed_time(start_time_log,end_time_log);
- elapsed_real:=elapsed_real_time(elapsed_time(start_time_log,end_time_log));
- end; {with log_data}
- end {if logoff}
- else seek(logfile,filesize(logfile));
- if length(buffer)>0 then log_data.comment:=copy(buffer,1,12);
- Write(logfile,log_data);
- Close(logfile);
-
- if logoff then
- begin
- writeln;
- writeln;
- write('Logged ',log_data.elapsed_log);
- if length(log_data.comment)>0 then write(' toward ',log_data.comment);
- if log_data.usage<>#0 then
- begin
- if log_data.usage='B' then write(' as Business time');
- if log_data.usage='P' then write(' as Personal time');
- if log_data.usage='@' then write(' as Misc/Administrative time');
- if not (log_data.usage in ['B','P','@']) then
- write(' as "',log_data.usage,'" time');
- end; {if usage <>#0}
- writeln('.');
- delay(2000);
- end; {if logoff}
- End.