comp.lang.ada
 help / color / mirror / Atom feed
* Re: Gnat 3.13p: Command_Name RM A.15
@ 2001-01-18 12:10 Schroeer, Joachim Dr.
  2001-01-18 12:19 ` Lutz Donnerhacke
  0 siblings, 1 reply; 24+ messages in thread
From: Schroeer, Joachim Dr. @ 2001-01-18 12:10 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'
  Cc: 'christoph.grein@eurocopter.de'

[-- Attachment #1: Type: text/plain, Size: 1743 bytes --]

Hallo Herr Grein,

ich habe auch ein kleines Paket, das ich innerhalb eines 
größeren Ada95 Projekts unter WinNT/98 zum Scannen der 
command-line benutzt habe. Es wurde bisher mit ObjectAda 
und GNAT eingesetzt und sollte auch auf anderen Plattformen 
laufen. Die function command_name dürfte Ihnen weiterhelfen.
Wenn Sie auch das Paket Portable.Standard haben wollen, 
das im Body benutzt wird, melden Sie sich bitte.

P.S. Eurocopter gehört doch zur EADS. Warum finde ich Ihren 
Namen dann nicht in unserer internen Mailing-Liste, wo doch 
die Kollegen von Daimler-Chrysler noch und die von der Casa 
schon zu sehen sind?

Beste Grüße
	J. Schröer


Dr.-Ing. Joachim Schröer
EADS Germany GmbH
Defense Electronics
Dept.: VEE22
Wörthstraße 85
D-89070 ULM
Telefon: +49 731 392 5993

Christoph Grein <christoph.grein@eurocopter.de> schrieb in im Newsbeitrag:
<mailman.979801451.11095.comp.lang.ada@ada.eu.org>...
> Thanks to all for their responses.
> 
> Randy Brukardt gave me a nice solution (it may not be applicable for all
cases, 
> but for me, it worked).
> 
> The original question was:
> 
> How do I get the full name of Ada.Command_Line.Command_Name? The result of

> Command_Name is implementation dependent.
> 
> Open the file with the name given by Command_Name, call the Name function
which 
> by A8.2(22) must return the full name, then close the file again:
> 
>   Open (File, in_file, Ada.Command_Line.Command_Name);
>   Full_Name := Name (File);  -- this is the idea only (careful, string
sizes)
>   Close (File);
> 
> OK, A8.2(22) actually says "should", but Randy confirmed that the ACATS
test for 
> the full name, so you can rely on this.
> 
> Christoph Grein
> 
> 


[-- Attachment #2: utilities-command_line.adb --]
[-- Type: application/octet-stream, Size: 3647 bytes --]

--                              -*- Mode: Ada -*-
-- Filename        : utilities-command_line.ads
-- Description     : Simplifies access on the command_line parameters 
--                   via key strings (options).
-- Author          : J. Schroeer
-- Created On      : 18. Feb. 1998
-- Last Modified By:
-- Last Modified On:
-- Update Count    : 1
-- Status          :

with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Strings.Unbounded;
with Portable.Operating_System;

package body Utilities.Command_Line is
  
  Dir_Sep : constant String  := Portable.Operating_System.Directory_Separator & "";
  ----------------------------------------------------------------------------
  function Argument(Key : in String) return String is
  begin
    for I in 1 .. Ada.Command_Line.Argument_Count - 1 loop
      if Key = Ada.Command_Line.Argument(I) then
        return Ada.Command_Line.Argument(I + 1);
      end if;
    end loop;
    return "";
  end Argument;
  ----------------------------------------------------------------------------
  function Argument(Key     : in String; 
                    Default : in String) return String is
                    
    Arg : constant String := Argument(Key);
  begin
    if Arg /= "" then
      return Arg;
    else
      return Default;
    end if;
  end Argument;
  ----------------------------------------------------------------------------                                 
  function Argument(Key     : in String; 
                    Default : in Float'Base) return Float'Base is
                    
    Arg : constant String := Argument(Key);
  begin
    if Arg /= "" then
      return Float'Value(Arg);
    else
      return Default;
    end if;
  end Argument;
  ----------------------------------------------------------------------------           
  function Argument(Key     : in String; 
                    Default : in Integer) return Integer is
                    
    Arg : constant String := Argument(Key);
  begin
    if Arg /= "" then
      return Integer'Value(Arg);
    else
      return Default;
    end if;
  end Argument;
  ----------------------------------------------------------------------------           
  function Has_Argument(Key : in String) return Boolean is
  begin
    for I in 1 .. Ada.Command_Line.Argument_Count loop
      if Key = Ada.Command_Line.Argument(I) then
        return True;
      end if;
    end loop;
    return False;
  end Has_Argument;
  ----------------------------------------------------------------------------
  function Command_Name(Full_Path : in Boolean := True) return String is
    Name : constant String := Ada.Command_Line.Command_Name;
  begin
    if Full_Path then
      return Name;
    else
      return Name(Ada.Strings.Fixed.Index(Source  => Name, 
												                  Pattern => Dir_Sep, 
												                  Going   => Ada.Strings.Backward) 
                  + 1 .. Name'Last);
    end if;
  end Command_Name;
  ----------------------------------------------------------------------------            
  function Total_Command_Line(Full_Path : in Boolean := True) return String is
    
    Cl : Ada.Strings.Unbounded.Unbounded_String := 
         Ada.Strings.Unbounded.Null_Unbounded_String;
    use type Ada.Strings.Unbounded.Unbounded_String;             
  begin
    for I in 1 .. Ada.Command_Line.Argument_Count loop
      Cl := Cl & " " & Ada.Command_Line.Argument(I);
    end loop;
    return Command_Name(Full_Path) & Ada.Strings.Unbounded.To_String(Cl);
  end Total_Command_Line;
  ----------------------------------------------------------------------------
end Utilities.Command_Line;  

[-- Attachment #3: utilities-command_line.ads --]
[-- Type: application/octet-stream, Size: 1948 bytes --]

--                              -*- Mode: Ada -*-
-- Filename        : utilities-command_line.ads
-- Description     : Simplifies access on the command_line parameters 
--                   via key strings (options).
-- Author          : J. Schroeer
-- Created On      : 18. Feb. 1998
-- Last Modified By:
-- Last Modified On:
-- Update Count    : 1
-- Status          :

package Utilities.Command_Line is

  -- All functions herein are case-sensitive for "key".

  function Argument(Key : in String) return String;

  -- Returns the argument on the command-line preceded by key if key is found,
  -- the empty string "" otherwise.
  --
  -- Example: If the main is called like
  --
  -- main -file filename -number 10
  --
  -- then argument("-file") = "filename", argument(key => "-number") = "10",
  -- argument("-FILE") = "".

  function Argument(Key     : in String;
                    Default : in String) return String;

  function Argument(Key     : in String;
                    Default : in Float'Base) return Float'Base;

  function Argument(Key     : in String;
                    Default : in Integer) return Integer;

  -- If has_argument(key) then return the string / float'value / integer'value 
  -- of the corresponding argument. 
  -- If not has_argument(key) then return the default.                  

  function Has_Argument(Key : in String) return Boolean;

  -- Returns true if key is an argument an the command_line, false otherwise.

  function Command_Name(Full_Path : in Boolean := True) return String;

  -- Returns ada.command_line.command_name if full_path.
  -- Returns ada.command_line.command_name without path when not full_path.
  -- ada.command_line.command_name is the full name of the Main-unit.

  function Total_Command_Line(Full_Path : in Boolean := True) return String;

  -- Returns the total command_line including command_name and all arguments
  -- separated by blanks.

end Utilities.Command_Line;

[-- Attachment #4: utilities.ads --]
[-- Type: application/octet-stream, Size: 362 bytes --]

--                              -*- Mode: Ada -*-
-- Filename        : utilities.ads
-- Description     : Parent package for Utilities
-- Author          : J. Schroeer
-- Created On      : Wed Mar 26 17:25:34 1997
-- Last Modified By:
-- Last Modified On: Wed Jul  2 13:41:50 1997
-- Update Count    : 2
-- Status          :

package Utilities is
end Utilities;

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: Gnat 3.13p: Command_Name RM A.15
@ 2001-01-19  7:26 Christoph Grein
  0 siblings, 0 replies; 24+ messages in thread
From: Christoph Grein @ 2001-01-19  7:26 UTC (permalink / raw)
  To: comp.lang.ada

Robert Dewar wrote:

> > Open the file with the name given by Command_Name, call the
> > Name function which
> > by A8.2(22) must return the full name, then close the file
> again:
> 
> This obviously does NOT work if the file is not in the current
> directory, which for an executable file is likely. Writing a
> program that only works if its executable is in the current
> directory is defintely very bad practice, so this "solution"
> cannot be recommended.

OK, I'm talking of Win98/NT only,where it works also for relative paths.

Call My_Executable, which is on drive C: at the relative path ..\X\
from drive E directory A:

E:\A> C:..\X\My_Executable

On Win98, Command_Name returns  C:\Full_Path\X\My_Executable.exe
on WinNT, it returns C:..\X\My_Executable

Open works with both strings (OK I have to first add the extension .exe if not 
present, and I know it must be .exe and nothing else), and Name returns the 
desired result: C:\Full_Path\X\My_Executable.exe

> There is no general way of getting the full path of the
> current executable if it is not availabel in arg(0), which
> is why this cannot be guaranteed.

I did not claim that this works on all conceivable OSs.

Christoph Grein





^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: Gnat 3.13p: Command_Name RM A.15
@ 2001-01-18  6:59 Christoph Grein
  2001-01-18 12:38 ` Larry Kilgallen
  2001-01-18 15:12 ` Robert Dewar
  0 siblings, 2 replies; 24+ messages in thread
From: Christoph Grein @ 2001-01-18  6:59 UTC (permalink / raw)
  To: comp.lang.ada

Thanks to all for their responses.

Randy Brukardt gave me a nice solution (it may not be applicable for all cases, 
but for me, it worked).

The original question was:

How do I get the full name of Ada.Command_Line.Command_Name? The result of 
Command_Name is implementation dependent.

Open the file with the name given by Command_Name, call the Name function which 
by A8.2(22) must return the full name, then close the file again:

  Open (File, in_file, Ada.Command_Line.Command_Name);
  Full_Name := Name (File);  -- this is the idea only (careful, string sizes)
  Close (File);

OK, A8.2(22) actually says "should", but Randy confirmed that the ACATS test for 
the full name, so you can rely on this.

Christoph Grein





^ permalink raw reply	[flat|nested] 24+ messages in thread
* Gnat 3.13p: Command_Name RM A.15
@ 2001-01-16  6:12 Christoph Grein
  2001-01-16 14:22 ` Marin David Condic
  0 siblings, 1 reply; 24+ messages in thread
