diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-05-04 06:44:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-05-04 06:44:23 -0700 |
commit | c8b26dd45545170b717ade1ddcb2fe800524c0f7 (patch) | |
tree | dbda4ee253c158b6f5f3a29ad744b2e238050bbb /txr.c | |
parent | e05dfea596bee5f26475b3715078ff315f22b5c2 (diff) | |
download | txr-c8b26dd45545170b717ade1ddcb2fe800524c0f7.tar.gz txr-c8b26dd45545170b717ade1ddcb2fe800524c0f7.tar.bz2 txr-c8b26dd45545170b717ade1ddcb2fe800524c0f7.zip |
Calculate sysroot even if executable is renamed.
If txr is renamed to something else in the same installation
directory, we can still calculate the sysroot.
* txr.c (substitute_basename): New function.
(sysroot_init): Make one more attempt to calculate the
sysroot by substituting the actual base name of
the program into the compile-time relative path, and
using that path agains the full path name.
Diffstat (limited to 'txr.c')
-rw-r--r-- | txr.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -257,6 +257,21 @@ static val maybe_sysroot(val exepart) sysroot_path = sub_str(prog_path, 0, neg(length(exepart)))); } +static val substitute_basename(val edited_path, val source_path) +{ + val lslash = rpos(chr('/'), edited_path, nil, nil); + val rslash = rpos(chr('/'), source_path, nil, nil); + val basename = if3(rslash, + sub_str(source_path, succ(rslash), t), + source_path); + + return if3(lslash, + format(nil, lit("~a~a"), + sub_str(edited_path, 0, succ(lslash)), + basename, nao), + basename); +} + static val sysroot(val target) { return format(nil, lit("~a~a"), sysroot_path, target, nao); @@ -276,7 +291,8 @@ static void sysroot_init(void) if (!(maybe_sysroot(lit(TXR_REL_PATH)) || maybe_sysroot(lit(TXR_REL_PATH EXE_SUFF)) || maybe_sysroot(lit(PROG_NAME)) || - maybe_sysroot(lit(PROG_NAME EXE_SUFF)))) + maybe_sysroot(lit(PROG_NAME EXE_SUFF)) || + maybe_sysroot(substitute_basename(lit(TXR_REL_PATH), prog_path)))) { format(std_error, lit("~a: unable to calculate sysroot\n"), prog_string, nao); |