home *** CD-ROM | disk | FTP | other *** search
- PROGRAM ROReader;
-
- Type Regpack = Record Case Integer of
- 1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: Integer);
- 2: (AL,AH,BL,BH,CL,CH,DL,DH : Byte);
- End;
- String40 = String[40];
-
- Var Target: Text;
- Fname: String40;
- F_Attr: Integer;
- Myfault: Integer;
- Regs: Regpack;
- Textline: String40;
-
- {This procedure checks the attribute of a file. If file is write-
- protected, it saves the current attribute of the file and unlocks it.}
- procedure clear_attr(Fname : String40);
- Var TempName: String40;
- BEGIN
- TempName := Fname + Chr(0); {User's pathname in Fname}
- WITH Regs DO { Cap with 0H for DOS }
- Begin
- AL := $00; AH := $43; DS := Seg(TempName);
- DX := Ofs(TempName) + 1; {Go 1 beyond Length byte}
- F_Attr := 0; {Clear our attribute}
- CX := 0; {Clear CX for good measure}
- MsDOS(Regs);
- If (Flags AND $1 <> 0) then Exit;
- F_Attr := CX; {Save attribute}
- If Odd(CX) then {If locked CX will be odd}
- Begin
- AL := $01; {Set for writing}
- AH := $43;
- CX := CX AND $FE; {Turn off low bit}
- DS := Seg(TempName); DX := Ofs(TempName)+1;
- MsDOS(Regs);
- End;
- End;
- END;
-
- { This procedure restores a file attribute. The attribute is stored
- in F_Attrib. The user has stored the file name in variable Fname.}
- procedure restore_attr(Fname : String40);
- Var TempName: String40;
- BEGIN
- TempName := Fname + Chr(0); {Cap name with 0 for DOS}
- With Regs Do
- Begin
- AL := $01; {Set write mode}
- AH := $43;
- DS := Seg(TempName); DX := Ofs(TempName) + 1;
- CX := F_Attr; {Write old attribute out}
- MsDOS(Regs);
- End;
- F_Attr := 0; {Clear our attribute var}
- END;
- BEGIN
- Fname := 'LOCKTEST.TXT'; Assign(Target,Fname);
- Clear_Attr(Fname);
- {$I-} Reset(Target) {$I+};
- MyFault := IOResult; If MyFault <> 0 then
- Begin
- Writeln('Error #',MyFault,' on file open.');
- Exit;
- End;
- While NOT EOF(Target) DO
- BEGIN
- Readln(Target,Textline);
- Writeln(Textline)
- END;
- {$I-} Close(Target) {$I+};
- MyFault := IOResult;
- If MyFault <> 0 then Writeln('Error on file close');
- Restore_Attr(Fname);
- END.