Debian Codegraph @

progs/arm_text.ads

raw
1 with ARM_Output,
2 ARM_Contents,
3 Ada.Text_IO;
4 package ARM_Text is
5
6 --
7 -- Ada reference manual formatter (ARM_Form).
8 --
9 -- This package defines the text output object.
10 -- Output objects are responsible for implementing the details of
11 -- a particular format.
12 --
13 -- ---------------------------------------
14 -- Copyright 2000, 2002, 2004, 2005, 2006, 2007, 2011, 2012
15 -- AXE Consultants. All rights reserved.
16 -- P.O. Box 1512, Madison WI 53701
17 -- E-Mail: [email protected]
18 --
19 -- ARM_Form is free software: you can redistribute it and/or modify
20 -- it under the terms of the GNU General Public License version 3
21 -- as published by the Free Software Foundation.
22 --
23 -- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS"
24 -- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY,
25 -- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL.
26 -- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL,
27 -- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES,
28 -- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
29 -- DAMAGES.
30 --
31 -- A copy of the GNU General Public License is available in the file
32 -- gpl-3-0.txt in the standard distribution of the ARM_Form tool.
33 -- Otherwise, see <http://www.gnu.org/licenses/>.
34 --
35 -- If the GPLv3 license is not satisfactory for your needs, a commercial
36 -- use license is available for this tool. Contact Randy at AXE Consultants
37 -- for more information.
38 --
39 -- ---------------------------------------
40 --
41 -- Edit History:
42 --
43 -- 4/14/00 - RLB - Created base package.
44 -- 4/18/00 - RLB - Added index and contents marker routines.
45 -- 4/21/00 - RLB - Added line break and hard space routines.
46 -- 4/24/00 - RLB - Added DR references and Insert/Delete text formats.
47 -- 4/25/00 - RLB - Added size to format.
48 -- 5/10/00 - RLB - Added End_Hang_Item.
49 -- 5/12/00 - RLB - Added No_Prefix to Start_Paragraph.
50 -- 5/13/00 - RLB - Added Special_Character.
51 -- 5/17/00 - RLB - Added New_Page.
52 -- 5/22/00 - RLB - Added Includes_Changes to Create.
53 -- 5/23/00 - RLB - Added Set_Column and New_Column.
54 -- - Added Tab_Info and Tab_Stops.
55 -- 5/24/00 - RLB - Added Location to Text_Format.
56 -- - RLB - Added No_Breaks and Keep_with_Next to Start_Paragraph.
57 -- 5/25/00 - RLB - Added Big_Files to Create. Added Justification.
58 -- - RLB - Added Separator_Lines and TOC routines.
59 -- 5/26/00 - RLB - Added table operations.
60 -- 6/ 2/00 - RLB - Added Soft_Line_Break.
61 -- 8/ 2/00 - RLB - Added Soft_Hyphen_Break.
62 -- 8/ 7/00 - RLB - Added Leading flag to Start_Paragraph.
63 -- 8/17/00 - RLB - Replaced "Leading" by "Space_After".
64 -- 8/22/00 - RLB - Added Revised_Clause_Header.
65 -- 8/23/00 - RLB - Added Real_Char_Count.
66 -- 7/18/02 - RLB - Removed Document parameter from Create, replaced by
67 -- three strings and For_ISO boolean.
68 -- - RLB - Added AI_Reference.
69 -- - RLB - Added Change_Version_Type and uses.
70 -- 9/10/04 - RLB - Added "Both" to possible changes to handle
71 -- replacement of changed text.
72 -- 9/14/04 - RLB - Moved Change_Version_Type to ARM_Contents.
73 -- 5/27/05 - RLB - Added arbitrary Unicode characters.
74 -- 1/11/06 - RLB - Eliminated dispatching Create in favor of tailored
75 -- versions.
76 -- 1/13/06 - RLB - Added new Link operations.
77 -- 2/ 8/06 - RLB - Added additional parameters to the table command.
78 -- 2/10/06 - RLB - Added even more additional parameters to the
79 -- table command.
80 -- - RLB - Added picture command.
81 -- 9/25/06 - RLB - Added Last_Column_Width to Start_Table.
82 -- 10/13/06 - RLB - Added Local_Link_Start and Local_Link_End to allow
83 -- formatting in the linked text.
84 -- 2/ 9/07 - RLB - Changed comments on AI_Reference.
85 -- 2/13/07 - RLB - Revised to separate style and indent information
86 -- for paragraphs.
87 -- 12/19/07 - RLB - Added limited colors to Text_Format.
88 -- 10/18/11 - RLB - Changed to GPLv3 license.
89 -- 10/25/11 - RLB - Added old insertion version to Revised_Clause_Header.
90 -- 8/31/12 - RLB - Added Output_Path.
91 -- 11/26/12 - RLB - Added subdivision names to Clause_Header and
92 -- Revised_Clause_Header.
93
94 type Text_Output_Type is new ARM_Output.Output_Type with private;
95
96 procedure Create (Output_Object : in out Text_Output_Type;
97 File_Prefix : in String;
98 Output_Path : in String;
99 Title : in String := "");
100 -- Create an Output_Object for a document.
101 -- The prefix of the output file names is File_Prefix - this
102 -- should be no more then 5 characters allowed in file names.
103 -- The result files will be written to Output_Path.
104 -- The title of the document is Title.
105
106 procedure Close (Output_Object : in out Text_Output_Type);
107 -- Close an Output_Object. No further output to the object is
108 -- allowed after this call.
109
110
111 procedure Section (Output_Object : in out Text_Output_Type;
112 Section_Title : in String;
113 Section_Name : in String);
114 -- Start a new section. The title is Section_Title (this is
115 -- intended for humans). The name is Section_Name (this is
116 -- intended to be suitable to be a portion of a file name).
117
118 procedure Set_Columns (Output_Object : in out Text_Output_Type;
119 Number_of_Columns : in ARM_Output.Column_Count);
120 -- Set the number of columns.
121 -- Raises Not_Valid_Error if in a paragraph.
122
123 procedure Start_Paragraph (Output_Object : in out Text_Output_Type;
124 Style : in ARM_Output.Paragraph_Style_Type;
125 Indent : in ARM_Output.Paragraph_Indent_Type;
126 Number : in String;
127 No_Prefix : in Boolean := False;
128 Tab_Stops : in ARM_Output.Tab_Info := ARM_Output.NO_TABS;
129 No_Breaks : in Boolean := False;
130 Keep_with_Next : in Boolean := False;
131 Space_After : in ARM_Output.Space_After_Type
132 := ARM_Output.Normal;
133 Justification : in ARM_Output.Justification_Type
134 := ARM_Output.Default);
135 -- Start a new paragraph. The style and indent of the paragraph is as
136 -- specified. The (AA)RM paragraph number (which might include update
137 -- and version numbers as well: [12.1/1]) is Number. If the format is
138 -- a type with a prefix (bullets, hangining items), the prefix is
139 -- omitted if No_Prefix is true. Tab_Stops defines the tab stops for
140 -- the paragraph. If No_Breaks is True, we will try to avoid page breaks
141 -- in the paragraph. If Keep_with_Next is true, we will try to avoid
142 -- separating this paragraph and the next one. (These may have no
143 -- effect in formats that don't have page breaks). Space_After
144 -- specifies the amount of space following the paragraph. Justification
145 -- specifies the text justification for the paragraph. Not_Valid_Error
146 -- is raised if Tab_Stops /= NO_TABS for a hanging or bulleted format.
147
148 procedure End_Paragraph (Output_Object : in out Text_Output_Type);
149 -- End a paragraph.
150
151 procedure Category_Header (Output_Object : in out Text_Output_Type;
152 Header_Text : String);
153 -- Output a Category header (that is, "Legality Rules",
154 -- "Dynamic Semantics", etc.)
155 -- (Note: We did not use a enumeration here to insure that these
156 -- headers are spelled the same in all output versions).
157 -- Raises Not_Valid_Error if in a paragraph.
158
159 procedure Clause_Header (Output_Object : in out Text_Output_Type;
160 Header_Text : in String;
161 Level : in ARM_Contents.Level_Type;
162 Clause_Number : in String;
163 Top_Level_Subdivision_Name : in ARM_Output.Top_Level_Subdivision_Name_Kind;
164 No_Page_Break : in Boolean := False);
165 -- Output a Clause header. The level of the header is specified
166 -- in Level. The Clause Number is as specified; the top-level (and
167 -- other) subdivision names are as specified. These should appear in
168 -- the table of contents.
169 -- For hyperlinked formats, this should generate a link target.
170 -- If No_Page_Break is True, suppress any page breaks.
171 -- Raises Not_Valid_Error if in a paragraph.
172
173 procedure Revised_Clause_Header
174 (Output_Object : in out Text_Output_Type;
175 New_Header_Text : in String;
176 Old_Header_Text : in String;
177 Level : in ARM_Contents.Level_Type;
178 Clause_Number : in String;
179 Version : in ARM_Contents.Change_Version_Type;
180 Old_Version : in ARM_Contents.Change_Version_Type;
181 Top_Level_Subdivision_Name : in ARM_Output.Top_Level_Subdivision_Name_Kind;
182 No_Page_Break : in Boolean := False);
183 -- Output a revised clause header. Both the original and new text will
184 -- be output. The level of the header is specified in Level. The Clause
185 -- Number is as specified; the top-level (and other) subdivision names
186 -- are as specified. These should appear in the table of contents.
187 -- For hyperlinked formats, this should generate a link target.
188 -- Version is the insertion version of the new text; Old_Version is
189 -- the insertion version of the old text.
190 -- If No_Page_Break is True, suppress any page breaks.
191 -- Raises Not_Valid_Error if in a paragraph.
192
193 procedure TOC_Marker (Output_Object : in out Text_Output_Type;
194 For_Start : in Boolean);
195 -- Mark the start (if For_Start is True) or end (if For_Start is
196 -- False) of the table of contents data. Output objects that
197 -- auto-generate the table of contents can use this to do needed
198 -- actions.
199
200 procedure New_Page (Output_Object : in out Text_Output_Type;
201 Kind : ARM_Output.Page_Kind_Type := ARM_Output.Any_Page);
202 -- Output a page break.
203 -- Note that this has no effect on non-printing formats.
204 -- Any_Page breaks to the top of the next page (whatever it is);
205 -- Odd_Page_Only breaks to the top of the odd-numbered page;
206 -- Soft_Page allows a page break but does not force one (use in
207 -- "No_Breaks" paragraphs.)
208 -- Raises Not_Valid_Error if in a paragraph if Kind = Any_Page or
209 -- Odd_Page, and if not in a paragraph if Kind = Soft_Page.
210
211 procedure New_Column (Output_Object : in out Text_Output_Type);
212 -- Output a column break.
213 -- Raises Not_Valid_Error if in a paragraph, or if the number of
214 -- columns is 1.
215
216 procedure Separator_Line (Output_Object : in out Text_Output_Type;
217 Is_Thin : Boolean := True);
218 -- Output a separator line. It is thin if "Is_Thin" is true.
219 -- Raises Not_Valid_Error if in a paragraph.
220
221 procedure Start_Table (Output_Object : in out Text_Output_Type;
222 Columns : in ARM_Output.Column_Count;
223 First_Column_Width : in ARM_Output.Column_Count;
224 Last_Column_Width : in ARM_Output.Column_Count;
225 Alignment : in ARM_Output.Column_Text_Alignment;
226 No_Page_Break : in Boolean;
227 Has_Border : in Boolean;
228 Small_Text_Size : in Boolean;
229 Header_Kind : in ARM_Output.Header_Kind_Type);
230 -- Starts a table. The number of columns is Columns; the first
231 -- column has First_Column_Width times the normal column width, and
232 -- the last column has Last_Column_Width times the normal column width.
233 -- Alignment is the horizontal text alignment within the columns.
234 -- No_Page_Break should be True to keep the table intact on a single
235 -- page; False to allow it to be split across pages.
236 -- Has_Border should be true if a border is desired, false otherwise.
237 -- Small_Text_Size means that the contents will have the AARM size;
238 -- otherwise it will have the normal size.
239 -- Header_Kind determines whether the table has headers.
240 -- This command starts a paragraph; the entire table is a single
241 -- paragraph. Text will be considered part of the caption until the
242 -- next table marker call.
243 -- Raises Not_Valid_Error if in a paragraph.
244
245 procedure Table_Marker (Output_Object : in out Text_Output_Type;
246 Marker : in ARM_Output.Table_Marker_Type);
247 -- Marks the end of an entity in a table.
248 -- If Marker is End_Caption, the table caption ends and the
249 -- future text is part of the table header.
250 -- If Marker is End_Header, the table header ends and the
251 -- future text is part of the table body.
252 -- If Marker is End_Row, a row in the table is completed, and another
253 -- row started.
254 -- If Marker is End_Item, an item in the table header or body is ended,
255 -- and another started.
256 -- If Marker is End_Table, the entire table is finished.
257 -- Raises Not_Valid_Error if not in a table.
258
259 -- Text output: These are only allowed after a Start_Paragraph and
260 -- before any End_Paragraph. Raises Not_Valid_Error if not allowed.
261
262 procedure Ordinary_Text (Output_Object : in out Text_Output_Type;
263 Text : in String);
264 -- Output ordinary text.
265 -- The text must end at a word break, never in the middle of a word.
266
267 procedure Ordinary_Character (Output_Object : in out Text_Output_Type;
268 Char : in Character);
269 -- Output an ordinary character.
270 -- Spaces will be used to break lines as needed.
271
272 procedure Hard_Space (Output_Object : in out Text_Output_Type);
273 -- Output a hard space. No line break should happen at a hard space.
274
275 procedure Line_Break (Output_Object : in out Text_Output_Type);
276 -- Output a line break. This does not start a new paragraph.
277 -- This corresponds to a "<BR>" in HTML.
278
279 procedure Index_Line_Break (Output_Object : in out Text_Output_Type;
280 Clear_Keep_with_Next : in Boolean);
281 -- Output a line break for the index. This does not start a new
282 -- paragraph in terms of spacing. This corresponds to a "<BR>"
283 -- in HTML. If Clear_Keep_with_Next is true, insure that the next
284 -- line does not require the following line to stay with it.
285
286 procedure Soft_Line_Break (Output_Object : in out Text_Output_Type);
287 -- Output a soft line break. This is a place (in the middle of a
288 -- "word") that we allow a line break. It is usually used after
289 -- underscores in long non-terminals.
290
291 procedure Soft_Hyphen_Break (Output_Object : in out Text_Output_Type);
292 -- Output a soft line break, with a hyphen. This is a place (in the middle of
293 -- a "word") that we allow a line break. If the line break is used,
294 -- a hyphen will be added to the text.
295
296 procedure Tab (Output_Object : in out Text_Output_Type);
297 -- Output a tab, inserting space up to the next tab stop.
298 -- Raises Not_Valid_Error if the paragraph was created with
299 -- Tab_Stops = ARM_Output.NO_TABS.
300
301 procedure Special_Character (Output_Object : in out Text_Output_Type;
302 Char : in ARM_Output.Special_Character_Type);
303 -- Output an special character.
304
305 procedure Unicode_Character (Output_Object : in out Text_Output_Type;
306 Char : in ARM_Output.Unicode_Type);
307 -- Output a Unicode character, with code position Char.
308
309 procedure End_Hang_Item (Output_Object : in out Text_Output_Type);
310 -- Marks the end of a hanging item. Call only once per paragraph.
311 -- Raises Not_Valid_Error if the paragraph style is not in
312 -- Text_Prefixed_Style_Subtype, or if this has already been
313 -- called for the current paragraph, or if the paragraph was started
314 -- with No_Prefix = True.
315
316 procedure Text_Format (Output_Object : in out Text_Output_Type;
317 Format : in ARM_Output.Format_Type);
318 -- Change the text format so that all of the properties are as specified.
319 -- Note: Changes to these properties ought be stack-like; that is,
320 -- Bold on, Italic on, Italic off, Bold off is OK; Bold on, Italic on,
321 -- Bold off, Italic off should be avoided (as separate commands).
322
323 procedure Clause_Reference (Output_Object : in out Text_Output_Type;
324 Text : in String;
325 Clause_Number : in String);
326 -- Generate a reference to a clause in the standard. The text of
327 -- the reference is "Text", and the number of the clause is
328 -- Clause_Number. For hyperlinked formats, this should generate
329 -- a link; for other formats, the text alone is generated.
330
331 procedure Index_Target (Output_Object : in out Text_Output_Type;
332 Index_Key : in Natural);
333 -- Generate a index target. This marks the location where an index
334 -- reference occurs. Index_Key names the index item involved.
335 -- For hyperlinked formats, this should generate a link target;
336 -- for other formats, nothing is generated.
337
338 procedure Index_Reference (Output_Object : in out Text_Output_Type;
339 Text : in String;
340 Index_Key : in Natural;
341 Clause_Number : in String);
342 -- Generate a reference to an index target in the standard. The text
343 -- of the reference is "Text", and Index_Key and Clause_Number denotes
344 -- the target. For hyperlinked formats, this should generate
345 -- a link; for other formats, the text alone is generated.
346
347 procedure DR_Reference (Output_Object : in out Text_Output_Type;
348 Text : in String;
349 DR_Number : in String);
350 -- Generate a reference to an DR from the standard. The text
351 -- of the reference is "Text", and DR_Number denotes
352 -- the target. For hyperlinked formats, this should generate
353 -- a link; for other formats, the text alone is generated.
354
355 procedure AI_Reference (Output_Object : in out Text_Output_Type;
356 Text : in String;
357 AI_Number : in String);
358 -- Generate a reference to an AI from the standard. The text
359 -- of the reference is "Text", and AI_Number denotes
360 -- the target (in unfolded format). For hyperlinked formats, this should
361 -- generate a link; for other formats, the text alone is generated.
362
363 procedure Local_Target (Output_Object : in out Text_Output_Type;
364 Text : in String;
365 Target : in String);
366 -- Generate a local target. This marks the potential target of local
367 -- links identified by "Target". Text is the text of the target.
368 -- For hyperlinked formats, this should generate a link target;
369 -- for other formats, only the text is generated.
370
371 procedure Local_Link (Output_Object : in out Text_Output_Type;
372 Text : in String;
373 Target : in String;
374 Clause_Number : in String);
375 -- Generate a local link to the target and clause given.
376 -- Text is the text of the link.
377 -- For hyperlinked formats, this should generate a link;
378 -- for other formats, only the text is generated.
379
380 procedure Local_Link_Start (Output_Object : in out Text_Output_Type;
381 Target : in String;
382 Clause_Number : in String);
383 -- Generate a local link to the target and clause given.
384 -- The link will surround text until Local_Link_End is called.
385 -- Local_Link_End must be called before this routine can be used again.
386 -- For hyperlinked formats, this should generate a link;
387 -- for other formats, only the text is generated.
388
389 procedure Local_Link_End (Output_Object : in out Text_Output_Type;
390 Target : in String;
391 Clause_Number : in String);
392 -- End a local link for the target and clause given.
393 -- This must be in the same paragraph as the Local_Link_Start.
394 -- For hyperlinked formats, this should generate a link;
395 -- for other formats, only the text is generated.
396
397 procedure URL_Link (Output_Object : in out Text_Output_Type;
398 Text : in String;
399 URL : in String);
400 -- Generate a link to the URL given.
401 -- Text is the text of the link.
402 -- For hyperlinked formats, this should generate a link;
403 -- for other formats, only the text is generated.
404
405 procedure Picture (Output_Object : in out Text_Output_Type;
406 Name : in String;
407 Descr : in String;
408 Alignment : in ARM_Output.Picture_Alignment;
409 Height, Width : in Natural;
410 Border : in ARM_Output.Border_Kind);
411 -- Generate a picture.
412 -- Name is the (simple) file name of the picture; Descr is a
413 -- descriptive name for the picture (it will appear in some web
414 -- browsers).
415 -- We assume that it is a .GIF or .JPG and that it will be present
416 -- in the same directory as the input files and the same directory as
417 -- the .HTML output files.
418 -- Alignment specifies the picture alignment.
419 -- Height and Width specify the picture size in pixels.
420 -- Border specifies the kind of border.
421
422 private
423
424 subtype Buffer_String is String (1 .. 120);
425 subtype Prefix_String is String(1..5);
426 type Text_Output_Type is new ARM_Output.Output_Type with record
427 Is_Valid : Boolean := False;
428 Is_In_Paragraph : Boolean := False;
429 Is_In_Table : Boolean := False; -- Are we processing a table?
430 Is_Hanging : Boolean := False; -- If we are in a paragraph,
431 -- is it a hanging paragraph?
432 Saw_Hang_End : Boolean := False; -- If we are in a hanging paragraph,
433 -- have we seen the end of the hanging part yet?
434 Output_Buffer : Buffer_String; -- Output buffer to make smarter breaks.
435 Output_Buffer_Len : Natural := 0; -- This should be empty between paragraphs.
436 -- The idea is that the buffer is always logically
437 -- preceeded by a space. Thus it is always OK to
438 -- move the text in the buffer to the next line.
439 Output_Buffer_Space_Before : Boolean := False;
440 -- Do we need to output a space before the buffer?
441 Output_File : Ada.Text_IO.File_Type;
442 Output_Path : Buffer_String;
443 Output_Path_Len : Natural := 0;
444 File_Prefix : Prefix_String; -- Blank padded.
445 Char_Count : Natural := 0; -- Characters on current line.
446 Out_Char_Count : Natural := 0; -- Characters output on current line.
447 Indent_Amount : Natural := 0; -- Amount to indent paragraphs.
448 Change : ARM_Output.Change_Type := ARM_Output.None;
449 Location : ARM_Output.Location_Type := ARM_Output.Normal;
450 Tab_Stops : ARM_Output.Tab_Info := ARM_Output.NO_TABS;
451 end record;
452
453 end ARM_Text;