home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BTP20.ZIP / STATS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-06-10  |  7.9 KB  |  264 lines

  1. PROGRAM Stats;                 { (C) 1993 John C. Leon   last updated 6/8/93 }
  2.  
  3. {
  4. This program will report stats on ANY Btrieve file; it is intended to provide
  5. the same functionality (and then some) of the "BUTIL -STAT" function.  Just
  6. supply the name of any valid Btrieve file on the command line, followed by an
  7. owner name if the file requires one.
  8. }
  9.  
  10. {$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}
  11.  
  12. USES
  13.    BTP;  
  14.  
  15. CONST
  16.    HasDescKey      : boolean = false;
  17.    HasSupplemental : boolean = false;
  18.    PriorSegmented  : boolean = false;
  19.    KeyCount        : integer = 0;
  20.  
  21. TYPE
  22.    PStatFile   = ^TStatFile;
  23.    TStatFile   = object(BFile)
  24.                     KeyType: string;
  25.                     procedure SetKeyType(KFlags: integer; EType: byte);
  26.                     end;
  27.  
  28. VAR
  29.    StatFile       : PStatFile;
  30.    StatFileName,
  31.    OwnerName,
  32.    KeyType, TempS,
  33.    S1, S2         : string;
  34.    Counter        : integer;
  35.  
  36. procedure TStatFile.SetKeyType(KFlags: integer; EType: byte);
  37. begin
  38. if (KFlags and Binary) = Binary then
  39.    KeyType := 'Unsigned'
  40.    else
  41.    begin
  42.    case EType of
  43.        0: KeyType := 'String  ';
  44.        1: KeyType := 'Integer ';
  45.        2: KeyType := 'Float   ';
  46.        3: KeyType := 'Date    ';
  47.        4: KeyType := 'Time    ';
  48.        5: KeyType := 'Decimal ';
  49.        6: KeyType := 'Money   ';
  50.        7: KeyType := 'Logical ';
  51.        8: KeyType := 'Numeric ';
  52.        9: KeyType := 'Bfloat  ';
  53.       10: KeyType := 'Lstring ';
  54.       11: KeyType := 'Zstring ';
  55.       14: KeyType := 'Unsigned';
  56.       15: KeyType := 'AutoInc ';
  57.       end;
  58.    end;
  59. end;
  60.  
  61. procedure PrintNotices;
  62. begin
  63.    writeln;
  64.    writeln('BTP Stats - Version 2.0 - (C) 1993 John C. Leon.  All Rights Reserved.');
  65.    writeln;
  66.    writeln('File stats for ', StatFileName);
  67.    writeln;
  68. end;
  69.  
  70.  
  71. procedure DoFileStatLine;
  72. begin
  73.    if length(S1) < 37 then
  74.       for Counter := length(S1) to 37 do
  75.          S1 := S1 + ' ';
  76.    writeln(S1, S2);
  77. end;
  78.  
  79. procedure PrintFileHeaderStats;
  80. begin
  81.    with StatFile^ do
  82.    begin
  83.       str(Specs.RecLen, TempS);
  84.       S1 :=('Record length    = ' + TempS);
  85.       S2 := 'Variable Length  = ';
  86.       if (Specs.FileFlags and VarLength) = VarLength then
  87.          begin
  88.          S2 := S2 + 'Yes  Free Space = ';
  89.          case (Specs.FileFlags SHR 6) of          {get to free threshold bits}
  90.             0: S2 := S2 + 'N/A';              {not created w/a threshold flag}
  91.             1: S2 := S2 + '10%';              {if Specs.FileFlags and 64 = 64}
  92.             2: S2 := S2 + '20%';            {if Specs.FileFlags and 128 = 128}
  93.             3: S2 := S2 + '30%';            {if Specs.FileFlags and 192 = 192}
  94.             end;
  95.          end
  96.          else
  97.          S2 := S2 + 'No';
  98.       DoFileStatLine;
  99.       str(Specs.NumKeys, TempS);
  100.       S1 := 'Number keys/segs = ' + TempS + ' / ';
  101.       str(NumSegs, TempS);
  102.       S1 := S1 + TempS;
  103.       S2 := 'Blank Truncation = ';
  104.       if (Specs.FileFlags and BlankTrunc) = BlankTrunc then
  105.          S2 := S2 + 'Yes' else S2 := S2 + 'No';
  106.       DoFileStatLine;
  107.       str(Specs.UnusedPgs, TempS);
  108.       S1 := 'Unused pages     = ' + TempS;
  109.       S2 := 'Preallocation    = ';
  110.       if (Specs.FileFlags and PreAllocate) = PreAllocate then
  111.          begin
  112.          str(Specs.PreAlloc, TempS);
  113.          S2 := S2 + 'Yes  Pages = ' + TempS;
  114.          end
  115.          else
  116.          S2 := S2 + 'No ';
  117.       DoFileStatLine;
  118.       str(Specs.PageSize, TempS);
  119.       S1 := 'Page size        = ' + TempS;
  120.       S2 := 'Data Compression = ';
  121.       if (Specs.FileFlags and DataComp) = DataComp then
  122.          S2 := S2 + 'Yes' else S2 := S2 + 'No';
  123.       DoFileStatLine;
  124.       str(NumRecs, TempS);
  125.       S1 := 'Number records   = ' + TempS;
  126.       S2 := 'Key Only File    = ';
  127.       if (Specs.FileFlags and KeyOnly) = KeyOnly then
  128.          S2 := S2 + 'Yes' else S2 := S2 + 'No';
  129.       DoFileStatLine;
  130.    end;
  131. end;
  132.  
  133. procedure PrintFileSegmentStats;
  134. begin
  135.    with StatFile^ do
  136.    begin
  137.       writeln;
  138.       write('Key  Position  Length  Duplicates  Modifiable   Type    ');
  139.       writeln('Null    Total');
  140.       writeln;
  141.  
  142.       for Counter := 1 to NumSegs do
  143.          with Specs.KeyArray[Counter-1] do
  144.             begin
  145.             write(KeyCount:3);
  146.             if (KeyFlags and Supplemental) = Supplemental then
  147.                begin
  148.                write('S');
  149.                HasSupplemental := true;
  150.                end
  151.                else
  152.                write(' ');
  153.             write(KeyPos:7, KeyLen:8, '        ');
  154.             if (KeyFlags and Segmented) = Segmented then
  155.                PriorSegmented := true
  156.                else
  157.                PriorSegmented := false;
  158.             if ((KeyFlags and Segmented) <> Segmented) and
  159.                (PriorSegmented = false) then inc(KeyCount);
  160.             if (KeyFlags and Duplicates) = Duplicates then
  161.                write('Yes') else write(' No');
  162.             if (KeyFlags and Modifiable) = Modifiable then
  163.                write('         Yes   ') else write('         No    ');
  164.             SetKeyType(KeyFlags, ExtKeyType);
  165.             if (KeyFlags and AltCol) = AltCol then
  166.                write(' *', KeyType) else write('  ', KeyType);
  167.             if (KeyFlags and Descending) = Descending then
  168.                begin
  169.                write(' <');
  170.                HasDescKey := true;
  171.                end
  172.                else
  173.                write('  ');
  174.             if (KeyFlags and Null) = Null then
  175.                write(NullValue) else write('--');
  176.             write(NumUnique: 10);
  177.             writeln;
  178.             if ((Counter = 10) and (Counter < NumSegs)) then
  179.                begin
  180.                writeln;
  181.                writeln('-- press Enter to continue');
  182.                readln; writeln;
  183.                end;
  184.             end;                           {with Specs.KeyArray[Counter-1] do}
  185.  
  186.       if HasAltCol then
  187.          begin
  188.          writeln;
  189.          write('* Alternate Collating Sequence is: ');
  190.          for Counter := 1 to 8 do
  191.             write(AltColName[Counter]);
  192.          end;
  193.  
  194.       if HasDescKey then
  195.          begin
  196.          writeln;
  197.          write('< Indicates descending key segment');
  198.          end;
  199.  
  200.       if HasSupplemental then
  201.          begin
  202.          writeln;
  203.          write('S Indicates supplemental key');
  204.          end;
  205.  
  206.       writeln;
  207.  
  208.    end;
  209. end;
  210.  
  211.  
  212. BEGIN
  213.  
  214.    if IsBtrieveLoaded = false then
  215.       begin
  216.       writeln('Please load Btrieve before running this program.');
  217.       halt(1);
  218.       end;
  219.  
  220.    {get filename to act on and store it in uppercase}
  221.    if (paramcount < 1) then
  222.       begin
  223.       writeln;
  224.       writeln('USAGE: STATS filename <owner name>');
  225.       writeln('       A filename is required.  The optional owner name is');
  226.       writeln('       required only if the file itself requires one.');
  227.       halt(2);
  228.       end;
  229.  
  230.    StatFileName := paramstr(1);
  231.    for Counter := 1 to length(StatFileName) do
  232.       StatFileName[Counter] := upcase(StatFileName[Counter]);
  233.  
  234.    OwnerName := '';
  235.    if paramcount >= 2 then
  236.       OwnerName := paramstr(2);
  237.  
  238.    {open the file in read only mode}
  239.    StatFile := new(PStatFile, Init(StatFileName, ReadOnly, OwnerName));
  240.  
  241.    if BStatus <> 0 then
  242.       begin
  243.       dispose(StatFile, Done);
  244.       writeln('Error opening Btrieve file.  Program terminated.');
  245.       writeln('Status code: ', BStatus);
  246.       if BStatus = 51 then
  247.          begin
  248.          writeln;
  249.          writeln('File appears to require an owner name for access, OR');
  250.          writeln('the owner name you provided is incorrect, OR');
  251.          writeln('you provided an owner name when none is needed.');
  252.          writeln('Remember that owner names are case sensitive!');
  253.          end;
  254.       halt(3);
  255.       end;
  256.  
  257.    StatFile^.Close;       {We have the stats encapsulated, so close the file.}
  258.    PrintNotices;          {Display copyright and Btrieve file name.}
  259.    PrintFileHeaderStats;
  260.    PrintFileSegmentStats;
  261.    dispose(StatFile, Done);
  262.  
  263. END.
  264.