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.9 required=5.0 tests=BAYES_00 autolearn=ham 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-24 16:07:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!ppp-4-206.5800-11.telinco.NET!not-for-mail From: nickroberts@ukf.net (Nick Roberts) Newsgroups: comp.lang.ada Subject: Re: How to find directory where the program is? Date: Wed, 24 Apr 2002 23:08:28 GMT Message-ID: <3cc73115.426446486@news.cis.dfn.de> References: <3CC6D15A.2070509@mail.com> NNTP-Posting-Host: ppp-4-206.5800-11.telinco.net (212.1.155.206) X-Trace: fu-berlin.de 1019689668 9098085 212.1.155.206 (16 [25716]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:23087 Date: 2002-04-24T23:08:28+00:00 List-Id: On Wed, 24 Apr 2002 11:38:02 -0400, Hyman Rosen strongly typed: >Preben Randhol wrote: >> 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. > >There is no a priori reason for this to even be possible. Your Ada >program could be loaded in PROM on your toaster, and even in UNIX, >the same executable file could have many links to it in different >directories, with different names. Furthermore, one has to ask the question "why?" (Why do you wish your program to discover its own executable?) As Hyman points out, there may not be one (there may zero or several), but even if there is one, your program may not have (any) access permission to it. (Side Issue 1, see below.) Actually, what kind of access would you require? Side Issue 1. It may just be me, but I would suggest that (on a well managed system ;-) the vast majority of Ada programs will not need to, and should not, have any access to their own executables. (If you're wondering why, think about how viruses propagate themselves.) If your program is, say, a discombobulator, and supposing it needs to add itself to a cron-list (or equivalent), in order to complete one of its actions perhaps, I would suggest you: (a) try to find a program argument named say "-phase2" and use the value of the argument following it; (b) if that fails, get the value of the environment variable named say "discombob2"; (c) if that fails, use whatever strategy you do to obtain the program's configuration file, and search for a line there beginning with "phase2=" and use the remainder of the line; (d) if that fails, obtain the configuration file's directory D and use D & Ada.Command_Line.Command_Name; (e) if that fails, use D & Default_Program_File_Name (which you have defined, e.g. a function which returns "discombob" under UNIX systems and "DISCOMB.EXE" under DOS/Windows). (Simple ;-) Your program installer should generate a configuration file with e.g. "phase1=C:\SUPASOFT\BOBULTNS\DISCOMB.EXE" and "phase2=C:\SUPASOFT\BOBULTNS\DISCOMB.EXE" in it, so that your program is spared the effort (and hit-and-miss qualities) of trying to find out the incantation necessary to run itself, and so that users are given maximum flexibility in managing their system. Hope this post has some element of enlightening qualities. (Not really sure if it does; that's how posts go sometimes :-) -- Nick Roberts