2
0
mirror of git://gcc.gnu.org/git/gcc.git synced 2025-03-29 07:10:24 +08:00

re PR ada/4720 (GNAT programs do not support --help and --version)

2007-08-30  Vincent Celier  <celier@adacore.com>

	PR ada/4720

	* gnatchop.adb, gnatfind.adb, gnatlink.adb, gnatls.adb, 
	gnatname.adb, gnatxref.adb, gprep.adb, clean.adb gnatbind.adb
	(Check_Version_And_Help): New procedure in package Switch to process
	switches --version and --help.
	Use Check_Version_And_Help in GNAT tools

	* make.adb:  Ditto.
	(Compile_Sources): Make sure that sources that are "excluded" are not
	compiled.
	(Gnatmake): Do not issue -aO. to gnatbind and only issue -I- if a
	project file is used.
	(Version_Switch): Remove, moved to Switch
	(Help_Switch): Remove, moved to Switch
	(Display_Version): Remove, moved to Switch

	* switch.ads, switch.adb (Check_Version_And_Help): New procedure in
	package Switch to process switches --version and --help.
	(Display_Version): New procedure

	* gnatvsn.ads, gnatvsn.adb (Copyright_Holder): New function.

From-SVN: r127967
This commit is contained in:
Vincent Celier 2007-08-31 12:19:18 +02:00 committed by Arnaud Charlet
parent c66bc9cc91
commit 41c8951a8d
14 changed files with 277 additions and 188 deletions

@ -26,7 +26,6 @@
with ALI; use ALI;
with Csets;
with Gnatvsn; use Gnatvsn;
with Makeutl;
with MLib.Tgt; use MLib.Tgt;
with Namet; use Namet;
@ -39,6 +38,7 @@ with Prj.Ext;
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;
@ -1342,11 +1342,7 @@ package body Clean is
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;
@ -1640,9 +1636,14 @@ package body Clean is
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);

@ -37,7 +37,6 @@ with Csets;
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;
@ -423,6 +422,12 @@ begin
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;
@ -553,13 +558,7 @@ begin
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

@ -6,7 +6,7 @@
-- --
-- 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- --
@ -36,8 +36,8 @@ with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Heap_Sort_G;
with GNAT.Table;
with Gnatvsn;
with Hostparm;
with Switch; use Switch;
with Types;
procedure Gnatchop is
@ -1158,14 +1158,7 @@ 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;
@ -1767,6 +1760,10 @@ begin
-- 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;

@ -24,13 +24,12 @@
-- --
------------------------------------------------------------------------------
with Opt;
with Osint; use Osint;
with Switch; use Switch;
with Types; use Types;
with Xr_Tabls; use Xr_Tabls;
with Xref_Lib; use Xref_Lib;
with Osint; use Osint;
with Types; use Types;
with Gnatvsn;
with Opt;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
@ -69,8 +68,11 @@ procedure Gnatfind is
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 --
@ -78,6 +80,14 @@ procedure Gnatfind is
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
@ -232,14 +242,12 @@ procedure Gnatfind is
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;
@ -276,8 +284,19 @@ procedure Gnatfind is
& " 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;

@ -205,6 +205,9 @@ procedure Gnatlink is
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
@ -291,6 +294,10 @@ procedure Gnatlink is
-- 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;
@ -1329,32 +1336,12 @@ procedure Gnatlink is
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]");
@ -1385,6 +1372,28 @@ procedure Gnatlink is
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

@ -40,6 +40,7 @@ with Output; use Output;
with Rident; use Rident;
with Sdefault;
with Snames;
with Switch; use Switch;
with Targparm; use Targparm;
with Types; use Types;
@ -1528,6 +1529,10 @@ begin
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;
@ -1572,13 +1577,7 @@ begin
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;

@ -24,12 +24,12 @@
-- --
------------------------------------------------------------------------------
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;
@ -169,12 +169,7 @@ procedure Gnatname is
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;
@ -184,6 +179,12 @@ procedure Gnatname is
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

@ -33,6 +33,15 @@
package body Gnatvsn is
----------------------
-- Copyright_Holder --
----------------------
function Copyright_Holder return String is
begin
return "Free Software Foundation, Inc.";
end Copyright_Holder;
------------------------
-- Gnat_Free_Software --
------------------------

@ -68,6 +68,10 @@ package Gnatvsn is
-- 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

@ -24,13 +24,12 @@
-- --
------------------------------------------------------------------------------
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;
@ -57,6 +56,9 @@ procedure Gnatxref is
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
@ -66,6 +68,10 @@ procedure Gnatxref is
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
@ -205,14 +211,12 @@ procedure Gnatxref is
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, " &
@ -238,6 +242,17 @@ procedure Gnatxref is
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;

@ -27,7 +27,6 @@
with Csets;
with Err_Vars; use Err_Vars;
with Errutil;
with Gnatvsn; use Gnatvsn;
with Namet; use Namet;
with Opt;
with Osint; use Osint;
@ -37,15 +36,16 @@ with Scng;
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
@ -138,10 +138,7 @@ 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;
@ -704,7 +701,13 @@ package body GPrep is
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

@ -392,8 +392,6 @@ package body Make is
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);
@ -509,9 +507,6 @@ package body Make is
-- 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
@ -3562,15 +3557,22 @@ package body Make is
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;
@ -4063,26 +4065,6 @@ package body Make is
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 --
-------------
@ -4821,14 +4803,7 @@ package body Make is
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
@ -4901,7 +4876,6 @@ package body Make is
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
@ -4914,10 +4888,6 @@ package body Make is
Compiler, Append_Switch => False,
And_Save => False);
Add_Switch ("-aO" & Normalized_CWD,
Binder,
Append_Switch => False,
And_Save => False);
end if;
else
@ -4930,6 +4900,7 @@ package body Make is
-- 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
@ -6670,49 +6641,16 @@ package body Make is
-- 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
Check_Version_And_Help ("GNATMAKE", "1995", Makeusg'Access);
for Next_Arg in 1 .. Argument_Count loop
Args (Next_Arg) := new String'(Argument (Next_Arg));
-- Scan again the switch and arguments, now that we are sure that
-- they do not include --version or --help.
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;
-- If --version was used, display version and exit
if Version_Switch_Present then
Set_Standard_Output;
Display_Version;
Exit_Program (E_Success);
end if;
-- 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;

@ -6,7 +6,7 @@
-- --
-- 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- --
@ -24,7 +24,8 @@
-- --
------------------------------------------------------------------------------
with Osint;
with Osint; use Osint;
with Output; use Output;
package body Switch is
@ -42,6 +43,87 @@ 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 --
-------------------------

@ -6,7 +6,7 @@
-- --
-- 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- --
@ -31,30 +31,43 @@
-- 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