home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0817.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  6.0 KB  |  163 lines

  1. Program DeterminOVROrder;
  2. { This program is used to display the oreder of the units in  }
  3. { a program as they were placed into the OVR file.  Since     }
  4. { each unit contains a call to a signature procedure, we will }
  5. { read from a file that contains a unit name and its unique   }
  6. { signature.  Then, when we find a signature within the OVR   }
  7. { file, we can output the unit name that has that signature.  }
  8. { This should be saved with the file name OVRORDER.PAS        }
  9.  
  10. Uses
  11.   Crt, Dos;             { Necessary Support Units             }
  12.  
  13. Const
  14.   MaxSigs = 100;        { Maximum number of signatures        }
  15.  
  16. Type
  17.   SigType = Array[1..2] of Byte; { Size of each signature     }
  18.  
  19.   SigRec = Record       { Type to hold name and signature     }
  20.     UnitName : String;
  21.     Signature : SigType;
  22.   End;
  23.  
  24. Var
  25.   F : File of Byte;     { Open the OVR file as a file of BYTE }
  26.   TotalSigs,            { Total number read from sig file     }
  27.   B : Byte;             { Value read from the file            }
  28.   Signatures : Array[1..MaxSigs] of SigRec;
  29.   SigRead : SigType;    { Signature read from the OVR file    }
  30.   SigFileName,          { Name of the Signature File          }
  31.   OvrFileName : String; { Name of the OVR file used as input  }
  32.  
  33. Function Exists( FName : String ) : Boolean;
  34. { This function uses a new technique to determine if a file   }
  35. { exists.  It uses the FExpand function, and passes it the    }
  36. { name of the file we are looking for.  If FExpand returns a  }
  37. { NUL string, then ther file does not exist in the current    }
  38. { directory.  Note that this can be changed to accept a       }
  39. { second parameter, which would be a list of directories to   }
  40. { search.                                                     }
  41.  
  42. Var
  43.   S : String;     { Result of call to FSearch Function        }
  44.  
  45. Begin
  46.   FName := FExpand( FName );{ Expand the name to a full name  }
  47.   S := FSearch( FName, '' );{ Check for existence of file     }
  48.   Exists := S <> '';        { Return result in function name  }
  49. End;
  50.  
  51. Function GetFileNames( Var S, O : String ) : Boolean;
  52. { This function will read the command line for the two files  }
  53. { that will be searched.  If either of them is not found, or  }
  54. { if there are not two arguments on the command line, the     }
  55. { function will return FALSE.  It also returns FALSE if       }
  56. { either of the two files do not exist.  Otherwise, it will   }
  57. { return TRUE, and the program will continue.                 }
  58.  
  59. Begin
  60.   GetFileNames := True;     { Assume success                  }
  61.   If( ParamCount < 2 ) Then { See how many parameters passed  }
  62.   Begin                     { If fewer than two, quit         }
  63.     Writeln( 'Usage:  OVRORDER signaturefile ovrfile' );
  64.     Writeln;
  65.     GetFileNames := False;  { Set result to Failure           }
  66.     Exit;
  67.   End;
  68.   S := ParamStr( 1 );       { Get first command line argument }
  69.   If( Not( Exists( S ) ) ) Then
  70.   Begin                     { If file not there, fail         }
  71.     Writeln( 'Signature file NOT FOUND.' );
  72.     Writeln;
  73.     GetFileNames := False;
  74.     Exit;
  75.   End;
  76.   O := ParamStr( 2 );      { Get second command line argument }
  77.   If( Not( Exists( O ) ) ) Then
  78.   Begin
  79.     Writeln( 'Overlay file NOT FOUND.' );
  80.     Writeln;
  81.     GetFileNames := False;
  82.   End;
  83. End;
  84.  
  85. Procedure ReadSigFile( FName : String );
  86. { This procedure will read from the signature file, the unit  }
  87. { name and its corresponding signature.                       }
  88.  
  89. Var
  90.   Temp,
  91.   S : String;              { Temporary working strings        }
  92.   Err,                     { Result of calling VAL procedure  }
  93.   Index,                   { Index into the SigRec Array      }
  94.   P : Integer;             { Result of Pos function call      }
  95.   F : Text;                { Input File Variable              }
  96.  
  97. Begin
  98.   FillChar( Signatures, SizeOf( Signatures ), #0 );
  99.   Assign( F, FName );
  100.   Reset( F );              { Open the Input File              }
  101.   Index := 1;              { Set Starting position            }
  102.   While( ( Not( EOF( F ) ) ) And ( Index <= MaxSigs ) ) Do
  103.   Begin
  104.     Readln( F, S );        { Read a data item                 }
  105.     P := Pos( ' ', S );    { Parse the information            }
  106.     Signatures[Index].UnitName := Copy( S, 1, P - 1 );
  107.     Delete( S, 1, P );
  108.     P := Pos( ' ', S );
  109.     Temp := Copy( S, 1, P - 1 );
  110.     Val( Temp, Signatures[Index].Signature[1], Err );
  111.     Delete( S, 1, P );
  112.     Val( S, Signatures[Index].Signature[2], Err );
  113.   End;
  114.   TotalSigs := Index;
  115.   Close( F );
  116. End;
  117.  
  118. Procedure ShowIt( S : SigType );
  119. { This procedure will step through the array of signatures,   }
  120. { and write out the unit name that has the signature passed.  }
  121. { If no signature is found, the procedure will terminate.     }
  122.  
  123. Var
  124.   Index : Byte;            { Index into Signature Array       }
  125.  
  126. Begin
  127.   Index := 1;
  128.   While( Index <= TotalSigs ) Do
  129.   Begin
  130.     If( ( Signatures[Index].Signature[1] = S[1] ) And
  131.         ( Signatures[Index].Signature[2] = S[2] ) ) Then
  132.     Begin
  133.       GotoXY( 10,WhereY ); { Position the cursor for output   }
  134.       Writeln( Signatures[Index].UnitName );
  135.       Exit;
  136.     End;
  137.     Inc( Index );
  138.   End;
  139. End;
  140.  
  141. Begin
  142.   If( Not( GetFileNames( SigFileName, OvrFileName ) ) ) Then
  143.     Halt;              { If files not found, exit program     }
  144.   ClrScr;
  145.   GotoXY( 5,2 );
  146.   Writeln( 'Unit order in ', OvrFileName, ':' );
  147.   Writeln;
  148.   ReadSigFile( SigFileName ); { Read the signature file       }
  149.   Assign( F, OvrFileName );   { Associate the OVR file with F }
  150.   Reset( F );                 { Open the file F               }
  151.   While( Not( EOF( F ) ) ) Do { Read the entire file          }
  152.   Begin
  153.     Read( F, B );             { Read a byte from the file.    }
  154.     If( B = $90 ) Then        { Compare to NOP OpCode value   }
  155.     Begin
  156.       Read( F, SigRead[1] );  { Found a possible signature    }
  157.       Read( F, SigRead[2] );  { Get next two bytes from file  }
  158.       ShowIt( SigRead );      { Now see if valid signature    }
  159.     End;
  160.   End;
  161.   Close( F );                 { Close the input file          }
  162. End.
  163.