1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                               S W I T C H                                --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2003 Free Software Foundation, Inc.          --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17-- for  more details.  You should have  received  a copy of the GNU General --
18-- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20-- MA 02111-1307, USA.                                                      --
21--                                                                          --
22-- GNAT was originally developed  by the GNAT team at  New York University. --
23-- Extensive contributions were provided by Ada Core Technologies Inc.      --
24--                                                                          --
25------------------------------------------------------------------------------
26
27--  This package together with a child package appropriate to the client
28--  tool scans switches. Note that the body of the appropraite Usage package
29--  must be coordinated with the switches that are recognized by this package.
30--  These Usage packages also act as the official documentation for the
31--  switches that are recognized. In addition, package Debug documents
32--  the otherwise undocumented debug switches that are also recognized.
33
34with Types; use Types;
35
36package Switch is
37
38   --  Note: The default switch character is indicated by Switch_Character,
39   --  but regardless of what it is, a hyphen is always allowed as an
40   --  (alternative) switch character.
41
42   --  Note: In GNAT, the case of switches is not significant if
43   --  Switches_Case_Sensitive is False. If this is the case, switch
44   --  characters, or letters appearing in the parameter to a switch, may be
45   --  either upper case or lower case.
46
47   -----------------
48   -- Subprograms --
49   -----------------
50
51   function Is_Switch (Switch_Chars : String) return Boolean;
52   --  Returns True iff Switch_Chars is at least two characters long,
53   --  and the first character indicates it is a switch.
54
55   function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
56   --  Returns True iff Switch_Chars represents a front-end switch,
57   --  ie. it starts with -I or -gnat.
58
59private
60
61   --  This section contains some common routines used by the tool dependent
62   --  child packages (there is one such child package for each tool that
63   --  uses Switches to scan switches - Compiler/gnatbind/gnatmake/.
64
65   Bad_Switch : exception;
66   --  Exception raised if bad switch encountered
67
68   Bad_Switch_Value : exception;
69   --  Exception raised if bad switch value encountered
70
71   Missing_Switch_Value : exception;
72   --  Exception raised if no switch value encountered
73
74   Too_Many_Output_Files : exception;
75   --  Exception raised if the -o switch is encountered more than once
76
77   Switch_Max_Value : constant := 999_999;
78   --  Maximum value permitted in switches that take a value
79
80   procedure Scan_Nat
81     (Switch_Chars : String;
82      Max          : Integer;
83      Ptr          : in out Integer;
84      Result       : out Nat);
85   --  Scan natural integer parameter for switch. On entry, Ptr points
86   --  just past the switch character, on exit it points past the last
87   --  digit of the integer value.
88
89   procedure Scan_Pos
90     (Switch_Chars : String;
91      Max          : Integer;
92      Ptr          : in out Integer;
93      Result       : out Pos);
94   --  Scan positive integer parameter for switch. On entry, Ptr points
95   --  just past the switch character, on exit it points past the last
96   --  digit of the integer value.
97
98end Switch;
99