comp.lang.ada
 help / color / mirror / Atom feed
* RE: How to find directory where the program is?
@ 2002-04-23 23:28 Beard, Frank [Contractor]
  2002-04-24  0:49 ` Larry Kilgallen
  0 siblings, 1 reply; 54+ messages in thread
From: Beard, Frank [Contractor] @ 2002-04-23 23:28 UTC (permalink / raw)


Now that you mention it.  The last time I worked on VAX VMS
was around 1990.  So, the routine we used had to have been
from one of the packages supplied with the VAX Ada83 compiler.

-----Original Message-----
From: Kilgallen@SpamCop.net [mailto:Kilgallen@SpamCop.net]
Sent: Tuesday, April 23, 2002 6:42 PM
To: comp.lang.ada@ada.eu.org
Subject: RE: How to find directory where the program is?


In article <mailman.1019591882.7577.comp.lang.ada@ada.eu.org>, "Beard, Frank
[Contractor]" <beardf@spawar.navy.mil> writes:

> I didn't realize I misread your question until Randy's
> response.  He's right.  Every platform I've run on (VAX,
> several flavors of unix, and Windows) has returned the
> path when I called Ada.Command_Line.Command_Name.  But,
> I don't use the GNAT compiler, so I can't speak for it.

So what Ada95 compiler and what operating system do you use on VAX ?
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 54+ messages in thread
* RE: How to find directory where the program is?
@ 2002-04-25 16:43 Beard, Frank [Contractor]
  0 siblings, 0 replies; 54+ messages in thread
From: Beard, Frank [Contractor] @ 2002-04-25 16:43 UTC (permalink / raw)


"Grein, Christoph" wrote:
> 
> Observation for Ada.Command_Line.Command_Name:
>    Win98: Always the full path and extension are returned.
>    WinNT: Only the name as entered on the command line is returned.

I don't know what's different about your version of NT but I'm running
on NT 4.0 and it's returned the full path on every service pack from
3.0 to 6a.



^ permalink raw reply	[flat|nested] 54+ messages in thread
* Re: How to find directory where the program is?
@ 2002-04-24  9:44 Grein, Christoph
  2002-04-25 10:35 ` Thierry Lelegard
  0 siblings, 1 reply; 54+ messages in thread
From: Grein, Christoph @ 2002-04-24  9:44 UTC (permalink / raw)


Observation for Ada.Command_Line.Command_Name:
   Win98: Always the full path and extension are returned.
   WinNT: Only the name as entered on the command line is returned.
Thus we have to look for a portable way.
RM A.15(16) leaves the string completely implementation defined.
RM A.8.2(22) requires the full name to be returned.
Thanks to Randy Brukardt for this hint (a long time ago, about Jan 2001).
It may however not be possible to open the executable file with Text_IO.

  function Full_Name return String is
    -- Retrieve the full name via RM A.8.2(22).
    Command: String renames Ada.Command_Line.Command_Name;
    use Ada.Text_IO;
    Executable: File_Type;
  begin
    if Extension (Command) = "" then
      Open (Executable, In_File, Command & ".exe");
    else
      Open (Executable, In_File, Command);
    end if;
    declare
      Full_Name: String renames Name (Executable);
    begin
      Close (Executable);
      return Full_Name;
    end;
  exception
    when Name_Error =>  -- file not found
      return "";        -- set error condition
  end Full_Name;



