-- -- $Id$ -- with Ada.Text_IO; use Ada.Text_IO; with Command_Line_Arguments; use Command_Line_Arguments; with Getopt_R; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package body Commands is function Prompt return String is begin return "RTEMS> "; end Prompt; function C_Prompt return chars_ptr is begin return New_String (Prompt); end C_Prompt; function Command_Test_Arguments (ArgC : Argument_Count_Type; ArgV : Argument_Vector_Type) return int is Arguments : Argument_Array (1 .. ArgC); Count : Argument_Count_Type := 1; begin Arguments := Argument_Vector_Package.Value (ArgV, ArgC); loop exit when Count > ArgC; Put_Line (Value (Arguments (Count))); Count := Count + 1; end loop; return 0; end Command_Test_Arguments; function Command_Getopt_R (ArgC : Argument_Count_Type; ArgV : Argument_Vector_Type) return int is Test_String : String := "c:di:n:p:u:V"; Optchar : character; V : Integer; Reent : aliased Getopt_R.Reentrant; begin Getopt_R.Initialize( Reent'Unrestricted_Access, Argc, Argv ); loop V := Getopt_R.Getopt( Reent'Unrestricted_Access, Test_String ); exit when V = -1; optchar := Character'Val( V ); case optchar is when 'c' => Put_Line("command is "& To_String(Reent.Optarg)); when 'd' => Put_Line("debug on"); when 'i' => Put_line("got -i, its argument is:" & To_String(Reent.Optarg) ); when 'n' => Put_line("got -n, its argument is:" & To_String(Reent.Optarg)); when 'p' => Put_line("got -p, its argument is:" & To_String(Reent.Optarg)); when 'u' => Put_line("got -u, its argument is:" & To_String(Reent.Optarg)); when 'V' => Put_line("got -V"); when '?' => Put_Line("got ?, optopt is " & Reent.Optopt); when ':' => Put_Line("get :, optopt is "& Reent.optopt); when others => null; end case; end loop; for Count in Reent.Optind .. Reent.ArgC loop Put_Line (ptrdiff_t'Image(Count) & ": " & Get_Argument(Argv, Count)); end loop; return 0; end Command_Getopt_R; end Commands;