1 ------------------------------------------------------------------------------
3 -- GNAT SYSTEM UTILITIES --
5 -- A L F A _ T E S T --
9 -- Copyright (C) 2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This utility program is used to test proper operation of the Get_ALFA and
27 -- Put_ALFA units. To run it, compile any source file with switch -gnatd.E or
28 -- -gnatd.F to get an ALI file file.ALI containing ALFA information. Then run
29 -- this utility using:
33 -- This test will read the ALFA information from the ALI file, and use
34 -- Get_ALFA to store this in binary form in the internal tables in ALFA. Then
35 -- Put_ALFA is used to write the information from these tables back into text
36 -- form. This output is compared with the original ALFA information in the ALI
37 -- file and the two should be identical. If not an error message is output.
43 with Types; use Types;
45 with Ada.Command_Line; use Ada.Command_Line;
46 with Ada.Streams; use Ada.Streams;
47 with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
50 procedure ALFA_Test is
52 Outfile_1 : File_Type;
53 Outfile_2 : File_Type;
57 -- Terminate execution
62 if Argument_Count /= 1 then
63 Ada.Text_IO.Put_Line ("Usage: alfa_test FILE.ali");
67 Create (Outfile_1, Out_File, "log1");
68 Create (Outfile_2, Out_File, "log2");
69 Open (Infile, In_File, Argument (1));
71 -- Read input file till we get to first 'F' line
74 Output_Col : Positive := 1;
76 function Get_Char (F : File_Type) return Character;
77 -- Read one character from specified file
79 procedure Put_Char (F : File_Type; C : Character);
80 -- Write one character to specified file
82 function Get_Output_Col return Positive;
83 -- Return current column in output file, where each line starts at
84 -- column 1 and terminate with LF, and HT is at columns 1, 9, etc.
85 -- All output is supposed to be carried through Put_Char.
91 function Get_Char (F : File_Type) return Character is
92 Item : Stream_Element_Array (1 .. 1);
93 Last : Stream_Element_Offset;
101 return Character'Val (Item (1));
109 function Get_Output_Col return Positive is
118 procedure Put_Char (F : File_Type; C : Character) is
119 Item : Stream_Element_Array (1 .. 1);
122 if C /= CR and then C /= EOF then
126 Output_Col := ((Output_Col + 6) / 8) * 8 + 1;
128 Output_Col := Output_Col + 1;
131 Item (1) := Character'Pos (C);
136 -- Subprograms used by Get_ALFA (these also copy the output to Outfile_1
137 -- for later comparison with the output generated by Put_ALFA).
139 function Getc return Character;
140 function Nextc return Character;
147 function Getc return Character is
150 C := Get_Char (Infile);
151 Put_Char (Outfile_1, C);
159 function Nextc return Character is
163 C := Get_Char (Infile);
166 Set_Index (Infile, Index (Infile) - 1);
178 pragma Unreferenced (C);
183 -- Subprograms used by Put_ALFA, which write information to Outfile_2
185 function Write_Info_Col return Positive;
186 procedure Write_Info_Char (C : Character);
187 procedure Write_Info_Initiate (Key : Character);
188 procedure Write_Info_Nat (N : Nat);
189 procedure Write_Info_Terminate;
195 function Write_Info_Col return Positive is
197 return Get_Output_Col;
200 ---------------------
201 -- Write_Info_Char --
202 ---------------------
204 procedure Write_Info_Char (C : Character) is
206 Put_Char (Outfile_2, C);
209 -------------------------
210 -- Write_Info_Initiate --
211 -------------------------
213 procedure Write_Info_Initiate (Key : Character) is
215 Write_Info_Char (Key);
216 end Write_Info_Initiate;
222 procedure Write_Info_Nat (N : Nat) is
225 Write_Info_Nat (N / 10);
228 Write_Info_Char (Character'Val (48 + N mod 10));
231 --------------------------
232 -- Write_Info_Terminate --
233 --------------------------
235 procedure Write_Info_Terminate is
237 Write_Info_Char (LF);
238 end Write_Info_Terminate;
240 -- Local instantiations of Put_ALFA and Get_ALFA
242 procedure Get_ALFA_Info is new Get_ALFA;
243 procedure Put_ALFA_Info is new Put_ALFA;
245 -- Start of processing for Process
248 -- Loop to skip till first 'F' line
251 C := Get_Char (Infile);
256 elsif C = LF or else C = CR then
258 C := Get_Char (Infile);
259 exit when C /= LF and then C /= CR;
266 -- Position back to initial 'F' of first 'F' line
268 Set_Index (Infile, Index (Infile) - 1);
270 -- Read ALFA information to internal ALFA tables, also copying ALFA info
273 Initialize_ALFA_Tables;
276 -- Write ALFA information from internal ALFA tables to Outfile_2
280 -- Junk blank line (see comment at end of Lib.Writ)
282 Write_Info_Terminate;
284 -- Now Outfile_1 and Outfile_2 should be identical
286 Compare_Files : declare
293 Reset (Outfile_1, In_File);
294 Reset (Outfile_2, In_File);
296 -- Loop to compare the two files
301 C1 := Get_Char (Outfile_1);
302 C2 := Get_Char (Outfile_2);
303 exit when C1 = EOF or else C1 /= C2;
313 -- If we reached the end of file, then the files were identical,
314 -- otherwise, we have a failure in the comparison.
317 -- Success: exit silently
323 (Argument (1) & ": failure, files log1 and log2 differ at line"
324 & Line'Img & " column" & Col'Img);