home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / decus / RB125 / wildexpa.pas < prev   
Pascal/Delphi Source File  |  1995-06-04  |  4KB  |  189 lines

  1. TYPE
  2.     WildExpandRegisters =
  3.     RECORD
  4.     CASE INTEGER OF
  5.      1: (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : INTEGER);
  6.      2: (AL, AH, BL, BH, CL, CH, DL, DH           : BYTE)
  7.     END;
  8.  
  9. CONST
  10.     WildExpandFlagCarry     = $0001;
  11.  
  12. TYPE
  13.     WildExpandMsDosBlock =
  14.     RECORD
  15.     Reserved01        : ARRAY [1..21] OF BYTE;
  16.     FileAttributes        : BYTE;
  17.     FileTime        : INTEGER;
  18.     FileDate        : INTEGER;
  19.     FileSizeLow        : INTEGER;
  20.     FileSizeHigh        : INTEGER;
  21.     FileName        : ARRAY [1..13] OF CHAR
  22.     END;
  23.  
  24. CONST
  25.     WildExpandPathLength    = 255;
  26.  
  27. TYPE
  28.     WildExpandPathSpec        = STRING [WildExpandPathLength];
  29.  
  30.     WildExpandHistory =
  31.     RECORD
  32.     MSDosBlock        : WildExpandMsDosBlock;
  33.     LeadingInformation    : WildExpandPathSpec;
  34.     CurrentlyValid        : BOOLEAN;
  35.     END;
  36.  
  37. VAR
  38.     WildExpandHistoryBlock    : WildExpandHistory;
  39.  
  40.  
  41. FUNCTION WildExpandInitialize
  42.    (    PathName  : WildExpandPathSpec;
  43.     MatchAttr : INTEGER) : BOOLEAN;
  44.  
  45.     VAR
  46.     LastSlashIndex    : INTEGER;
  47.     OldDTA        : ^ CHAR;
  48.     Registers    : WildExpandRegisters;
  49.     SearchIndex    : INTEGER;
  50.  
  51.     BEGIN
  52.  
  53.     {  Obtain leading path spec information.  }
  54.  
  55.     LastSlashIndex := 0;
  56.     FOR SearchIndex := 1 TO Length (PathName)
  57.     DO
  58.     IF (PathName [SearchIndex] = '/') OR
  59.        (PathName [SearchIndex] = '\') OR
  60.        (PathName [SearchIndex] = ':')
  61.     THEN
  62.         LastSlashIndex := SearchIndex
  63.     ELSE
  64.         PathName [SearchIndex] := UpCase (PathName [SearchIndex]);
  65.     WildExpandHistoryBlock.LeadingInformation :=
  66.     Copy (PathName, 1, LastSlashIndex);
  67.  
  68.     {  If the pattern ends in a terminator, assume *.*    }
  69.  
  70.     IF LastSlashIndex = Length (PathName)
  71.     THEN
  72.     Insert ('*.*', PathName, Length (PathName) + 1);
  73.  
  74.     {  Save the current disk transfer address.    }
  75.  
  76.     Registers.AH := $2F;
  77.     MsDos (Registers);
  78.     OldDTA := Ptr (Registers.ES, Registers.BX);
  79.  
  80.     {  Have MS-DOS initialize the block.  }
  81.  
  82.     Registers.AH := $1A;
  83.     Registers.DS := Seg (WildExpandHistoryBlock.MSDosBlock);
  84.     Registers.DX := Ofs (WildExpandHistoryBlock.MSDosBlock);
  85.     MsDos (Registers);
  86.  
  87.     PathName := PathName + #$00;
  88.     Registers.AH := $4E;
  89.     Registers.DS := Seg (PathName [1]);
  90.     Registers.DX := Ofs (PathName [1]);
  91.     Registers.CX := MatchAttr;
  92.     MsDos (Registers);
  93.  
  94.     {  But '.' and '..' are not desired  }
  95.  
  96.     WHILE ((Registers.Flags AND WildExpandFlagCarry) = 0) AND
  97.       (WildExpandHistoryBlock.MSDosBlock.FileName [1] = '.')
  98.     DO
  99.     BEGIN
  100.  
  101.     Registers.AH := $4F;
  102.     MsDos (Registers)
  103.  
  104.     END;
  105.  
  106.     WildExpandHistoryBlock.CurrentlyValid :=
  107.     (Registers.Flags AND WildExpandFlagCarry) = 0;
  108.  
  109.     {  Reset the disk transfer address.  }
  110.  
  111.     Registers.AH := $1A;
  112.     Registers.DS := Seg (OldDTA ^);
  113.     Registers.DX := Ofs (OldDTA ^);
  114.     MsDos (Registers);
  115.  
  116.     {  Return whether successful.  }
  117.  
  118.     WildExpandInitialize := WildExpandHistoryBlock.CurrentlyValid
  119.  
  120.     END;
  121.  
  122. PROCEDURE WildExpandContinue                        {011}
  123.    (VAR ResultName : WildExpandPathSpec;                {011}
  124.     VAR ResultAttr : INTEGER);                        {011}
  125.  
  126.     VAR
  127.     Registers : WildExpandRegisters;
  128.     ScanIndex : INTEGER;
  129.     OldDTA      : ^ CHAR;
  130.  
  131.     BEGIN
  132.  
  133.     IF NOT WildExpandHistoryBlock.CurrentlyValid
  134.     THEN
  135.  
  136.     BEGIN
  137.  
  138.     {  Save the current disk transfer address.  }
  139.  
  140.     Registers.AH := $2F;
  141.     MsDos (Registers);
  142.     OldDTA := Ptr (Registers.ES, Registers.BX);
  143.  
  144.     {  Get the next path specification.  }
  145.  
  146.     Registers.AH := $1A;
  147.     Registers.DS := Seg (WildExpandHistoryBlock.MSDosBlock);
  148.     Registers.DX := Ofs (WildExpandHistoryBlock.MSDosBlock);
  149.     MsDos (Registers);
  150.  
  151.     Registers.AH := $4F;
  152.     MsDos (Registers);
  153.  
  154.     WildExpandHistoryBlock.CurrentlyValid :=
  155.         (Registers.Flags AND WildExpandFlagCarry) = 0;
  156.  
  157.     {  Reset the disk transfer address.  }
  158.  
  159.     Registers.AH := $1A;
  160.     Registers.DS := Seg (OldDTA ^);
  161.     Registers.DX := Ofs (OldDTA ^);
  162.     MsDos (Registers)
  163.  
  164.     END;
  165.  
  166.     IF WildExpandHistoryBlock.CurrentlyValid
  167.     THEN
  168.  
  169.     BEGIN
  170.     ScanIndex := 1;
  171.     WHILE WildExpandHistoryBlock.MsDosBlock.FileName [ScanIndex] <> #$00
  172.     DO
  173.         ScanIndex := ScanIndex + 1;
  174.     ResultName := WildExpandHistoryBlock.LeadingInformation +    {011}
  175.         Copy (WildExpandHistoryBlock.MsDosBlock.FileName, 1,
  176.         ScanIndex - 1);
  177.     ResultAttr := WildExpandHistoryBlock.MsDosBlock.FileAttributes; {011}
  178.     WildExpandHistoryBlock.CurrentlyValid := FALSE
  179.     END
  180.  
  181.     ELSE
  182.     BEGIN                                {011}
  183.  
  184.     ResultName := '';                        {011}
  185.     ResultAttr := 0                         {011}
  186.  
  187.     END                                {011}
  188.     END;
  189.