From f0321138951d8e5a52d17a9f13dbeaab26d05052 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 27 Jun 2016 22:59:47 -0700 Subject: Handle two possible home dir locations on Cygwin. Under the Cygwin port, if we are running in the Cygwin shell enviroment, there is a HOME variable which contains a POSIX path like /home/kaz. This path works fine and we use that. If we are not running in the Cygwin environment, but running as an application that uses the Cygwin DLL, then the HOME variable is still defined, but the path doesn't resolve. We must detect this, and fall back on the USERPROFILE environment variable, which holds something like C:\Users\kaz. * parser.c (get_home_path): New static function, defined separately for Cygwin and other platforms. (repl): Use get_home_path to determine home directory. --- parser.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/parser.c b/parser.c index 281dd81c..6589bd47 100644 --- a/parser.c +++ b/parser.c @@ -644,6 +644,32 @@ static val read_eval_ret_last(val env, val counter, return t; } +#ifdef __CYGWIN__ +static val get_home_path(void) +{ + val path_exists_p = intern(lit("path-exists-p"), user_package); + + { + val posixy_home = getenv_wrap(lit("HOME")); + if (funcall1(path_exists_p, posixy_home)) + return posixy_home; + } + + { + val windowsy_home = getenv_wrap(lit("USERPROFILE")); + if (funcall1(path_exists_p, windowsy_home)) + return windowsy_home; + } + + return nil; +} +#else +static val get_home_path(void) +{ + return getenv_wrap(lit("HOME")); +} +#endif + val repl(val bindings, val in_stream, val out_stream) { val ifd = stream_get_prop(in_stream, fd_k); @@ -661,7 +687,7 @@ val repl(val bindings, val in_stream, val out_stream) val result_hash = make_hash(nil, nil, nil); val done = nil; val counter = one; - val home = getenv_wrap(lit("HOME")); + val home = get_home_path(); val histfile = if2(home, format(nil, lit("~a/.txr_history"), home, nao)); char *histfile_u8 = if3(home, utf8_dup_to(c_str(histfile)), NULL); val rcfile = if2(home, format(nil, lit("~a/.txr_profile"), home, nao)); -- cgit v1.2.3