home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / msh_ut11.zip / DSKFREE.PAS < prev    next >
Pascal/Delphi Source File  |  1992-05-09  |  2KB  |  99 lines

  1. PROGRAM DskFree;
  2. { Support-Program for MiShell, JP 92       }
  3. { Write just capacity and free space of    }
  4. { drive in (specified or default) file     }
  5. { Call: dskfree <drivespec> [<targetfile>] }
  6. USES DOS;
  7.  
  8. CONST TargetFile = 'DSKFREE.TXT'; { Change for your drive }
  9. VAR   Thousands, Decimal : CHAR;
  10.  
  11.   PROCEDURE OSInit; { Get Thousands/Decimal-Separator from DOS }
  12.   VAR
  13.      Regs : REGISTERS;
  14.      CountryBuf : ARRAY [0..$21] OF CHAR;
  15.      Major      : BYTE;
  16.   BEGIN
  17.      WITH regs DO
  18.      BEGIN
  19.         Ah := $30;
  20.         MSDOS (Regs);
  21.         Major := Al;
  22.         AX := $3800;
  23.         DS := SEG (CountryBuf);
  24.         DX := OFS (CountryBuf);
  25.         INTR ($21, Regs);
  26.         IF Major >= 3 THEN
  27.         BEGIN
  28.            Thousands := CountryBuf [$7];
  29.            Decimal := CountryBuf [$9];
  30.         END
  31.         ELSE
  32.         BEGIN
  33.            Thousands := CountryBuf [$04];
  34.            Decimal := CountryBuf [$06];
  35.         END;
  36.      END;
  37.   END;
  38.  
  39.  PROCEDURE diskpar(drive : Byte; VAR capacity, freespace : LONGINT);
  40.  VAR                                   { DRIVE : 0 = Current Drive }
  41.   regs : Registers;                    {         1 = Drive A       }
  42.  BEGIN                                 {         2 = Drive B       }
  43.   WITH regs DO                         {         and so on         }
  44.    BEGIN
  45.     ax := $3600;
  46.     dx := drive;
  47.     MsDos(regs);
  48.     IF (ax <> $ffff) THEN
  49.     BEGIN
  50.       capacity := ax*cx;
  51.       freespace := capacity*bx;
  52.       capacity := capacity*dx;
  53.     END
  54.     ELSE
  55.     BEGIN
  56.       capacity := 0;
  57.       freespace  := 0;
  58.     END;
  59.    END;
  60.  END;
  61.  
  62.  PROCEDURE Formatted (l : LONGINT; VAR s : STRING; len : BYTE);
  63.  VAR i : INTEGER;
  64.  BEGIN
  65.    STR(l, s);
  66.    i := length(s) - 3;
  67.    WHILE (i>0) DO
  68.    BEGIN
  69.      Insert(Thousands, s, i + 1);
  70.      DEC(i, 3);
  71.    END;
  72.    WHILE Length(s)<len DO
  73.      s := ' ' + s;
  74.  END;
  75.  
  76. VAR Fil      : TEXT;
  77.     kap, fre : LONGINT;
  78.     i        : BYTE;
  79.     drv      : STRING[2];
  80.     t, f     : STRING;
  81. BEGIN
  82.   IF ParamCount>0 THEN
  83.   BEGIN
  84.     OSInit;
  85.     drv := Copy(ParamStr(1), 1, 1) + ':'; drv[1] := Upcase(Drv[1]);
  86.     diskpar(ORD(drv[1]) - ORD('A') + 1, kap, fre);
  87.     Formatted(kap, t, 13);
  88.     Formatted(fre, f, 13);
  89.     IF ParamStr(2)<>'' THEN
  90.       ASSIGN(Fil, paramStr(2))
  91.      ELSE
  92.       ASSIGN(Fil, TargetFile);
  93.     REWRITE(Fil);
  94.     WRITELN(Fil,  t, ' bytes in ', drv);
  95.     WRITELN(Fil,  f, ' bytes free');
  96.     CLOSE(Fil);
  97.   END;
  98. END.
  99.