--  ls1.adb
--    Purpose: list contents of directory or directories
--    Action:  if no args, use .  else list files in args

with
  Ada.Command_Line,
  Ada.Text_IO,
  POSIX.Files;

with
  EUP.Strings;

procedure ls is
   procedure Put_Name (D_Entry : in     POSIX.Files.Directory_Entry;
                       Quit    : in out Boolean) is
   begin
      Ada.Text_IO.Put_Line
        (EUP.Strings.To_Ada_String (POSIX.Files.Filename_Of (D_Entry)));
   end Put_Name;

   procedure List is
     new POSIX.Files.For_Every_Directory_Entry (Action => Put_Name);
begin
   if Ada.Command_Line.Argument_Count < 1 then
      List (".");
   else
      for Index in 1 .. Ada.Command_Line.Argument_Count loop
         Ada.Text_IO.Put_Line (Ada.Command_Line.Argument (Index) & ":");
         List (POSIX.To_POSIX_String (Ada.Command_Line.Argument (Index)));
      end loop;
   end if;
end ls;

