with GNAT.Command_Line; use GNAT.Command_Line;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Gnatvsn; use Gnatvsn;
with Osint; use Osint;
with Output; use Output;
with Symbols; use Symbols;
with Table;
procedure Gnatsym is
Empty_String : aliased String := "";
Empty : constant String_Access := Empty_String'Unchecked_Access;
Copyright_Displayed : Boolean := False;
Success : Boolean := True;
Symbol_Policy : Policy := Autonomous;
Verbose : Boolean := False;
Quiet : Boolean := False;
Symbol_File_Name : String_Access := null;
Reference_Symbol_File_Name : String_Access := Empty;
Version_String : String_Access := Empty;
package Object_Files is new Table.Table
(Table_Component_Type => String_Access,
Table_Index_Type => Natural,
Table_Low_Bound => 0,
Table_Initial => 10,
Table_Increment => 10,
Table_Name => "Gnatsymb.Object_Files");
Object_File : Natural := 0;
procedure Display_Copyright;
procedure Parse_Cmd_Line;
procedure Usage;
procedure Display_Copyright is
begin
if not Copyright_Displayed then
Write_Eol;
Write_Str ("GNATSYMB ");
Write_Str (Gnat_Version_String);
Write_Eol;
Write_Str ("Copyright 2003-2004 Free Software Foundation, Inc");
Write_Eol;
Copyright_Displayed := True;
end if;
end Display_Copyright;
procedure Parse_Cmd_Line is
begin
loop
case GNAT.Command_Line.Getopt ("c C q r: R s: v V:") is
when ASCII.NUL =>
exit;
when 'c' =>
Symbol_Policy := Compliant;
when 'C' =>
Symbol_Policy := Controlled;
when 'q' =>
Quiet := True;
when 'r' =>
Reference_Symbol_File_Name :=
new String'(GNAT.Command_Line.Parameter);
when 'R' =>
Symbol_Policy := Restricted;
when 's' =>
Symbol_File_Name := new String'(GNAT.Command_Line.Parameter);
when 'v' =>
Verbose := True;
when 'V' =>
Version_String := new String'(GNAT.Command_Line.Parameter);
when others =>
Fail ("invalid switch: ", Full_Switch);
end case;
end loop;
loop
declare
S : constant String_Access :=
new String'(GNAT.Command_Line.Get_Argument);
begin
exit when S'Length = 0;
Object_Files.Increment_Last;
Object_Files.Table (Object_Files.Last) := S;
end;
end loop;
exception
when Invalid_Switch =>
Usage;
Fail ("invalid switch : ", Full_Switch);
end Parse_Cmd_Line;
procedure Usage is
begin
Write_Line ("gnatsym [options] object_file {object_file}");
Write_Eol;
Write_Line (" -c Compliant symbol policy");
Write_Line (" -C Controlled symbol policy");
Write_Line (" -q Quiet mode");
Write_Line (" -r<ref> Reference symbol file name");
Write_Line (" -R Restricted symbol policy");
Write_Line (" -s<sym> Symbol file name");
Write_Line (" -v Verbose mode");
Write_Line (" -V<ver> Version");
Write_Eol;
Write_Line ("Specifying a symbol file with -s<sym> is compulsory");
Write_Eol;
end Usage;
begin
Object_Files.Set_Last (0);
Parse_Cmd_Line;
if Verbose then
Display_Copyright;
end if;
if Symbol_File_Name = null or else Object_Files.Last = 0 then
Usage;
OS_Exit (1);
else
if Verbose then
Write_Str ("Initializing symbol file """);
Write_Str (Symbol_File_Name.all);
Write_Line ("""");
end if;
Symbols.Initialize
(Symbol_File => Symbol_File_Name.all,
Reference => Reference_Symbol_File_Name.all,
Symbol_Policy => Symbol_Policy,
Quiet => Quiet,
Version => Version_String.all,
Success => Success);
Object_File := 0;
while Success and then Object_File < Object_Files.Last loop
Object_File := Object_File + 1;
if Verbose then
Write_Str ("Processing object file """);
Write_Str (Object_Files.Table (Object_File).all);
Write_Line ("""");
end if;
Process (Object_Files.Table (Object_File).all, Success);
end loop;
if Success then
if Verbose then
Write_Str ("Finalizing """);
Write_Str (Symbol_File_Name.all);
Write_Line ("""");
end if;
Finalize (Quiet, Success);
end if;
if not Success then
Fail ("unable to build symbol file");
end if;
end if;
end Gnatsym;