home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / lovelace / show.adb < prev    next >
Encoding:
Text File  |  1995-09-10  |  959 b   |  36 lines

  1. with Ada.Command_Line, Text_IO, Ada.Strings.Unbounded, Ustrings;
  2. use  Ada.Command_Line, Text_IO, Ada.Strings.Unbounded, Ustrings;
  3.  
  4. procedure Show is
  5. -- Take each command line argument as a filename and display
  6. -- each file, indented.
  7.  
  8.   procedure Show_File(Filename : String) is
  9.   -- Open "Filename" and display it, indented.
  10.     File : File_Type;
  11.     Input : Unbounded_String;
  12.   begin
  13.       Put("Printing file ");
  14.       Put_Line(Filename);
  15.       Open(File, In_File, Filename);
  16.  
  17.       while (not End_Of_File(File)) loop
  18.         Get_Line(File, Input);
  19.         Put(' ');          -- indent.
  20.         Put_Line(Input);
  21.       end loop;
  22.       Close(File);
  23.   end Show_File;
  24.  
  25. begin -- procedure Show
  26.   if Argument_Count = 0 then
  27.     Put_Line(Current_Error, "Error - No file names given.");
  28.     Set_Exit_Status(Failure);
  29.   else
  30.     -- Open each file and show it.
  31.     for Arg in 1 .. Argument_Count loop
  32.       Show_File(Argument(Arg));
  33.     end loop;
  34.   end if;
  35. end Show;
  36.