From c8b26dd45545170b717ade1ddcb2fe800524c0f7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 4 May 2016 06:44:23 -0700 Subject: 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. --- txr.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/txr.c b/txr.c index bd38d4d1..83bdf1a8 100644 --- a/txr.c +++ b/txr.c @@ -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); -- cgit v1.2.3