home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SPACE.ZIP / SPACE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-06-25  |  6.7 KB  |  181 lines

  1. {This program is written by Micheal J. Chatfield  CS #71250,2766
  2.  this source code is presented as is and I assume no responsibility
  3.  for any errors in the source, nor any responsibility for any damages.
  4.  I am releasing this into the public domain}
  5. {$M 16384, 22000, 22000 }
  6. {$R-,S-,I+,D-,T-,F-,V-,B-,N-,L+ }
  7. uses Crt,Qwik,WndwVars,dos,Wndw;
  8.  
  9.   {WindVars,Wndw,and Qwik units are written and copywrited (shareware)
  10.    by James H. Lemay (CS76011,217), thanks to James for some
  11.    very powerfull screen handling utilities}
  12.  
  13. var
  14.   cmd : char;
  15.   i,j,k,m,OldCursor   : word;
  16.   real1,real2,real3   : real; {variables for calculating percentage}
  17.   totalspacefree,
  18.   totaldvsize,
  19.   userdatasize        : longint;
  20.   s                   : string[6];
  21.   s1                  : string[5];
  22.   s2                  : string[1];
  23.   s3                  : string[6];
  24.   s4                  : string[1];
  25.   usrsz               : string[10];
  26. procedure CheckCursor;
  27.  var
  28.    CursorMode: integer absolute $0040:$0060;
  29.        begin
  30.          if (ActiveDispDev=MdaMono) and (CursorMode=$0607) then
  31.          CursorChange($0C0D,OldCursor);
  32.        end;
  33. procedure ShowDriveSpace; {Displays Bytes on each partition and Total Bytes}
  34.  var
  35.     Drive,
  36.     ValidDrive : byte;
  37.     freestg    : string[10];
  38.     s          : string[9];
  39.     FreeBytes,
  40.     runtotal,
  41.     hold,
  42.     result     : longint;
  43.  begin
  44.     hold      := 0; {Init hold variable to zero for adding total bytes}
  45.     Drive     := 2; {Skip Floppy A & B by setting to 2, include set to 0}
  46.     ValidDrive:= 0; {Init ValidDrive variable to zero}
  47.     FreeBytes := 0; {Init FreeBytes variable to zero}
  48.     hold      := 0; {Init hold variable to zero}
  49.     freestg   :='';
  50.     s         :='';
  51.      while (Drive < 26) and (ValidDrive < 26) do
  52.       begin
  53.         gotoxy((7 + ValidDrive mod 5 * 13),(1 + ValidDrive div 5));
  54.         inc(Drive);  {Set up Display within the active window}
  55.         FreeBytes:= diskfree(Drive);  {Move result of diskfree to FreeBytes}
  56.            if FreeBytes > 0 then {Add up all Partitions in Bytes}
  57.                  begin
  58.                     hold:=hold + FreeBytes; {Keep track of running total}
  59.                     totalspacefree:=hold;
  60.                 end;
  61.              if (FreeBytes >= 0) then  {if any Bytes on any Partition Display It}
  62.                 begin
  63.                      write(chr((Drive - 1) + ord('A')),':');
  64.                      write(FreeBytes:9,s);
  65.                      inc(ValidDrive); {Go to the next Drive}
  66.                 end;
  67.              if Drive = 26 then
  68.                    begin;
  69.                      MakeWindow (9,2,3,39,green,cyan+redBG,Borders(11),Window5);
  70.                      TitleWindow(Top,Center,' Total Available Storage ');
  71.                      accesswindow(window5);
  72.                         str(hold,freestg);
  73.                         QwriteC(10,3,39,2,freestg);
  74.                     end;
  75.       end;
  76.  end; { procedure ShowDriveSpace and Total Space}
  77. procedure ShowDriveSize; {Displays Max Size on each partition and Total Bytes}
  78.   var
  79.     Drive,
  80.     ValidDrive : byte;
  81.     s          : string[9];
  82.     maxstg     : string[10];
  83.     TotalBytes,
  84.     hold1      : longint;
  85. begin
  86.    Drive       := 2; {Skip Floppy A & B by setting to 2, include set to 0}
  87.    ValidDrive  := 0; {Init ValidDrive variable to zero}
  88.    TotalBytes  := 0; {Init TotalBytes variable to zero}
  89.    hold1       := 0; {Init hold1 variable, keeps track of the running total}
  90.    s           :='';
  91.    maxstg      :='';
  92.    while (Drive < 26) and (ValidDrive < 26) do
  93.     begin
  94.         gotoxy((7 + ValidDrive mod 5 * 13),(1 + ValidDrive div 5));
  95.         inc(Drive);  {Set up Display within the active window}
  96.         TotalBytes:= Disksize(Drive);  {Move result of diskfree to FreeBytes}
  97.         if Totalbytes >= 0 then {Add up all Partitions in Bytes}
  98.              begin
  99.                hold1:=hold1 + Totalbytes; {Keep track of running total}
  100.              end;
  101.         totaldvsize:=hold1;
  102.         if (TotalBytes > 0) then  {if any Bytes on any Partition Display It}
  103.              begin
  104.                write(chr((Drive - 1)+ ord('A')),':');
  105.                write(TotalBytes:9,s);
  106.                inc(ValidDrive); {Go to the next Drive}
  107.              end;
  108.        if Drive = 26 then
  109.                  begin
  110.                      MakeWindow (9,41,3,39,green,cyan+redBG,Borders(11),Window4);
  111.                      TitleWindow(Top,Center,' Total Storage Capacity ');
  112.                      accesswindow(window4);
  113.                         str(hold1,maxstg);
  114.                         QwriteC(10,41,78,2,maxstg);
  115.                   end;
  116.      end;
  117. end;
  118. begin {Main Program} { The equivalent to the Unix DF command }
  119.   { Initialize program variables }
  120.  totalspacefree :=0;
  121.  totaldvsize    :=0;
  122.  userdatasize   :=0;
  123.  real1          :=0;
  124.  real2          :=0;
  125.  real3          :=0;
  126.  s1             :='';
  127.  s2             :='';
  128.  s3             :='';
  129.  s4             :='';
  130. qinit;
  131. clrscr;
  132. initwindow (0,false); { set up windows }
  133.   setwindowmodes ($10);
  134.   CheckCursor;
  135.   CursorOff;
  136.     MakeWindow (1,2,8,78,white+green+yellow+blackBG,lightgray+redBG,Borders(7),Window2);
  137.     TitleWindow(Top,Center,' Unused Storage on Each Partition ');
  138.     accesswindow(window2);
  139.   showdrivespace; {Shows Free Space on each Partition}
  140.     MakeWindow (12,2,8,78,white+green+yellow+blackBG,lightgray+redBG,Borders(7),Window3);
  141.     TitleWindow(Top,Center,' Size of Each Partition ');
  142.     accesswindow(window3);
  143.   showdrivesize; {Shows Max Space on each Partition}
  144.     MakeWindow (23,21,2,40,black,cyan+red,Borders(7),Window6);
  145.     TitleWindow(Top,Center,' Q to Quit ');
  146.     accesswindow(window6);
  147.     MakeWindow (20,2,3,39,green,cyan+redBG,Borders(11),Window7);
  148.     TitleWindow(Top,Center,' User Data Stored in Bytes ');
  149.     accesswindow(window7);
  150.         userdatasize:= (totaldvsize mod totalspacefree); {calculate user date stored}
  151.         str(userdatasize,usrsz);  {convert to a string}
  152.         QwriteC(21,3,39,2,usrsz);
  153.     MakeWindow (20,41,3,39,green,cyan+redBG,Borders(11),Window8);
  154.     TitleWindow(Top,Center,' Percent Free All Partitions ');
  155.     accesswindow(window8);
  156.         real1:=totaldvsize;
  157.         real2:=totalspacefree;
  158.         real3:=(real2 / real1);
  159.         str(real3:12:5,s);
  160.         s1:=copy(s,3,4); {Get the percentage value from the Longint into string}
  161.         s4:='.';
  162.         s2:='%';
  163.         s3:=concat(s1,s2);
  164.         insert(s4,s3,3);
  165.         QwriteC(21,41,78,2,s3);
  166.  repeat
  167.      cmd :=readkey;
  168.   until (cmd = 'q') or (cmd = 'Q');
  169.  begin
  170.     removewindow;
  171.     removewindow;
  172.     removewindow;
  173.     removewindow;
  174.     removewindow;
  175.     removewindow;
  176.     removewindow;
  177.     cursoron; {Turn Cursor back on}
  178.  end;
  179. end. {End Main Program Body}
  180.  
  181.