home *** CD-ROM | disk | FTP | other *** search
- {beginning SAVEDEF.INC}
-
- { PROGRAM SaveDef; }
- { For DOS versions of Turbo only }
-
- (* The major portion of this routine was written by Brian Foley, with his
- special thanks to Randy Forgaard for his suggestions, as well as to Bob
- Tolz, Bela Lubkin, and James Troutman.
- The Function was modified to take advantage of standard identifiers
- (for me) and to avoid parameter matching.
- Brian did point out that this means two things:
- Only one area of the .COM file can be changed.
- If care is not taken with "Standard Headers" there could be
- two matching version strings.
- For the full documentation on this routine (in original) you must
- download MODIFY.PAS in Borland 100 sig DL 4.
- Thanks to Brian Foley for letting me include this routine in full in
- my source files.
-
- *)
-
-
- (*external typed constants must be in master file:
- VerCheck : string[14] = Version; {Beginning of constants must remain}
- ProgName : string[12] = 'PROGLIST.COM';{Name of Program to be changed }
- ProgPath : string[64] = ''; {Path of Program to be changed}
-
- {Other typed constants to be cloned.}
- Tail : byte = 0; {End of constants }
-
- Version is a Constant to keep the changes simple. *)
-
- Const
- {SaveDef error Constants}
- Err0 = ' : Was modified successfully.';
- Err1 = ' : Must be in logged directory.';
- Err2 = ' : Error reading.';
- Err3 = ' : Error writing.';
- Err4 = ' : No error msg.';
- Err5 = ' : Wrong Version or .COM file.';
- Err : array[0..5] of string[40] = (Err0,Err1,Err2,Err3,Err4,Err5);
-
-
-
- Function SaveDef : Byte;
- { Adapted Modify.Pas }
-
- VAR
- F : File;
- Data : Array[ 1..256 ] Of Byte Absolute VerCheck;
- Check : String[ 255 ] Absolute VerCheck;
- Actual : String[ 255 ];
- SavToStr : String[80];
- CheckSize,
- DataSize,
- Result : Integer;
- LABEL
- Stop;
-
-
- BEGIN
- SaveDef := 0; { Assume success }
- SavToStr := ProgPath + ProgName;
- Assign( F, SavToStr);
- {$I-}
- Reset( F, 1 );
- {$I+}
- IF IOResult <> 0 THEN BEGIN
- SaveDef := 1; { File wasn't found or couldn't be opened }
- GOTO Stop;
- END;
- {$I-}
- Seek( F, Ofs( VerCheck ) - $100 ); { Find position of header string in
- the .COM file; adjust for size of
- Program Segment Prefix }
- {$I+}
- IF IOResult <> 0 THEN BEGIN
- SaveDef := 2; { Error when trying to locate header }
- GOTO Stop;
- END;
- CheckSize := Succ( Ord( Check[0] ) ); { Length of the header string + 1 }
- BlockRead( F, Actual, CheckSize, Result );
- IF ( Result <> CheckSize ) Or ( Actual <> Check ) THEN BEGIN
- IF Result <> CheckSize THEN SaveDef := 2 { Read error }
- { Actual <> Check } ELSE SaveDef := 5; { Header strings don't match }
- GOTO Stop;
- END;
- DataSize := Ofs( Tail ) - ( Ofs( VerCheck ) + CheckSize );
- { Now, write everything--from the byte just beyond the header string
- to the tail marker--out to disk. File pointer already points to
- the first byte after the header string. }
- BlockWrite( F, Data[ Succ( CheckSize ) ], DataSize, Result );
- IF ( Result <> DataSize ) THEN SaveDef := 3; { Disk write error }
- Stop:
- Close( F );
- END;
- {end SAVEDEF.INC}