diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index b245d233..813a0129 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -30,6 +30,7 @@ ***************************************************************************/ #include +#include using namespace std; #include @@ -48,6 +49,34 @@ ClassImpQ(PStartupHandler) */ PStartupHandler::PStartupHandler() { + fStartupFileFound = false; + fStartupFilePath = ""; + + // get default path (for the moment only linux like) + char *pmusrpath; + char musrpath[128]; + char startup_path_name[128]; + + // check if the startup file is found in the current directory + strcpy(startup_path_name, "./musrfit_startup.xml"); + if (StartupFileExists(startup_path_name)) { + fStartupFileFound = true; + fStartupFilePath = TString(startup_path_name); + } else { // startup file is not found in the current directory + // check if the MUSRFITPATH system variable is set + pmusrpath = getenv("MUSRFITPATH"); + if (pmusrpath == 0) { // not set, will try default one + strcpy(musrpath, "/home/nemu/analysis/bin"); + cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl; + } else { + strncpy(musrpath, pmusrpath, sizeof(musrpath)); + } + sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); + if (StartupFileExists(startup_path_name)) { + fStartupFileFound = true; + fStartupFilePath = TString(startup_path_name); + } + } } //-------------------------------------------------------------------------- @@ -440,5 +469,30 @@ void PStartupHandler::CheckLists() } } -// end --------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// StartupFileExists +//-------------------------------------------------------------------------- +/** + *

+ * + */ +bool PStartupHandler::StartupFileExists(char *fln) +{ + bool result = false; + + ifstream ifile(fln); + + if (ifile.fail()) { + result = false; + } else { + result = true; + ifile.close(); + } + + return result; +} + +// ------------------------------------------------------------------------- +// end +// ------------------------------------------------------------------------- diff --git a/src/include/PStartupHandler.h b/src/include/PStartupHandler.h index 1543a941..e8c9a1c4 100644 --- a/src/include/PStartupHandler.h +++ b/src/include/PStartupHandler.h @@ -56,6 +56,9 @@ class PStartupHandler : public TObject, public TQObject virtual void OnFatalError(const char*); // SLOT virtual void OnCdataBlock(const char*, Int_t); // SLOT + virtual bool StartupFileFound() { return fStartupFileFound; } + virtual TString GetStartupFilePath() { return fStartupFilePath; } + virtual void CheckLists(); virtual PMsrFourierStructure GetFourierDefaults() { return fFourierDefaults; } @@ -70,11 +73,15 @@ class PStartupHandler : public TObject, public TQObject eColorList, eColor}; EKeyWords fKey; + bool fStartupFileFound; + TString fStartupFilePath; PMsrFourierStructure fFourierDefaults; PStringVector fDataPathList; PIntVector fMarkerList; PIntVector fColorList; + bool StartupFileExists(char *fln); + ClassDef(PStartupHandler, 1) }; diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 54f327cd..7e571c68 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -554,22 +554,11 @@ int main(int argc, char *argv[]) } - // get default path (for the moment only linux like) - char *pmusrpath; - char musrpath[128]; - pmusrpath = getenv("MUSRFITPATH"); - if (pmusrpath == 0) { // not set, will try default one - strcpy(musrpath, "/home/nemu/analysis/bin"); - cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl; - } else { - strncpy(musrpath, pmusrpath, sizeof(musrpath)); - } - // read startup file char startup_path_name[128]; - sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); TSAXParser *saxParser = new TSAXParser(); PStartupHandler *startupHandler = new PStartupHandler(); + strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); saxParser->ConnectToHandler("PStartupHandler", startupHandler); status = saxParser->ParseFile(startup_path_name); // check for parse errors diff --git a/src/musrgui/PAdmin.cpp b/src/musrgui/PAdmin.cpp index dcb41df7..321cdbc4 100644 --- a/src/musrgui/PAdmin.cpp +++ b/src/musrgui/PAdmin.cpp @@ -235,10 +235,13 @@ PAdmin::PAdmin() fHelpMain = QString(""); // XML Parser part - QString path = getenv("MUSRFITPATH"); - if (path.isEmpty()) - path = "/home/nemu/analysis/bin"; - QString fln = path + "/musrgui_startup.xml"; + QString fln = "./musrgui_startup.xml"; + if (!QFile::exists(fln)) { + QString path = getenv("MUSRFITPATH"); + if (path.isEmpty()) + path = "/home/nemu/analysis/bin"; + fln = path + "/musrgui_startup.xml"; + } if (QFile::exists(fln)) { // administration file present PAdminXMLParser handler(this); QFile xmlFile(fln); diff --git a/src/musrt0.cpp b/src/musrt0.cpp index 61588dc1..77fb553f 100644 --- a/src/musrt0.cpp +++ b/src/musrt0.cpp @@ -97,22 +97,11 @@ int main(int argc, char *argv[]) return PMUSR_WRONG_STARTUP_SYNTAX; } - // get default path (for the moment only linux like) - char *pmusrpath; - char musrpath[128]; - pmusrpath = getenv("MUSRFITPATH"); - if (pmusrpath == 0) { // not set, will try default one - strcpy(musrpath, "/home/nemu/analysis/bin"); - cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl; - } else { - strncpy(musrpath, pmusrpath, sizeof(musrpath)); - } - // read startup file char startup_path_name[128]; - sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); TSAXParser *saxParser = new TSAXParser(); PStartupHandler *startupHandler = new PStartupHandler(); + strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); saxParser->ConnectToHandler("PStartupHandler", startupHandler); status = saxParser->ParseFile(startup_path_name); // check for parse errors diff --git a/src/musrview.cpp b/src/musrview.cpp index 0ed4a2cf..3aa2cc2f 100644 --- a/src/musrview.cpp +++ b/src/musrview.cpp @@ -98,23 +98,12 @@ int main(int argc, char *argv[]) return PMUSR_WRONG_STARTUP_SYNTAX; } - // get default path (for the moment only linux like) - char *pmusrpath; - char musrpath[128]; - pmusrpath = getenv("MUSRFITPATH"); - if (pmusrpath == 0) { // not set, will try default one - strcpy(musrpath, "/home/nemu/analysis/bin"); - cout << endl << "**WARNING** MUSRFITPATH environment variable not set will try " << musrpath << endl; - } else { - strncpy(musrpath, pmusrpath, sizeof(musrpath)); - } - // read startup file char startup_path_name[128]; - sprintf(startup_path_name, "%s/musrfit_startup.xml", musrpath); TSAXParser *saxParser = new TSAXParser(); PStartupHandler *startupHandler = new PStartupHandler(); saxParser->ConnectToHandler("PStartupHandler", startupHandler); + strcpy(startup_path_name, startupHandler->GetStartupFilePath().Data()); status = saxParser->ParseFile(startup_path_name); // check for parse errors if (status) { // error