Re: Euphoria environment variables (was: quick cgi question)
Ed Davis wrote:
> Juergen Luethje wrote:
>
>> The interpreter/translator just had to look for a file "Euphoria.ini"
>> in the same directory where it is located itself. 100%
>> cross-platform, and no hassle with environment variables any more.
>> What do you think?
>
> But is this cross-platform?
>
> Under DOS and Windows, C compilers use argv[0] to get the complete path
> to the program.
>
> However, argv[0] isn't populated the same way under Linux. argv[0]
> appears to contain the command string that was typed to start the
> executable. This is on RedHat, SlackWare, and Knoppix. I assume the
> other distributions are the same?
>
> I don't know about FreeBSD, but I assume this is a Unix thing.
>
> So, how does a program find the complete path to itself on Linux?
I don't know how this would work with C, but fortunately the Euphoria
interpreter front-end and translator are written in Euphoria now.
-- tested with Eu 2.5 on Windows
-- (should work on all supported platforms)
include misc.e -- for constant LINUX
function path_end (sequence name, integer slash)
for i = length(name) to 1 by -1 do
if name[i] = slash then
return i
end if
end for
return find(':', name)
end function
function file_path (sequence name, integer slash)
-- in : name : filename, e.g. "c:\\programs\\nicetool.exe"
-- slash: slash charecter in use
-- out: path, always with trailing slash or colon
integer p
p = path_end(name, slash)
if p = length(name) or name[p+1] != '.' then
return name[1..p]
else
return name & slash
end if
end function
function prog_path ()
-- out: full path where this program itself is located,
-- always with trailing slash or colon
sequence cmd
integer slash
cmd = command_line()
if platform() = LINUX then
slash = '/'
else
slash = '\\'
end if
return file_path(cmd[2], slash)
end function
constant INI_NAME = "euphoria.ini" -- we can choose this name freely
sequence ini_file
ini_file = prog_path() & INI_NAME -- full pathname of the INI file
puts(1, ini_file) -- ( which is needed e.g for open() )
if getc(0) then end if
> Finally, I agree, it would be nice to not require environment
> variables!
Thanks! Since several people now had said that they share this opinion,
it shows me that the idea was not too crazy.
Regards,
Juergen
|
Not Categorized, Please Help
|
|