summaryrefslogtreecommitdiff
path: root/shell/commands.adb
blob: da8548d253225b76a843c70b6875a37f039b6b28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--
--  $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;