Add a '-a' option that allows to override the program path (i.e. Application.Path and Args[0]).

[INTERPRETER]
* NEW: Add a '-a' option that allows to override the program path (i.e. Application.Path and Args[0]).
This commit is contained in:
gambas 2020-11-02 22:09:35 +01:00
parent f3587c71d7
commit 6586e7d7cc
4 changed files with 15 additions and 4 deletions

View File

@ -271,6 +271,7 @@ int main(int argc, char *argv[])
printf(" -e evaluate an expression\n");
printf(
" -a <path> override application path\n"
" -g enter debugging mode\n"
" -h --help display this help\n"
" -H --httpd run through an embedded http server\n"
@ -376,6 +377,9 @@ int main(int argc, char *argv[])
{
PROJECT_run_tests = TRUE;
}
else if (is_option_arg(argv, argc, &i, 'a', NULL, &PROJECT_override))
{
}
else if (is_option(argv[i], '-'))
{
i++;

View File

@ -60,14 +60,17 @@ static bool _daemon = FALSE;
BEGIN_PROPERTY(Application_Path)
GB_ReturnString(PROJECT_path);
if (PROJECT_override)
GB_ReturnNewZeroString(FILE_get_dir(PROJECT_override));
else
GB_ReturnString(PROJECT_path);
END_PROPERTY
BEGIN_PROPERTY(Application_Name)
GB_ReturnConstZeroString(PROJECT_name);
GB_ReturnConstZeroString(PROJECT_name);
END_PROPERTY
@ -134,7 +137,9 @@ BEGIN_METHOD(Application_Args_get, GB_INTEGER index)
if (index >= PROJECT_argc)
GB_ReturnVoidString();
else
else if (index == 0 && PROJECT_override)
GB_ReturnNewZeroString(FILE_get_name(PROJECT_override));
else
GB_ReturnConstZeroString(PROJECT_argv[index]);
END_METHOD

View File

@ -46,7 +46,6 @@
char *PROJECT_path = NULL;
char *PROJECT_exec_path = NULL;
char *PROJECT_name = NULL;
char *PROJECT_title = NULL;
const char *PROJECT_startup = NULL;
@ -62,6 +61,8 @@ char *PROJECT_oldcwd = NULL;
bool PROJECT_run_httpd = FALSE;
bool PROJECT_run_tests = FALSE;
const char *PROJECT_override = NULL;
static char *project_buffer;
//static char *project_ptr;

View File

@ -51,6 +51,7 @@ EXTERN char *PROJECT_oldcwd;
EXTERN char *PROJECT_user_home;
EXTERN bool PROJECT_run_httpd;
EXTERN bool PROJECT_run_tests;
EXTERN const char *PROJECT_override;
#endif
void PROJECT_init(const char *file);