| 1 |
with Ada.Text_IO, |
| 2 |
Ada.Strings.Fixed, |
| 3 |
Ada.Strings.Unbounded, |
| 4 |
Ada.Characters.Handling, |
| 5 |
Ada.Command_Line; |
| 6 |
with ARM_Master, |
| 7 |
ARM_Contents, |
| 8 |
ARM_Format; |
| 9 |
procedure ARM_Formatter is |
| 10 |
|
| 11 |
-- |
| 12 |
-- Ada reference manual formatter (ARM_Form). |
| 13 |
-- |
| 14 |
-- This is the main subprogram: format the sources for the |
| 15 |
-- Ada reference manual and other documents |
| 16 |
-- (in a vaguely Scribe-like macro language) into the actual |
| 17 |
-- reference manual files (in various formats). |
| 18 |
-- |
| 19 |
-- --------------------------------------- |
| 20 |
-- Copyright 2000, 2002, 2004, 2005, 2006, 2011, 2012, 2016, 2017, 2019 |
| 21 |
-- AXE Consultants. All rights reserved. |
| 22 |
-- P.O. Box 1512, Madison WI 53701 |
| 23 |
-- E-Mail: [email protected] |
| 24 |
-- |
| 25 |
-- ARM_Form is free software: you can redistribute it and/or modify |
| 26 |
-- it under the terms of the GNU General Public License version 3 |
| 27 |
-- as published by the Free Software Foundation. |
| 28 |
-- |
| 29 |
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS" |
| 30 |
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, |
| 31 |
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL. |
| 32 |
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL, |
| 33 |
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, |
| 34 |
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 35 |
-- DAMAGES. |
| 36 |
-- |
| 37 |
-- A copy of the GNU General Public License is available in the file |
| 38 |
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool. |
| 39 |
-- Otherwise, see <http://www.gnu.org/licenses/>. |
| 40 |
-- |
| 41 |
-- If the GPLv3 license is not satisfactory for your needs, a commercial |
| 42 |
-- use license is available for this tool. Contact Randy at AXE Consultants |
| 43 |
-- for more information. |
| 44 |
-- |
| 45 |
-- --------------------------------------- |
| 46 |
-- |
| 47 |
-- Edit History: |
| 48 |
-- |
| 49 |
-- 3/ 9/00 - RLB - Created base program. |
| 50 |
-- 4/14/00 - RLB - Created from analysis program. |
| 51 |
-- 4/18/00 - RLB - Added scanning pass. |
| 52 |
-- 4/19/00 - RLB - Split 03 into two files. Added HTML output object. |
| 53 |
-- 4/24/00 - RLB - Added Change_Kind and Display_Index_Entries. |
| 54 |
-- 5/15/00 - RLB - Split formatter from input. |
| 55 |
-- 5/16/00 - RLB - Added missing Destroy for formatting objects. |
| 56 |
-- 5/18/00 - RLB - Added RTF output object. |
| 57 |
-- 5/25/00 - RLB - Added the Big-Files option. Added the library separator. |
| 58 |
-- 5/28/00 - RLB - Added index. |
| 59 |
-- 8/31/00 - RLB - Added the New-Changes option. |
| 60 |
-- 7/18/02 - RLB - Changed copyright date. |
| 61 |
-- - RLB - Changed Creates to include title and header. |
| 62 |
-- - RLB - Added Version parameter to command line and formatting |
| 63 |
-- commands. |
| 64 |
-- 9/10/04 - RLB - Updated descriptions of standard commands. |
| 65 |
-- 9/14/04 - RLB - Moved version to ARM_Contents. |
| 66 |
-- 12/05/04 - RLB - Split/added various source files. |
| 67 |
-- 6/ 2/05 - RLB - Added Corrigendum output module for comparisons to |
| 68 |
-- Amendment document. |
| 69 |
-- 10/12/05 - RLB - Changed the title to reflect what we learned from ISO. |
| 70 |
-- 10/28/05 - RLB - Added Annex Q. |
| 71 |
-- 1/ 5/06 - RLB - Revised to use master files, rather than hard-coded |
| 72 |
-- properties. |
| 73 |
-- 1/12/06 - RLB - Removed Document completely. |
| 74 |
-- 10/18/11 - RLB - Changed to GPLv3 license. |
| 75 |
-- 10/19/11 - RLB - Removed junk withs (now in master file handler). |
| 76 |
-- 4/ 3/12 - RLB - Removed dead variable. |
| 77 |
-- 8/31/12 - RLB - Added output path parameter. |
| 78 |
-- 3/17/16 - RLB - Added lower version to command line. |
| 79 |
|
| 80 |
-- Standard commands for Ada standards: |
| 81 |
-- For Original (Ada 95) RM: |
| 82 |
-- Arm_Form RM <Format> No-Changes 0 0 |
| 83 |
-- For Original AARM: |
| 84 |
-- Arm_Form AARM <Format> No-Changes 0 0 |
| 85 |
-- For RM with Corr: |
| 86 |
-- [With change bars for Word 97/2000:] |
| 87 |
-- Arm_Form RM RTF New-Changes 1 1 |
| 88 |
-- [Final versions with no changes:] |
| 89 |
-- Arm_Form RM <Format> New-Only 1 1 |
| 90 |
-- For AARM with Corr: |
| 91 |
-- [HTML; RTF for display]: |
| 92 |
-- Arm_Form AARM <Format> Show-Changes 1 1 |
| 93 |
-- [TXT; RTF for printing]: |
| 94 |
-- Arm_Form AARM <Format> New-Only 1 1 |
| 95 |
-- For RM with Corr and Amd: |
| 96 |
-- [With change bars for Word 97/2000:] |
| 97 |
-- Arm_Form RM RTF New-Changes 1 2 |
| 98 |
-- [With change ballons for Word XP/2003:] |
| 99 |
-- Arm_Form RM RTF Show-Changes 1 2 |
| 100 |
-- [Final versions with no changes:] |
| 101 |
-- Arm_Form RM <Format> New-Only 1 2 |
| 102 |
-- For AARM with Corr and Amd: |
| 103 |
-- [HTML; RTF for display]: |
| 104 |
-- Arm_Form AARM <Format> Show-Changes 2 2 |
| 105 |
-- (for only Amd changes) or |
| 106 |
-- Arm_Form AARM <Format> Show-Changes 1 2 |
| 107 |
-- (for all changes) |
| 108 |
-- [TXT; RTF for printing]: |
| 109 |
-- Arm_Form AARM <Format> New-Only 2 2 |
| 110 |
-- For Ada 2012 RM: (To include TC1, change 3 to 4). |
| 111 |
-- [With change ballons for Word XP/2003:] |
| 112 |
-- Arm_Form RM RTF Show-Changes 1 3 |
| 113 |
-- [For change bar version for Word 97/2000:] |
| 114 |
-- Arm_Form RM RTF Show-Changes 3 3 |
| 115 |
-- [Final versions with no changes:] |
| 116 |
-- Arm_Form RM <Format> New-Only 3 3 |
| 117 |
-- For Ada 2012 AARM: (To include TC1, change 3 to 4). |
| 118 |
-- [HTML; RTF for display]: |
| 119 |
-- Arm_Form AARM <Format> Show-Changes 3 3 |
| 120 |
-- (for only Amd 2012 changes) or |
| 121 |
-- Arm_Form AARM <Format> Show-Changes 1 3 |
| 122 |
-- (for all changes) |
| 123 |
-- [TXT; RTF for printing]: |
| 124 |
-- Arm_Form AARM <Format> New-Only 1 3 |
| 125 |
-- For Ada 202x RM: |
| 126 |
-- [For change bar version:] |
| 127 |
-- Arm_Form RM RTF Show-Changes 4 5 |
| 128 |
-- [Final versions with no changes:] |
| 129 |
-- Arm_Form RM <Format> New-Only 5 5 |
| 130 |
-- For Ada 202x AARM with: |
| 131 |
-- [HTML; RTF for display]: |
| 132 |
-- Arm_Form AARM <Format> Show-Changes 4 5 |
| 133 |
-- (for only Amd 2012 changes) or |
| 134 |
-- Arm_Form AARM <Format> Show-Changes 1 5 |
| 135 |
-- (for all changes) |
| 136 |
-- [TXT; RTF for printing]: |
| 137 |
-- Arm_Form AARM <Format> New-Only 5 5 |
| 138 |
|
| 139 |
|
| 140 |
No_Command_Error : exception; |
| 141 |
|
| 142 |
Format : ARM_Master.Output_Format_Type; -- Format to generate. |
| 143 |
Master_File : Ada.Strings.Unbounded.Unbounded_String; -- Master file for document to generate. |
| 144 |
Change_Kind : ARM_Format.Change_Kind; -- Changes to generate. |
| 145 |
Base_Change_Version : ARM_Contents.Change_Version_Type; -- Lower Change version. |
| 146 |
Change_Version : ARM_Contents.Change_Version_Type; -- (Upper) Change version. |
| 147 |
Output_Path : Ada.Strings.Unbounded.Unbounded_String; -- Output path. |
| 148 |
|
| 149 |
procedure Get_Commands is |
| 150 |
-- Process the command line for this program. |
| 151 |
begin |
| 152 |
if Ada.Command_Line.Argument_Count not in 1 .. 6 then |
| 153 |
Ada.Text_IO.Put_Line ("** Wrong number of arguments"); |
| 154 |
raise No_Command_Error; |
| 155 |
end if; |
| 156 |
if Ada.Command_Line.Argument_Count >= 6 then |
| 157 |
Output_Path := Ada.Strings.Unbounded.To_Unbounded_String( |
| 158 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(6), |
| 159 |
Ada.Strings.Right)); |
| 160 |
-- Check that the Output_Path ends with a path separator. |
| 161 |
-- Note: This is a simple Windows check; it doesn't check for and |
| 162 |
-- allow bare disk names. This check works on Linux but allows |
| 163 |
-- ending with '\' which does not work on Linux (that will be |
| 164 |
-- failed when the files are opened). |
| 165 |
declare |
| 166 |
Last : constant Character := |
| 167 |
Ada.Strings.Unbounded.Element (Ada.Strings.Unbounded.Tail (Output_Path, 1), 1); |
| 168 |
begin |
| 169 |
if Last = '/' or else Last = '\' then |
| 170 |
null; -- OK; this ends with a path separator. |
| 171 |
else |
| 172 |
Ada.Text_IO.Put_Line ("** Output path does not end with a path separator: " & |
| 173 |
Ada.Strings.Unbounded.To_String (Output_Path)); |
| 174 |
raise No_Command_Error; |
| 175 |
end if; |
| 176 |
end; |
| 177 |
else |
| 178 |
Output_Path := Ada.Strings.Unbounded.To_Unbounded_String |
| 179 |
("./output/"); -- Use '/' so this works on Linux and Windows. |
| 180 |
end if; |
| 181 |
if Ada.Command_Line.Argument_Count >= 5 then |
| 182 |
declare |
| 183 |
Version_Arg : String := |
| 184 |
Ada.Characters.Handling.To_Lower ( |
| 185 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(5), |
| 186 |
Ada.Strings.Right)); |
| 187 |
begin |
| 188 |
if Version_Arg'Length = 1 and then |
| 189 |
Version_Arg(Version_Arg'First) in ARM_Contents.Change_Version_Type then |
| 190 |
Change_Version := Version_Arg(Version_Arg'First); |
| 191 |
else |
| 192 |
Ada.Text_IO.Put_Line ("** Unrecognized change version: " & Version_Arg); |
| 193 |
raise No_Command_Error; |
| 194 |
end if; |
| 195 |
end; |
| 196 |
else |
| 197 |
Change_Version := '0'; |
| 198 |
end if; |
| 199 |
if Ada.Command_Line.Argument_Count >= 4 then |
| 200 |
declare |
| 201 |
Version_Arg : String := |
| 202 |
Ada.Characters.Handling.To_Lower ( |
| 203 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(4), |
| 204 |
Ada.Strings.Right)); |
| 205 |
begin |
| 206 |
if Version_Arg'Length = 1 and then |
| 207 |
Version_Arg(Version_Arg'First) in ARM_Contents.Change_Version_Type then |
| 208 |
Base_Change_Version := Version_Arg(Version_Arg'First); |
| 209 |
else |
| 210 |
Ada.Text_IO.Put_Line ("** Unrecognized change version: " & Version_Arg); |
| 211 |
raise No_Command_Error; |
| 212 |
end if; |
| 213 |
end; |
| 214 |
else |
| 215 |
Base_Change_Version := '0'; |
| 216 |
end if; |
| 217 |
if Ada.Command_Line.Argument_Count >= 3 then |
| 218 |
declare |
| 219 |
Changes_Arg : String := |
| 220 |
Ada.Characters.Handling.To_Lower ( |
| 221 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(3), |
| 222 |
Ada.Strings.Right)); |
| 223 |
begin |
| 224 |
if Changes_Arg = "no-changes" then |
| 225 |
Change_Kind := ARM_Format.Old_Only; |
| 226 |
elsif Changes_Arg = "new-only" then |
| 227 |
Change_Kind := ARM_Format.New_Only; |
| 228 |
elsif Changes_Arg = "show-changes" then |
| 229 |
Change_Kind := ARM_Format.Show_Changes; |
| 230 |
elsif Changes_Arg = "new-changes" then |
| 231 |
Change_Kind := ARM_Format.New_Changes; |
| 232 |
else |
| 233 |
Ada.Text_IO.Put_Line ("** Unrecognized changes: " & Changes_Arg); |
| 234 |
raise No_Command_Error; |
| 235 |
end if; |
| 236 |
end; |
| 237 |
else |
| 238 |
Change_Kind := ARM_Format.New_Only; |
| 239 |
end if; |
| 240 |
if Ada.Command_Line.Argument_Count >= 2 then |
| 241 |
declare |
| 242 |
Format_Arg : String := |
| 243 |
Ada.Characters.Handling.To_Lower ( |
| 244 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(2), |
| 245 |
Ada.Strings.Right)); |
| 246 |
begin |
| 247 |
if Format_Arg = "rtf" then |
| 248 |
Format := ARM_Master.RTF; |
| 249 |
elsif Format_Arg = "html" then |
| 250 |
Format := ARM_Master.HTML; |
| 251 |
elsif Format_Arg = "text" then |
| 252 |
Format := ARM_Master.Text; |
| 253 |
elsif Format_Arg = "corr" then |
| 254 |
Format := ARM_Master.Corr; |
| 255 |
elsif Format_Arg = "info" then |
| 256 |
Format := ARM_Master.Info; |
| 257 |
else |
| 258 |
Ada.Text_IO.Put_Line ("** Unrecognized format: " & Format_Arg); |
| 259 |
raise No_Command_Error; |
| 260 |
end if; |
| 261 |
end; |
| 262 |
else |
| 263 |
Format := ARM_Master.HTML; |
| 264 |
end if; |
| 265 |
declare |
| 266 |
use type Ada.Strings.Unbounded.Unbounded_String; |
| 267 |
begin |
| 268 |
Master_File := Ada.Strings.Unbounded.To_Unbounded_String( |
| 269 |
Ada.Strings.Fixed.Trim (Ada.Command_Line.Argument(1), |
| 270 |
Ada.Strings.Right)); |
| 271 |
if Ada.Strings.Unbounded.Index (Master_File, ".") = 0 then |
| 272 |
-- Add extension if it is missing. |
| 273 |
Master_File := Master_File & ".MSM"; |
| 274 |
end if; |
| 275 |
end; |
| 276 |
exception |
| 277 |
when No_Command_Error => |
| 278 |
Ada.Text_IO.Put_Line (" Usage: Arm_Form <Master_File> [<Format>[ <Changes>[ <BaseVers>[ <ChgVers>[ <Output Path>]]]]]}"); |
| 279 |
Ada.Text_IO.Put_Line (" where: <Master_File> is the file name (and optional path) for the master file"); |
| 280 |
Ada.Text_IO.Put_Line (" for the document;"); |
| 281 |
Ada.Text_IO.Put_Line (" where: <Format> = 'Text' (text files),"); |
| 282 |
Ada.Text_IO.Put_Line (" 'HTML' (HTML files),"); |
| 283 |
Ada.Text_IO.Put_Line (" 'RTF' (RTF files for Word 97 or later),"); |
| 284 |
Ada.Text_IO.Put_Line (" 'Corr' (Corrigendum-style command files for comparisons);"); |
| 285 |
Ada.Text_IO.Put_Line (" where: <Changes> = 'No-Changes' (Original RM text),"); |
| 286 |
Ada.Text_IO.Put_Line (" 'New-Only' (Revised RM text only up to <ChgVers>),"); |
| 287 |
Ada.Text_IO.Put_Line (" 'Show-Changes' (Text with changes marked between"); |
| 288 |
Ada.Text_IO.Put_Line (" <BaseVers> and <ChgVers>),"); |
| 289 |
Ada.Text_IO.Put_Line (" 'New-Changes' (Text with insertions marked between"); |
| 290 |
Ada.Text_IO.Put_Line (" <BaseVers> and <ChgVers>);"); |
| 291 |
Ada.Text_IO.Put_Line (" where: <BaseVers> and <ChgVers> = a value in 0 .. 9 representing the"); |
| 292 |
Ada.Text_IO.Put_Line (" base and primary change versions, respectively"); |
| 293 |
Ada.Text_IO.Put_Line (" 0-Original Ada 95 (equivalent to No-Changes)"); |
| 294 |
Ada.Text_IO.Put_Line (" 1-Technical Corrigendum 1"); |
| 295 |
Ada.Text_IO.Put_Line (" 2-Amendment 1"); |
| 296 |
Ada.Text_IO.Put_Line (" 3-Ada 2012"); |
| 297 |
Ada.Text_IO.Put_Line (" 4-Ada 2012 Technical Corrigendum 1"); |
| 298 |
Ada.Text_IO.Put_Line (" 5-Ada 202x"); |
| 299 |
Ada.Text_IO.Put_Line (" where: <Output_Path> = it the path where to write the result files. This must"); |
| 300 |
Ada.Text_IO.Put_Line (" end with a path separator. It defaults to ./output/"); |
| 301 |
raise No_Command_Error; |
| 302 |
end Get_Commands; |
| 303 |
|
| 304 |
|
| 305 |
begin |
| 306 |
Ada.Text_IO.Put_Line ("Ada Manual formatter"); |
| 307 |
Ada.Text_IO.Put_Line (" Copyright 2000, 2002, 2004, 2005, 2006, 2011, 2012, 2016, "); |
| 308 |
Ada.Text_IO.Put_Line (" 2017, 2019 AXE Consultants"); |
| 309 |
Ada.Text_IO.Put_Line (" P.O. Box 1512, Madison WI 53701"); |
| 310 |
|
| 311 |
Get_Commands; |
| 312 |
|
| 313 |
Ada.Text_IO.Put_Line (" Master File = " & Ada.Strings.Unbounded.To_String(Master_File)); |
| 314 |
Ada.Text_IO.Put_Line (" Format = " & ARM_Master.Output_Format_Type'Image(Format)); |
| 315 |
Ada.Text_IO.Put_Line (" Changes = " & ARM_Format.Change_Kind'Image(Change_Kind)); |
| 316 |
Ada.Text_IO.Put_Line (" Version = " & Change_Version); |
| 317 |
|
| 318 |
ARM_Master.Read_and_Process_Master_File ( |
| 319 |
File_Name => Ada.Strings.Unbounded.To_String(Master_File), |
| 320 |
The_Change_Kind => Change_Kind, |
| 321 |
The_Change_Version => Change_Version, |
| 322 |
The_Base_Change_Version => Base_Change_Version, |
| 323 |
Output_Format => Format, |
| 324 |
Output_Path => Ada.Strings.Unbounded.To_String(Output_Path)); |
| 325 |
|
| 326 |
Ada.Text_IO.Put_Line ("Ada document created"); |
| 327 |
exception |
| 328 |
when No_Command_Error => |
| 329 |
null; -- Error message displayed by command line processor. |
| 330 |
end ARM_Formatter; |