with ALI; use ALI;
with Csets;
-with Gnatvsn; use Gnatvsn;
with Makeutl;
with MLib.Tgt; use MLib.Tgt;
with Namet; use Namet;
with Prj.Pars;
with Prj.Util; use Prj.Util;
with Snames;
+with Switch; use Switch;
with Table;
with Targparm; use Targparm;
with Types; use Types;
begin
if not Copyright_Displayed then
Copyright_Displayed := True;
- Put_Line
- ("GNATCLEAN " & Gnatvsn.Gnat_Version_String
- & " Copyright 2003-"
- & Current_Year
- & " Free Software Foundation, Inc.");
+ Display_Version ("GNATCLEAN", "2003");
end if;
end Display_Copyright;
procedure Parse_Cmd_Line is
Last : constant Natural := Argument_Count;
Source_Index : Int := 0;
- Index : Positive := 1;
+ Index : Positive;
begin
+ -- First, check for --version and --help
+
+ Check_Version_And_Help ("GNATCLEAN", "2003", Usage'Access);
+
+ Index := 1;
while Index <= Last loop
declare
Arg : constant String := Argument (Index);
with Debug; use Debug;
with Fmap;
with Fname; use Fname;
-with Gnatvsn; use Gnatvsn;
with Namet; use Namet;
with Opt; use Opt;
with Osint; use Osint;
Shared_Libgnat := (Shared_Libgnat_Default = SHARED);
end;
+ -- Scan the switches and arguments
+
+ -- First, scan to detect --version and/or --help
+
+ Check_Version_And_Help ("GNATBIND", "1995", Bindusg.Display'Access);
+
-- Use low level argument routines to avoid dragging in the secondary stack
Next_Arg := 1;
if Verbose_Mode then
Write_Eol;
- Write_Str ("GNATBIND ");
- Write_Str (Gnat_Version_String);
- Write_Eol;
- Write_Str ("Copyright 1995-" &
- Current_Year &
- ", Free Software Foundation, Inc.");
- Write_Eol;
+ Display_Version ("GNATBIND", "1995");
end if;
-- Output usage information if no files
-- --
-- B o d y --
-- --
--- Copyright (C) 1998-2007, AdaCore --
+-- Copyright (C) 1998-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
with GNAT.Heap_Sort_G;
with GNAT.Table;
-with Gnatvsn;
with Hostparm;
+with Switch; use Switch;
with Types;
procedure Gnatchop is
when 'v' =>
Verbose_Mode := True;
-
- -- Why is following written to standard error. Most other
- -- tools write to standard output ???
-
- Put (Standard_Error, "GNATCHOP ");
- Put_Line (Standard_Error, Gnatvsn.Gnat_Version_String);
- Put_Line
- (Standard_Error, "Copyright 1998-2005, AdaCore");
+ Display_Version ("GNATCHOP", "1998");
when 'w' =>
Overwrite_Files := True;
-- Process command line options and initialize global variables
+ -- First, scan to detect --version and/or --help
+
+ Check_Version_And_Help ("GNATCHOP", "1998", Usage'Unrestricted_Access);
+
if not Scan_Arguments then
Set_Exit_Status (Failure);
return;
-- --
------------------------------------------------------------------------------
-with Xr_Tabls; use Xr_Tabls;
-with Xref_Lib; use Xref_Lib;
+with Opt;
with Osint; use Osint;
+with Switch; use Switch;
with Types; use Types;
-
-with Gnatvsn;
-with Opt;
+with Xr_Tabls; use Xr_Tabls;
+with Xref_Lib; use Xref_Lib;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
procedure Parse_Cmd_Line;
-- Parse every switch on the command line
+ procedure Usage;
+ -- Display the usage
+
procedure Write_Usage;
- -- Print a small help page for program usage
+ -- Print a small help page for program usage and exit program
--------------------
-- Parse_Cmd_Line --
procedure Parse_Cmd_Line is
begin
+ -- First check for --version or --help
+
+ Check_Version_And_Help ("GNATFIND", "1998", Usage'Unrestricted_Access);
+
+ -- Now scan the other switches
+
+ GNAT.Command_Line.Initialize_Option_Scan;
+
loop
case
GNAT.Command_Line.Getopt
Write_Usage;
end Parse_Cmd_Line;
- -----------------
- -- Write_Usage --
- -----------------
+ -----------
+ -- Usage --
+ -----------
- procedure Write_Usage is
+ procedure Usage is
begin
- Put_Line ("GNATFIND " & Gnatvsn.Gnat_Version_String);
- Put_Line ("Copyright 1998-2005, AdaCore");
Put_Line ("Usage: gnatfind pattern[:sourcefile[:line[:column]]] "
& "[file1 file2 ...]");
New_Line;
& " only)");
Put_Line (" -s Print source line");
Put_Line (" -t Print type hierarchy");
+ end Usage;
+
+ -----------------
+ -- Write_Usage --
+ -----------------
+
+ procedure Write_Usage is
+ begin
+ Display_Version ("GNATFIND", "1998");
New_Line;
+ Usage;
+
raise Usage_Error;
end Write_Usage;
procedure Process_Binder_File (Name : String);
-- Reads the binder file and extracts linker arguments
+ procedure Usage;
+ -- Display usage
+
procedure Write_Header;
-- Show user the program name, version and copyright
-- linker's argument without parsing it.
begin
+ -- First, check for --version and --help
+
+ Check_Version_And_Help ("GNATLINK", "1995", Usage'Unrestricted_Access);
+
-- Loop through arguments of gnatlink command
Next_Arg := 1;
Status := fclose (Fd);
end Process_Binder_File;
- ------------------
- -- Write_Header --
- ------------------
+ -----------
+ -- Usage --
+ -----------
- procedure Write_Header is
+ procedure Usage is
begin
- if Verbose_Mode then
- Write_Eol;
- Write_Str ("GNATLINK ");
- Write_Str (Gnat_Version_String);
- Write_Eol;
- Write_Str ("Copyright 1995-" &
- Current_Year &
- ", Free Software Foundation, Inc");
- Write_Eol;
- end if;
- end Write_Header;
-
- -----------------
- -- Write_Usage --
- -----------------
-
- procedure Write_Usage is
- begin
- Write_Header;
-
Write_Str ("Usage: ");
Write_Str (Base_Name (Command_Name));
Write_Str (" switches mainprog.ali [non-Ada-objects] [linker-options]");
Write_Eol;
Write_Line (" [non-Ada-objects] list of non Ada object files");
Write_Line (" [linker-options] other options for the linker");
+ end Usage;
+
+ ------------------
+ -- Write_Header --
+ ------------------
+
+ procedure Write_Header is
+ begin
+ if Verbose_Mode then
+ Write_Eol;
+ Display_Version ("GNATLINK", "1995");
+ end if;
+ end Write_Header;
+
+ -----------------
+ -- Write_Usage --
+ -----------------
+
+ procedure Write_Usage is
+ begin
+ Write_Header;
+ Usage;
end Write_Usage;
-- Start of processing for Gnatlink
with Rident; use Rident;
with Sdefault;
with Snames;
+with Switch; use Switch;
with Targparm; use Targparm;
with Types; use Types;
Csets.Initialize;
Snames.Initialize;
+ -- First check for --version or --help
+
+ Check_Version_And_Help ("GNATLS", "1997", Usage'Unrestricted_Access);
+
-- Loop to scan out arguments
Next_Arg := 1;
Targparm.Get_Target_Parameters;
Write_Eol;
- Write_Str ("GNATLS ");
- Write_Str (Gnat_Version_String);
- Write_Eol;
- Write_Str ("Copyright 1997-" &
- Current_Year &
- ", Free Software Foundation, Inc.");
- Write_Eol;
+ Display_Version ("GNATLS", "1997");
Write_Eol;
Write_Str ("Source Search Path:");
Write_Eol;
-- --
------------------------------------------------------------------------------
-with Gnatvsn; use Gnatvsn;
with Hostparm;
with Opt;
with Osint; use Osint;
with Output; use Output;
with Prj.Makr;
+with Switch; use Switch;
with Table;
with Ada.Command_Line; use Ada.Command_Line;
if not Version_Output then
Version_Output := True;
Output.Write_Eol;
- Output.Write_Str ("GNATNAME ");
- Output.Write_Line (Gnatvsn.Gnat_Version_String);
- Output.Write_Line
- ("Copyright 2001-" &
- Current_Year &
- ", Free Software Foundation, Inc.");
+ Display_Version ("GNATNAME", "2001");
end if;
end Output_Version;
procedure Scan_Args is
begin
+ -- First check for --version or --help
+
+ Check_Version_And_Help ("GNATNAME", "2001", Usage'Unrestricted_Access);
+
+ -- Now scan the other switches
+
Initialize_Option_Scan;
-- Scan options first
package body Gnatvsn is
+ ----------------------
+ -- Copyright_Holder --
+ ----------------------
+
+ function Copyright_Holder return String is
+ begin
+ return "Free Software Foundation, Inc.";
+ end Copyright_Holder;
+
------------------------
-- Gnat_Free_Software --
------------------------
-- Text to be displayed by the different GNAT tools when switch --version
-- is used. This text depends on the GNAT build type.
+ function Copyright_Holder return String;
+ -- Return the name of the Copyright holder to be displayed by the different
+ -- GNAT tools when switch --version is used.
+
Ver_Len_Max : constant := 64;
-- Longest possible length for Gnat_Version_String in this or any
-- other version of GNAT. This is used by the binder to establish
-- --
------------------------------------------------------------------------------
-with Xr_Tabls; use Xr_Tabls;
-with Xref_Lib; use Xref_Lib;
+with Opt;
with Osint; use Osint;
with Types; use Types;
-
-with Gnatvsn;
-with Opt;
+with Switch; use Switch;
+with Xr_Tabls; use Xr_Tabls;
+with Xref_Lib; use Xref_Lib;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
procedure Parse_Cmd_Line;
-- Parse every switch on the command line
+ procedure Usage;
+ -- Display the usage
+
procedure Write_Usage;
-- Print a small help page for program usage
procedure Parse_Cmd_Line is
begin
+ -- First check for --version or --help
+
+ Check_Version_And_Help ("GNATXREF", "1998", Usage'Unrestricted_Access);
+
loop
case
GNAT.Command_Line.Getopt
Write_Usage;
end Parse_Cmd_Line;
- -----------------
- -- Write_Usage --
- -----------------
+ -----------
+ -- Usage --
+ -----------
- procedure Write_Usage is
+ procedure Usage is
begin
- Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String);
- Put_Line ("Copyright 1998-2005, AdaCore");
Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
New_Line;
Put_Line (" file ... list of source files to xref, " &
Put_Line (" -v Print a 'tags' file for vi");
New_Line;
+ end Usage;
+
+ -----------------
+ -- Write_Usage --
+ -----------------
+
+ procedure Write_Usage is
+ begin
+ Display_Version ("GNATXREF", "1998");
+ New_Line;
+ Usage;
raise Usage_Error;
end Write_Usage;
with Csets;
with Err_Vars; use Err_Vars;
with Errutil;
-with Gnatvsn; use Gnatvsn;
with Namet; use Namet;
with Opt;
with Osint; use Osint;
with Sinput.C;
with Snames;
with Stringt; use Stringt;
+with Switch; use Switch;
with Types; use Types;
-with Ada.Text_IO; use Ada.Text_IO;
+with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Case_Util; use GNAT.Case_Util;
with GNAT.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
-with System.OS_Lib; use System.OS_Lib;
+with System.OS_Lib; use System.OS_Lib;
package body GPrep is
procedure Display_Copyright is
begin
if not Copyright_Displayed then
- Write_Line ("GNAT Preprocessor " & Gnatvsn.Gnat_Version_String);
- Write_Line ("Copyright 1996-" &
- Current_Year &
- ", Free Software Foundation, Inc.");
+ Display_Version ("GNAT Preprocessor", "1996");
Copyright_Displayed := True;
end if;
end Display_Copyright;
Switch : Character;
begin
- -- Parse the switches
+ -- First check for --version or --help
+
+ Check_Version_And_Help ("GNATPREP", "1996", Usage'Access);
+
+ -- Now scan the other switches
+
+ GNAT.Command_Line.Initialize_Option_Scan;
loop
begin
Shared_String : aliased String := "-shared";
Force_Elab_Flags_String : aliased String := "-F";
- Version_Switch : constant String := "--version";
- Help_Switch : constant String := "--help";
No_Shared_Switch : aliased Argument_List := (1 .. 0 => null);
Shared_Switch : aliased Argument_List := (1 => Shared_String'Access);
-- Misc Routines --
-------------------
- procedure Display_Version;
- -- Display version when switch --version is used
-
procedure List_Depend;
-- Prints to standard output the list of object dependencies. This list
-- can be used directly in a Makefile. A call to Compile_Sources must
if Uid /= Prj.No_Unit_Index then
Udata := Project_Tree.Units.Table (Uid);
- if Udata.File_Names (Body_Part).Name /=
- No_File
+ if
+ Udata.File_Names (Body_Part).Name /=
+ No_File
+ and then
+ Udata.File_Names (Body_Part).Path /= Slash
then
Sfile := Udata.File_Names (Body_Part).Name;
Source_Index :=
Udata.File_Names (Body_Part).Index;
- elsif Udata.File_Names (Specification).Name /=
- No_File
+ elsif
+ Udata.File_Names (Specification).Name /=
+ No_File
+ and then
+ Udata.File_Names (Specification).Path /=
+ Slash
then
Sfile :=
Udata.File_Names (Specification).Name;
Display_Executed_Programs := Display;
end Display_Commands;
- ---------------------
- -- Display_Version --
- ---------------------
-
- procedure Display_Version is
- begin
- Write_Str ("GNATMAKE ");
- Write_Str (Gnatvsn.Gnat_Version_String);
- Write_Eol;
-
- Write_Str ("Copyright (C) 1995-");
- Write_Str (Gnatvsn.Current_Year);
- Write_Str (", Free Software Foundation, Inc.");
- Write_Eol;
-
- Write_Str (Gnatvsn.Gnat_Free_Software);
- Write_Eol;
- Write_Eol;
- end Display_Version;
-
-------------
-- Empty_Q --
-------------
if Verbose_Mode then
Write_Eol;
- Write_Str ("GNATMAKE ");
- Write_Str (Gnatvsn.Gnat_Version_String);
- Write_Eol;
- Write_Str
- ("Copyright 1995-" &
- Current_Year &
- ", Free Software Foundation, Inc.");
- Write_Eol;
+ Display_Version ("GNATMAKE ", "1995");
end if;
if Main_Project /= No_Project
Main_Index := Current_File_Index;
end if;
- Add_Switch ("-I-", Binder, And_Save => True);
Add_Switch ("-I-", Compiler, And_Save => True);
if Main_Project = No_Project then
Compiler, Append_Switch => False,
And_Save => False);
- Add_Switch ("-aO" & Normalized_CWD,
- Binder,
- Append_Switch => False,
- And_Save => False);
end if;
else
-- projects.
Look_In_Primary_Dir := False;
+ Add_Switch ("-I-", Binder, And_Save => True);
end if;
-- If the user wants a program without a main subprogram, add the
-- Scan the switches and arguments
- declare
- Args : Argument_List (1 .. Argument_Count);
- Version_Switch_Present : Boolean := False;
- Help_Switch_Present : Boolean := False;
+ -- First, scan to detect --version and/or --help
- begin
- -- First, scan to detect --version and/or --help
-
- for Next_Arg in 1 .. Argument_Count loop
- Args (Next_Arg) := new String'(Argument (Next_Arg));
-
- if Args (Next_Arg).all = Version_Switch then
- Version_Switch_Present := True;
- elsif Args (Next_Arg).all = Help_Switch then
- Help_Switch_Present := True;
- end if;
- end loop;
+ Check_Version_And_Help ("GNATMAKE", "1995", Makeusg'Access);
- -- If --version was used, display version and exit
-
- if Version_Switch_Present then
- Set_Standard_Output;
- Display_Version;
- Exit_Program (E_Success);
- end if;
+ -- Scan again the switch and arguments, now that we are sure that
+ -- they do not include --version or --help.
- -- If --help was used, display help and exit
-
- if Help_Switch_Present then
- Set_Standard_Output;
- Makeusg;
- Write_Eol;
- Write_Line ("Report bugs to report@adacore.com");
- Exit_Program (E_Success);
- end if;
-
- -- Scan again the switch and arguments, now that we are sure that
- -- they do not include --version or --help.
-
- Scan_Args : for Next_Arg in Args'Range loop
- Scan_Make_Arg (Args (Next_Arg).all, And_Save => True);
- end loop Scan_Args;
- end;
+ Scan_Args : for Next_Arg in 1 .. Argument_Count loop
+ Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
+ end loop Scan_Args;
if Commands_To_Stdout then
Set_Standard_Output;
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- --
------------------------------------------------------------------------------
-with Osint;
+with Osint; use Osint;
+with Output; use Output;
package body Switch is
Osint.Fail ("invalid switch: ", Switch);
end Bad_Switch;
+ ----------------------------
+ -- Check_Version_And_Help --
+ ----------------------------
+
+ procedure Check_Version_And_Help
+ (Tool_Name : String;
+ Initial_Year : String;
+ Usage : Procedure_Ptr;
+ Version_String : String := Gnatvsn.Gnat_Version_String)
+ is
+ Version_Switch_Present : Boolean := False;
+ Help_Switch_Present : Boolean := False;
+ Next_Arg : Natural;
+
+ begin
+ -- First check for --version or --help
+
+ Next_Arg := 1;
+ while Next_Arg < Arg_Count loop
+ declare
+ Next_Argv : String (1 .. Len_Arg (Next_Arg));
+ begin
+ Fill_Arg (Next_Argv'Address, Next_Arg);
+
+ if Next_Argv = Version_Switch then
+ Version_Switch_Present := True;
+
+ elsif Next_Argv = Help_Switch then
+ Help_Switch_Present := True;
+ end if;
+
+ Next_Arg := Next_Arg + 1;
+ end;
+ end loop;
+
+ -- If --version was used, display version and exit
+
+ if Version_Switch_Present then
+ Set_Standard_Output;
+ Display_Version (Tool_Name, Initial_Year, Version_String);
+ Write_Str (Gnatvsn.Gnat_Free_Software);
+ Write_Eol;
+ Write_Eol;
+ Exit_Program (E_Success);
+ end if;
+
+ -- If --help was used, display help and exit
+
+ if Help_Switch_Present then
+ Set_Standard_Output;
+ Usage.all;
+ Write_Eol;
+ Write_Line ("Report bugs to report@adacore.com");
+ Exit_Program (E_Success);
+ end if;
+ end Check_Version_And_Help;
+
+ ---------------------
+ -- Display_Version --
+ ---------------------
+
+ procedure Display_Version
+ (Tool_Name : String;
+ Initial_Year : String;
+ Version_String : String := Gnatvsn.Gnat_Version_String)
+ is
+ begin
+ Write_Str (Tool_Name);
+ Write_Char (' ');
+ Write_Str (Version_String);
+ Write_Eol;
+
+ Write_Str ("Copyright (C) ");
+ Write_Str (Initial_Year);
+ Write_Char ('-');
+ Write_Str (Gnatvsn.Current_Year);
+ Write_Str (", ");
+ Write_Str (Gnatvsn.Copyright_Holder);
+ Write_Eol;
+ end Display_Version;
+
-------------------------
-- Is_Front_End_Switch --
-------------------------
-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- switches that are recognized. In addition, package Debug documents
-- the otherwise undocumented debug switches that are also recognized.
+with Gnatvsn;
with Types; use Types;
package Switch is
- -- Note: The default switch character is indicated by Switch_Character,
- -- but regardless of what it is, a hyphen is always allowed as an
- -- (alternative) switch character.
+ -- Common switches for GNU tools
- -- Note: In GNAT, the case of switches is not significant if
- -- Switches_Case_Sensitive is False. If this is the case, switch
- -- characters, or letters appearing in the parameter to a switch, may be
- -- either upper case or lower case.
+ Version_Switch : constant String := "--version";
+ Help_Switch : constant String := "--help";
-----------------
-- Subprograms --
-----------------
+ type Procedure_Ptr is access procedure;
+
+ procedure Check_Version_And_Help
+ (Tool_Name : String;
+ Initial_Year : String;
+ Usage : Procedure_Ptr;
+ Version_String : String := Gnatvsn.Gnat_Version_String);
+ -- Check if switches --version or --help is used. If one of this switch
+ -- is used, issue the proper messages and end the process.
+
+ procedure Display_Version
+ (Tool_Name : String;
+ Initial_Year : String;
+ Version_String : String := Gnatvsn.Gnat_Version_String);
+ -- Display version of a tool when switch --version is used
+
function Is_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars is at least two characters long,
- -- and the first character indicates it is a switch.
+ -- and the first character is an hyphen ('-').
function Is_Front_End_Switch (Switch_Chars : String) return Boolean;
-- Returns True iff Switch_Chars represents a front-end switch,
- -- ie. it starts with -I or -gnat.
+ -- ie. it starts with -I, -gnat or -?RTS.
private