Skip to content

Commit d5b3801

Browse files
committed
Command line arguments to set paths.
1 parent c4a70a0 commit d5b3801

File tree

4 files changed

+104
-3
lines changed

4 files changed

+104
-3
lines changed

ugbase/bridge/misc_bridges/util_bridge.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,18 @@ void RegisterBridge_Util(Registry& reg, string parentGroup)
133133
reg.add_function("ug_get_current_path", &GetCurrentPath, grp,
134134
"pathName", "", "Returns the current path");
135135

136-
reg.add_function("ug_set_root_path", &SetRootPath, grp,
136+
reg.add_function("ug_set_root_path", static_cast<void(*)(const std::string&)>(&SetRootPath), grp,
137137
"", "pathName", "Sets the paths relative to passed root path");
138138

139+
reg.add_function("ug_set_script_path", static_cast<void(*)(const std::string&)>(&SetScriptPath), grp,
140+
"", "pathName", "Sets the script path");
141+
142+
reg.add_function("ug_set_apps_path", static_cast<void(*)(const std::string&)>(&SetAppsPath), grp,
143+
"", "pathName", "Sets the script path");
144+
145+
reg.add_function("ug_set_plugin_path", static_cast<void(*)(const std::string&)>(&SetPluginPath), grp,
146+
"", "pathName", "Sets the plugin path");
147+
139148
reg.add_function("ExecuteSystemCommand", &ExecuteSystemCommand, grp,
140149
"success", "command", "Executes a command in the system shell");
141150

ugbase/ug.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,69 @@ void SetRootPath(const std::string& strRoot)
152152
PathProvider::set_path(APPS_PATH, strRoot + pathSep + "apps");
153153
}
154154

155+
/**
156+
* init app, script and data paths for a given root path
157+
*/
158+
void SetRootPath(const char* c_strRoot)
159+
{
160+
std::string strRoot(c_strRoot);
161+
SetRootPath(strRoot);
162+
}
163+
164+
/**
165+
* init script path
166+
*/
167+
void SetScriptPath(const std::string& strScript)
168+
{
169+
PROFILE_FUNC();
170+
PathProvider::set_path(SCRIPT_PATH, strScript);
171+
}
172+
173+
/**
174+
* init script path
175+
*/
176+
void SetScriptPath(const char* c_strScript)
177+
{
178+
std::string strScript(c_strScript);
179+
SetScriptPath(strScript);
180+
}
181+
182+
/**
183+
* init apps path
184+
*/
185+
void SetAppsPath(const std::string& strApps)
186+
{
187+
PROFILE_FUNC();
188+
PathProvider::set_path(APPS_PATH, strApps);
189+
}
190+
191+
/**
192+
* init apps path
193+
*/
194+
void SetAppsPath(const char* c_strApps)
195+
{
196+
std::string strApps(c_strApps);
197+
SetAppsPath(strApps);
198+
}
199+
200+
/**
201+
* init plugin path
202+
*/
203+
void SetPluginPath(const std::string& strPlugin)
204+
{
205+
PROFILE_FUNC();
206+
PathProvider::set_path(PLUGIN_PATH, strPlugin);
207+
}
208+
209+
/**
210+
* init plugin path
211+
*/
212+
void SetPluginPath(const char* c_strPlugin)
213+
{
214+
std::string strPlugin(c_strPlugin);
215+
SetPluginPath(strPlugin);
216+
}
217+
155218
////////////////////////////////////////////////////////////////////////
156219
/// initializes ug
157220
/** This method should be called at the beginning of main(...).

ugbase/ug.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ UG_API bool InitPaths(const char* argv0);
8686
* - PLUGIN_PATH
8787
*/
8888
UG_API void SetRootPath(const std::string& strRoot);
89+
UG_API void SetRootPath(const char* c_strRoot);
90+
91+
/// Initializes the SCRIPT_PATH of ug::PathProvider.
92+
UG_API void SetScriptPath(const std::string& strScript);
93+
UG_API void SetScriptPath(const char* c_strScript);
94+
95+
/// Initializes the APPS_PATH of ug::PathProvider.
96+
UG_API void SetAppsPath(const std::string& strApps);
97+
UG_API void SetAppsPath(const char* c_strApps);
98+
99+
/// Initializes the PLUGIN_PATH of ug::PathProvider.
100+
UG_API void SetPluginPath(const std::string& strPlugin);
101+
UG_API void SetPluginPath(const char* c_strPlugin);
89102

90103
/// finalizes ug
91104
/** If ug has been compiled for parallel use (UG_PARALLEL is defined)

ugbase/ug_shell/ugshell_main.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,28 @@ int ugshell_main(int argc, char* argv[])
361361
if(FindParam("-profile", argc, argv))
362362
UGOutputProfileStatsOnExit(true);
363363

364-
const bool quiet = FindParam("-quiet", argc, argv);
364+
const bool quiet = FindParam("-quiet", argc, argv);
365365

366-
const bool help = FindParam("-help", argc, argv);
366+
const bool help = FindParam("-help", argc, argv);
367367

368368
const bool interactiveShellRequested = FindParam("-noquit", argc, argv);
369369
bool defaultInteractiveShell = true; // may be changed later
370+
371+
const char* rootPath = NULL;
372+
if(ParamToString(&rootPath, "-rootpath", argc, argv))
373+
SetRootPath(rootPath);
374+
375+
const char* scriptPath = NULL;
376+
if(ParamToString(&scriptPath, "-scriptpath", argc, argv))
377+
SetScriptPath(scriptPath);
378+
379+
const char* appsPath = NULL;
380+
if(ParamToString(&appsPath, "-appspath", argc, argv))
381+
SetAppsPath(appsPath);
382+
383+
const char* pluginPath = NULL;
384+
if(ParamToString(&pluginPath, "-pluginpath", argc, argv))
385+
SetPluginPath(pluginPath);
370386

371387
#ifdef UG_PARALLEL
372388
const bool parallelEnvironment = (pcl::NumProcs() > 1);

0 commit comments

Comments
 (0)