-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcommands.adb
99 lines (84 loc) · 3.29 KB
/
commands.adb
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
88
89
90
91
92
93
94
95
96
97
98
99
------------------------------------------------------------------------------
-- --
-- GNATcoverage --
-- --
-- Copyright (C) 2009-2024, AdaCore --
-- --
-- GNATcoverage is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This software is distributed in the hope that it will be useful --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Outputs; use Outputs;
package body Commands is
------------------
-- Check_Option --
------------------
procedure Check_Option
(Option : String;
Command : Command_Type;
Accepted_Commands : Command_Array) is
begin
for J in Accepted_Commands'Range loop
if Accepted_Commands (J) = Command then
return;
end if;
end loop;
Fatal_Error ("No option " & Option
& " for command " & To_Switch (Command));
end Check_Option;
------------------------
-- For_Command_Switch --
------------------------
function For_Command_Switch (Command : Command_Type) return String is
begin
if Command = No_Command then
return "";
else
return " for " & To_Switch (Command);
end if;
end For_Command_Switch;
----------------
-- To_Command --
----------------
function To_Command (Opt_String : String) return Command_Type is
Literal : String (1 .. Opt_String'Length) := Opt_String;
begin
for J in Literal'Range loop
if Literal (J) = '-' then
Literal (J) := '_';
end if;
end loop;
begin
if Literal (1 .. 2) = "__" then
return Command_Type'Value ("cmd_" & Literal (3 .. Literal'Last));
else
return Command_Type'Value ("cmd_" & Literal);
end if;
exception
when Constraint_Error =>
return No_Command;
end;
end To_Command;
---------------
-- To_Switch --
---------------
function To_Switch (Command : Command_Type) return String is
Result : String := To_Lower (Command'Img);
begin
for J in Result'Range loop
if Result (J) = '_' then
Result (J) := '-';
end if;
end loop;
-- Skip 'cmd_' prefix
return Result (Result'First + 4 .. Result'Last);
end To_Switch;
end Commands;