home *** CD-ROM | disk | FTP | other *** search
- {$P128}
-
- PROGRAM chkcom;
- {-check a Turbo .COM file for heap/stack}
- TYPE
- comfile = FILE OF Byte;
- pathname = STRING[64];
- VAR
- f : comfile;
- p : pathname;
-
- FUNCTION existfile(p : pathname; VAR f : comfile) : Boolean;
- {-return true and open file if p exists}
- VAR
- oksofar : Boolean;
- BEGIN
- Assign(f, p);
- {$I-} Reset(f); {$I+}
- oksofar := (IOResult = 0);
- IF oksofar THEN
- {see if file is large enough to be a Turbo .COM file}
- oksofar := (FileSize(f) > 11000) OR (FileSize(f) < 0);
- existfile := oksofar;
- END; {existfile}
-
- PROCEDURE getinfo;
- {-find information about the compiled program}
- VAR
- firstjump, minheap, maxheap : Integer;
- TYPE
- hexstring = STRING[4];
-
- FUNCTION hex(i : Integer) : hexstring;
- CONST
- hexchar : ARRAY[0..15] OF Char = '0123456789ABCDEF';
- VAR
- ipos, nib, tint : Integer; s : hexstring;
- BEGIN
- s := ''; ipos := 1; tint := i;
- REPEAT
- nib := tint AND $F;
- s := hexchar[nib]+s;
- tint := tint SHR 4;
- ipos := ipos+1;
- UNTIL ipos > 4;
- hex := s;
- END; {hex}
-
- PROCEDURE readint(VAR f : comfile; VAR i : Integer);
- {-read an integer from a BYTE file}
- VAR
- l, h : Byte;
- BEGIN
- Read(f, l);
- Read(f, h);
- i := l OR (h SHL 8);
- END; {readint}
-
- BEGIN
- Seek(f, 1);
- readint(f, firstjump);
- Seek(f, firstjump+16);
- readint(f, minheap);
- readint(f, maxheap);
- WriteLn('MinHeap: ', hex(minheap), ' MaxHeap: ', hex(maxheap));
- END; {getinfo}
-
- BEGIN
- {get the input file}
- IF ParamCount = 0 THEN
- REPEAT
- Write(Con, 'Enter .COM file name: ');
- ReadLn(p);
- IF Length(p) = 0 THEN Halt;
- UNTIL existfile(p, f)
- ELSE IF NOT(existfile(ParamStr(1), f)) THEN
- Halt(1);
-
- {read the information}
- getinfo;
-
- Close(f);
- END.
-