^ permalink raw reply	[flat|nested] 54+ messages in thread
* RE: How to find directory where the program is?
@ 2002-04-23 19:56 Beard, Frank [Contractor]
  2002-04-23 22:41 ` Larry Kilgallen
  0 siblings, 1 reply; 54+ messages in thread
From: Beard, Frank [Contractor] @ 2002-04-23 19:56 UTC (permalink / raw)


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

I didn't realize I misread your question until Randy's
response.  He's right.  Every platform I've run on (VAX,
several flavors of unix, and Windows) has returned the
path when I called Ada.Command_Line.Command_Name.  But,
I don't use the GNAT compiler, so I can't speak for it.

The attached program shows some ways I've used it.  Of
course, the problem is it isn't guaranteed.  It just
happens to be the way everyone seems to have implemented
it.

Frank



-----Original Message-----
From: Preben Randhol [mailto:randhol+abuse@pvv.org]
Sent: Tuesday, April 23, 2002 2:29 PM
To: comp.lang.ada@ada.eu.org
Subject: How to find directory where the program is?


How can one in Ada95 find out from which directory the Ada program is
stored in.  I mean I need to find out if my program is stored in
/usr/bin/ or /usr/local/bin or some other directory. Does anybody know
how I can do this. Note that current directory is not equal to the
directory the program is stored in. I use GNAT so if GNAT has some
routines for this that I have missed, please tell me. I'll make it
portable later if needed.

Thanks for any hints in advance.

No it is not a homework (neither am I a student taking courses) it is
for my Glosa program (http://www.pvv.org/~randhol/Ada95/Glosa/).

Preben
-- 
"Jeg tror nordmenn har glemt hvordan de tilbreder fisk. De er mest
 opptatt av firkantet fisk."
  --  Kristian Kristiansen, yrkesfisker, aftenposten.no 19/04/02
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada


[-- Attachment #2: AdaCommandLineTest.ada --]
[-- Type: application/octet-stream, Size: 1619 bytes --]

with Ada.Command_Line;
with Ada.Text_Io;

procedure AdaCommandLineTest is
    
    char : character := ' ';
    
    function Get_Directory(the_String : string) return string is
    begin
        
        for I in reverse the_String'range loop
            if (the_String(I) = '\') or else (the_String(I) = '/') then
                return (the_String(the_String'first .. I));
            end if;
        end loop;
        
        return the_String;
        
    end Get_Directory;

    function Remove_Directory(the_String : string) return string is
    begin
        
        for I in reverse the_String'range loop
            if (the_String(I) = '\') or else (the_String(I) = '/') then
                return (the_String(I+1 .. the_String'last));
            end if;
        end loop;
        
        return the_String;
        
    end Remove_Directory;

begin
    
    Ada.Text_Io.Put_Line("Full Command_Name [" & Ada.Command_Line.Command_Name & "]");
    Ada.Text_Io.Put_Line("Directory         [" & Get_Directory(Ada.Command_Line.Command_Name) & "]");
    Ada.Text_Io.Put_Line("Command_Name      [" & Remove_Directory(Ada.Command_Line.Command_Name) & "]");
    Ada.Text_Io.Put_Line("Argument_Count    [" & natural'image(Ada.Command_Line.Argument_Count) & "]");
    Ada.Text_Io.New_Line(2);
    
    for I in 1 .. Ada.Command_Line.Argument_Count loop
        Ada.Text_Io.Put_Line("Argument (" & natural'image(I) & " ) - [" & Ada.Command_Line.Argument(I) & "]");
    end loop;
    
    Ada.Text_Io.New_Line(2);
    Ada.Text_Io.Put("Hit me ...");
    Ada.Text_Io.Get_Immediate(char);
    
end AdaCommandLineTest;


^ permalink raw reply	[flat|nested] 54+ messages in thread
* RE: How to find directory where the program is?
@ 2002-04-23 19:24 Beard, Frank [Contractor]
  0 siblings, 0 replies; 54+ messages in thread
From: Beard, Frank [Contractor] @ 2002-04-23 19:24 UTC (permalink / raw)


I pretty sure GNAT has an OS package that provides that functionality.

Or, if you have access to a POSIX binding, call Get_Working_Directory
in the POSIX.Process_Environment package.  You can use Pascal Obry's
binding for Windows, or get Florist for several unix flavors.  The
links can be found from www.adapower.com.

Frank

-----Original Message-----
From: Preben Randhol [mailto:randhol+abuse@pvv.org]
Sent: Tuesday, April 23, 2002 2:29 PM
To: comp.lang.ada@ada.eu.org
Subject: How to find directory where the program is?


How can one in Ada95 find out from which directory the Ada program is
stored in.  I mean I need to find out if my program is stored in
/usr/bin/ or /usr/local/bin or some other directory. Does anybody know
how I can do this. Note that current directory is not equal to the
directory the program is stored in. I use GNAT so if GNAT has some
routines for this that I have missed, please tell me. I'll make it
portable later if needed.

Thanks for any hints in advance.

No it is not a homework (neither am I a student taking courses) it is
for my Glosa program (http://www.pvv.org/~randhol/Ada95/Glosa/).

Preben
-- 
"Jeg tror nordmenn har glemt hvordan de tilbreder fisk. De er mest
 opptatt av firkantet fisk."
  --  Kristian Kristiansen, yrkesfisker, aftenposten.no 19/04/02
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 54+ messages in thread
* How to find directory where the program is?
@ 2002-04-23 18:28 Preben Randhol
  2002-04-23 19:10 ` Florian Weimer
                   ` (6 more replies)
  0 siblings, 7 replies; 54+ messages in thread
From: Preben Randhol @ 2002-04-23 18:28 UTC (permalink / raw)


How can one in Ada95 find out from which directory the Ada program is
stored in.  I mean I need to find out if my program is stored in
/usr/bin/ or /usr/local/bin or some other directory. Does anybody know
how I can do this. Note that current directory is not equal to the
directory the program is stored in. I use GNAT so if GNAT has some
routines for this that I have missed, please tell me. I'll make it
portable later if needed.

Thanks for any hints in advance.

No it is not a homework (neither am I a student taking courses) it is
for my Glosa program (http://www.pvv.org/~randhol/Ada95/Glosa/).

Preben
-- 
"Jeg tror nordmenn har glemt hvordan de tilbreder fisk. De er mest
 opptatt av firkantet fisk."
  --  Kristian Kristiansen, yrkesfisker, aftenposten.no 19/04/02



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

end of thread, other threads:[~2002-04-29 15:52 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-23 23:28 How to find directory where the program is? Beard, Frank [Contractor]
2002-04-24  0:49 ` Larry Kilgallen
2002-04-24  2:31   ` achrist
2002-04-24 10:29     ` Preben Randhol
2002-04-24 15:28       ` Darren New
2002-04-24 17:43         ` Preben Randhol
2002-04-24 18:33           ` Randy Brukardt
2002-04-24 21:00             ` Wes Groleau
2002-04-25 19:26               ` Randy Brukardt
2002-04-25  2:37             ` Steve Doiel
2002-04-25  7:26               ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2002-04-25 16:43 Beard, Frank [Contractor]
2002-04-24  9:44 Grein, Christoph
2002-04-25 10:35 ` Thierry Lelegard
2002-04-25 19:30   ` Philippe Waroquiers
2002-04-25 22:57     ` Larry Kilgallen
2002-04-23 19:56 Beard, Frank [Contractor]
2002-04-23 22:41 ` Larry Kilgallen
2002-04-23 19:24 Beard, Frank [Contractor]
2002-04-23 18:28 Preben Randhol
2002-04-23 19:10 ` Florian Weimer
2002-04-23 19:37 ` Randy Brukardt
2002-04-23 20:53   ` Preben Randhol
2002-04-23 21:04 ` Joachim Schr�er
2002-04-24  8:35 ` Thierry Lelegard
2002-04-24  8:43 ` Jean-Pierre Rosen
2002-04-24 10:33   ` Preben Randhol
2002-04-24 11:43     ` Jean-Pierre Rosen
2002-04-24 14:44       ` Preben Randhol
2002-04-24 15:38 ` Hyman Rosen
2002-04-24 17:44   ` Preben Randhol
2002-04-24 23:08   ` Nick Roberts
2002-04-25  7:28     ` Preben Randhol
2002-04-25 14:18       ` Marin David Condic
2002-04-26 16:24         ` Stephen Leake
2002-04-26 20:41           ` achrist
2002-04-26 21:31           ` Larry Kilgallen
2002-04-29 15:38           ` Marin David Condic
2002-04-25 17:10       ` Sergey Koshcheyev
2002-04-25 21:11         ` Nick Roberts
2002-04-25 23:28           ` Sergey Koshcheyev
2002-04-26  5:57             ` Preben Randhol
2002-04-26 16:22           ` Stephen Leake
2002-04-26 17:13         ` Anders Gidenstam
2002-04-26 12:18       ` Jacob Sparre Andersen
2002-04-26 12:23         ` Preben Randhol
2002-04-26 12:48           ` David C. Hoos
2002-04-26 14:13             ` Preben Randhol
2002-04-27  8:18               ` Eric G. Miller
2002-04-26 13:09         ` Marin David Condic
2002-04-27 14:39           ` Larry Kilgallen
2002-04-27 21:12             ` Nick Roberts
2002-04-29 15:52             ` Marin David Condic
2002-04-24 17:44 ` Egil Harald Hoevik

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