home *** CD-ROM | disk | FTP | other *** search
- {$S-,I-}
-
- {*********************************************************}
- {* UNITINFO.PAS 1.2 *}
- {* Copyright (c) TurboPower Software 1989,1990. *}
- {* All rights reserved. *}
- {*********************************************************}
-
- program UnitInfo;
- {-Display information about a 5.5 or 6.0 TPU file}
- uses
- Dos, OpString, OpDos;
- type
- SigType = array[1..4] of Char; {a TPU header signature}
- const
- {$IFDEF Ver60}
- SigForTPU60 : SigType = 'TPU9'; {signature for 6.0 TPU files}
- {$ELSE}
- SigForTPU55 : SigType = 'TPU6'; {signature for 5.5 TPU files}
- {$ENDIF}
- DebugOnly : Boolean = False;
- LocalsOnly : Boolean = False;
- NumericOnly : Boolean = False;
- OverlayOnly : Boolean = False;
- ShowSymSize : Boolean = False;
- type
- {$IFDEF Ver60}
- TpuHeader = {format of the TPU header: 6.0 only}
- record
- TPUsig : SigType; {"TPU9" signature}
- NextUnit, {segment in memory for next unit}
- NextLibrary, {segment in memory for next library}
- UsesPtr, {offset to unit name/symbol table}
- ScopePtr, {offset to hash table}
- ProcPtr, {offset to procedure table}
- GroupPtr, {offset to Group table}
- ConGrPtr, {Const group table pointer}
- DatGrPtr, {Data group table pointer}
- LinkPtr, {offset to link names table}
- DunnoPtr,
- NamePtr, {offset to filename table}
- DebugPtr, {offset to line number table}
- UnitSize, {symbol table size}
- CodeSize, {total code (bytes)}
- ConstSize, {initialized data (bytes)}
- FixupSize, {size of code fixup table}
- ConFixSize, {size of constant fixup section}
- DataSize, {uninitialized data (bytes)}
- DScopePtr, {debug scope pointer}
- Flags, {1 if unit compiled with $N+, 2 if $O+}
- ExecBase, {relative code segment}
- ExecSize, {code used (bytes)}
- OvLaySize : Word; {overlay code size}
- Private : array[1..8] of Word;
- end;
- {$ELSE}
- TpuHeader = {format of the TPU header: 5.5 only}
- record
- TPUsig : SigType; {"TPU6" signature}
- NextUnit, {segment in memory for next unit}
- NextLibrary, {segment in memory for next library}
- UsesPtr, {offset to unit name/symbol table}
- ScopePtr, {offset to hash table}
- ProcPtr, {offset to procedure table}
- GroupPtr, {offset to Group table}
- ConGrPtr, {Const group table pointer}
- DatGrPtr, {Data group table pointer}
- LinkPtr, {offset to link names table}
- NamePtr, {offset to filename table}
- DebugPtr, {offset to line number table}
- UnitSize, {symbol table size}
- CodeSize, {total code (bytes)}
- ConstSize, {initialized data (bytes)}
- ConFixSize, {size of the constant fixup section}
- FixupSize, {size of fixup table (follows code in TPU)}
- DataSize, {uninitialized data (bytes)}
- DScopePtr, {debug scope pointer}
- Flags, {1 if unit compiled with $N+, 2 if $O+}
- ExecBase, {relative code segment}
- ExecSize, {code used (bytes)}
- OvLaySize, {overlay code size}
- {...}
- FilePtr, {???}
- CodeSeg, {segment for code (while compiling)}
- FixupSeg, {segment for relocation table (while compiling)}
- ConstSeg, {segment for initialized data (while compiling)}
- FixupCnt, {fixup group count}
- RelocCnt : Word; {relocation item count}
- Private : array[1..4] of Byte;
- end;
- {$ENDIF}
-
-
- procedure DumpUnit(Name : string; var H : TpuHeader);
- {-Dump unit information}
- const
- PlusMinus : array[Boolean] of Char = ('-', '+');
- var
- HasDebug, HasLocals, HasNumeric, HasOverlay : Boolean;
- begin
- with H do begin
- HasDebug := (UnitSize > DebugPtr);
- HasLocals := (DScopePtr > ScopePtr);
- HasNumeric := (Flags and 1 <> 0);
- HasOverlay := (Flags and 2 <> 0);
-
- if DebugOnly and not HasDebug then
- Exit;
- if LocalsOnly and not HasLocals then
- Exit;
- if NumericOnly and not HasNumeric then
- Exit;
- if OverlayOnly and not HasOverlay then
- Exit;
-
- Write(Pad(JustName(Name), 10));
- {$IFDEF Ver60}
- if TPUsig <> SigForTPU60 then
- WriteLn('is not a 6.0 TPU file')
- {$ELSE}
- if TPUsig <> SigForTPU55 then
- WriteLn('is not a 5.5 TPU file')
- {$ENDIF}
- else begin
- Write( '$D', PlusMinus[HasDebug]);
- Write(', $L', PlusMinus[HasLocals]);
- Write(', $N', PlusMinus[HasNumeric]);
- Write(', $O', PlusMinus[HasOverlay]);
- Write(', ', CodeSize:5, ' code');
- Write(', ', ConstSize+DataSize:5, ' data');
- if ShowSymSize then
- Write(', ', UnitSize:5, ' symbols');
- WriteLn;
- end;
- end;
- end;
-
- procedure ReadUnit(Path, FName : PathStr);
- {-Read the TPU file}
- var
- F : File of TpuHeader;
- H : TpuHeader;
- begin
- FName := AddBackslash(JustPathName(Path))+FName;
- if JustExtension(FName) <> 'TPU' then
- Exit;
- Assign(F, FName);
- Reset(F);
- if IoResult <> 0 then begin
- WriteLn('Error reading ', FName);
- Exit;
- end;
- Read(F, H);
- if IoResult <> 0 then
- WriteLn('Error reading ', FName)
- else
- DumpUnit(FName, H);
- Close(F);
- if IoResult <> 0 then ;
- end;
-
- procedure Help;
- {-Display instructions}
- begin
- WriteLn('UNITINFO. Copyright (c) 1989,1990 TurboPower Software. Version 1.2.');
- WriteLn;
- WriteLn('Usage:');
- WriteLn(' UNITINFO [Options] mask [mask] [mask]');
- WriteLn;
- WriteLn('Options:');
- WriteLn(' /D Show only files with $D+');
- WriteLn(' /L Show only files with $L+');
- WriteLn(' /N Show only files with $N+');
- WriteLn(' /O Show only files with $O+');
- WriteLn(' /S Show symbol table size');
- WriteLn;
- WriteLn('Examples:');
- WriteLn(' UNITINFO myunit.tpu single file');
- WriteLn(' UNITINFO myunit single file, .TPU assumed');
- WriteLn(' UNITINFO *.tpu multiple files');
- WriteLn(' UNITINFO * multiple files, .TPU assumed');
- WriteLn(' UNITINFO *.* multiple files, same as *.TPU');
- WriteLn(' UNITINFO *.tpu \dir\*.tpu multiple masks');
- WriteLn(' UNITINFO /D *.tpu units without $D+ ignored');
- WriteLn(' UNITINFO /D /L *.tpu units without both $D+ and $L+ ignored');
- WriteLn(' (options must precede first mask)');
- Halt(0);
- end;
-
- var
- S : string;
- I, E : Word;
- SearchRecord : SearchRec;
- const
- MaskCount : Word = 0;
- begin
- if ParamCount = 0 then
- Help;
-
- for I := 1 to ParamCount do begin
- S := StUpcase(ParamStr(I));
- if (S[1] = '-') or (S[1] = '/') then begin
- if Length(S) > 2 then
- WriteLn('Invalid option: ', S)
- else case S[2] of
- 'D' : DebugOnly := True;
- 'L' : LocalsOnly := True;
- 'N' : NumericOnly := True;
- 'O' : OverlayOnly := True;
- 'S' : ShowSymSize := True;
- else WriteLn('Invalid option: ', S);
- end;
- end
- else begin
- Inc(MaskCount);
- if S = '.' then
- S := '*'
- else if S[Length(S)] = '\' then
- S := S+'*'
- else if IsDirectory(S) then
- S := AddBackSlash(S)+'*';
- S := DefaultExtension(S, 'TPU');
- FindFirst(S, $6, SearchRecord);
- E := IoResult;
- if (DosError = 0) and (E = 0) then begin
- ReadUnit(S, SearchRecord.Name);
- {get the rest of the files}
- while DosError = 0 do begin
- FindNext(SearchRecord);
- if DosError = 0 then
- ReadUnit(S, SearchRecord.Name);
- end;
- end
- else
- WriteLn('No matching files found (', S, ')');
- end;
- end;
- if MaskCount = 0 then
- Help;
- end.