home *** CD-ROM | disk | FTP | other *** search
-
- PROGRAM DTSTAMP;
-
- {This routine is for changing the date/time stamp on a disk
- file. It is a useful supplement to the Norton's Utilities.
- These routines can also be used for adding the date and time
- to directory listings. JEH 10/8/86. }
-
- Uses Dos,
- Crt;
- TYPE
-
- String20 = string[20];
- String80 = string[80];
-
- Register = Registers;
-
- PROCEDURE Chirp; {A pleasantly soft audio signal. }
-
- Begin
-
- sound(2000);
- delay(8);
- nosound;
-
- End; {Chirp}
-
- PROCEDURE TrimLine (Var StrT : String);
-
- {Deletes leading and trailing spaces from input StrT. }
-
- Begin
-
- if Length (StrT) = 0 then
- Exit;
-
- while (StrT[ length (StrT) ] = #32) and (length (StrT) > 0) do
- StrT[0] := pred (StrT[0]); {Eliminate trailing blanks, }
-
- while (StrT[1] = #32) and (length (StrT) > 0) do
- delete (StrT, 1, 1);
-
- End; {TrimLine}
-
-
- FUNCTION HashDate (Date : String) : integer;
-
- {This takes as input a string in the form mm-dd-yy and hashes
- it to the code required by the DOS service call $57. It
- returns - 1 if the date is unacceptable. }
-
- {Hashed Date = (Year - 1980) * 512 + Month * 32 + Day}
-
- VAR
-
- C, K : integer;
- HoldS : String20;
- Code : integer;
- D, M, Y : integer;
-
- Begin
-
- HashDate := - 1; {Default return. }
- K := Pos ('-', Date);
- if K = 0 then
- Exit; {Bad format. }
-
- HoldS := copy (Date, 1, K - 1); {Get month. }
- Val (HoldS, M, C);
- IF C = 0 THEN
- IF Abs(M) > MaxInt THEN Exit;(* Version 4.0 can overflow on *)
- (* integers *)
-
- if C <> 0 then
- Exit;
- if not (M in [1..12]) then
- Exit;
- Delete (Date, 1, K);
-
- K := Pos ('-', Date); {Get day. }
- if K = 0 then
- Exit;
- HoldS := copy (Date, 1, K - 1);
- Val (HoldS, D, C);
- IF C = 0 THEN
- IF Abs(D) > MaxInt THEN Exit;(* Version 4.0 can overflow on *)
- (* integers *)
- if C <> 0 then
- Exit;
- if not (D in [1..31]) then
- Exit;
- Delete (Date, 1, K);
-
- Val (Date, Y, C); {Get year. }
- IF C = 0 THEN
- IF Abs(Y) > MaxInt THEN Exit;(* Version 4.0 can overflow on *)
- (* integers *)
- if C <> 0 then
- Exit;
- if not (Y in [80..100]) then
- Exit;
-
- Y := Y - 80;
-
- HashDate := 512 * Y + 32 * M + D;
-
- End; {HashDate (Date : String) : integer}
-
- FUNCTION UnHashDate (DOSDate : integer) : String;
-
- {Converts hashed DOS date Date to a string dd-mm-yy. }
- VAR
-
- J, K : integer;
- DS, MS, YS : string[5];
- D, M, Y : integer;
- R : real;
-
- Begin
-
- R := 1.0 * DOSDate;
- if R < 0 then
- R := R + 65536.0;
- Y := Trunc (R / 512.0);
- R := R - Y * 512.0;
- M := Trunc (R / 32.0);
- D := Trunc (R - (M * 32.0));
-
- Y := Y + 80;
- Str (Y, YS);
- Str (M:2, MS);
- Str (D, DS);
-
- while length (DS) < 2 do
- DS := '0' + DS;
-
- UnHashDate := MS + '-' + DS + '-' + YS;
-
- End; {UnHashDate (DOSDate : integer) : String}
-
- FUNCTION HashTime (Time : String) : integer;
-
- {Hashes input Time in the form of hr.min or hr:min to integer
- required by DOS. Returns - 1 if input not acceptable. }
- {Hashed time = Hour * 2048 + Min * 32. }
- VAR
-
- C, K : integer;
- H, M : integer;
- HoldS : String20;
-
- Begin
-
- HashTime := - 1; {Default return. }
- TrimLine (Time);
- K := Pos ('.', Time);
- if K = 0 then {Check for both terminators. }
- K := Pos (':', Time);
- if K = 0 then
- Exit; {Improper format. }
- HoldS := Copy (Time, 1, K - 1);
- Val (HoldS, H, C);
- IF C = 0 THEN
- IF Abs(H) > MaxInt THEN Exit;(* Version 4.0 can overflow on *)
- (* integers *)
- if C <> 0 then
- Exit;
- if not (H in [0..23]) then
- Exit;
- Delete (Time, 1, K);
- Val (Time, M, C);
- IF C = 0 THEN
- IF Abs(M) > MaxInt THEN Exit;(* Version 4.0 can overflow on *)
- (* integers *)
- if C <> 0 then
- Exit;
- if not (M in [0..59]) then
- Exit;
-
- HashTime := 2048 * H + 32 * M;
-
- End; {HashTime (Time : String) : integer}
-
- FUNCTION UnHashTime (DOSTime : integer; VAR APTime : String) : String;
-
- {Converts hashed DOSTime to string hr(24):min. APTime also
- returns the time in the am/pm format used in the DOS directory
- listing. }
- VAR
-
- H, M, HAP : integer;
- HS, MS : string[10];
- J, K : integer;
- R : real;
-
- Begin
-
- R := 1.0 * DOSTime; {Real necessary because DOSTime can }
- if R < 0 then {be < 0. }
- R := R + 65536.0;
- H := Trunc (R / 2048.0);
- R := R - (H * 2048.0);
- M := Trunc (R / 32.0);
-
- Str (H:2, HS);
- Str (M, MS);
- while length (MS) < 2 do
- MS := '0' + MS;
-
- UnHashTime := HS + ':' + MS;
-
- HAP := H Mod 12; {Format am/pm time. }
- if HAP = 0 then
- HAP := 12;
- Str (HAP:2, HS);
- APTime := HS + ':' + MS;
- if H > 11
- then
- APTime := APTime + 'p'
- else
- APTime := APTime + 'a';
-
- End; {UnHashTime (DOSTime : integer) : String}
-
-
- FUNCTION GetFileHandle (PathFileName : String) : integer;
-
- {Opens file 'PathFileName' and returns with the File Handle
- number. Returns - 1 if unable to open file. }
-
- VAR
-
- Reg : Register;
- DOSFileName : String;
- Handle : integer;
-
- Begin
-
- GetFileHandle := - 1; {Default return. }
- DOSFileName := PathFileName + #0; {Create ASCIIZ string. }
- with Reg do {Open DOS File. }
- begin
- AH := $3D; {DOS service for opening file. }
- AL := $0; {Access code. }
- DS := Seg (DOSFileName[1]);
- DX := Ofs (DOSFileName[1]);
- MsDos (Reg);
- if (Flags and 1) = 1 then {Unable to open file. }
- Exit;
- GetFileHandle := Reg.AX;
- end; {with}
-
- End; {GetFileHandle (PathFileName : String) : integer}
-
- FUNCTION ReleaseFileHandle (Handle : integer) : integer;
-
- {Closes file. Returns zero if OK or - 1 if error.}
- VAR
-
- Reg : Register;
-
- Begin
-
- ReleaseFileHandle := - 1; {Default return. }
- with Reg do
- begin
- AH := $3E; {DOS service for closing file handle.}
- BX := Handle; {File handle. }
- MsDos (Reg);
- if (Flags and 1) = 1 then
- Exit; {Error return. }
- end; {with}
-
- ReleaseFileHandle := 0;
-
- End; {ReleaseFileHandle (Handle : integer) : integer}
-
- FUNCTION GetDOSFileDateTime
- (Handle : integer; VAR DOSDate, DOSTime : integer) : integer;
-
- {Gets Date and Time hashed variables for a previously opened
- file. Returns 0 if OK and - 1 for an error. }
- VAR
-
- Reg : Register;
-
- Begin
-
- GetDOSFileDateTime := - 1; {Default return. }
- with Reg do
- begin {Get File date and time. }
- AH := $57; {DOS Date/Time service. }
- AL := $00; {Select Get. }
- BX := Handle;
- MsDos (Reg);
- if (Flags and 1) = 1 then
- Exit;
- DOSTime := CX;
- DOSDate := DX;
- end; {with}
-
- GetDOSFileDateTime := 0;
-
- End; {GetDOSFileDateTime
- (Handle : integer; VAR DOSDate, DOSTime : integer) : integer}
-
- FUNCTION SetDOSFileDateTime (Handle, DOSDate, DOSTime : integer) : integer;
-
- {Sets Date and Time for a previously opened file. Returns
- 0 if OK and - 1 for an error. }
- VAR
-
- Reg : Register;
-
- Begin
-
- SetDOSFileDateTime := - 1; {Default return. }
- with Reg do
- begin {Set File date and time. }
- AH := $57;
- AL := $01; {Select Set. }
- BX := Handle;
- CX := DOSTime;
- DX := DOSDate;
- MsDos (Reg);
- if (Flags and 1) = 1 then
- Exit;
- end; {with}
-
- SetDOSFileDateTime := 0;
-
- End; {SetDOSFileDateTime (Handle, DOSDate, DOSTime : integer) : integer}
-
- PROCEDURE Menu;
-
- CONST
-
- L1 = ' ROUTINE FOR CHANGING DATE AND TIME STAMP OF DISK FILES ';
- T = 8; {First line of menu. }
-
- VAR
-
- FileName : String;
- K : integer;
- Handle : integer;
- DOSDate : integer;
- DOSTime : integer;
- Date : String;
- Time : String;
- APTime : String;
- ch : char;
-
- Begin
-
- repeat {1}
- LowVideo;
- ClrScr;
- GoToXY (12, 5);
- NormVideo; Write (L1);
- GoToXY (57, 22);
- write (' JEH 10/86 ');
- LowVideo;
-
- repeat {2}
- GoToXY (5, T); ClrEol;
- write ('Enter Path/File Name (0 to Exit): ');
- NormVideo; read (FileName); LowVideo;
- TrimLine (FileName);
- if FileName = '0' then
- Exit;
- for K := 1 to Length (FileName) do
- FileName[K] := UpCase (FileName[K]);
- Handle := GetFileHandle (FileName);
- if Handle < 0 then
- begin
- Chirp;
- GoToXY (5, T + 2);
- write ('Unable to find ' + FileName + '. Please try again.');
- end;
- until Handle > 0; {Repeat (2)}
-
- K := GetDOSFileDateTime (Handle, DOSDate, DOSTime);
- Date := UnHashDate (DOSDate);
- Time := UnHashTime (DOSTime, APTime);
- GoToXY (5, T + 2); ClrEOL;
- write
- ('Present date and time for ' + FileName + ': ' + Date + ' ' + Time);
-
- repeat {3}
- GoToXY (5, T + 4); ClrEol;
- write (' Enter new date [mm-dd-yy]: ');
- NormVideo; readln (Date); LowVideo;
- TrimLine (Date);
- DOSDate := HashDate (Date);
- if DOSDate = - 1 then
- begin
- Chirp;
- GoToXY (5, T + 6);
- write (Date + ' is an invalid date. Please re-enter');
- end;
- until DOSDate <> - 1; {Repeat (3)}
-
- repeat {4}
- GoToXY (5, T + 6); ClrEol;
- write (' Enter new time [hr(24) : min]: ');
- NormVideo; readln(Time); LowVideo;
- TrimLine (Time);
- DOSTime := HashTime (Time);
- if DOSTime = - 1 then
- begin
- Chirp;
- GoToXY (5, T + 8);
- write (Time + ' is an invalid time. Please re-enter');
- end;
- until DOSTime <> - 1; {Repeat (4)}
-
- K := SetDOSFileDateTime (Handle, DOSDate, DOSTime);
- GoToXY (5, T + 8); ClrEol;
- if K >= 0
- then
- begin
- K := GetDOSFileDateTime (Handle, DOSDate, DOSTime);
- Date := UnHashDate (DOSDate);
- Time := UnHashTime (DOSTime, APTime);
- write ('Directory Date/Time entry for '
- + FileName + ' now reads: ' + Date + ' ' + APTime);
- end
- else
- write ('Updating of ' + FileName + ' failed.');
- K := ReleaseFileHandle (Handle);
- GoToXY (5, T + 10); ClrEol;
- write ('Press 0 to exit or any other key to continue. ');
- ch := ReadKey;
-
- until ch = '0'; {Repeat (1)}
-
- End; {Menu}
-
- BEGIN
-
- Menu;
- ClrScr;
-
- END.