From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,814d0ec938d6e4da X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-04-23 12:58:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Beard, Frank [Contractor]" Newsgroups: comp.lang.ada Subject: RE: How to find directory where the program is? Date: Tue, 23 Apr 2002 15:56:58 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C1EB01.08CF4FAE" X-Trace: avanie.enst.fr 1019591883 90105 137.194.161.2 (23 Apr 2002 19:58:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 23 Apr 2002 19:58:03 +0000 (UTC) Return-Path: X-Mailer: Internet Mail Service (5.5.2650.21) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:23012 Date: 2002-04-23T15:56:58-04:00 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C1EB01.08CF4FAE Content-Type: text/plain; charset="iso-8859-1" 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 ------_=_NextPart_000_01C1EB01.08CF4FAE Content-Type: application/octet-stream; name="AdaCommandLineTest.ada" Content-Disposition: attachment; filename="AdaCommandLineTest.ada" 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; ------_=_NextPart_000_01C1EB01.08CF4FAE--