diff --git a/src/classes/PStartupHandler.cpp b/src/classes/PStartupHandler.cpp index 9dde7722..bbbef9d3 100644 --- a/src/classes/PStartupHandler.cpp +++ b/src/classes/PStartupHandler.cpp @@ -91,7 +91,7 @@ int parseXmlFile(TSAXParser *saxParser, const char *startup_path_name) /** *
Constructor. Check if the musrfit_startup.xml file is found in some standard search paths
*/
-PStartupHandler::PStartupHandler()
+PStartupHandler::PStartupHandler(bool reset_startup_file)
{
fStartupFileFound = false;
fStartupFilePath = "";
@@ -145,6 +145,17 @@ PStartupHandler::PStartupHandler()
}
}
+ // musrfit_startup.xml found. Check if it should be rewritten
+ if (fStartupFileFound && reset_startup_file) {
+ std::cout << std::endl;
+ std::cout << ">> Will only reset the file: '" << fStartupFilePath.Data() << "'."<< std::endl;
+ std::cout << std::endl;
+ if (!WriteDefaultStartupFile(reset_startup_file)) {
+ std::cerr << std::endl << "**ERROR** couldn't re-write " << fStartupFilePath.Data() << "." << std::endl;
+ return;
+ }
+ }
+
// if musrfit_startup.xml is still not found, will create a default one
if (!fStartupFileFound) {
std::cout << std::endl << "**INFO** no musrfit_startup.xml file found, will write a default one." << std::endl;
@@ -617,33 +628,37 @@ Bool_t PStartupHandler::StartupFileExists(Char_t *fln)
//--------------------------------------------------------------------------
// WriteDefaultStartupFile
//--------------------------------------------------------------------------
-Bool_t PStartupHandler::WriteDefaultStartupFile()
+Bool_t PStartupHandler::WriteDefaultStartupFile(bool reset_startup_file)
{
- // get home
Char_t startup_path_name[256];
- Char_t *home = nullptr;
- home = getenv("HOME");
- if (home == nullptr) {
- std::cerr << std::endl << "**ERROR** couldn't obtain $HOME." << std::endl;
- return false;
- }
-
- // first check that $HOME/.musrfit exists and if NOT create it
- struct stat info;
-
- snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit", home);
- if (!stat(startup_path_name, &info)) {
- if (!(info.st_mode & S_IFDIR))
- return false;
- } else {
- if (mkdir(startup_path_name, 0777)) {
- std::cerr << std::endl << "**ERROR** couldn't create '" << startup_path_name << "'" << std::endl;
+ if (reset_startup_file) { // reset the found
+ snprintf(startup_path_name, sizeof(startup_path_name), "%s", fStartupFilePath.Data());
+ } else { // no musrfit_startup.xml found, hence write default under $HOME/.musrfit
+ // get home
+ Char_t *home = nullptr;
+ home = getenv("HOME");
+ if (home == nullptr) {
+ std::cerr << std::endl << "**ERROR** couldn't obtain $HOME." << std::endl;
return false;
}
- }
- // set path-name for musrfit_startup.xml
- snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home);
+ // first check that $HOME/.musrfit exists and if NOT create it
+ struct stat info;
+
+ snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit", home);
+ if (!stat(startup_path_name, &info)) {
+ if (!(info.st_mode & S_IFDIR))
+ return false;
+ } else {
+ if (mkdir(startup_path_name, 0777)) {
+ std::cerr << std::endl << "**ERROR** couldn't create '" << startup_path_name << "'" << std::endl;
+ return false;
+ }
+ }
+
+ // set path-name for musrfit_startup.xml
+ snprintf(startup_path_name, sizeof(startup_path_name), "%s/.musrfit/musrfit_startup.xml", home);
+ }
std::ofstream fout(startup_path_name, std::ofstream::out);
if (!fout.is_open()) {
diff --git a/src/include/PStartupHandler.h b/src/include/PStartupHandler.h
index d81e9925..cf48323f 100644
--- a/src/include/PStartupHandler.h
+++ b/src/include/PStartupHandler.h
@@ -54,7 +54,7 @@ int parseXmlFile(TSAXParser*, const char*);
class PStartupHandler : public TObject, public TQObject
{
public:
- PStartupHandler();
+ PStartupHandler(bool reset_startup_file=false);
virtual ~PStartupHandler();
virtual void OnStartDocument(); // SLOT
@@ -99,7 +99,7 @@ class PStartupHandler : public TObject, public TQObject
PStartupOptions fStartupOptions; ///< collects all startup options which will be requested by PMsrFileHandler
Bool_t StartupFileExists(Char_t *fln);
- Bool_t WriteDefaultStartupFile();
+ Bool_t WriteDefaultStartupFile(bool reset_startup_file=false);
ClassDef(PStartupHandler, 1)
};
diff --git a/src/musrfit.cpp b/src/musrfit.cpp
index 208a76b9..83a7187f 100644
--- a/src/musrfit.cpp
+++ b/src/musrfit.cpp
@@ -122,6 +122,12 @@ void musrfit_syntax()
std::cout << std::endl << " -u, --use-no-of-threads