| 1 |
--with ARM_Output; |
| 2 |
--with ARM_Index; |
| 3 |
with ARM_Contents; |
| 4 |
with Ada.Characters.Handling; |
| 5 |
with Ada.Strings.Fixed; |
| 6 |
with Ada.Unchecked_Deallocation; |
| 7 |
--with Ada.Text_IO; -- ** Temp. |
| 8 |
package body ARM_Subindex is |
| 9 |
|
| 10 |
-- |
| 11 |
-- Ada reference manual formatter (ARM_Form). |
| 12 |
-- |
| 13 |
-- This package contains the database to store subindex items for |
| 14 |
-- non-normative appendixes. |
| 15 |
-- |
| 16 |
-- --------------------------------------- |
| 17 |
-- Copyright 2005, 2006, 2007, 2011, 2012 |
| 18 |
-- AXE Consultants. All rights reserved. |
| 19 |
-- P.O. Box 1512, Madison WI 53701 |
| 20 |
-- E-Mail: [email protected] |
| 21 |
-- |
| 22 |
-- ARM_Form is free software: you can redistribute it and/or modify |
| 23 |
-- it under the terms of the GNU General Public License version 3 |
| 24 |
-- as published by the Free Software Foundation. |
| 25 |
-- |
| 26 |
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS" |
| 27 |
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, |
| 28 |
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL. |
| 29 |
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL, |
| 30 |
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, |
| 31 |
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 32 |
-- DAMAGES. |
| 33 |
-- |
| 34 |
-- A copy of the GNU General Public License is available in the file |
| 35 |
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool. |
| 36 |
-- Otherwise, see <http://www.gnu.org/licenses/>. |
| 37 |
-- |
| 38 |
-- If the GPLv3 license is not satisfactory for your needs, a commercial |
| 39 |
-- use license is available for this tool. Contact Randy at AXE Consultants |
| 40 |
-- for more information. |
| 41 |
-- |
| 42 |
-- --------------------------------------- |
| 43 |
-- |
| 44 |
-- Edit History: |
| 45 |
-- |
| 46 |
-- 10/28/05 - RLB - Created package. |
| 47 |
-- 8/ 4/06 - RLB - Fixed problems if unit was missing. |
| 48 |
-- 9/22/06 - RLB - Changed to use Clause_Number_Type. |
| 49 |
-- 2/13/07 - RLB - Changed Start_Paragraph to use explicit indents. |
| 50 |
-- 12/19/07 - RLB - Revised Text_Format calls. |
| 51 |
-- 10/18/11 - RLB - Changed to GPLv3 license. |
| 52 |
-- 4/ 3/12 - RLB - Removed unused declaration. |
| 53 |
|
| 54 |
type String_Ptr is access String; |
| 55 |
type Item is record |
| 56 |
Next : Item_List; |
| 57 |
Entity : String_Ptr := null; |
| 58 |
From_Unit : String_Ptr := null; |
| 59 |
Kind : Subindex_Item_Kind_Type := Top_Level; |
| 60 |
Clause : String (1..10); |
| 61 |
Clause_Len : Natural; |
| 62 |
Clause_Number : ARM_Contents.Clause_Number_Type; |
| 63 |
Paragraph : String (1..10); |
| 64 |
Paragraph_Len : Natural; |
| 65 |
Key : ARM_Index.Index_Key; |
| 66 |
end record; |
| 67 |
|
| 68 |
procedure Free is new Ada.Unchecked_Deallocation (Item, Item_List); |
| 69 |
procedure Free is new Ada.Unchecked_Deallocation (String, String_Ptr); |
| 70 |
|
| 71 |
|
| 72 |
procedure Create (Subindex_Object : in out Subindex_Type) is |
| 73 |
-- Initialize a Subindex object. |
| 74 |
begin |
| 75 |
Subindex_Object.Is_Valid := True; |
| 76 |
Subindex_Object.List := null; |
| 77 |
Subindex_Object.Item_Count := 0; |
| 78 |
end Create; |
| 79 |
|
| 80 |
|
| 81 |
procedure Destroy (Subindex_Object : in out Subindex_Type) is |
| 82 |
-- Destroy a Subindex object, freeing any resources used. |
| 83 |
Temp : Item_List; |
| 84 |
begin |
| 85 |
if not Subindex_Object.Is_Valid then |
| 86 |
raise Not_Valid_Error; |
| 87 |
end if; |
| 88 |
while Subindex_Object.List /= null loop |
| 89 |
Temp := Subindex_Object.List; |
| 90 |
Subindex_Object.List := Temp.Next; |
| 91 |
Free (Temp.Entity); |
| 92 |
Free (Temp.From_Unit); |
| 93 |
Free (Temp); |
| 94 |
end loop; |
| 95 |
Subindex_Object.Is_Valid := False; |
| 96 |
end Destroy; |
| 97 |
|
| 98 |
|
| 99 |
procedure Insert (Subindex_Object : in out Subindex_Type; |
| 100 |
Entity : in String; |
| 101 |
From_Unit : in String := ""; |
| 102 |
Kind : in Subindex_Item_Kind_Type := Top_Level; |
| 103 |
Clause : in String := ""; |
| 104 |
Paragraph : in String := ""; |
| 105 |
Key : in ARM_Index.Index_Key) is |
| 106 |
-- Insert an item into the Subindex object. |
| 107 |
-- The Key must be one returned by ARM_Index.Add or ARM_Index.Get_Key. |
| 108 |
-- Raises Not_Valid_Error if From_Unit, Clause, or Paragraph is not |
| 109 |
-- empty when the kind does not use it; or if From_Unit is empty |
| 110 |
-- when the kind requires it. |
| 111 |
Temp_Item : Item; |
| 112 |
begin |
| 113 |
if not Subindex_Object.Is_Valid then |
| 114 |
raise Not_Valid_Error; |
| 115 |
end if; |
| 116 |
if Kind = Top_Level and then From_Unit'Length /= 0 then |
| 117 |
raise Not_Valid_Error; -- No subterm here. |
| 118 |
end if; |
| 119 |
Ada.Strings.Fixed.Move (Target => Temp_Item.Clause, |
| 120 |
Source => Clause, |
| 121 |
Drop => Ada.Strings.Error, |
| 122 |
Pad => ' '); |
| 123 |
Temp_Item.Clause_Len := Clause'Length; |
| 124 |
Ada.Strings.Fixed.Move (Target => Temp_Item.Paragraph, |
| 125 |
Source => Paragraph, |
| 126 |
Drop => Ada.Strings.Error, |
| 127 |
Pad => ' '); |
| 128 |
Temp_Item.Paragraph_Len := Paragraph'Length; |
| 129 |
ARM_Contents.Make_Clause (Clause, Temp_Item.Clause_Number); |
| 130 |
Temp_Item.Kind := Kind; |
| 131 |
Temp_Item.Key := Key; |
| 132 |
Temp_Item.Entity := new String'(Entity); |
| 133 |
if From_Unit'Length /= 0 then |
| 134 |
Temp_Item.From_Unit := new String'(From_Unit); |
| 135 |
else |
| 136 |
if Kind = In_Unit or else |
| 137 |
Kind = Child_of_Parent or else |
| 138 |
Kind = Subtype_In_Unit or else |
| 139 |
Kind = Description_In_Unit or else |
| 140 |
Kind = Raised_Belonging_to_Unit then |
| 141 |
-- There must be a unit here. |
| 142 |
raise Not_Valid_Error; |
| 143 |
end if; |
| 144 |
end if; |
| 145 |
Temp_Item.Next := Subindex_Object.List; |
| 146 |
Subindex_Object.List := new Item'(Temp_Item); |
| 147 |
Subindex_Object.Item_Count := Subindex_Object.Item_Count + 1; |
| 148 |
end Insert; |
| 149 |
|
| 150 |
|
| 151 |
procedure Write_Subindex ( |
| 152 |
Subindex_Object : in out Subindex_Type; |
| 153 |
Output_Object : in out ARM_Output.Output_Type'Class; |
| 154 |
Use_Paragraphs : in Boolean := True; |
| 155 |
Minimize_Lines : in Boolean := False) is |
| 156 |
-- Generate the given subindex to Output_Object. |
| 157 |
-- References include paragraph numbers if Use_Paragraphs is true. |
| 158 |
-- Try to minimize lines if Minimize_Lines is True. |
| 159 |
-- Note: This should not leave us in a paragraph. |
| 160 |
Temp : Item_List; |
| 161 |
Last : Item_List := null; |
| 162 |
Items : array (1..Subindex_Object.Item_Count) of Item_List; |
| 163 |
|
| 164 |
Keep_Set : Boolean := False; |
| 165 |
|
| 166 |
CHARS_ON_SINGLE_LINE : constant := 38; |
| 167 |
-- The number of characters allowed on a single line if |
| 168 |
-- "Minimize_Lines" is True. |
| 169 |
|
| 170 |
function To_Lower (A : in String) return String renames |
| 171 |
Ada.Characters.Handling.To_Lower; |
| 172 |
|
| 173 |
|
| 174 |
function "<" (Left, Right : Item_List) return Boolean is |
| 175 |
use type ARM_Contents.Clause_Number_Type; |
| 176 |
|
| 177 |
type Compare_Result is (Less, Greater, Equal); |
| 178 |
function Compare (Left, Right : in String) return Compare_Result is |
| 179 |
-- By binding the arguments, we cut the heap usage by |
| 180 |
-- nearly half, and thus the runtime of the compare routine. |
| 181 |
begin |
| 182 |
if Left < Right then |
| 183 |
return Less; |
| 184 |
elsif Left > Right then |
| 185 |
return Greater; |
| 186 |
else |
| 187 |
return Equal; |
| 188 |
end if; |
| 189 |
end Compare; |
| 190 |
begin |
| 191 |
-- We sort first on "Entity", then on "Kind", then on "From_Unit", |
| 192 |
-- then on "Clause", and finally on "Paragraph". |
| 193 |
case Compare (To_Lower (Left.Entity.all), To_Lower (Right.Entity.all)) is |
| 194 |
when Less => return True; |
| 195 |
when Greater => return False; |
| 196 |
when Equal => null; -- Continue to next compare. |
| 197 |
end case; |
| 198 |
if Left.Kind = Right.Kind then |
| 199 |
null; -- Continue to next compare. |
| 200 |
elsif Left.Kind < Right.Kind then |
| 201 |
return True; |
| 202 |
else --if Left.Kind > Right.Kind then |
| 203 |
return False; |
| 204 |
end if; |
| 205 |
if Left.From_Unit = null then |
| 206 |
null; -- No string to compare (Kind=Top_Level) |
| 207 |
else |
| 208 |
case Compare (To_Lower (Left.From_Unit.all), To_Lower (Right.From_Unit.all)) is |
| 209 |
when Less => return True; |
| 210 |
when Greater => return False; |
| 211 |
when Equal => null; -- Continue to next compare. |
| 212 |
end case; |
| 213 |
end if; |
| 214 |
|
| 215 |
-- Note: We use the numbers, because the references don't |
| 216 |
-- sort right (11.1 comes before 2.8, etc.) |
| 217 |
if Left.Clause_Number < Right.Clause_Number then |
| 218 |
return True; |
| 219 |
elsif Left.Clause_Number = Right.Clause_Number then |
| 220 |
-- Make sure that single digit paragraph numbers sort before |
| 221 |
-- multiple digit ones: |
| 222 |
if Left.Paragraph_Len <= 1 or else Left.Paragraph(2) = '.' or else Left.Paragraph(2) = '/' then |
| 223 |
-- Single digit number: |
| 224 |
if Right.Paragraph_Len <= 1 or else Right.Paragraph(2) = '.' or else Right.Paragraph(2) = '/' then |
| 225 |
-- Single digit number, normal compare: |
| 226 |
return Left.Paragraph (1..Left.Paragraph_Len) < Right.Paragraph (1..Right.Paragraph_Len); |
| 227 |
else |
| 228 |
-- Single digit is always less than multiple digits: |
| 229 |
return True; |
| 230 |
end if; |
| 231 |
else -- Not single digit number: |
| 232 |
if Right.Paragraph_Len <= 1 or else Right.Paragraph(2) = '.' or else Right.Paragraph(2) = '/' then |
| 233 |
-- Single digit number, always less than multiple digits: |
| 234 |
return False; |
| 235 |
else |
| 236 |
-- Else both multiple, use normal compare: |
| 237 |
return Left.Paragraph (1..Left.Paragraph_Len) < Right.Paragraph (1..Right.Paragraph_Len); |
| 238 |
end if; |
| 239 |
end if; |
| 240 |
else -- Left.Clause_Number > Right.Clause_Number then |
| 241 |
return False; |
| 242 |
end if; |
| 243 |
end "<"; |
| 244 |
|
| 245 |
|
| 246 |
procedure Partition_Sort_Slice (Start_Index, End_Index : Natural) is |
| 247 |
-- Use quicksort partition sort to sort the slice between |
| 248 |
-- Start_Index and End_Index. |
| 249 |
Temp_Item : Item_List; |
| 250 |
begin |
| 251 |
case ((End_Index - Start_Index) + 1) is |
| 252 |
when 0 | 1 => null; -- A single element is obviously sorted (trivially). |
| 253 |
when 2 => |
| 254 |
-- Unrolled Insertion Sort. |
| 255 |
if Items(Start_Index+1) < Items(Start_Index) then |
| 256 |
-- Move the record down. |
| 257 |
Temp_Item := Items(Start_Index+1); |
| 258 |
Items(Start_Index+1) := Items(Start_Index ); |
| 259 |
Items(Start_Index ) := Temp_Item; -- Put at beginning. |
| 260 |
-- else Doesn't need to move. |
| 261 |
end if; |
| 262 |
when 3 => |
| 263 |
-- Unrolled Insertion Sort. |
| 264 |
if Items(Start_Index+1) < Items(Start_Index) then |
| 265 |
-- Move the record down. |
| 266 |
Temp_Item := Items(Start_Index+1); |
| 267 |
Items(Start_Index+1) := Items(Start_Index ); |
| 268 |
Items(Start_Index ) := Temp_Item; -- Put at beginning. |
| 269 |
-- else Doesn't need to move. |
| 270 |
end if; |
| 271 |
if Items(Start_Index+2) < Items(Start_Index+1) then |
| 272 |
-- Move the record down. |
| 273 |
Temp_Item := Items(Start_Index+2); |
| 274 |
Items(Start_Index+2) := Items(Start_Index+1); |
| 275 |
if Temp_Item < Items(Start_Index) then |
| 276 |
-- Move the record down. |
| 277 |
Items(Start_Index+1) := Items(Start_Index); |
| 278 |
Items(Start_Index) := Temp_Item; -- Put at beginning. |
| 279 |
else |
| 280 |
-- Put the record here. |
| 281 |
Items(Start_Index+1) := Temp_Item; |
| 282 |
end if; |
| 283 |
-- else Doesn't need to move. |
| 284 |
end if; |
| 285 |
when 4 => |
| 286 |
-- Unrolled Insertion Sort. |
| 287 |
if Items(Start_Index+1) < Items(Start_Index) then |
| 288 |
-- Move the record down. |
| 289 |
Temp_Item := Items(Start_Index+1); |
| 290 |
Items(Start_Index+1) := Items(Start_Index ); |
| 291 |
Items(Start_Index ) := Temp_Item; -- Put at beginning. |
| 292 |
-- else Doesn't need to move. |
| 293 |
end if; |
| 294 |
if Items(Start_Index+2) < Items(Start_Index+1) then |
| 295 |
-- Move the record down. |
| 296 |
Temp_Item := Items(Start_Index+2); |
| 297 |
Items(Start_Index+2) := Items(Start_Index+1); |
| 298 |
if Temp_Item < Items(Start_Index) then |
| 299 |
-- Move the record down. |
| 300 |
Items(Start_Index+1) := Items(Start_Index); |
| 301 |
Items(Start_Index) := Temp_Item; -- Put at beginning. |
| 302 |
else |
| 303 |
-- Put the record here. |
| 304 |
Items(Start_Index+1) := Temp_Item; |
| 305 |
end if; |
| 306 |
-- else Doesn't need to move. |
| 307 |
end if; |
| 308 |
if Items(Start_Index+3) < Items(Start_Index+2) then |
| 309 |
-- Move the record down. |
| 310 |
Temp_Item := Items(Start_Index+3); |
| 311 |
Items(Start_Index+3) := Items(Start_Index+2); |
| 312 |
if Temp_Item < Items(Start_Index+1) then |
| 313 |
-- Move the record down. |
| 314 |
Items(Start_Index+2) := Items(Start_Index+1); |
| 315 |
if Temp_Item < Items(Start_Index) then |
| 316 |
-- Move the record down. |
| 317 |
Items(Start_Index+1) := Items(Start_Index); |
| 318 |
Items(Start_Index) := Temp_Item; -- Put at beginning. |
| 319 |
else -- Put the record here. |
| 320 |
Items(Start_Index+1) := Temp_Item; |
| 321 |
end if; |
| 322 |
else |
| 323 |
-- Put the record here. |
| 324 |
Items(Start_Index+2) := Temp_Item; |
| 325 |
end if; |
| 326 |
-- else Don't move the record. |
| 327 |
end if; |
| 328 |
when others => -- Longer partitions, quicksort. |
| 329 |
declare |
| 330 |
Left_Index, Right_Index : Natural; |
| 331 |
Pivot_Item : Item_List; |
| 332 |
begin |
| 333 |
-- Split into partitions, and sort them. |
| 334 |
Left_Index := Start_Index; |
| 335 |
Right_Index := End_Index; |
| 336 |
-- Use the middle element for the pivot, in case the items are |
| 337 |
-- somewhat sorted. |
| 338 |
Pivot_Item := Items ((End_Index - Start_Index) / 2 + Start_Index); |
| 339 |
loop |
| 340 |
loop |
| 341 |
exit when not (Items(Left_Index) < Pivot_Item); -- >= |
| 342 |
Left_Index := Left_Index + 1; |
| 343 |
end loop; |
| 344 |
loop |
| 345 |
exit when not (Pivot_Item < Items(Right_Index)); |
| 346 |
Right_Index := Right_Index - 1; |
| 347 |
end loop; |
| 348 |
if Left_Index <= Right_Index then |
| 349 |
if Left_Index < Right_Index then |
| 350 |
Temp_Item := Items(Left_Index); |
| 351 |
Items(Left_Index) := Items(Right_Index); |
| 352 |
Items(Right_Index) := Temp_Item; |
| 353 |
end if; |
| 354 |
Left_Index := Left_Index + 1; |
| 355 |
Right_Index := Right_Index - 1; |
| 356 |
end if; |
| 357 |
exit when Left_Index > Right_Index; |
| 358 |
end loop; -- Repeat Loop |
| 359 |
-- Recursive calls on partitions. |
| 360 |
Partition_Sort_Slice (Left_Index, End_Index); |
| 361 |
Partition_Sort_Slice (Start_Index, Right_Index); |
| 362 |
end; |
| 363 |
end case; |
| 364 |
end Partition_Sort_Slice; |
| 365 |
|
| 366 |
|
| 367 |
procedure Term_Text (Text : in String) is |
| 368 |
A_Soft_Hyphen : Natural := Ada.Strings.Fixed.Index (Text, "@!"); |
| 369 |
begin |
| 370 |
if A_Soft_Hyphen = 0 then |
| 371 |
ARM_Output.Ordinary_Text (Output_Object, Text); |
| 372 |
else |
| 373 |
ARM_Output.Ordinary_Text (Output_Object, Text(Text'First .. A_Soft_Hyphen-1)); |
| 374 |
ARM_Output.Soft_Hyphen_Break (Output_Object); |
| 375 |
Term_Text (Text(A_Soft_Hyphen+2 .. Text'Last)); -- In case there is more than one soft hyphen. |
| 376 |
end if; |
| 377 |
end Term_Text; |
| 378 |
|
| 379 |
|
| 380 |
procedure Clause_Ref (Item : Item_List) is |
| 381 |
-- Generate a clause reference: |
| 382 |
begin |
| 383 |
if Item.Clause_Len > 5 and then Item.Clause (1..5) = "Annex" then |
| 384 |
-- Strip off the "Annex". |
| 385 |
if Use_Paragraphs and then Item.Paragraph_Len /= 0 then |
| 386 |
ARM_Output.Index_Reference (Output_Object, |
| 387 |
Text => Item.Clause (Item.Clause_Len) & '(' & |
| 388 |
Item.Paragraph (1..Item.Paragraph_Len) & ')', |
| 389 |
Index_Key => Item.Key, |
| 390 |
Clause_Number => Item.Clause (1..Item.Clause_Len)); |
| 391 |
else |
| 392 |
ARM_Output.Index_Reference (Output_Object, |
| 393 |
Text => Item.Clause (Item.Clause_Len) & "", |
| 394 |
Index_Key => Item.Key, |
| 395 |
Clause_Number => Item.Clause (1..Item.Clause_Len)); |
| 396 |
end if; |
| 397 |
elsif Use_Paragraphs and then Item.Paragraph_Len /= 0 then |
| 398 |
ARM_Output.Index_Reference (Output_Object, |
| 399 |
Text => Item.Clause (1..Item.Clause_Len) & '(' & |
| 400 |
Item.Paragraph (1..Item.Paragraph_Len) & ')', |
| 401 |
Index_Key => Item.Key, |
| 402 |
Clause_Number => Item.Clause (1..Item.Clause_Len)); |
| 403 |
else |
| 404 |
ARM_Output.Index_Reference (Output_Object, |
| 405 |
Text => Item.Clause (1..Item.Clause_Len), |
| 406 |
Index_Key => Item.Key, |
| 407 |
Clause_Number => Item.Clause (1..Item.Clause_Len)); |
| 408 |
end if; |
| 409 |
end Clause_Ref; |
| 410 |
|
| 411 |
|
| 412 |
procedure Italic_Text (Text : in String) is |
| 413 |
begin |
| 414 |
ARM_Output.Text_Format (Output_Object, |
| 415 |
Format => (Bold => False, Italic => True, |
| 416 |
Font => ARM_Output.Default, |
| 417 |
Size => 0, Color => ARM_Output.Default, |
| 418 |
Change => ARM_Output.None, |
| 419 |
Version | Added_Version => '0', |
| 420 |
Location => ARM_Output.Normal)); |
| 421 |
ARM_Output.Ordinary_Text (Output_Object, Text); |
| 422 |
ARM_Output.Text_Format (Output_Object, |
| 423 |
Format => (Bold => False, Italic => False, |
| 424 |
Font => ARM_Output.Default, |
| 425 |
Size => 0, Color => ARM_Output.Default, |
| 426 |
Change => ARM_Output.None, |
| 427 |
Version | Added_Version => '0', |
| 428 |
Location => ARM_Output.Normal)); |
| 429 |
end Italic_Text; |
| 430 |
|
| 431 |
|
| 432 |
procedure New_Kind (Item : Item_List; Reset_Keep : in Boolean; |
| 433 |
Last_Had_Same_Unit : Boolean := False) is |
| 434 |
-- Generate and item of a new kind. Note that the term has already |
| 435 |
-- been generated (at some point). |
| 436 |
begin |
| 437 |
case Item.Kind is |
| 438 |
when Top_Level => |
| 439 |
-- ** Must be first, so can't get here. |
| 440 |
Italic_Text ("*SORT ERROR*"); |
| 441 |
ARM_Output.Hard_Space (Output_Object); |
| 442 |
ARM_Output.Hard_Space (Output_Object); |
| 443 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 444 |
Clause_Ref (Item); |
| 445 |
|
| 446 |
when In_Unit => |
| 447 |
if Last_Had_Same_Unit then |
| 448 |
-- ** Must be before any other items with a unit, |
| 449 |
-- so can't get here. |
| 450 |
Italic_Text ("*SORT ERROR*"); |
| 451 |
end if; |
| 452 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => Reset_Keep); |
| 453 |
ARM_Output.Hard_Space (Output_Object); |
| 454 |
ARM_Output.Hard_Space (Output_Object); |
| 455 |
ARM_Output.Hard_Space (Output_Object); |
| 456 |
if Item.From_Unit /= null then |
| 457 |
Italic_Text ("in"); |
| 458 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 459 |
Term_Text (Item.From_Unit.all); |
| 460 |
-- else shouldn't be empty, but why crash? |
| 461 |
end if; |
| 462 |
ARM_Output.Hard_Space (Output_Object); |
| 463 |
ARM_Output.Hard_Space (Output_Object); |
| 464 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 465 |
Clause_Ref (Item); |
| 466 |
|
| 467 |
when Child_of_Parent => |
| 468 |
if Last_Had_Same_Unit then |
| 469 |
-- ** Must be before any other items with a unit, |
| 470 |
-- so can't get here. |
| 471 |
Italic_Text ("*SORT ERROR*"); |
| 472 |
end if; |
| 473 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => Reset_Keep); |
| 474 |
ARM_Output.Hard_Space (Output_Object); |
| 475 |
ARM_Output.Hard_Space (Output_Object); |
| 476 |
ARM_Output.Hard_Space (Output_Object); |
| 477 |
if Item.From_Unit /= null then |
| 478 |
Italic_Text ("child of"); |
| 479 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 480 |
Term_Text (Item.From_Unit.all); |
| 481 |
-- else shouldn't be empty, but why crash? |
| 482 |
end if; |
| 483 |
ARM_Output.Hard_Space (Output_Object); |
| 484 |
ARM_Output.Hard_Space (Output_Object); |
| 485 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 486 |
Clause_Ref (Item); |
| 487 |
|
| 488 |
when Subtype_In_Unit => |
| 489 |
if Last_Had_Same_Unit then |
| 490 |
-- ** Must be before any other items with a unit, |
| 491 |
-- so can't get here. |
| 492 |
Italic_Text ("*SORT ERROR*"); |
| 493 |
end if; |
| 494 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => Reset_Keep); |
| 495 |
ARM_Output.Hard_Space (Output_Object); |
| 496 |
ARM_Output.Hard_Space (Output_Object); |
| 497 |
ARM_Output.Hard_Space (Output_Object); |
| 498 |
if Item.From_Unit /= null then |
| 499 |
Italic_Text ("in"); |
| 500 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 501 |
Term_Text (Item.From_Unit.all); |
| 502 |
-- else shouldn't be empty, but why crash? |
| 503 |
end if; |
| 504 |
ARM_Output.Hard_Space (Output_Object); |
| 505 |
ARM_Output.Hard_Space (Output_Object); |
| 506 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 507 |
Clause_Ref (Item); |
| 508 |
|
| 509 |
when Description_In_Unit => |
| 510 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => Reset_Keep); |
| 511 |
if not Last_Had_Same_Unit then |
| 512 |
ARM_Output.Hard_Space (Output_Object); |
| 513 |
ARM_Output.Hard_Space (Output_Object); |
| 514 |
ARM_Output.Hard_Space (Output_Object); |
| 515 |
if Item.From_Unit /= null then |
| 516 |
Italic_Text ("in"); |
| 517 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 518 |
Term_Text (Item.From_Unit.all); |
| 519 |
-- else shouldn't be empty, but why crash? |
| 520 |
end if; |
| 521 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => False); |
| 522 |
end if; |
| 523 |
ARM_Output.Hard_Space (Output_Object); |
| 524 |
ARM_Output.Hard_Space (Output_Object); |
| 525 |
ARM_Output.Hard_Space (Output_Object); |
| 526 |
ARM_Output.Hard_Space (Output_Object); |
| 527 |
ARM_Output.Hard_Space (Output_Object); |
| 528 |
ARM_Output.Hard_Space (Output_Object); |
| 529 |
Italic_Text ("description"); |
| 530 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 531 |
Clause_Ref (Item); |
| 532 |
|
| 533 |
when Raised_Belonging_to_Unit => |
| 534 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => Reset_Keep); |
| 535 |
if not Last_Had_Same_Unit then |
| 536 |
ARM_Output.Hard_Space (Output_Object); |
| 537 |
ARM_Output.Hard_Space (Output_Object); |
| 538 |
ARM_Output.Hard_Space (Output_Object); |
| 539 |
if Item.From_Unit /= null then |
| 540 |
Italic_Text ("in"); |
| 541 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 542 |
Term_Text (Item.From_Unit.all); |
| 543 |
-- else shouldn't be empty, but why crash? |
| 544 |
end if; |
| 545 |
ARM_Output.Index_Line_Break (Output_Object, Clear_Keep_with_Next => False); |
| 546 |
end if; |
| 547 |
ARM_Output.Hard_Space (Output_Object); |
| 548 |
ARM_Output.Hard_Space (Output_Object); |
| 549 |
ARM_Output.Hard_Space (Output_Object); |
| 550 |
ARM_Output.Hard_Space (Output_Object); |
| 551 |
ARM_Output.Hard_Space (Output_Object); |
| 552 |
ARM_Output.Hard_Space (Output_Object); |
| 553 |
Italic_Text ("raised"); |
| 554 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 555 |
Clause_Ref (Item); |
| 556 |
|
| 557 |
end case; |
| 558 |
end New_Kind; |
| 559 |
|
| 560 |
function Is_Last_for_Entity (Item : in Item_List) return Boolean is |
| 561 |
-- Returns True if this is the last line for Item's Entity. |
| 562 |
begin |
| 563 |
--Ada.Text_IO.Put_Line("Enter Is_Last"); |
| 564 |
if Item.Next = null then |
| 565 |
--Ada.Text_IO.Put_Line(" No follower (True)"); |
| 566 |
return True; |
| 567 |
elsif To_Lower (Item.Entity.all) /= To_Lower(Item.Next.Entity.all) then |
| 568 |
-- The next item has a different entity. |
| 569 |
--Ada.Text_IO.Put_Line(" Different entity (True)"); |
| 570 |
return True; |
| 571 |
elsif Item.Kind /= Item.Next.Kind then |
| 572 |
-- The next item has a different kind, so another line will |
| 573 |
-- be generated. |
| 574 |
--Ada.Text_IO.Put_Line(" Different kind (False)"); |
| 575 |
return False; |
| 576 |
elsif Item.Kind /= Top_Level and then |
| 577 |
Item.From_Unit.all /= Item.Next.From_Unit.all then |
| 578 |
-- The next item has a different unit, so another line will |
| 579 |
-- be generated. |
| 580 |
--Ada.Text_IO.Put_Line(" Different unit (False)"); |
| 581 |
return False; |
| 582 |
else |
| 583 |
-- The following entity will just add another clause reference. |
| 584 |
-- So we must look at the entity following that: |
| 585 |
--Ada.Text_IO.Put_Line(" Recurse"); |
| 586 |
return Is_Last_for_Entity (Item.Next); |
| 587 |
end if; |
| 588 |
end Is_Last_for_Entity; |
| 589 |
|
| 590 |
begin |
| 591 |
if not Subindex_Object.Is_Valid then |
| 592 |
raise Not_Valid_Error; |
| 593 |
end if; |
| 594 |
|
| 595 |
Keep_Set := False; |
| 596 |
|
| 597 |
-- Load the items: |
| 598 |
Temp := Subindex_Object.List; |
| 599 |
for I in Items'range loop |
| 600 |
Items(I) := Temp; |
| 601 |
Temp := Temp.Next; |
| 602 |
end loop; |
| 603 |
|
| 604 |
-- Sort the items: |
| 605 |
Partition_Sort_Slice (Items'First, Items'Last); |
| 606 |
|
| 607 |
-- Relink the items in the sorted order: |
| 608 |
for I in Items'First .. Items'Last - 1 loop |
| 609 |
Items(I).Next := Items(I+1); |
| 610 |
end loop; |
| 611 |
if Items'Length > 0 then |
| 612 |
Items(Items'Last).Next := null; |
| 613 |
Subindex_Object.List := Items(1); |
| 614 |
else |
| 615 |
Subindex_Object.List := null; |
| 616 |
end if; |
| 617 |
|
| 618 |
ARM_Output.Start_Paragraph (Output_Object, ARM_Output.Index, |
| 619 |
Indent => 0, Number => "", No_Breaks => True); |
| 620 |
|
| 621 |
Temp := Subindex_Object.List; |
| 622 |
while Temp /= null loop |
| 623 |
-- First, check for the new entity: |
| 624 |
if Last = null or else |
| 625 |
To_Lower(Last.Entity.all) /= To_Lower(Temp.Entity.all) then |
| 626 |
-- New term: (Note that we ignore case differences here. |
| 627 |
-- Perhaps there ought to be a warning?) |
| 628 |
if Last /= null then |
| 629 |
ARM_Output.End_Paragraph (Output_Object); |
| 630 |
if Temp.Kind = Top_Level then |
| 631 |
ARM_Output.Start_Paragraph (Output_Object, ARM_Output.Index, |
| 632 |
Indent => 0, Number => "", |
| 633 |
No_Breaks => True); |
| 634 |
Keep_Set := False; |
| 635 |
--Ada.Text_IO.Put_Line("New Item: Entity=" & Temp.Entity.all & |
| 636 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 637 |
--" Keep_Set=" & Boolean'Image(Keep_Set)); |
| 638 |
elsif Minimize_Lines and then |
| 639 |
Temp.Kind = In_Unit and then |
| 640 |
Temp.Entity'Length + 4 + Temp.From_Unit'Length < CHARS_ON_SINGLE_LINE then |
| 641 |
-- Write as a single line. |
| 642 |
ARM_Output.Start_Paragraph (Output_Object, ARM_Output.Index, |
| 643 |
Indent => 0, Number => "", |
| 644 |
No_Breaks => True); |
| 645 |
Keep_Set := False; |
| 646 |
--Ada.Text_IO.Put_Line("New Item: Entity=" & Temp.Entity.all & |
| 647 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 648 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 649 |
else -- The item has at least two lines; keep them together. |
| 650 |
ARM_Output.Start_Paragraph (Output_Object, ARM_Output.Index, |
| 651 |
Indent => 0, Number => "", |
| 652 |
No_Breaks => True, Keep_with_Next => True); |
| 653 |
Keep_Set := True; |
| 654 |
--Ada.Text_IO.Put_Line("New Item: Entity=" & Temp.Entity.all & |
| 655 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 656 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 657 |
end if; |
| 658 |
end if; |
| 659 |
if Temp.Kind /= Subtype_In_Unit then |
| 660 |
Term_Text (Temp.Entity.all); |
| 661 |
else |
| 662 |
declare |
| 663 |
Of_Loc : Natural := |
| 664 |
Ada.Strings.Fixed.Index (Temp.Entity.all, |
| 665 |
" subtype of "); |
| 666 |
begin |
| 667 |
if Of_Loc = 0 then |
| 668 |
-- Weird, "subtype of" not found. |
| 669 |
Term_Text (Temp.Entity.all); |
| 670 |
else |
| 671 |
Term_Text (Temp.Entity (Temp.Entity'First .. Of_Loc)); |
| 672 |
Italic_Text ("subtype of"); |
| 673 |
Term_Text (Temp.Entity (Of_Loc+11 .. Temp.Entity'Last)); |
| 674 |
end if; |
| 675 |
end; |
| 676 |
end if; |
| 677 |
if Temp.Kind = Top_Level then |
| 678 |
ARM_Output.Hard_Space (Output_Object); |
| 679 |
ARM_Output.Hard_Space (Output_Object); |
| 680 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 681 |
Clause_Ref (Temp); |
| 682 |
else |
| 683 |
if Is_Last_for_Entity (Temp) then |
| 684 |
-- Last (only) item of this term, always clear Keep: |
| 685 |
--Ada.Text_IO.Put_Line("Only New Item: Entity=" & Temp.Entity.all & |
| 686 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 687 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 688 |
if Minimize_Lines and then |
| 689 |
Temp.Kind = In_Unit and then |
| 690 |
Temp.Entity'Length + 4 + Temp.From_Unit'Length < CHARS_ON_SINGLE_LINE then |
| 691 |
-- Write this as a single line: |
| 692 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 693 |
Italic_Text ("in"); |
| 694 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 695 |
Term_Text (Temp.From_Unit.all); |
| 696 |
ARM_Output.Hard_Space (Output_Object); |
| 697 |
ARM_Output.Hard_Space (Output_Object); |
| 698 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 699 |
Clause_Ref (Temp); |
| 700 |
else |
| 701 |
New_Kind (Temp, Reset_Keep => True, Last_Had_Same_Unit => False); |
| 702 |
Keep_Set := False; |
| 703 |
end if; |
| 704 |
else -- Leave keep set: |
| 705 |
--Ada.Text_IO.Put_Line("More New Item: Entity=" & Temp.Entity.all & |
| 706 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 707 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 708 |
New_Kind (Temp, Reset_Keep => False, Last_Had_Same_Unit => False); |
| 709 |
end if; |
| 710 |
end if; |
| 711 |
elsif Last.Kind /= Temp.Kind then |
| 712 |
If Last.Kind /= Top_Level and then |
| 713 |
Temp.Kind /= Top_Level and then |
| 714 |
Last.From_Unit.all = Temp.From_Unit.all then |
| 715 |
--Ada.Text_IO.Put_Line("New Kind, same unit: Entity=" & Temp.Entity.all & |
| 716 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 717 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 718 |
New_Kind (Temp, Reset_Keep => Keep_Set, Last_Had_Same_Unit => True); |
| 719 |
else |
| 720 |
--if Temp.Kind /= Top_Level then |
| 721 |
--Ada.Text_IO.Put_Line("New Kind: Entity=" & Temp.Entity.all & |
| 722 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 723 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 724 |
--else |
| 725 |
--Ada.Text_IO.Put_Line("New Kind: Entity=" & Temp.Entity.all & |
| 726 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 727 |
--" Keep_Set=" & Boolean'Image(Keep_Set)); |
| 728 |
--end if; |
| 729 |
New_Kind (Temp, Reset_Keep => Keep_Set, Last_Had_Same_Unit => False); |
| 730 |
end if; |
| 731 |
Keep_Set := False; |
| 732 |
elsif (Temp.Kind = In_Unit or else |
| 733 |
Temp.Kind = Child_of_Parent or else |
| 734 |
Temp.Kind = Subtype_In_Unit or else |
| 735 |
Temp.Kind = Description_In_Unit or else |
| 736 |
Temp.Kind = Raised_Belonging_to_Unit) and then |
| 737 |
Last.From_Unit.all /= Temp.From_Unit.all then |
| 738 |
--Ada.Text_IO.Put_Line("Same Kind, new unit: Entity=" & Temp.Entity.all & |
| 739 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 740 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 741 |
New_Kind (Temp, Reset_Keep => Keep_Set, Last_Had_Same_Unit => False); |
| 742 |
Keep_Set := False; |
| 743 |
elsif Last.Clause (1..Last.Clause_Len) = Temp.Clause (1..Temp.Clause_Len) and then |
| 744 |
Last.Paragraph (1..Last.Paragraph_Len) = Temp.Paragraph (1..Temp.Paragraph_Len) then |
| 745 |
-- The reference and everything else is the same, so just |
| 746 |
-- forget this item. |
| 747 |
null; |
| 748 |
else |
| 749 |
--if Temp.Kind /= Top_Level then |
| 750 |
--Ada.Text_IO.Put_Line("Same: Entity=" & Temp.Entity.all & |
| 751 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 752 |
--" From_Unit=" & Temp.From_Unit.all & " Keep_Set=" & Boolean'Image(Keep_Set)); |
| 753 |
--else |
| 754 |
--Ada.Text_IO.Put_Line("Same: Entity=" & Temp.Entity.all & |
| 755 |
--" Kind=" & Subindex_Item_Kind_Type'Image(Temp.Kind) & |
| 756 |
--" Keep_Set=" & Boolean'Image(Keep_Set)); |
| 757 |
--end if; |
| 758 |
-- Just add the next clause. |
| 759 |
ARM_Output.Ordinary_Character (Output_Object, ','); |
| 760 |
ARM_Output.Ordinary_Character (Output_Object, ' '); |
| 761 |
Clause_Ref (Temp); |
| 762 |
end if; |
| 763 |
Last := Temp; |
| 764 |
Temp := Temp.Next; |
| 765 |
end loop; |
| 766 |
|
| 767 |
ARM_Output.End_Paragraph (Output_Object); |
| 768 |
|
| 769 |
end Write_Subindex; |
| 770 |
|
| 771 |
end ARM_Subindex; |
| 772 |
|
| 773 |
|