From 6586e7d7cc4dc902194102ecff3dccf27625da9e Mon Sep 17 00:00:00 2001 From: gambas Date: Mon, 2 Nov 2020 22:09:35 +0100 Subject: [PATCH] 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]). --- main/gbx/gbx.c | 4 ++++ main/gbx/gbx_c_application.c | 11 ++++++++--- main/gbx/gbx_project.c | 3 ++- main/gbx/gbx_project.h | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main/gbx/gbx.c b/main/gbx/gbx.c index 9b414a567..834399be5 100644 --- a/main/gbx/gbx.c +++ b/main/gbx/gbx.c @@ -271,6 +271,7 @@ int main(int argc, char *argv[]) printf(" -e evaluate an expression\n"); printf( + " -a 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++; diff --git a/main/gbx/gbx_c_application.c b/main/gbx/gbx_c_application.c index 64eedafd5..90fe3a468 100644 --- a/main/gbx/gbx_c_application.c +++ b/main/gbx/gbx_c_application.c @@ -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 diff --git a/main/gbx/gbx_project.c b/main/gbx/gbx_project.c index f92ca974b..740753524 100644 --- a/main/gbx/gbx_project.c +++ b/main/gbx/gbx_project.c @@ -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; diff --git a/main/gbx/gbx_project.h b/main/gbx/gbx_project.h index b7c61abb9..7f130818b 100644 --- a/main/gbx/gbx_project.h +++ b/main/gbx/gbx_project.h @@ -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);