Changeset c53f12b in ada-examples


Ignore:
Timestamp:
Feb 2, 2011, 7:08:06 PM (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
ada-examples-4-10-branch, master
Children:
ba922cb
Parents:
e5636e3
Message:

2011-02-02 Joel Sherrill <joel.sherrill@…>

  • commands.adb, commands.ads, rtems_shell.ads, shell.adb: Add getopt_r Package and example command.
  • command_line_arguments.adb, command_line_arguments.ads, getopt_r.adb, getopt_r.ads: New files.
Location:
shell
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • shell/ChangeLog

    re5636e3 rc53f12b  
     12011-02-02      Joel Sherrill <joel.sherrill@gmail.com>
     2
     3        * commands.adb, commands.ads, rtems_shell.ads, shell.adb: Add getopt_r
     4        Package and example command.
     5        * command_line_arguments.adb, command_line_arguments.ads, getopt_r.adb,
     6        getopt_r.ads: New files.
     7
    182009-09-17      Joel Sherrill <joel.sherrill@oarcorp.com>
    29
  • shell/commands.adb

    re5636e3 rc53f12b  
    44
    55with Ada.Text_IO; use Ada.Text_IO;
     6with Command_Line_Arguments; use Command_Line_Arguments;
     7with Getopt_R;
     8with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
     9
    610
    711package body Commands is
     
    3337   end Command_Test_Arguments;
    3438
     39   function Command_Getopt_R
     40     (ArgC : Argument_Count_Type;
     41      ArgV : Argument_Vector_Type)
     42   return int is
     43      Test_String : String := "c:di:n:p:u:V";
     44      Optchar : character;
     45      V       : Integer;
     46      Reent   : aliased Getopt_R.Reentrant;
     47   begin
     48     Getopt_R.Initialize( Reent'Unrestricted_Access, Argc, Argv );
     49     loop
     50        V := Getopt_R.Getopt( Reent'Unrestricted_Access, Test_String );
     51        exit when V = -1;
     52
     53        optchar :=  Character'Val( V );
     54        case optchar is
     55           when 'c' =>
     56              Put_Line("command is "& To_String(Reent.Optarg));
     57           when 'd' =>
     58               Put_Line("debug on");
     59           when 'i' =>
     60              Put_line("got -i, its argument is:" & To_String(Reent.Optarg) );
     61           when 'n' =>
     62              Put_line("got -n, its argument is:" & To_String(Reent.Optarg));
     63           when 'p' =>
     64              Put_line("got -p, its argument is:" & To_String(Reent.Optarg));
     65           when 'u' =>
     66              Put_line("got -u, its argument is:" & To_String(Reent.Optarg));
     67           when 'V' =>
     68              Put_line("got -V");
     69
     70           when '?' =>
     71              Put_Line("got ?, optopt is " & Reent.Optopt);
     72
     73           when ':' =>
     74              Put_Line("get :, optopt is "& Reent.optopt);
     75
     76           when others => null;
     77        end case;
     78     end loop;
     79
     80     for Count in Reent.Optind .. Reent.ArgC
     81     loop
     82        Put_Line (ptrdiff_t'Image(Count) & ": " & Get_Argument(Argv, Count));
     83     end loop;
     84
     85     return 0;
     86   end Command_Getopt_R;
    3587end Commands;
  • shell/commands.ads

    re5636e3 rc53f12b  
    33--
    44
    5 with Interfaces.C;         use Interfaces.C;
    6 with Interfaces.C.Strings; use Interfaces.C.Strings;
    7 with RTEMS_Shell;          use RTEMS_Shell;
     5with RTEMS_Shell;            use RTEMS_Shell;
     6with Command_Line_Arguments; use Command_Line_Arguments;
     7with Interfaces.C;           use Interfaces.C;
     8with Interfaces.C.Strings;   use Interfaces.C.Strings;
    89
    910package Commands is
     
    1920   pragma Convention (C, Command_Test_Arguments);
    2021
     22   function Command_Getopt_R
     23     (ArgC : Argument_Count_Type;
     24      ArgV : Argument_Vector_Type)
     25      return int;
     26   pragma Convention (C, Command_Getopt_R);
     27
    2128end Commands;
  • shell/rtems_shell.ads

    re5636e3 rc53f12b  
    33--
    44
    5 with Interfaces.C;          use Interfaces.C;
    6 with Interfaces.C.Strings;  use Interfaces.C.Strings;
     5with Command_Line_Arguments; use Command_Line_Arguments;
     6with Interfaces.C;           use Interfaces.C;
     7with Interfaces.C.Strings;   use Interfaces.C.Strings;
    78with Interfaces.C.Pointers;
    89
    910package RTEMS_Shell is
    10 
    11    type Argument_Array is array (ptrdiff_t range <>) of aliased chars_ptr;
    12 
    13    package Argument_Vector_Package is
    14       new Pointers (Index              => ptrdiff_t,
    15                     Element            => chars_ptr,
    16                     Element_Array      => Argument_Array,
    17                     Default_Terminator => Null_Ptr);
    18 
    19    subtype Argument_Count_Type is ptrdiff_t;
    20    subtype Argument_Vector_Type is Argument_Vector_Package.Pointer;
    2111
    2212   type Command_Function_Type is access function (ArgC : Argument_Count_Type;
  • shell/shell.adb

    re5636e3 rc53f12b  
    77with RTEMS_Shell;          use RTEMS_Shell;
    88
    9 procedure Main is
     9procedure Shell is
    1010begin
     11   RTEMS_Shell_Add_Command
     12     (New_String ("getopt"),
     13      New_String ("test"),
     14      New_String ("Example of getopt with pattern c:di:n:p:u:V"),
     15      Command_Getopt_R'Access);
     16
    1117   RTEMS_Shell_Add_Command
    1218     (New_String ("args"),
     
    1420      New_String ("Test passing arguments"),
    1521      Command_Test_Arguments'Access);
     22
    1623   Set_RTEMS_Shell_Prompt_Function (C_Prompt'Access);
    17    Initialize_Telnet_Daemon;
     24   --  Initialize_Telnet_Daemon;
    1825   loop
    1926      Invoke_RTEMS_Shell;
    2027   end loop;
    21 end Main;
     28end Shell;
Note: See TracChangeset for help on using the changeset viewer.