!
! *** Routine to load array with files matching specified
! *** wild card names from directory into array.
!

%record %format Dir Fm (%string (13) File, %byte Index)

%routine Load Wild Directory (%record (Dir Fm) %array %name Store (1:*),
                              %integer %name                Number of Files,
                              %string (6)                   Directory,
                              %string (13)                  Wild File)

   %string (127) Line, A, B
   %integer Flag = 0, Index

   %on 1,2,3,4,5,6,7,8,9,10 %start
      %if Flag = 0 %start
         Event_Message = "Spurious Error" %if Event_Message = ""
         Print String ("Load Directory: ".Event_Message)
         New Line
         %return
      %finish
      -> End Load
   %finish

   Directory = Directory . ":" %if Directory # ""
   Open Input (3, Directory."Directory")
   Select Input (3)
   Flag = 1

   Index = 1
   Number of Files = 0
   %cycle
      Read Line (Line)
      %if Matches (Line, Wild File) %start
         %if Wild File = "*" %start
            Index = Index + 1 %and %continue %if Line -> A .("."). B
         %finish
         Number of Files = Number of Files + 1
         Store (Number of Files)_File  = Line
         Store (Number of Files)_Index = Index
      %finish
      Index = Index + 1
   %repeat

End Load:
   Close Input
   Select Input (0)
%end

%end %of %file
