Debian Codegraph @

progs/arm_cont.ads

raw
1 with Ada.Strings.Unbounded;
2 package ARM_Contents is
3
4 --
5 -- Ada reference manual formatter (ARM_Form).
6 --
7 -- This package contains the routines to manage section/clause/subclause
8 -- references.
9 --
10 -- ---------------------------------------
11 -- Copyright 2000, 2004, 2006, 2007, 2009, 2011, 2012
12 -- AXE Consultants. All rights reserved.
13 -- P.O. Box 1512, Madison WI 53701
14 -- E-Mail: [email protected]
15 --
16 -- ARM_Form is free software: you can redistribute it and/or modify
17 -- it under the terms of the GNU General Public License version 3
18 -- as published by the Free Software Foundation.
19 --
20 -- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS"
21 -- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY,
22 -- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL.
23 -- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL,
24 -- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
25 -- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
26 -- DAMAGES.
27 --
28 -- A copy of the GNU General Public License is available in the file
29 -- gpl-3-0.txt in the standard distribution of the ARM_Form tool.
30 -- Otherwise, see <http://www.gnu.org/licenses/>.
31 --
32 -- If the GPLv3 license is not satisfactory for your needs, a commercial
33 -- use license is available for this tool. Contact Randy at AXE Consultants
34 -- for more information.
35 --
36 -- ---------------------------------------
37 --
38 -- Edit History:
39 --
40 -- 4/19/00 - RLB - Created base package.
41 -- 4/26/00 - RLB - Added Previous_Clause and Next_Clause.
42 -- 5/15/00 - RLB - Added rules about unnumbered sections.
43 -- 5/22/00 - RLB - Added Unnumbered_Section level.
44 -- 8/ 7/00 - RLB - Made Make_Clause visible.
45 -- 8/22/00 - RLB - Added Old_Title handling.
46 -- 9/14/04 - RLB - Moved Change_Version_Type here, to avoid mutual
47 -- dependence.
48 -- - RLB - Added version to changes.
49 -- 9/22/06 - RLB - Created type Clause_Number_Type and added SubSubClause.
50 -- 12/18/07 - RLB - Added Plain_Annex.
51 -- 5/06/09 - RLB - Added Versioned_String.
52 -- 5/07/09 - RLB - Added Dead_Clause.
53 -- 10/18/11 - RLB - Changed to GPLv3 license.
54 -- 10/19/11 - RLB - Added Parent_Clause from Stephen Leake's version.
55 -- 10/25/11 - RLB - Added version to Old name strings.
56 -- 8/30/12 - RLB - Added initialization of Section to UNKNOWN to
57 -- detect bugs earlier.
58
59 subtype Title_Type is String (1 .. 80);
60 -- The type of a title.
61
62 type Section_Number_Type is range 0 .. 58;
63 -- Values > 30 represent annex letters (31 => A, 32 => B, etc.)
64 -- Value = 0 represents the preface, introduction, etc. No
65 -- number is generated if Section_Number = 0.
66 ANNEX_START : constant := 31; -- First annex section number.
67 UNKNOWN : constant Section_Number_Type := 58; -- Uninitialized sections get this.
68
69 subtype Change_Version_Type is Character range '0' .. '9';
70 -- Defines the change version. Version 0 is the original text.
71
72 type Versioned_String is array (ARM_Contents.Change_Version_Type) of
73 Ada.Strings.Unbounded.Unbounded_String;
74
75 type Clause_Number_Type is record
76 Section : Section_Number_Type := UNKNOWN;
77 Clause : Natural := 0;
78 Subclause : Natural := 0;
79 Subsubclause : Natural := 0;
80 end record;
81
82 Not_Found_Error : exception;
83
84 Bad_Clause_Error : exception;
85 -- Raised by any of the below if the Clause_Number is
86 -- invalid (potentially depending on the other parameters,
87 -- like the level).
88
89 procedure Initialize;
90 -- Initialize this package; make sure the contents are empty.
91
92 type Level_Type is (Section, Unnumbered_Section, Plain_Annex,
93 Normative_Annex, Informative_Annex,
94 Clause, Subclause, Subsubclause, Dead_Clause);
95 -- Defines the level of a clause header.
96 -- Clause is "xx.nn"; Subclause is "xx.nn.nn"; Subsubclause is "xx.nn.nn.nn".
97
98 function "<" (Left, Right : Clause_Number_Type) return Boolean;
99 -- True if Left comes before Right in the collating order.
100
101 function ">" (Left, Right : Clause_Number_Type) return Boolean;
102 -- True if Left comes after Right in the collating order.
103
104 function "<=" (Left, Right : Clause_Number_Type) return Boolean;
105 -- True if Left comes before or is the same as Right in the
106 -- collating order.
107
108 function ">=" (Left, Right : Clause_Number_Type) return Boolean;
109 -- True if Left comes after or is the same as Right in the
110 -- collating order.
111
112 procedure Add (Title : in Title_Type;
113 Level : in Level_Type;
114 Clause_Number : in Clause_Number_Type;
115 Version : in ARM_Contents.Change_Version_Type := '0');
116 -- Add a section or clause to the contents. It has the specified
117 -- characteristics.
118
119 procedure Add_Old (Old_Title : in Title_Type;
120 Level : in Level_Type;
121 Clause_Number : in Clause_Number_Type;
122 Version : in ARM_Contents.Change_Version_Type := '0');
123 -- Add an old title for a section or clause to the contents. It has
124 -- the specified characteristics; the version is the version for which
125 -- it first was present in the document.
126
127 function Make_Clause_Number (Level : in Level_Type;
128 Clause_Number : in Clause_Number_Type) return String;
129 -- Returns a properly formatted Section or clause number reference.
130 -- Note that an unnumbered section returns a number with a
131 -- Section_Number of zero (for sorting purposes).
132
133 procedure Make_Clause (Clause_String : in String;
134 Clause_Number : out Clause_Number_Type);
135 -- Returns the clause number for a properly formatted Section or
136 -- clause string.
137
138 function Lookup_Clause_Number (Title : in Title_Type) return String;
139 -- Given the title of a clause, returns the formatted Section or
140 -- clause number reference for that title. The Title must match
141 -- exactly, except for case. Raises Not_Found_Error if not found.
142
143 function Lookup_Level (Title : in Title_Type) return Level_Type;
144 -- Given the title of a clause, returns the level for that title. The Title must match
145 -- exactly, except for case. Raises Not_Found_Error if not found.
146
147 function Lookup_Title (Level : in Level_Type;
148 Clause_Number : in Clause_Number_Type) return Title_Type;
149 -- Given the level and clause numbers, return the appropriate
150 -- title. Raises Not_Found_Error if not found.
151
152 function Lookup_Old_Title (Level : in Level_Type;
153 Clause_Number : in Clause_Number_Type) return Title_Type;
154 -- Given the level and clause numbers, return the appropriate
155 -- old title. Calls Lookup_Title if not found (thus returning the
156 -- regular (new) title.
157
158 function Previous_Clause (Clause : in String) return String;
159 -- Returns the string of the previous clause (in the table of contents)
160 -- for the properly formatted clause string Clause.
161 -- Raises Not_Found_Error if not found.
162
163 function Next_Clause (Clause : in String) return String;
164 -- Returns the string of the next clause (in the table of contents)
165 -- for the properly formatted clause string Clause.
166 -- Raises Not_Found_Error if not found.
167
168 function Parent_Clause (Clause : in String) return String;
169 -- Returns the string of the parent clause (in the table of contents)
170 -- for the properly formatted clause string Clause.
171 --
172 -- Result is a null string if Clause is a top level clause;
173 -- Section, Unnumbered_Section, Normative_Annex,
174 -- Informative_Annex, Plain_Annex.
175
176 generic
177 with procedure Operate (Title : in Title_Type;
178 Level : in Level_Type;
179 Clause_Number : in Clause_Number_Type;
180 Version : in ARM_Contents.Change_Version_Type;
181 Quit : out Boolean) is <>;
182 procedure For_Each;
183 -- Call Operate for each title in the contents, in the order that
184 -- they were added to the contents. If the Quit parameter to Operate
185 -- is True when Operate returns, the iteration is abandoned.
186
187 end ARM_Contents;