Path: utzoo!attcan!uunet!clyde.concordia.ca!news-server.csri.toronto.edu!utgpu!watserv1!ria!uwovax!7103_2622 From: 7103_2622@uwovax.uwo.ca (Eric Smith) Newsgroups: comp.sys.atari.st.tech Subject: Re: The program's name and path - how can I get them? Message-ID: <7319.27104c1c@uwovax.uwo.ca> Date: 8 Oct 90 13:51:23 GMT References: <1990Oct8.110346@heike.informatik.uni-dortmund.de> Lines: 36 > Does someone have a general solution? It would be sufficient to get only > the directory where the program is located - without knowing the program's > name. Even better would be a possibility to retrieve the program's name > also, and the best would be if this could be done without GEM functions. > And yes, of course only legal solutions are useful. > I don't think there is a legal solution that always works (and the illegal ones involving looking for variables in the parent's basepage certainly break under multitasking systems, and probably on the TT as well). However, a combination of legal solutions may work most of the time: What I usually do is look at argv[0] in main(); gcc, MWC, and many other compilers will fill this in with the program name if run from a shell that supports the Atari ARGV= extended argument passing scheme. Note: some shells will put only the program name (e.g. "arcgsh") in argv[0]; if so, then you'll have to search the directories given in the PATH variable to find the complete program. If argv[0] is invalid (see below), then the best bet may be to look for a PATH environment variable and search along it for your configuration file, and/or use shel_find or shel_read. Almost all shells will set PATH, so if no PATH is found and an invalid argv[0] is present then the program was probably run from the desktop, and so the shel_* functions ought to work. The ANSI standard says that argv[0] should be an empty string if the program name is not available; the new gcc library does this. The old (1.27) gcc library used to put "a.prg" in argv[0] by default, and some compilers may put "a.out" there. -- Eric R. Smith email: Dept. of Mathematics ersmith@uwovax.uwo.ca University of Western Ontario ersmith@uwovax.bitnet London, Ont. Canada N6A 5B7 ph: (519) 661-3638