home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / MISC.ZIP / CHKCOM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-09-29  |  2.1 KB  |  84 lines

  1.   {$P128}
  2.  
  3. PROGRAM chkcom;
  4.     {-check a Turbo .COM file for heap/stack}
  5.   TYPE
  6.     comfile = FILE OF Byte;
  7.     pathname = STRING[64];
  8.   VAR
  9.     f : comfile;
  10.     p : pathname;
  11.  
  12.   FUNCTION existfile(p : pathname; VAR f : comfile) : Boolean;
  13.       {-return true and open file if p exists}
  14.     VAR
  15.       oksofar : Boolean;
  16.     BEGIN
  17.       Assign(f, p);
  18.       {$I-} Reset(f);         {$I+}
  19.       oksofar := (IOResult = 0);
  20.       IF oksofar THEN
  21.         {see if file is large enough to be a Turbo .COM file}
  22.         oksofar := (FileSize(f) > 11000) OR (FileSize(f) < 0);
  23.       existfile := oksofar;
  24.     END;                      {existfile}
  25.  
  26.   PROCEDURE getinfo;
  27.       {-find information about the compiled program}
  28.     VAR
  29.       firstjump, minheap, maxheap : Integer;
  30.     TYPE
  31.       hexstring = STRING[4];
  32.  
  33.     FUNCTION hex(i : Integer) : hexstring;
  34.       CONST
  35.         hexchar : ARRAY[0..15] OF Char = '0123456789ABCDEF';
  36.       VAR
  37.         ipos, nib, tint : Integer; s : hexstring;
  38.       BEGIN
  39.         s := ''; ipos := 1; tint := i;
  40.         REPEAT
  41.           nib := tint AND $F;
  42.           s := hexchar[nib]+s;
  43.           tint := tint SHR 4;
  44.           ipos := ipos+1;
  45.         UNTIL ipos > 4;
  46.         hex := s;
  47.       END;                    {hex}
  48.  
  49.     PROCEDURE readint(VAR f : comfile; VAR i : Integer);
  50.         {-read an integer from a BYTE file}
  51.       VAR
  52.         l, h : Byte;
  53.       BEGIN
  54.         Read(f, l);
  55.         Read(f, h);
  56.         i := l OR (h SHL 8);
  57.       END;                    {readint}
  58.  
  59.     BEGIN
  60.       Seek(f, 1);
  61.       readint(f, firstjump);
  62.       Seek(f, firstjump+16);
  63.       readint(f, minheap);
  64.       readint(f, maxheap);
  65.       WriteLn('MinHeap: ', hex(minheap), ' MaxHeap: ', hex(maxheap));
  66.     END;                      {getinfo}
  67.  
  68.   BEGIN
  69.     {get the input file}
  70.     IF ParamCount = 0 THEN
  71.       REPEAT
  72.         Write(Con, 'Enter .COM file name: ');
  73.         ReadLn(p);
  74.         IF Length(p) = 0 THEN Halt;
  75.       UNTIL existfile(p, f)
  76.     ELSE IF NOT(existfile(ParamStr(1), f)) THEN
  77.       Halt(1);
  78.  
  79.     {read the information}
  80.     getinfo;
  81.  
  82.     Close(f);
  83.   END.
  84.