Debian Codegraph @

progs/arm_text.adb

raw
1 with --ARM_Output,
2 --ARM_Contents,
3 --Ada.Text_IO,
4 Ada.Exceptions,
5 Ada.Strings.Fixed;
6 package body ARM_Text is
7
8 --
9 -- Ada reference manual formatter (ARM_Form).
10 --
11 -- This package defines the text output object.
12 -- Output objects are responsible for implementing the details of
13 -- a particular format.
14 --
15 -- ---------------------------------------
16 -- Copyright 2000, 2002, 2004, 2005, 2006, 2007, 2011, 2012
17 -- AXE Consultants. All rights reserved.
18 -- P.O. Box 1512, Madison WI 53701
19 -- E-Mail: [email protected]
20 --
21 -- ARM_Form is free software: you can redistribute it and/or modify
22 -- it under the terms of the GNU General Public License version 3
23 -- as published by the Free Software Foundation.
24 --
25 -- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS"
26 -- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY,
27 -- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL.
28 -- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL,
29 -- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
30 -- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
31 -- DAMAGES.
32 --
33 -- A copy of the GNU General Public License is available in the file
34 -- gpl-3-0.txt in the standard distribution of the ARM_Form tool.
35 -- Otherwise, see <http://www.gnu.org/licenses/>.
36 --
37 -- If the GPLv3 license is not satisfactory for your needs, a commercial
38 -- use license is available for this tool. Contact Randy at AXE Consultants
39 -- for more information.
40 --
41 -- ---------------------------------------
42 --
43 -- Edit History:
44 --
45 -- 4/14/00 - RLB - Created base package.
46 -- 4/18/00 - RLB - Added index and contents marker routines.
47 -- - Improved formatting.
48 -- 4/21/00 - RLB - Added line break and hard space routines.
49 -- 4/24/00 - RLB - Added DR references and Insert/Delete text formats.
50 -- 4/25/00 - RLB - Added size to format.
51 -- 4/29/00 - RLB - Added more formats.
52 -- 5/10/00 - RLB - Added even more formats.
53 -- - RLB - Added End_Hang_Item.
54 -- 5/12/00 - RLB - Added No_Prefix to Start_Paragraph.
55 -- 5/13/00 - RLB - Added Special_Character.
56 -- 5/17/00 - RLB - Added New_Page.
57 -- 5/22/00 - RLB - Added Includes_Changes to Create.
58 -- 5/23/00 - RLB - Added Set_Column and New_Column.
59 -- - Added Tab_Info and Tab_Stops.
60 -- 5/24/00 - RLB - Added Location to Text_Format.
61 -- - RLB - Added No_Breaks and Keep_with_Next to Start_Paragraph.
62 -- 5/25/00 - RLB - Added Big_Files to Create. Added Justification.
63 -- - RLB - Added Separator_Lines and TOC routines.
64 -- 5/26/00 - RLB - Added table operations.
65 -- 6/ 2/00 - RLB - Added Soft_Line_Break.
66 -- 8/ 2/00 - RLB - Added Soft_Hyphen_Break and left and right quote
67 -- characters.
68 -- - RLB - Added additional styles.
69 -- 8/ 4/00 - RLB - Added additional styles.
70 -- 8/ 7/00 - RLB - Added Leading flag to Start_Paragraph, removed "Leading"
71 -- styles.
72 -- 8/11/00 - RLB - Added Hanging_in_Bulleted styles.
73 -- 8/16/00 - RLB - Added Code_Indented_Nested_Bulleted.
74 -- 8/17/00 - RLB - Replaced "Leading" by "Space_After".
75 -- - RLB - Added Nested_Enumerated.
76 -- 8/22/00 - RLB - Added Revised_Clause_Header.
77 -- 8/23/00 - RLB - Fixed a problem with long lines in examples.
78 -- 9/26/00 - RLB - Added Syntax_Summary style.
79 -- 7/18/02 - RLB - Removed Document parameter from Create, replaced by
80 -- three strings and For_ISO boolean.
81 -- - RLB - Added AI_Reference.
82 -- - RLB - Added Change_Version_Type and uses.
83 -- 9/10/04 - RLB - Added "Both" to possible changes to handle
84 -- replacement of changed text.
85 -- 9/14/04 - RLB - Moved Change_Version_Type to ARM_Contents.
86 -- 11/03/04 - RLB - Added Nested_X2_Bulleted.
87 -- 11/15/04 - RLB - Added Indented_Nested_Bulleted.
88 -- 1/24/05 - RLB - Added Inner_Indented.
89 -- 2/ 1/05 - RLB - Added Turkish chars to allow an AARM note.
90 -- 5/27/05 - RLB - Added arbitrary Unicode characters.
91 -- 1/11/06 - RLB - Eliminated dispatching Create in favor of tailored
92 -- versions.
93 -- 1/13/06 - RLB - Added new Link operations.
94 -- 1/18/06 - RLB - Added additional styles.
95 -- 2/ 8/06 - RLB - Added additional parameters to the table command.
96 -- 2/10/06 - RLB - Added even more additional parameters to the
97 -- table command.
98 -- - RLB - Added picture command.
99 -- 9/22/06 - RLB - Added Subsubclause.
100 -- 9/25/06 - RLB - Handled optional renaming of TOC.
101 -- - RLB - Added Last_Column_Width to Start_Table.
102 -- 10/13/06 - RLB - Added Local_Link_Start and Local_Link_End to allow
103 -- formatting in the linked text.
104 -- 2/ 9/07 - RLB - Changed comments on AI_Reference.
105 -- 2/13/07 - RLB - Revised to separate style and indent information
106 -- for paragraphs.
107 -- 12/18/07 - RLB - Added Plain_Annex.
108 -- 12/19/07 - RLB - Added limited colors to Text_Format.
109 -- 10/18/11 - RLB - Changed to GPLv3 license.
110 -- 10/25/11 - RLB - Fixed "hidden" indent (lost due to space for
111 -- paragraph number).
112 -- - RLB - Added old insertion version to Revised_Clause_Header.
113 -- 8/31/12 - RLB - Added Output_Path.
114 -- 10/18/12 - RLB - Added additional hanging styles.
115 -- 11/26/12 - RLB - Added subdivision names to Clause_Header and
116 -- Revised_Clause_Header.
117
118 LINE_LENGTH : constant := 78;
119 -- Maximum intended line length.
120
121 procedure Put_Line_Centered (File : in out Ada.Text_IO.File_Type;
122 Text : in String) is
123 -- Put a line of text centered.
124 begin
125 for I in 1 .. (LINE_LENGTH - Text'Length - 1) / 2 loop
126 -- Center the heading.
127 Ada.Text_IO.Put (File, ' ');
128 end loop;
129 Ada.Text_IO.Put_Line (File, Text);
130 end Put_Line_Centered;
131
132
133 procedure Create (Output_Object : in out Text_Output_Type;
134 File_Prefix : in String;
135 Output_Path : in String;
136 Title : in String := "") is
137 -- Create an Output_Object for a document.
138 -- The prefix of the output file names is File_Prefix - this
139 -- should be no more then 5 characters allowed in file names.
140 -- The result files will be written to Output_Path.
141 -- The title of the document is Title.
142 begin
143 if Output_Object.Is_Valid then
144 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
145 "Already valid object");
146 end if;
147 Output_Object.Is_Valid := True;
148 Ada.Strings.Fixed.Move (Target => Output_Object.File_Prefix,
149 Source => File_Prefix);
150 Ada.Strings.Fixed.Move (Target => Output_Object.Output_Path,
151 Source => Output_Path);
152 Output_Object.Output_Path_Len := Output_Path'Length;
153 -- We don't use the title.
154 end Create;
155
156
157 procedure Close (Output_Object : in out Text_Output_Type) is
158 -- Close an Output_Object. No further output to the object is
159 -- allowed after this call.
160 begin
161 if not Output_Object.Is_Valid then
162 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
163 "Not valid object");
164 end if;
165 if Ada.Text_IO.Is_Open (Output_Object.Output_File) then
166 Ada.Text_IO.Close (Output_Object.Output_File);
167 end if;
168 Output_Object.Is_Valid := False;
169 end Close;
170
171
172 procedure Section (Output_Object : in out Text_Output_Type;
173 Section_Title : in String;
174 Section_Name : in String) is
175 -- Start a new section. The title is Section_Title (this is
176 -- intended for humans). The name is Section_Name (this is
177 -- intended to be suitable to be a portion of a file name).
178 begin
179 if not Output_Object.Is_Valid then
180 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
181 "Not valid object");
182 end if;
183 if Output_Object.Is_In_Paragraph then
184 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
185 "Section in paragraph");
186 end if;
187 if Ada.Text_IO.Is_Open (Output_Object.Output_File) then
188 Ada.Text_IO.Close (Output_Object.Output_File);
189 end if;
190 -- Create a new file for this section:
191 -- Unix directory separators for Windows and Debian
192 Ada.Text_IO.Create (Output_Object.Output_File, Ada.Text_IO.Out_File,
193 Output_Object.Output_Path(1..Output_Object.Output_Path_Len) &
194 Ada.Strings.Fixed.Trim (Output_Object.File_Prefix, Ada.Strings.Right) &
195 "-" & Section_Name & ".TXT");
196 Ada.Text_IO.New_Line (Output_Object.Output_File);
197 end Section;
198
199
200 procedure Set_Columns (Output_Object : in out Text_Output_Type;
201 Number_of_Columns : in ARM_Output.Column_Count) is
202 -- Set the number of columns.
203 -- Raises Not_Valid_Error if in a paragraph.
204 begin
205 if not Output_Object.Is_Valid then
206 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
207 "Not valid object");
208 end if;
209 if Output_Object.Is_In_Paragraph then
210 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
211 "In paragraph");
212 end if;
213 -- No columns in text format.
214 end Set_Columns;
215
216
217 procedure Make_Indent (Output_Object : in out Text_Output_Type) is
218 -- Internal:
219 -- Output the appropriate indent after a New_Line or Put_Line.
220 begin
221 --Ada.Text_IO.Put_Line("Make_Indent: Amount=" & Natural'Image(Output_Object.Indent_Amount));
222 for I in 1 .. Output_Object.Indent_Amount loop
223 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
224 end loop;
225 Output_Object.Char_Count := Output_Object.Indent_Amount;
226 Output_Object.Out_Char_Count := Output_Object.Indent_Amount;
227 Output_Object.Output_Buffer_Space_Before := False;
228 end Make_Indent;
229
230
231 procedure Spill (Output_Object : in out Text_Output_Type) is
232 -- Internal:
233 -- Empty the output buffer in preperation for a New_Line or Put_Line.
234 begin
235 if Output_Object.Output_Buffer_Space_Before then
236 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
237 Output_Object.Char_Count := Output_Object.Char_Count + 1; -- Count the space.
238 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + 1; -- Count the space.
239 end if;
240 if Output_Object.Output_Buffer_Len /= 0 then
241 Ada.Text_IO.Put (Output_Object.Output_File,
242 Output_Object.Output_Buffer (1 .. Output_Object.Output_Buffer_Len));
243 --Ada.Text_IO.Put_Line("Spill: Len=" & Natural'Image(Output_Object.Output_Buffer_Len) &
244 -- " Space added=" & Boolean'Image(Output_Object.Output_Buffer_Space_Before) & " Text=" &
245 -- Output_Object.Output_Buffer (1 .. Output_Object.Output_Buffer_Len));
246 Output_Object.Output_Buffer_Len := 0;
247 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count +
248 Output_Object.Output_Buffer_Len;
249 end if;
250 Output_Object.Output_Buffer_Space_Before := False;
251 end Spill;
252
253
254 procedure Buffer (Output_Object : in out Text_Output_Type;
255 Char : in Character) is
256 -- Internal:
257 -- Add Char to the output buffer. Char will *not* be a word break
258 -- character.
259 begin
260 if Output_Object.Output_Buffer_Len = Output_Object.Output_Buffer'Last then
261 -- Oops, buffer is full. Spill it, and this character.
262 --Ada.Text_IO.Put_Line("** Buffer overflow!!");
263 Spill (Output_Object);
264 Ada.Text_IO.Put (Output_Object.Output_File, Char);
265 Output_Object.Char_Count := Output_Object.Char_Count + 1;
266 return;
267 end if;
268 Output_Object.Output_Buffer_Len := Output_Object.Output_Buffer_Len + 1;
269 Output_Object.Output_Buffer(Output_Object.Output_Buffer_Len) := Char;
270 Output_Object.Char_Count := Output_Object.Char_Count + 1;
271 end Buffer;
272
273
274 procedure Start_Paragraph (Output_Object : in out Text_Output_Type;
275 Style : in ARM_Output.Paragraph_Style_Type;
276 Indent : in ARM_Output.Paragraph_Indent_Type;
277 Number : in String;
278 No_Prefix : in Boolean := False;
279 Tab_Stops : in ARM_Output.Tab_Info := ARM_Output.NO_TABS;
280 No_Breaks : in Boolean := False;
281 Keep_with_Next : in Boolean := False;
282 Space_After : in ARM_Output.Space_After_Type
283 := ARM_Output.Normal;
284 Justification : in ARM_Output.Justification_Type
285 := ARM_Output.Default) is
286 -- Start a new paragraph. The style and indent of the paragraph is as
287 -- specified. The (AA)RM paragraph number (which might include update
288 -- and version numbers as well: [12.1/1]) is Number. If the format is
289 -- a type with a prefix (bullets, hangining items), the prefix is
290 -- omitted if No_Prefix is true. Tab_Stops defines the tab stops for
291 -- the paragraph. If No_Breaks is True, we will try to avoid page breaks
292 -- in the paragraph. If Keep_with_Next is true, we will try to avoid
293 -- separating this paragraph and the next one. (These may have no
294 -- effect in formats that don't have page breaks). Space_After
295 -- specifies the amount of space following the paragraph. Justification
296 -- specifies the text justification for the paragraph. Not_Valid_Error
297 -- is raised if Tab_Stops /= NO_TABS for a hanging or bulleted format.
298 Start_Indent : Natural;
299 begin
300 if not Output_Object.Is_Valid then
301 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
302 "Not valid object");
303 end if;
304 if Output_Object.Is_In_Paragraph then
305 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
306 "Already in paragraph");
307 end if;
308 Output_Object.Is_In_Paragraph := True;
309 Output_Object.Is_Hanging := False;
310 Output_Object.Saw_Hang_End := False;
311 Output_Object.Char_Count := 0;
312 Output_Object.Out_Char_Count := 0;
313 Output_Object.Output_Buffer_Space_Before := False; -- Nothing in it or on the line.
314 Output_Object.Output_Buffer_Len := 0;
315
316 if ARM_Output."/=" (Indent, 0) then
317 Output_Object.Indent_Amount := Natural(Indent)*4 + 4;
318 else
319 Output_Object.Indent_Amount := 0;
320 end if;
321 Start_Indent := Output_Object.Indent_Amount;
322
323 case Style is
324 when ARM_Output.Normal => null;
325 when ARM_Output.Wide_Above => null;
326 when ARM_Output.Small => null;
327 when ARM_Output.Small_Wide_Above => null;
328 when ARM_Output.Header => null;
329 when ARM_Output.Small_Header => null;
330 when ARM_Output.Title => null;
331 when ARM_Output.Index => null;
332 when ARM_Output.Syntax_Summary => null;
333 when ARM_Output.Examples => null;
334 when ARM_Output.Small_Examples => null;
335 when ARM_Output.Swiss_Examples => null;
336 when ARM_Output.Small_Swiss_Examples => null;
337 when ARM_Output.Bulleted | ARM_Output.Nested_Bulleted |
338 ARM_Output.Small_Bulleted | ARM_Output.Small_Nested_Bulleted =>
339 if No_Prefix then
340 null;
341 else -- Has prefix (added later)
342 Start_Indent := Start_Indent - 4;
343 end if;
344
345 when ARM_Output.Giant_Hanging | ARM_Output.Small_Giant_Hanging =>
346 Output_Object.Is_Hanging := True;
347 if No_Prefix then -- Four units for prefix.
348 Output_Object.Saw_Hang_End := True;
349 else -- Has prefix
350 Output_Object.Saw_Hang_End := False;
351 Start_Indent := Start_Indent - 16; -- Leave space for prefix.
352 end if;
353
354 when ARM_Output.Wide_Hanging | ARM_Output.Small_Wide_Hanging =>
355 Output_Object.Is_Hanging := True;
356 if No_Prefix then -- Three units for prefix.
357 Output_Object.Saw_Hang_End := True;
358 else -- Has prefix
359 Output_Object.Saw_Hang_End := False;
360 Start_Indent := Start_Indent - 12; -- Leave space for prefix.
361 end if;
362
363 when ARM_Output.Medium_Hanging | ARM_Output.Small_Medium_Hanging =>
364 Output_Object.Is_Hanging := True;
365 if No_Prefix then -- Two units for prefix.
366 Output_Object.Saw_Hang_End := True;
367 else -- Has prefix
368 Output_Object.Saw_Hang_End := False;
369 Start_Indent := Start_Indent - 8; -- Leave space for prefix.
370 end if;
371
372 when ARM_Output.Narrow_Hanging | ARM_Output.Small_Narrow_Hanging => null;
373 Output_Object.Is_Hanging := True;
374 if No_Prefix then -- One unit for prefix.
375 Output_Object.Saw_Hang_End := True;
376 else -- Has prefix.
377 Output_Object.Saw_Hang_End := False;
378 Start_Indent := Start_Indent - 4; -- Leave space for prefix.
379 end if;
380
381 when ARM_Output.Hanging_in_Bulleted |
382 ARM_Output.Small_Hanging_in_Bulleted =>
383 Output_Object.Is_Hanging := True;
384 if No_Prefix then -- Two units for prefix.
385 Output_Object.Saw_Hang_End := True;
386 else -- Has prefix.
387 Output_Object.Saw_Hang_End := False;
388 Start_Indent := Start_Indent - 8; -- Leave space for prefix.
389 end if;
390
391 when ARM_Output.Enumerated | ARM_Output.Small_Enumerated =>
392 Output_Object.Is_Hanging := True;
393 if No_Prefix then -- One unit for prefix.
394 Output_Object.Saw_Hang_End := True;
395 else -- Has prefix.
396 Output_Object.Saw_Hang_End := False;
397 Start_Indent := Start_Indent - 4; -- Leave space for prefix.
398 end if;
399 end case;
400 if Number /= "" then
401 -- Note: The following assumes that Start_Indent is a multiple of 4.
402 Ada.Text_IO.Put (Output_Object.Output_File, Number);
403 Output_Object.Char_Count := Output_Object.Char_Count + Number'Length;
404 for I in Integer'Min(Number'Length + 1, 4) .. 4 loop
405 -- The 'Min here ensures that every number is always followed
406 -- by at least one space.
407 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
408 Output_Object.Char_Count := Output_Object.Char_Count + 1;
409 end loop;
410 -- Add the next four characters of indent (only if needed), taking
411 -- into account any use of this space by the paragraph number.
412 if Start_Indent > 4 then -- (Really 8 or more); add the next three characters of the indent, but take into account any paragraph number length.
413 if Number'Length <= 3 then
414 Ada.Text_IO.Put (Output_Object.Output_File, " ");
415 Output_Object.Char_Count := Output_Object.Char_Count + 4;
416 elsif Number'Length = 4 then
417 Ada.Text_IO.Put (Output_Object.Output_File, " ");
418 Output_Object.Char_Count := Output_Object.Char_Count + 3;
419 elsif Number'Length = 5 then
420 Ada.Text_IO.Put (Output_Object.Output_File, " ");
421 Output_Object.Char_Count := Output_Object.Char_Count + 2;
422 elsif Number'Length = 6 then
423 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
424 Output_Object.Char_Count := Output_Object.Char_Count + 1;
425 end if;
426 end if;
427 -- Add the next four characters of indent (only if needed), taking
428 -- into account any use of this space by the paragraph number.
429 if Start_Indent > 8 then -- (Really 12 or more); add the next three characters of the indent, but take into account any paragraph number length.
430 if Number'Length <= 7 then
431 Ada.Text_IO.Put (Output_Object.Output_File, " ");
432 Output_Object.Char_Count := Output_Object.Char_Count + 4;
433 elsif Number'Length = 8 then
434 Ada.Text_IO.Put (Output_Object.Output_File, " ");
435 Output_Object.Char_Count := Output_Object.Char_Count + 3;
436 elsif Number'Length = 9 then
437 Ada.Text_IO.Put (Output_Object.Output_File, " ");
438 Output_Object.Char_Count := Output_Object.Char_Count + 2;
439 elsif Number'Length = 10 then
440 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
441 Output_Object.Char_Count := Output_Object.Char_Count + 1;
442 end if;
443 end if;
444 if Start_Indent > 12 then -- Add any remaining indent.
445 for I in 1 .. (Start_Indent-12)/4 loop
446 Ada.Text_IO.Put (Output_Object.Output_File, " ");
447 Output_Object.Char_Count := Output_Object.Char_Count + 4;
448 end loop;
449 end if;
450 else -- No paragraph number:
451 if Start_Indent /= 0 then
452 for I in 1 .. Start_Indent/4 loop
453 Ada.Text_IO.Put (Output_Object.Output_File, " ");
454 Output_Object.Char_Count := Output_Object.Char_Count + 4;
455 end loop;
456 end if;
457 end if;
458
459 -- Add bullets if needed:
460 case Style is
461 when ARM_Output.Bulleted | ARM_Output.Nested_Bulleted |
462 ARM_Output.Small_Bulleted | ARM_Output.Small_Nested_Bulleted =>
463 if No_Prefix then
464 null;
465 else -- Has prefix (added later)
466 Ada.Text_IO.Put (Output_Object.Output_File, " * ");
467 Output_Object.Char_Count := Output_Object.Char_Count + 4;
468 end if;
469 when others =>
470 null;
471 end case;
472
473 case Style is
474 when ARM_Output.Normal | ARM_Output.Wide_Above |
475 ARM_Output.Small | ARM_Output.Small_Wide_Above |
476 ARM_Output.Header | ARM_Output.Small_Header |
477 ARM_Output.Index | ARM_Output.Syntax_Summary |
478 ARM_Output.Title |
479 ARM_Output.Examples | ARM_Output.Small_Examples |
480 ARM_Output.Swiss_Examples | ARM_Output.Small_Swiss_Examples =>
481 Output_Object.Tab_Stops := Tab_Stops;
482 -- We'll expand proportional stops here (text characters
483 -- are larger than the variable ones these are set up for).
484 for I in 1 .. Tab_Stops.Number loop
485 if ARM_Output."=" (Tab_Stops.Stops(I).Kind,
486 ARM_Output.Left_Proportional) then
487 Output_Object.Tab_Stops.Stops(I).Stop :=
488 (Tab_Stops.Stops(I).Stop * 5 / 4) + Output_Object.Indent_Amount;
489 else
490 Output_Object.Tab_Stops.Stops(I).Stop :=
491 Tab_Stops.Stops(I).Stop + Output_Object.Indent_Amount;
492 end if;
493 end loop;
494 when ARM_Output.Bulleted | ARM_Output.Nested_Bulleted |
495 ARM_Output.Small_Bulleted | ARM_Output.Small_Nested_Bulleted |
496 ARM_Output.Giant_Hanging | ARM_Output.Wide_Hanging |
497 ARM_Output.Medium_Hanging | ARM_Output.Narrow_Hanging |
498 ARM_Output.Hanging_in_Bulleted |
499 ARM_Output.Small_Giant_Hanging | ARM_Output.Small_Wide_Hanging |
500 ARM_Output.Small_Medium_Hanging | ARM_Output.Small_Narrow_Hanging |
501 ARM_Output.Small_Hanging_in_Bulleted |
502 ARM_Output.Enumerated | ARM_Output.Small_Enumerated =>
503 if Tab_Stops.Number /= 0 then
504 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
505 "Tabs in hanging/bulleted paragraph");
506 end if;
507 end case;
508 Output_Object.Out_Char_Count := Output_Object.Char_Count;
509
510 -- Note: No_Breaks, Keep_with_Next, and Justification have no effect
511 -- here.
512 --Ada.Text_IO.Put_Line ("Start_Paragraph - Indent=" & Natural'Image(Output_Object.Indent_Amount) & " Cnt=" &
513 -- Natural'Image(Output_Object.Char_Count));
514 end Start_Paragraph;
515
516
517 procedure End_Paragraph (Output_Object : in out Text_Output_Type) is
518 -- End a paragraph.
519 begin
520 if not Output_Object.Is_Valid then
521 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
522 "Not valid object");
523 end if;
524 if not Output_Object.Is_In_Paragraph then
525 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
526 "Not in paragraph");
527 end if;
528 if Output_Object.Output_Buffer_Len /= 0 then
529 Spill (Output_Object);
530 end if;
531 Output_Object.Is_In_Paragraph := False;
532 Ada.Text_IO.New_Line (Output_Object.Output_File, 2); -- Double space paragraphs.
533 end End_Paragraph;
534
535
536 procedure Category_Header (Output_Object : in out Text_Output_Type;
537 Header_Text : String) is
538 -- Output a Category header (that is, "Legality Rules",
539 -- "Dynamic Semantics", etc.)
540 -- (Note: We did not use a enumeration here to insure that these
541 -- headers are spelled the same in all output versions).
542 -- Raises Not_Valid_Error if in a paragraph.
543 begin
544 if not Output_Object.Is_Valid then
545 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
546 "Not valid object");
547 end if;
548 if Output_Object.Is_In_Paragraph then
549 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
550 "Header in paragraph");
551 end if;
552 Ada.Text_IO.New_Line (Output_Object.Output_File);
553 Put_Line_Centered (Output_Object.Output_File, Header_Text);
554 Ada.Text_IO.New_Line (Output_Object.Output_File);
555 Output_Object.Char_Count := 0;
556 Output_Object.Out_Char_Count := 0;
557 end Category_Header;
558
559
560 procedure Clause_Header (Output_Object : in out Text_Output_Type;
561 Header_Text : in String;
562 Level : in ARM_Contents.Level_Type;
563 Clause_Number : in String;
564 Top_Level_Subdivision_Name : in ARM_Output.Top_Level_Subdivision_Name_Kind;
565 No_Page_Break : in Boolean := False) is
566 -- Output a Clause header. The level of the header is specified
567 -- in Level. The Clause Number is as specified; the top-level (and
568 -- other) subdivision names are as specified. These should appear in
569 -- the table of contents.
570 -- For hyperlinked formats, this should generate a link target.
571 -- If No_Page_Break is True, suppress any page breaks.
572 -- Raises Not_Valid_Error if in a paragraph.
573 begin
574 if not Output_Object.Is_Valid then
575 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
576 "Not valid object");
577 end if;
578 if Output_Object.Is_In_Paragraph then
579 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
580 "Header in paragraph");
581 end if;
582 Ada.Text_IO.New_Line (Output_Object.Output_File);
583
584 -- Special for table of contents:
585 if Clause_Number = "" and then
586 (Header_Text = "Table of Contents" or else -- Ada 95 format
587 Header_Text = "Contents") then -- ISO 2004 format.
588 Put_Line_Centered (Output_Object.Output_File,
589 Header_Text);
590 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
591 Output_Object.Char_Count := 0;
592 Output_Object.Out_Char_Count := 0;
593 return;
594 end if;
595
596 case Level is
597 when ARM_Contents.Plain_Annex =>
598 Put_Line_Centered (Output_Object.Output_File,
599 Clause_Number); -- Note: Clause_Number includes "Annex"
600 Put_Line_Centered (Output_Object.Output_File,
601 Header_Text);
602 when ARM_Contents.Normative_Annex =>
603 Put_Line_Centered (Output_Object.Output_File,
604 Clause_Number); -- Note: Clause_Number includes "Annex"
605 Put_Line_Centered (Output_Object.Output_File,
606 "(normative)");
607 Ada.Text_IO.New_Line (Output_Object.Output_File);
608 Put_Line_Centered (Output_Object.Output_File,
609 Header_Text);
610 when ARM_Contents.Informative_Annex =>
611 Put_Line_Centered (Output_Object.Output_File,
612 Clause_Number); -- Note: Clause_Number includes "Annex"
613 Put_Line_Centered (Output_Object.Output_File,
614 "(informative)");
615 Ada.Text_IO.New_Line (Output_Object.Output_File);
616 Put_Line_Centered (Output_Object.Output_File,
617 Header_Text);
618 when ARM_Contents.Section =>
619 case Top_Level_Subdivision_Name is
620 when ARM_Output.Chapter =>
621 Put_Line_Centered (Output_Object.Output_File,
622 "Chapter " & Clause_Number & ": " & Header_Text);
623 when ARM_Output.Section =>
624 Put_Line_Centered (Output_Object.Output_File,
625 "Section " & Clause_Number & ": " & Header_Text);
626 when ARM_Output.Clause =>
627 Put_Line_Centered (Output_Object.Output_File,
628 Clause_Number & " " & Header_Text);
629 end case;
630 when ARM_Contents.Unnumbered_Section =>
631 if Header_Text /= "" then
632 Put_Line_Centered (Output_Object.Output_File,
633 Header_Text);
634 end if;
635 when ARM_Contents.Clause | ARM_Contents.Subclause |
636 ARM_Contents.Subsubclause =>
637 Ada.Text_IO.Put_Line (Output_Object.Output_File,
638 Clause_Number & ' ' & Header_Text);
639 when ARM_Contents.Dead_Clause =>
640 raise Program_Error; -- No headers for dead clauses.
641 end case;
642 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
643 Output_Object.Char_Count := 0;
644 Output_Object.Out_Char_Count := 0;
645 -- We don't have any page breaks here to suppress.
646 end Clause_Header;
647
648
649 procedure Revised_Clause_Header
650 (Output_Object : in out Text_Output_Type;
651 New_Header_Text : in String;
652 Old_Header_Text : in String;
653 Level : in ARM_Contents.Level_Type;
654 Clause_Number : in String;
655 Version : in ARM_Contents.Change_Version_Type;
656 Old_Version : in ARM_Contents.Change_Version_Type;
657 Top_Level_Subdivision_Name : in ARM_Output.Top_Level_Subdivision_Name_Kind;
658 No_Page_Break : in Boolean := False) is
659 -- Output a revised clause header. Both the original and new text will
660 -- be output. The level of the header is specified in Level. The Clause
661 -- Number is as specified; the top-level (and other) subdivision names
662 -- are as specified. These should appear in the table of contents.
663 -- For hyperlinked formats, this should generate a link target.
664 -- Version is the insertion version of the new text; Old_Version is
665 -- the insertion version of the old text.
666 -- If No_Page_Break is True, suppress any page breaks.
667 -- Raises Not_Valid_Error if in a paragraph.
668 function Header_Text return String is
669 -- Note: Version and Old_Version are not used.
670 begin
671 return '{' & New_Header_Text & "} [" & Old_Header_Text & ']';
672 end Header_Text;
673 begin
674 if not Output_Object.Is_Valid then
675 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
676 "Not valid object");
677 end if;
678 if Output_Object.Is_In_Paragraph then
679 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
680 "Header in paragraph");
681 end if;
682 Ada.Text_IO.New_Line (Output_Object.Output_File);
683
684 -- Special for table of contents:
685 if Clause_Number = "" and then
686 (Header_Text = "Table of Contents" or else -- Ada 95 format
687 Header_Text = "Contents") then -- ISO 2004 format.
688 Put_Line_Centered (Output_Object.Output_File,
689 Header_Text);
690 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
691 Output_Object.Char_Count := 0;
692 Output_Object.Out_Char_Count := 0;
693 return;
694 end if;
695
696 case Level is
697 when ARM_Contents.Plain_Annex =>
698 Put_Line_Centered (Output_Object.Output_File,
699 Clause_Number); -- Note: Clause_Number includes "Annex"
700 Put_Line_Centered (Output_Object.Output_File,
701 Header_Text);
702 when ARM_Contents.Normative_Annex =>
703 Put_Line_Centered (Output_Object.Output_File,
704 Clause_Number); -- Note: Clause_Number includes "Annex"
705 Put_Line_Centered (Output_Object.Output_File,
706 "(normative)");
707 Ada.Text_IO.New_Line (Output_Object.Output_File);
708 Put_Line_Centered (Output_Object.Output_File,
709 Header_Text);
710 when ARM_Contents.Informative_Annex =>
711 Put_Line_Centered (Output_Object.Output_File,
712 Clause_Number); -- Note: Clause_Number includes "Annex"
713 Put_Line_Centered (Output_Object.Output_File,
714 "(informative)");
715 Ada.Text_IO.New_Line (Output_Object.Output_File);
716 Put_Line_Centered (Output_Object.Output_File,
717 Header_Text);
718 when ARM_Contents.Section =>
719 case Top_Level_Subdivision_Name is
720 when ARM_Output.Chapter =>
721 Put_Line_Centered (Output_Object.Output_File,
722 "Chapter " & Clause_Number & ": " & Header_Text);
723 when ARM_Output.Section =>
724 Put_Line_Centered (Output_Object.Output_File,
725 "Section " & Clause_Number & ": " & Header_Text);
726 when ARM_Output.Clause =>
727 Put_Line_Centered (Output_Object.Output_File,
728 Clause_Number & " " & Header_Text);
729 end case;
730 when ARM_Contents.Unnumbered_Section =>
731 if Header_Text /= "" then
732 Put_Line_Centered (Output_Object.Output_File,
733 Header_Text);
734 end if;
735 when ARM_Contents.Clause | ARM_Contents.Subclause |
736 ARM_Contents.Subsubclause =>
737 Ada.Text_IO.Put_Line (Output_Object.Output_File,
738 Clause_Number & ' ' & Header_Text);
739 when ARM_Contents.Dead_Clause =>
740 raise Program_Error; -- No headers for dead clauses.
741 end case;
742 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
743 Output_Object.Char_Count := 0;
744 Output_Object.Out_Char_Count := 0;
745 -- We don't have any page breaks here to suppress.
746 end Revised_Clause_Header;
747
748
749 procedure TOC_Marker (Output_Object : in out Text_Output_Type;
750 For_Start : in Boolean) is
751 -- Mark the start (if For_Start is True) or end (if For_Start is
752 -- False) of the table of contents data. Output objects that
753 -- auto-generate the table of contents can use this to do needed
754 -- actions.
755 begin
756 if not Output_Object.Is_Valid then
757 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
758 "Not valid object");
759 end if;
760 null; -- We don't care about this.
761 end TOC_Marker;
762
763
764 procedure New_Page (Output_Object : in out Text_Output_Type;
765 Kind : ARM_Output.Page_Kind_Type := ARM_Output.Any_Page) is
766 -- Output a page break.
767 -- Note that this has no effect on non-printing formats.
768 -- Any_Page breaks to the top of the next page (whatever it is);
769 -- Odd_Page_Only breaks to the top of the odd-numbered page;
770 -- Soft_Page allows a page break but does not force one (use in
771 -- "No_Breaks" paragraphs.)
772 -- Raises Not_Valid_Error if in a paragraph if Kind = Any_Page or
773 -- Odd_Page, and if not in a paragraph if Kind = Soft_Page.
774 begin
775 if not Output_Object.Is_Valid then
776 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
777 "Not valid object");
778 end if;
779 case Kind is
780 when ARM_Output.Any_Page | ARM_Output.Odd_Page_Only =>
781 if Output_Object.Is_In_Paragraph then
782 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
783 "Page in paragraph");
784 end if;
785 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
786 when ARM_Output.Soft_Page =>
787 if not Output_Object.Is_In_Paragraph then
788 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
789 "Soft page not in paragraph");
790 end if;
791 null; -- No page breaks.
792 Spill (Output_Object);
793 end case;
794 end New_Page;
795
796
797 procedure New_Column (Output_Object : in out Text_Output_Type) is
798 -- Output a column break.
799 -- Raises Not_Valid_Error if in a paragraph, or if the number of
800 -- columns is 1.
801 begin
802 if not Output_Object.Is_Valid then
803 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
804 "Not valid object");
805 end if;
806 if Output_Object.Is_In_Paragraph then
807 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
808 "New column in paragraph");
809 end if;
810 -- No columns in text format.
811 Ada.Text_IO.New_Line (Output_Object.Output_File);
812 end New_Column;
813
814
815 procedure Start_Table (Output_Object : in out Text_Output_Type;
816 Columns : in ARM_Output.Column_Count;
817 First_Column_Width : in ARM_Output.Column_Count;
818 Last_Column_Width : in ARM_Output.Column_Count;
819 Alignment : in ARM_Output.Column_Text_Alignment;
820 No_Page_Break : in Boolean;
821 Has_Border : in Boolean;
822 Small_Text_Size : in Boolean;
823 Header_Kind : in ARM_Output.Header_Kind_Type) is
824 -- Starts a table. The number of columns is Columns; the first
825 -- column has First_Column_Width times the normal column width, and
826 -- the last column has Last_Column_Width times the normal column width.
827 -- Alignment is the horizontal text alignment within the columns.
828 -- No_Page_Break should be True to keep the table intact on a single
829 -- page; False to allow it to be split across pages.
830 -- Has_Border should be true if a border is desired, false otherwise.
831 -- Small_Text_Size means that the contents will have the AARM size;
832 -- otherwise it will have the normal size.
833 -- Header_Kind determines whether the table has headers.
834 -- This command starts a paragraph; the entire table is a single
835 -- paragraph. Text will be considered part of the caption until the
836 -- next table marker call.
837 -- Raises Not_Valid_Error if in a paragraph.
838 begin
839 -- Alignment, No_Page_Break, Border, Small_Text_Size, and Header_Kind
840 -- not used here.
841 if not Output_Object.Is_Valid then
842 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
843 "Not valid object");
844 end if;
845 if Output_Object.Is_In_Paragraph then
846 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
847 "Table in paragraph");
848 end if;
849
850 Output_Object.Tab_Stops.Number := Columns;
851 declare
852 Column_Units : constant ARM_Output.Column_Count :=
853 Columns+First_Column_Width+Last_Column_Width-2;
854 Width : Natural :=
855 (72/(Column_Units));
856 begin
857 if Column_Units <= 3 then -- Keep it from getting too wide.
858 Width := 22;
859 end if;
860 for I in 1 .. Columns loop
861 Output_Object.Tab_Stops.Stops(I) := (Kind => ARM_Output.Left_Fixed,
862 Stop => Width*(I+First_Column_Width-1)+10);
863 end loop;
864 end;
865
866 Output_Object.Indent_Amount := 10;
867 Ada.Text_IO.Put (Output_Object.Output_File, " ");
868 Output_Object.Char_Count := 10;
869 Output_Object.Out_Char_Count := 10;
870
871 Output_Object.Is_In_Paragraph := True;
872 Output_Object.Is_In_Table := True;
873 end Start_Table;
874
875
876 procedure Table_Marker (Output_Object : in out Text_Output_Type;
877 Marker : in ARM_Output.Table_Marker_Type) is
878 -- Marks the end of an entity in a table.
879 -- If Marker is End_Caption, the table caption ends and the
880 -- future text is part of the table header.
881 -- If Marker is End_Header, the table header ends and the
882 -- future text is part of the table body.
883 -- If Marker is End_Row, a row in the table is completed, and another
884 -- row started.
885 -- If Marker is End_Row_Next_Is_Last, a row in the table is completed,
886 -- and another row started. That row is the last row in the table.
887 -- If Marker is End_Item, an item in the table header or body is ended,
888 -- and another started.
889 -- If Marker is End_Table, the entire table is finished.
890 -- Raises Not_Valid_Error if not in a table.
891 begin
892 if not Output_Object.Is_Valid then
893 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
894 "Not valid object");
895 end if;
896 if (not Output_Object.Is_In_Paragraph) or (not Output_Object.Is_In_Table) then
897 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
898 "Table marker not in table");
899 end if;
900 case Marker is
901 when ARM_Output.End_Item =>
902 -- Just tab over one row:
903 Spill (Output_Object);
904 Ada.Text_IO.Put (Output_Object.Output_File, " ");
905 Output_Object.Char_Count := Output_Object.Char_Count + 1;
906 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + 1;
907 for I in 1 .. Output_Object.Tab_Stops.Number loop
908 if Output_Object.Tab_Stops.Stops(I).Stop > Output_Object.Char_Count then
909 for J in Output_Object.Char_Count+1 .. Output_Object.Tab_Stops.Stops(I).Stop-1 loop
910 Ada.Text_IO.Put (Output_Object.Output_File, " ");
911 Output_Object.Char_Count := Output_Object.Char_Count + 1;
912 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + 1;
913 end loop;
914 end if;
915 end loop;
916
917 when ARM_Output.End_Caption =>
918 Spill (Output_Object);
919 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
920 Ada.Text_IO.Put (Output_Object.Output_File, " ");
921 Output_Object.Char_Count := 10;
922 Output_Object.Out_Char_Count := 10;
923 when ARM_Output.End_Header =>
924 Spill (Output_Object);
925 Ada.Text_IO.New_Line (Output_Object.Output_File, 2);
926 Ada.Text_IO.Put (Output_Object.Output_File, " ");
927 Output_Object.Char_Count := 10;
928 Output_Object.Out_Char_Count := 10;
929 when ARM_Output.End_Row | ARM_Output.End_Row_Next_Is_Last =>
930 Spill (Output_Object);
931 Ada.Text_IO.New_Line (Output_Object.Output_File, 1);
932 Ada.Text_IO.Put (Output_Object.Output_File, " ");
933 Output_Object.Char_Count := 10;
934 Output_Object.Out_Char_Count := 10;
935 when ARM_Output.End_Table =>
936 Spill (Output_Object);
937 Output_Object.Is_In_Paragraph := False;
938 Output_Object.Is_In_Table := False;
939 Ada.Text_IO.New_Line (Output_Object.Output_File);
940 Output_Object.Tab_Stops := ARM_Output.NO_TABS;
941 end case;
942 end Table_Marker;
943
944
945 procedure Separator_Line (Output_Object : in out Text_Output_Type;
946 Is_Thin : Boolean := True) is
947 -- Output a separator line. It is thin if "Is_Thin" is true.
948 -- Raises Not_Valid_Error if in a paragraph.
949 begin
950 if not Output_Object.Is_Valid then
951 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
952 "Not valid object");
953 end if;
954 if Output_Object.Is_In_Paragraph then
955 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
956 "Separator in paragraph");
957 end if;
958 Ada.Text_IO.New_Line (Output_Object.Output_File);
959 if Is_Thin then
960 Ada.Text_IO.Put_Line (Output_Object.Output_File, "---------------------------------------------------------------------");
961 else
962 Ada.Text_IO.Put_Line (Output_Object.Output_File, "=====================================================================");
963 end if;
964 Ada.Text_IO.New_Line (Output_Object.Output_File);
965 end Separator_Line;
966
967
968 -- Text output: These are only allowed after a Start_Paragraph and
969 -- before any End_Paragraph. Raises Not_Valid_Error if not allowed.
970
971 procedure Ordinary_Text (Output_Object : in out Text_Output_Type;
972 Text : in String) is
973 -- Output ordinary text.
974 -- The text must end at a word break, never in the middle of a word.
975 begin
976 if not Output_Object.Is_Valid then
977 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
978 "Not valid object");
979 end if;
980 if not Output_Object.Is_In_Paragraph then
981 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
982 "Not in paragraph");
983 end if;
984 --Ada.Text_IO.Put_Line ("Ordinary_Text: Cnt=" & Natural'Image(Output_Object.Char_Count) &
985 --" Buffer=" & Natural'Image(Output_Object.Output_Buffer_Len));
986 if Output_Object.Char_Count + Text'Length >= LINE_LENGTH - 2 and then
987 Output_Object.Out_Char_Count > Output_Object.Indent_Amount then
988 -- We want a line break here if the line is too long and something was output:
989 Ada.Text_IO.New_Line (Output_Object.Output_File);
990 Make_Indent (Output_Object);
991 --Output_Object.Output_Buffer_Space_Before := False;
992 -- Start of line, this is done by Make_Indent.
993 Spill (Output_Object);
994 else
995 Spill (Output_Object);
996 end if;
997 Ada.Text_IO.Put (Output_Object.Output_File, Text);
998 Output_Object.Char_Count := Output_Object.Char_Count + Text'Length;
999 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + Text'Length;
1000 Output_Object.Output_Buffer_Space_Before := False; -- No space between
1001 -- this and any following text.
1002 end Ordinary_Text;
1003
1004
1005 procedure Ordinary_Character (Output_Object : in out Text_Output_Type;
1006 Char : in Character) is
1007 -- Output an ordinary character.
1008 -- Spaces will be used to break lines as needed.
1009 begin
1010 if not Output_Object.Is_Valid then
1011 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1012 "Not valid object");
1013 end if;
1014 if not Output_Object.Is_In_Paragraph then
1015 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1016 "Not in paragraph");
1017 end if;
1018
1019 if Output_Object.Char_Count >= LINE_LENGTH and then
1020 Output_Object.Out_Char_Count > Output_Object.Indent_Amount then
1021 -- Insert a break here if anything has been output (but don't
1022 -- Spill the buffer):
1023 --Ada.Text_IO.Put_Line ("Ordinary_Char [Break, no spill]: Cnt=" & Natural'Image(Output_Object.Char_Count));
1024 Ada.Text_IO.New_Line (Output_Object.Output_File);
1025 Make_Indent (Output_Object);
1026 --Output_Object.Output_Buffer_Space_Before := False;
1027 -- Start of line, this is done by Make_Indent.
1028 -- Note that this may make the space disappear.
1029 -- Add the contents of the buffer to the character count for this line:
1030 Output_Object.Char_Count := Output_Object.Char_Count +
1031 Output_Object.Output_Buffer_Len;
1032 if Char /= ' ' then
1033 Buffer (Output_Object, Char);
1034 else -- Break character, spill on the new line:
1035 if Output_Object.Output_Buffer_Len /= 0 then
1036 Spill (Output_Object); -- Output the buffer up to the space.
1037 Output_Object.Output_Buffer_Space_Before := True; -- Mid-line now.
1038 -- else nothing in buffer, so nothing to output; just skip it.
1039 end if;
1040 end if;
1041 elsif Char = ' ' then
1042 -- Break character, and it fits on this line:
1043 if Output_Object.Output_Buffer_Len /= 0 then
1044 --Ada.Text_IO.Put_Line ("Ordinary_Char [Space spill]: Cnt=" & Natural'Image(Output_Object.Char_Count));
1045 Spill (Output_Object); -- Output the buffer up to the space.
1046 Output_Object.Output_Buffer_Space_Before := True; -- Mid-line now.
1047 else -- nothing in buffer.
1048 -- nothing to output. But make sure we display a space before
1049 -- the next item.
1050 Output_Object.Output_Buffer_Space_Before := True; -- Mid-line now.
1051 end if;
1052 else
1053 Buffer (Output_Object, Char);
1054 end if;
1055 end Ordinary_Character;
1056
1057
1058 procedure Hard_Space (Output_Object : in out Text_Output_Type) is
1059 -- Output a hard space. No line break should happen at a hard space.
1060 begin
1061 if not Output_Object.Is_Valid then
1062 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1063 "Not valid object");
1064 end if;
1065 if not Output_Object.Is_In_Paragraph then
1066 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1067 "Not in paragraph");
1068 end if;
1069 Buffer (Output_Object, ' ');
1070 end Hard_Space;
1071
1072
1073 procedure Line_Break (Output_Object : in out Text_Output_Type) is
1074 -- Output a line break. This does not start a new paragraph.
1075 -- This corresponds to a "<BR>" in HTML.
1076 begin
1077 if not Output_Object.Is_Valid then
1078 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1079 "Not valid object");
1080 end if;
1081 if not Output_Object.Is_In_Paragraph then
1082 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1083 "Not in paragraph");
1084 end if;
1085 --Ada.Text_Io.Put_Line ("Line_Break");
1086 if Output_Object.Output_Buffer_Len /= 0 then
1087 Spill (Output_Object);
1088 end if;
1089 Ada.Text_IO.New_Line (Output_Object.Output_File);
1090 Make_Indent (Output_Object);
1091 end Line_Break;
1092
1093
1094 procedure Index_Line_Break (Output_Object : in out Text_Output_Type;
1095 Clear_Keep_with_Next : in Boolean) is
1096 -- Output a line break for the index. This does not start a new
1097 -- paragraph in terms of spacing. This corresponds to a "<BR>"
1098 -- in HTML. If Clear_Keep_with_Next is true, insure that the next
1099 -- line does not require the following line to stay with it.
1100 -- Raises Not_Valid_Error if the paragraph is not in the index format.
1101 begin
1102 Line_Break (Output_Object);
1103 end Index_Line_Break;
1104
1105
1106 procedure Soft_Line_Break (Output_Object : in out Text_Output_Type) is
1107 -- Output a soft line break. This is a place (in the middle of a
1108 -- "word") that we allow a line break. It is usually used after
1109 -- underscores in long non-terminals.
1110 begin
1111 if not Output_Object.Is_Valid then
1112 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1113 "Not valid object");
1114 end if;
1115 if not Output_Object.Is_In_Paragraph then
1116 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1117 "Not in paragraph");
1118 end if;
1119 if Output_Object.Char_Count >= LINE_LENGTH - 10 then
1120 if Output_Object.Output_Buffer_Len /= 0 then
1121 Spill (Output_Object);
1122 end if;
1123 Ada.Text_IO.New_Line (Output_Object.Output_File);
1124 Make_Indent (Output_Object);
1125 -- else we don't need a line break.
1126 end if;
1127 end Soft_Line_Break;
1128
1129
1130 procedure Soft_Hyphen_Break (Output_Object : in out Text_Output_Type) is
1131 -- Output a soft line break, with a hyphen. This is a place (in the middle of
1132 -- a "word") that we allow a line break. If the line break is used,
1133 -- a hyphen will be added to the text.
1134 begin
1135 if not Output_Object.Is_Valid then
1136 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1137 "Not valid object");
1138 end if;
1139 if not Output_Object.Is_In_Paragraph then
1140 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1141 "Not in paragraph");
1142 end if;
1143 if Output_Object.Char_Count >= LINE_LENGTH - 8 then
1144 Spill (Output_Object);
1145 Ada.Text_IO.Put_Line (Output_Object.Output_File, "-"); -- Add the hyphen and break.
1146 Make_Indent (Output_Object);
1147 -- else we don't need a line break.
1148 end if;
1149 end Soft_Hyphen_Break;
1150
1151
1152 procedure Tab (Output_Object : in out Text_Output_Type) is
1153 -- Output a tab, inserting space up to the next tab stop.
1154 -- Raises Not_Valid_Error if the paragraph was created with
1155 -- Tab_Stops = ARM_Output.NO_TABS.
1156 begin
1157 if not Output_Object.Is_Valid then
1158 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1159 "Not valid object");
1160 end if;
1161 if not Output_Object.Is_In_Paragraph then
1162 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1163 "Not in paragraph");
1164 end if;
1165 if ARM_Output."="(Output_Object.Tab_Stops, ARM_Output.NO_TABS) then
1166 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1167 "Tab, but none set");
1168 end if;
1169 -- We use the tab stops as characters here, and fixed and proportional
1170 -- stops are treated identically.
1171 -- Find the first stop greater than the current character count. (After
1172 -- writing a space).
1173 --Ada.Text_IO.Put_Line ("Tab");
1174 Spill (Output_Object);
1175 Ada.Text_IO.Put (Output_Object.Output_File, " ");
1176 Output_Object.Char_Count := Output_Object.Char_Count + 1;
1177 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + 1;
1178 for I in 1 .. Output_Object.Tab_Stops.Number loop
1179 if Output_Object.Tab_Stops.Stops(I).Stop > Output_Object.Char_Count then
1180 for J in Output_Object.Char_Count+1 .. Output_Object.Tab_Stops.Stops(I).Stop-1 loop
1181 Ada.Text_IO.Put (Output_Object.Output_File, " ");
1182 Output_Object.Char_Count := Output_Object.Char_Count + 1;
1183 Output_Object.Out_Char_Count := Output_Object.Out_Char_Count + 1;
1184 --Ada.Text_IO.Put ("#");
1185 end loop;
1186 exit;
1187 end if;
1188 end loop; -- If we drop out without finding a tab, we just use the single
1189 -- space already written.
1190 --Ada.Text_IO.New_Line;
1191 Output_Object.Output_Buffer_Space_Before := False; -- Spaces needed were output.
1192 end Tab;
1193
1194
1195 procedure Special_Character (Output_Object : in out Text_Output_Type;
1196 Char : in ARM_Output.Special_Character_Type) is
1197 -- Output an special character.
1198 begin
1199 case Char is
1200 when ARM_Output.EM_Dash =>
1201 Ordinary_Character (Output_Object, '-'); -- Not available in plain text.
1202 when ARM_Output.EN_Dash =>
1203 Ordinary_Character (Output_Object, '-'); -- Not available in plain text.
1204 when ARM_Output.GEQ =>
1205 Ordinary_Text (Output_Object, ">="); -- Not available in plain text, use the Ada one.
1206 when ARM_Output.LEQ =>
1207 Ordinary_Text (Output_Object, "<="); -- Not available in plain text, use the Ada one.
1208 when ARM_Output.NEQ =>
1209 Ordinary_Text (Output_Object, "/="); -- Not available in plain text, use the Ada one.
1210 when ARM_Output.PI =>
1211 Ordinary_Text (Output_Object, "PI"); -- Not available in plain text.
1212 when ARM_Output.Left_Ceiling =>
1213 Ordinary_Text (Output_Object, "Ceiling("); -- Not available in plain text.
1214 when ARM_Output.Right_Ceiling =>
1215 Ordinary_Text (Output_Object, ")"); -- Not available in plain text.
1216 when ARM_Output.Left_Floor =>
1217 Ordinary_Text (Output_Object, "Floor("); -- Not available in plain text.
1218 when ARM_Output.Right_Floor =>
1219 Ordinary_Text (Output_Object, ")"); -- Not available in plain text.
1220 when ARM_Output.Thin_Space =>
1221 Ordinary_Text (Output_Object, " "); -- Not available in plain text.
1222 when ARM_Output.Left_Quote =>
1223 Ordinary_Text (Output_Object, "`"); -- Not available in plain text, use back-quote.
1224 when ARM_Output.Right_Quote =>
1225 Ordinary_Text (Output_Object, "'"); -- Not available in plain text, use quote.
1226 when ARM_Output.Left_Double_Quote =>
1227 Ordinary_Text (Output_Object, """"); -- Not available in plain text, use double quote.
1228 when ARM_Output.Right_Double_Quote =>
1229 Ordinary_Text (Output_Object, """"); -- Not available in plain text, use double quote.
1230 when ARM_Output.Small_Dotless_I =>
1231 Ordinary_Text (Output_Object, "i"); -- Not available in plain text, use the nearest text.
1232 when ARM_Output.Capital_Dotted_I =>
1233 Ordinary_Text (Output_Object, "I"); -- Not available in plain text, use the nearest text.
1234 end case;
1235 end Special_Character;
1236
1237
1238 procedure Unicode_Character (Output_Object : in out Text_Output_Type;
1239 Char : in ARM_Output.Unicode_Type) is
1240 -- Output a Unicode character, with code position Char.
1241 Char_Code : constant String := ARM_Output.Unicode_Type'Image(Char);
1242 begin
1243 -- We don't check, but we assume this is not a normal character.
1244 Ordinary_Text (Output_Object, "<Unicode-" & Char_Code(2..Char_Code'Last) & ">");
1245 end Unicode_Character;
1246
1247
1248 procedure End_Hang_Item (Output_Object : in out Text_Output_Type) is
1249 -- Marks the end of a hanging item. Call only once per paragraph.
1250 -- Raises Not_Valid_Error if the paragraph style is not in
1251 -- Text_Prefixed_Style_Subtype, or if this has already been
1252 -- called for the current paragraph, or if the paragraph was started
1253 -- with No_Prefix = True.
1254 begin
1255 if not Output_Object.Is_Valid then
1256 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1257 "Not valid object");
1258 end if;
1259 if not Output_Object.Is_In_Paragraph then
1260 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1261 "Not in paragraph");
1262 end if;
1263 if not Output_Object.Is_Hanging then
1264 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1265 "Not a hanging paragraph");
1266 end if;
1267 if Output_Object.Saw_Hang_End then
1268 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1269 "Already saw the end of the hanging part");
1270 end if;
1271 Output_Object.Saw_Hang_End := True;
1272
1273 if Output_Object.Char_Count >= Output_Object.Indent_Amount then
1274 if Output_Object.Output_Buffer_Len /= 0 then
1275 Spill (Output_Object);
1276 end if;
1277 Ada.Text_IO.New_Line (Output_Object.Output_File);
1278 Make_Indent (Output_Object);
1279 else
1280 Spill (Output_Object);
1281 for I in Output_Object.Char_Count + 1 ..
1282 Output_Object.Indent_Amount loop
1283 Ada.Text_IO.Put (Output_Object.Output_File, ' ');
1284 end loop;
1285 Output_Object.Char_Count := Output_Object.Indent_Amount;
1286 Output_Object.Out_Char_Count := Output_Object.Indent_Amount;
1287 Output_Object.Output_Buffer_Space_Before := False; -- Spaces needed were output.
1288 end if;
1289 end End_Hang_Item;
1290
1291
1292 procedure Text_Format (Output_Object : in out Text_Output_Type;
1293 Format : in ARM_Output.Format_Type) is
1294 -- Change the text format so that all of the properties are as specified.
1295 -- Note: Changes to these properties ought be stack-like; that is,
1296 -- Bold on, Italic on, Italic off, Bold off is OK; Bold on, Italic on,
1297 -- Bold off, Italic off should be avoided (as separate commands).
1298 use type ARM_Output.Change_Type;
1299 use type ARM_Output.Location_Type;
1300 begin
1301 if not Output_Object.Is_Valid then
1302 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1303 "Not valid object");
1304 end if;
1305 if not Output_Object.Is_In_Paragraph then
1306 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1307 "Not in paragraph");
1308 end if;
1309 if Format.Location /= Output_Object.Location then
1310 if Output_Object.Location /= ARM_Output.Normal then
1311 Buffer(Output_Object, ')');
1312 end if;
1313 end if;
1314 if Format.Change /= Output_Object.Change then
1315 if Format.Change = ARM_Output.Both then
1316 -- Open only the one(s) needed:
1317 case Output_Object.Change is
1318 -- Note: Version is not used.
1319 when ARM_Output.Insertion =>
1320 -- Open the deletion:
1321 Buffer(Output_Object, '[');
1322 when ARM_Output.Deletion =>
1323 -- Open the insertion:
1324 Buffer(Output_Object, '{');
1325 when ARM_Output.None =>
1326 Buffer(Output_Object, '{');
1327 Buffer(Output_Object, '[');
1328 when ARM_Output.Both =>
1329 null;
1330 end case;
1331 elsif Output_Object.Change = ARM_Output.Both then
1332 -- Close only the one(s) needed:
1333 case Format.Change is
1334 -- Note: Version is not used.
1335 when ARM_Output.Insertion =>
1336 -- Close the deletion:
1337 Buffer(Output_Object, ']');
1338 when ARM_Output.Deletion =>
1339 -- Close the insertion:
1340 Buffer(Output_Object, '}');
1341 when ARM_Output.None =>
1342 Buffer(Output_Object, ']');
1343 Buffer(Output_Object, '}');
1344 when ARM_Output.Both =>
1345 null;
1346 end case;
1347 else -- Both can't get here.
1348 case Output_Object.Change is
1349 when ARM_Output.Insertion =>
1350 Buffer(Output_Object, '}');
1351 when ARM_Output.Deletion =>
1352 Buffer(Output_Object, ']');
1353 when ARM_Output.None =>
1354 null;
1355 when ARM_Output.Both =>
1356 Buffer(Output_Object, ']');
1357 Buffer(Output_Object, '}');
1358 end case;
1359 case Format.Change is
1360 -- Note: Version is not used.
1361 when ARM_Output.Insertion =>
1362 Buffer(Output_Object, '{');
1363 when ARM_Output.Deletion =>
1364 Buffer(Output_Object, '[');
1365 when ARM_Output.None =>
1366 null;
1367 when ARM_Output.Both =>
1368 Buffer(Output_Object, '{');
1369 Buffer(Output_Object, '[');
1370 end case;
1371 end if;
1372 Output_Object.Change := Format.Change;
1373 end if;
1374 if Format.Location /= Output_Object.Location then
1375 if Format.Location /= ARM_Output.Normal then
1376 Buffer(Output_Object, '(');
1377 end if;
1378 Output_Object.Location := Format.Location;
1379 end if;
1380 null; -- Nothing else to do for plain text.
1381 end Text_Format;
1382
1383
1384 procedure Clause_Reference (Output_Object : in out Text_Output_Type;
1385 Text : in String;
1386 Clause_Number : in String) is
1387 -- Generate a reference to a clause in the standard. The text of
1388 -- the reference is "Text", and the number of the clause is
1389 -- Clause_Number. For hyperlinked formats, this should generate
1390 -- a link; for other formats, the text alone is generated.
1391 begin
1392 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1393 end Clause_Reference;
1394
1395
1396 procedure Index_Target (Output_Object : in out Text_Output_Type;
1397 Index_Key : in Natural) is
1398 -- Generate a index target. This marks the location where an index
1399 -- reference occurs. Index_Key names the index item involved.
1400 -- For hyperlinked formats, this should generate a link target;
1401 -- for other formats, nothing is generated.
1402 begin
1403 if not Output_Object.Is_Valid then
1404 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1405 "Not valid object");
1406 end if;
1407 if not Output_Object.Is_In_Paragraph then
1408 Ada.Exceptions.Raise_Exception (ARM_Output.Not_Valid_Error'Identity,
1409 "Not in paragraph");
1410 end if;
1411 null; -- Nothing to do for plain text.
1412 end Index_Target;
1413
1414
1415 procedure Index_Reference (Output_Object : in out Text_Output_Type;
1416 Text : in String;
1417 Index_Key : in Natural;
1418 Clause_Number : in String) is
1419 -- Generate a reference to an index target in the standard. The text
1420 -- of the reference is "Text", and Index_Key and Clause_Number denotes
1421 -- the target. For hyperlinked formats, this should generate
1422 -- a link; for other formats, the text alone is generated.
1423 begin
1424 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1425 end Index_Reference;
1426
1427
1428 procedure DR_Reference (Output_Object : in out Text_Output_Type;
1429 Text : in String;
1430 DR_Number : in String) is
1431 -- Generate a reference to an DR from the standard. The text
1432 -- of the reference is "Text", and DR_Number denotes
1433 -- the target. For hyperlinked formats, this should generate
1434 -- a link; for other formats, the text alone is generated.
1435 begin
1436 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1437 end DR_Reference;
1438
1439
1440 procedure AI_Reference (Output_Object : in out Text_Output_Type;
1441 Text : in String;
1442 AI_Number : in String) is
1443 -- Generate a reference to an AI from the standard. The text
1444 -- of the reference is "Text", and AI_Number denotes
1445 -- the target (in unfolded format). For hyperlinked formats, this should
1446 -- generate a link; for other formats, the text alone is generated.
1447 begin
1448 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1449 end AI_Reference;
1450
1451
1452 procedure Local_Target (Output_Object : in out Text_Output_Type;
1453 Text : in String;
1454 Target : in String) is
1455 -- Generate a local target. This marks the potential target of local
1456 -- links identified by "Target". Text is the text of the target.
1457 -- For hyperlinked formats, this should generate a link target;
1458 -- for other formats, only the text is generated.
1459 begin
1460 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1461 end Local_Target;
1462
1463
1464 procedure Local_Link (Output_Object : in out Text_Output_Type;
1465 Text : in String;
1466 Target : in String;
1467 Clause_Number : in String) is
1468 -- Generate a local link to the target and clause given.
1469 -- Text is the text of the link.
1470 -- For hyperlinked formats, this should generate a link;
1471 -- for other formats, only the text is generated.
1472 begin
1473 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1474 end Local_Link;
1475
1476
1477 procedure Local_Link_Start (Output_Object : in out Text_Output_Type;
1478 Target : in String;
1479 Clause_Number : in String) is
1480 -- Generate a local link to the target and clause given.
1481 -- The link will surround text until Local_Link_End is called.
1482 -- Local_Link_End must be called before this routine can be used again.
1483 -- For hyperlinked formats, this should generate a link;
1484 -- for other formats, only the text is generated.
1485 begin
1486 null; -- No link, nothing to do.
1487 end Local_Link_Start;
1488
1489
1490 procedure Local_Link_End (Output_Object : in out Text_Output_Type;
1491 Target : in String;
1492 Clause_Number : in String) is
1493 -- End a local link for the target and clause given.
1494 -- This must be in the same paragraph as the Local_Link_Start.
1495 -- For hyperlinked formats, this should generate a link;
1496 -- for other formats, only the text is generated.
1497 begin
1498 null; -- No link, nothing to do.
1499 end Local_Link_End;
1500
1501
1502 procedure URL_Link (Output_Object : in out Text_Output_Type;
1503 Text : in String;
1504 URL : in String) is
1505 -- Generate a link to the URL given.
1506 -- Text is the text of the link.
1507 -- For hyperlinked formats, this should generate a link;
1508 -- for other formats, only the text is generated.
1509 begin
1510 Ordinary_Text (Output_Object, Text); -- Nothing special in this format.
1511 end URL_Link;
1512
1513
1514 procedure Picture (Output_Object : in out Text_Output_Type;
1515 Name : in String;
1516 Descr : in String;
1517 Alignment : in ARM_Output.Picture_Alignment;
1518 Height, Width : in Natural;
1519 Border : in ARM_Output.Border_Kind) is
1520 -- Generate a picture.
1521 -- Name is the (simple) file name of the picture; Descr is a
1522 -- descriptive name for the picture (it will appear in some web
1523 -- browsers).
1524 -- We assume that it is a .GIF or .JPG and that it will be present
1525 -- in the same directory as the input files and the same directory as
1526 -- the .HTML output files.
1527 -- Alignment specifies the picture alignment.
1528 -- Height and Width specify the picture size in pixels.
1529 -- Border specifies the kind of border.
1530 begin
1531 case Alignment is
1532 when ARM_Output.Inline |
1533 ARM_Output.Float_Left | ARM_Output.Float_Right =>
1534 -- Inside a paragraph:
1535 Ordinary_Text (Output_Object, "[Picture: " & Name &
1536 " - " & Descr & "]");
1537 when ARM_Output.Alone_Left | ARM_Output.Alone_Right |
1538 ARM_Output.Alone_Center =>
1539 -- Not in a paragraph:
1540 Ada.Text_IO.New_Line (Output_Object.Output_File);
1541 Ada.Text_IO.Put_Line (Output_Object.Output_File, "[Picture: " & Name &
1542 " - " & Descr & "]");
1543 Ada.Text_IO.New_Line (Output_Object.Output_File);
1544 end case;
1545 end Picture;
1546
1547 end ARM_Text;