diff --git a/app/Main.cc b/app/Main.cc index cd447c1f..d3fce4ba 100644 --- a/app/Main.cc +++ b/app/Main.cc @@ -20,7 +20,6 @@ #include #include "StaConfig.hh" // STA_VERSION -#include "StringUtil.hh" #include "Sta.hh" @@ -28,15 +27,16 @@ namespace sta { extern const char *tcl_inits[]; } +using std::string; using sta::stringEq; using sta::findCmdLineFlag; using sta::Sta; using sta::initSta; using sta::evalTclInit; -using sta::stringPrintTmp; using sta::sourceTclFile; using sta::parseThreadsArg; using sta::tcl_inits; +using sta::is_regular_file; // Swig uses C linkage for init functions. extern "C" { @@ -116,9 +116,11 @@ staTclAppInit(int argc, Tcl_Eval(interp, "sta::show_splash"); if (!findCmdLineFlag(argc, argv, "-no_init")) { - char *init_path = stringPrintTmp("[file join $env(HOME) %s]", - init_filename); - sourceTclFile(init_path, true, true, interp); + string init_path = getenv("HOME"); + init_path += "/"; + init_path += init_filename; + if (is_regular_file(init_path.c_str())) + sourceTclFile(init_path.c_str(), true, true, interp); } bool exit_after_cmd_file = findCmdLineFlag(argc, argv, "-exit"); diff --git a/app/StaMain.cc b/app/StaMain.cc index 39b64f69..812bb729 100644 --- a/app/StaMain.cc +++ b/app/StaMain.cc @@ -18,6 +18,7 @@ #include #include +#include #include "StringUtil.hh" #include "Vector.hh" @@ -139,4 +140,12 @@ unencode(const char *inits[]) return unencoded; } +// Hack until c++17 filesystem is better supported. +bool +is_regular_file(const char *filename) +{ + struct stat sb; + return stat(filename, &sb) == 0 && S_ISREG(sb.st_mode); +} + } // namespace diff --git a/include/sta/StaMain.hh b/include/sta/StaMain.hh index 5fa97c4f..11d0be41 100644 --- a/include/sta/StaMain.hh +++ b/include/sta/StaMain.hh @@ -62,5 +62,7 @@ sourceTclFile(const char *filename, bool echo, bool verbose, Tcl_Interp *interp); +bool +is_regular_file(const char *filename); } // namespace