1 Unit Common; 2 3 interface 4 5 const 6 Max_Arguments = 1024; 7 8 var 9 num_arguments : integer; 10 (* the number of arguments contained in the 'arguments' array *) 11 12 arguments : array[0..Max_Arguments-1] of ^string; 13 (* This array will hold all arguments after wildcard expansion *) 14 (* note that it will not contain the original arguments that *) 15 (* were before 'first_argument' of Expand_Wildcards *) 16 17 procedure Expand_WildCards( first_argument : integer; 18 default_extension : string ); 19 (* expand all wildcards into filenames *) 20 21 implementation 22 23 uses Dos; 24 25 procedure Split( Original : String; 26 var Base : String; 27 var Name : String ); 28 var 29 n : integer; 30 begin 31 n := length(Original); 32 33 while ( n > 0 ) do 34 if ( Original[n] = '\' ) or 35 ( Original[n] = '/' ) then 36 begin 37 Base := Copy( Original, 1, n-1 ); 38 Name := Copy( Original, n+1, length(Original) ); 39 exit; 40 end 41 else 42 dec(n); 43 44 Base := ''; 45 Name := Original; 46 end; 47 48 49 procedure Expand_WildCards( first_argument : integer; 50 default_extension : string ); 51 var 52 i, n : integer; 53 base, name : string; 54 SRec : SearchRec; 55 begin 56 num_arguments := 0; 57 i := first_argument; 58 59 while ( i <= ParamCount ) do 60 begin 61 Split( ParamStr(i), base, name ); 62 if base <> '' then 63 base := base + '\'; 64 65 FindFirst( base+name, Archive+ReadOnly+Hidden, SRec ); 66 if DosError <> 0 then 67 FindFirst( base+name+default_extension, AnyFile, SRec ); 68 69 while (DosError = 0) and (num_arguments < Max_Arguments) do 70 begin 71 GetMem( arguments[num_arguments], length(base)+length(SRec.Name)+1 ); 72 arguments[num_arguments]^ := base + SRec.Name; 73 inc( num_arguments ); 74 FindNext( SRec ); 75 end; 76 77 {$IFDEF OS2} 78 FindClose( SRec ); 79 {$ENDIF} 80 inc( i ); 81 end; 82 end; 83 84 end. 85