From: Christoph Grein @ 2001-01-16  6:12 UTC (permalink / raw)
  To: report, comp.lang.ada

On win98 with Gnat3.13p, Ada.Command_Line.Command_Name always returns the full 
path, irrespective of the actual command line (executable only, relative or 
absolute path), whereas on winNT, only the string as entered on the command line 
is returned.

This different behaviour is annoying when trying to write portable code and you 
need the full path (including drive).

There are several Win32 flavours out there...

I know A.15 leaves this completely implementation defined,  there is not even an 
Implementation Advice as to how the string should look. But A.8.2(22) requires 
that Name return the full path (OK, it says "should"). So why is there the 
difference in the RM?





^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2001-01-19 20:31 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-18 12:10 Gnat 3.13p: Command_Name RM A.15 Schroeer, Joachim Dr.
2001-01-18 12:19 ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2001-01-19  7:26 Christoph Grein
2001-01-18  6:59 Christoph Grein
2001-01-18 12:38 ` Larry Kilgallen
2001-01-18 14:32   ` Marin David Condic
2001-01-18 14:54   ` Ted Dennison
2001-01-18 15:12 ` Robert Dewar
2001-01-16  6:12 Christoph Grein
2001-01-16 14:22 ` Marin David Condic
2001-01-16 18:14   ` Jean-Pierre Rosen
2001-01-17 13:15     ` Marin David Condic
2001-01-17 19:12       ` Jean-Pierre Rosen
2001-01-18  3:28         ` Robert Dewar
2001-01-18 13:23           ` Marin David Condic
2001-01-18 15:15             ` Robert Dewar
2001-01-18 17:37           ` Jean-Pierre Rosen
2001-01-19 20:31             ` Florian Weimer
2001-01-18  3:25       ` Robert Dewar
2001-01-18 14:06         ` Marin David Condic
2001-01-17 19:17   ` Stephen Leake
2001-01-18  3:31     ` Robert Dewar
2001-01-18 14:13       ` Marin David Condic
2001-01-18 15:16     ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox