diff options
Diffstat (limited to 'shell/commands.adb')
-rw-r--r-- | shell/commands.adb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/shell/commands.adb b/shell/commands.adb index d7971ce..da8548d 100644 --- a/shell/commands.adb +++ b/shell/commands.adb @@ -3,6 +3,10 @@ -- 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 @@ -32,4 +36,52 @@ package body Commands is 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; |