home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PROLST.ZIP / SAVEDEF.INC < prev    next >
Encoding:
Text File  |  1986-11-08  |  3.4 KB  |  98 lines

  1. {beginning SAVEDEF.INC}
  2.  
  3.  {  PROGRAM SaveDef; }
  4.  {  For DOS versions of Turbo only }
  5.  
  6.  (* The major portion of this routine was written by Brian Foley, with his
  7.     special thanks to Randy Forgaard for his suggestions, as well as to Bob
  8.     Tolz, Bela Lubkin, and James Troutman.
  9.     The Function was modified to take advantage of standard identifiers
  10.       (for me) and to avoid parameter matching.
  11.    Brian did point out that this means two things:
  12.       Only one area of the .COM file can be changed.
  13.       If care is not taken with "Standard Headers" there could be
  14.         two matching version strings.
  15.    For the full documentation on this routine (in original) you must
  16.    download MODIFY.PAS in Borland 100 sig DL 4.
  17.    Thanks to Brian Foley for letting me include this routine in full in
  18.    my source files.
  19.  
  20.  *)
  21.  
  22.  
  23. (*external typed constants must be in master file:
  24.   VerCheck : string[14] = Version;       {Beginning of constants must remain}
  25.   ProgName : string[12] = 'PROGLIST.COM';{Name of Program to be changed }
  26.   ProgPath : string[64] = '';            {Path of Program to be changed}
  27.  
  28.     {Other typed constants to be cloned.}
  29.   Tail     : byte = 0;                   {End of constants }
  30.  
  31.   Version is a Constant to keep the changes simple.  *)
  32.  
  33. Const
  34.  {SaveDef error  Constants}
  35.       Err0 = ' : Was modified successfully.';
  36.       Err1 = ' : Must be in logged directory.';
  37.       Err2 = ' : Error reading.';
  38.       Err3 = ' : Error writing.';
  39.       Err4 = ' : No error msg.';
  40.       Err5 = ' : Wrong Version or .COM file.';
  41.  Err : array[0..5] of string[40] = (Err0,Err1,Err2,Err3,Err4,Err5);
  42.  
  43.  
  44.  
  45. Function SaveDef : Byte;
  46.   { Adapted Modify.Pas }
  47.  
  48.  VAR
  49.     F          : File;
  50.     Data       : Array[ 1..256 ] Of Byte Absolute VerCheck;
  51.     Check      : String[ 255 ] Absolute VerCheck;
  52.     Actual     : String[ 255 ];
  53.     SavToStr   : String[80];
  54.     CheckSize,
  55.     DataSize,
  56.     Result     : Integer;
  57.  LABEL
  58.     Stop;
  59.  
  60.  
  61. BEGIN
  62.     SaveDef := 0;               { Assume success }
  63.     SavToStr := ProgPath + ProgName;
  64.     Assign( F, SavToStr);
  65.     {$I-}
  66.     Reset( F, 1 );
  67.     {$I+}
  68.     IF IOResult <> 0 THEN BEGIN
  69.         SaveDef := 1;           { File wasn't found or couldn't be opened }
  70.         GOTO Stop;
  71.     END;
  72.     {$I-}
  73.     Seek( F, Ofs( VerCheck ) - $100 );  { Find position of header string in
  74.                                       the .COM file; adjust for size of
  75.                                       Program Segment Prefix }
  76.     {$I+}
  77.     IF IOResult <> 0 THEN BEGIN
  78.         SaveDef := 2;                { Error when trying to locate header }
  79.         GOTO Stop;
  80.     END;
  81.     CheckSize := Succ( Ord( Check[0] ) );  { Length of the header string + 1 }
  82.     BlockRead( F, Actual, CheckSize, Result );
  83.     IF ( Result <> CheckSize ) Or ( Actual <> Check ) THEN BEGIN
  84.         IF Result <> CheckSize THEN SaveDef := 2  { Read error }
  85.          { Actual <> Check }   ELSE SaveDef := 5; { Header strings don't match }
  86.         GOTO Stop;
  87.     END;
  88.     DataSize := Ofs( Tail ) - ( Ofs( VerCheck ) + CheckSize );
  89.        { Now, write everything--from the byte just beyond the header string
  90.          to the tail marker--out to disk.  File pointer already points to
  91.          the first byte after the header string. }
  92.     BlockWrite( F, Data[ Succ( CheckSize ) ], DataSize, Result );
  93.     IF ( Result <> DataSize ) THEN SaveDef := 3; { Disk write error }
  94.  Stop:
  95.     Close( F );
  96.  END;
  97. {end SAVEDEF.INC}
  98.