Przeglądaj źródła

added Config resolution of relative config pathes

Johannes Ruehle 11 lat temu
rodzic
commit
ee1f7bdcb2
1 zmienionych plików z 18 dodań i 1 usunięć
  1. 18 1
      core/basics/Config.cpp

+ 18 - 1
core/basics/Config.cpp

@@ -2,6 +2,9 @@
 #include <assert.h>
 #include <fstream>
 
+#include <unistd.h> //for getpwd() under linux
+#include <sys/param.h> //for MAXPATHLEN - the maximal path length
+
 // nice-core includes
 #include "core/basics/Exception.h"
 #include "core/basics/Config.h"
@@ -35,7 +38,21 @@ Config::Config ( int argc,
 {
   readFromArguments ( argc, argv );
   std::string configfile = gS("main", "config", "" );
-  
+
+  NICE::FileName t_ConfigFilename( configfile );
+
+  // check for relative path correction:
+  // if dataset is a relative path, then make it absolute using the
+  // currend working directory
+  if( t_ConfigFilename.isRelative() )
+  {
+      char sCWDPath[MAXPATHLEN];
+      getcwd(sCWDPath, MAXPATHLEN);
+      t_ConfigFilename.set( string(sCWDPath) + "/" + configfile );
+      t_ConfigFilename.convertToRealPath();
+      configfile = t_ConfigFilename.str();
+  }
+  m_sConfigFilename = configfile;
   std::cerr << "configfile: " << configfile << std::endl;
   ioUntilEndOfFile = gB("main", "ioUntilEndOfFile", true );
   if ( configfile.size() > 0 )