source: ada-examples/shell/getopt_r.ads @ c53f12b

ada-examples-4-10-branch
Last change on this file since c53f12b was c53f12b, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 2, 2011 at 7:08:06 PM

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.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1--
2--                            REENTRANT GETOPT
3--                             SPECIFICATION
4-- $Id$
5--
6--  Based upon getopt by Nasser Abbasi.
7--  modifications to support reentrancy by Joel Sherrill.
8--
9--  Copyright (C) 1998 Nasser Abbasi <nabbasi@pacbell.net>
10--  Copyright (C) 2011 Joel Sherrill <joe.sherrill@oarcorp.com>
11--
12-- This is free software;  you can  redistribute it  and/or modify it under
13-- terms of the  GNU General Public License as published  by the Free Soft-
14-- ware  Foundation;  either version 2,  or (at your option) any later ver-
15-- sion. GETOPT is distributed in the hope that it will be useful, but WITH
16-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY
17-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18-- for  more details. Free Software Foundation,  59 Temple Place - Suite
19-- 330,  Boston, MA 02111-1307, USA.
20--
21-- As a special exception,  if other files  instantiate  generics from this
22-- unit, or you link  this unit with other files  to produce an executable,
23-- this  unit  does not  by itself cause  the resulting  executable  to  be
24-- covered  by the  GNU  General  Public  License.  This exception does not
25-- however invalidate  any other reasons why  the executable file  might be
26-- covered by the  GNU Public License.
27--
28------------------------------------------------------------------------------
29--
30-- change history:
31--
32-- name         changes
33-- ----------   --------------------------------------------------------------
34-- NMA021899    created
35-- NMA030299    Changed header to make it modified GPL
36--
37-- description:
38--
39-- This package is an Ada implementation of getopt() as specified by the
40-- document "The Single UNIX Specification, Version 2", Copyright 1997 The
41-- Open Group
42--
43-- This describes the items involveed using example
44--
45--
46--         curopt
47--           |
48--           V
49-- "-f foo -dbc -k"
50--  ^
51--  |
52-- optind
53--
54-- optind is position (index) that tells which command line argument is
55-- being processed now.
56-- curopt tells which optchar is being processed within one command line
57-- argument. This is needed only if more that one optchar are stuck
58-- togother in one argument with no space, as in -df where both d and f
59-- are valid optchar and d takes no optarg.
60--
61-- Compiler used: GCC 4.5.2 targeting i386-rtems4.10
62-- Platform:      Fedora 14/x86_64
63--
64
65
66with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
67with Command_Line_Arguments; use Command_Line_Arguments;
68
69package Getopt_R is
70
71   pragma Elaborate_Body;
72
73   type Reentrant is
74   record 
75     Optind : Argument_Count_type;
76     Optarg : Unbounded_String;
77     Optopt : Character := ' ';
78     Opterr : Integer := 1;
79     Curopt : Natural := 2;
80     Argc   : Argument_Count_Type;
81     Argv   : Argument_Vector_Type;
82   end record; 
83
84   type Reentrant_Ptr is access all Reentrant;
85
86   procedure Initialize (
87     R     : Reentrant_Ptr;
88     Argc  : Argument_Count_Type;
89     Argv  : Argument_Vector_Type);
90
91   function Getopt (
92     R : Reentrant_Ptr;
93     Optstring : String
94   ) return Integer;
95
96end Getopt_R;
Note: See TracBrowser for help on using the repository browser.