Jump to content
Excelsior Forums
Sign in to follow this  
qnr

Is there an equivalent to "~" for /home/user ?

Recommended Posts

I have some constants that contain a path to a directory in my $HOME - this works for me, but would have to be changed by anyone else. I know that I can obtain the path with ProgEnv.String("HOME", str) but that kind of keeps it out of the global constants.  I will eventually be using a configuration file, but until that time, I was wondering if there was any equivalent to ~ (like the way $HOME can be used when you're compiling)

Share this post


Link to post
Share on other sites

Maybe you could use something like 'whoami' to fetch the current username which in most cases is the name of the current users home directory. I am sure I remember a function 'getusername' in Linux. But I am not sure if this is what you want -

Regards

Christoph

Share this post


Link to post
Share on other sites

Thanks Christoph - well, when it comes to that point, I can get the get it a number of ways, and I've added code for it.  I was just wondering about using the ~ or an equivalent that the compiler (edit: or rather, the system the code is running on) would recognize by default., before any actual code was run.

Thanks for the help!

Terry

Share this post


Link to post
Share on other sites

OK, I'm trying it this way, can anyone tell me why it doesn't work? From the docs, it seems to accept the tilde

MODULE Test01;

IMPORT FilePath, STextIO, DStrings, SYSTEM, FormStr;

CONST
  p6datPath = "./p6dat/dat;~/p6dat/dat;/home/terry/p6dat/dat;.";
  fileName  = "version";

VAR
  fname  : DStrings.String;
  output : ARRAY [0..80] OF CHAR;
  result : SYSTEM.INT16;

BEGIN  
  FilePath.Lookup(p6datPath, fileName, fname, result);
  FormStr.print(output, "result: %d   file name: %s\n", result, fname^);
  STextIO.WriteString(output);
END Test01.

However, it gives me this output.  It finds the match on the 3rd item ( [tt]/home/terry/p6dat/dat/version [/tt] ) which is essentially the same as the 2nd item ( [tt]~/p6dat/dat/version[/tt] ) -- the 2nd item would be more generic, which is what I need.

[tt]terry@dorsai:~/projects/modula-2/xds/FileStuff$ ./Test01

result: 3  file name: /home/terry/p6dat/dat/version

[/tt]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×