Skip to content

Commit 22a6d0b

Browse files
committed
FEAT: added possibility not to process default application arguments on boot
1 parent bb16a3b commit 22a6d0b

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

src/core/b-init.c

+33-11
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ extern const REBYTE Str_Banner[];
368368
}
369369

370370

371-
372371
/***********************************************************************
373372
**
374373
*/ static void Init_Ops(void)
@@ -821,6 +820,27 @@ static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
821820
REBCHR *data;
822821
REBCNT n;
823822

823+
#ifdef RAW_MAIN_ARGS
824+
REBSER *str;
825+
REBVAL *new;
826+
// make system/options/flags block even when not used...
827+
val = Get_System(SYS_OPTIONS, OPTIONS_FLAGS);
828+
Set_Block(val, Make_Block(3));
829+
// clear list of default flags (system/catalog/boot-flags)
830+
val = Get_System(SYS_CATALOG, CAT_BOOT_FLAGS);
831+
SET_NONE(val);
832+
// convert raw argument strings to block of strings...
833+
ser = Make_Block(3);
834+
for (n = 1; n < rargs->argc ; n++) {
835+
REBCHR *arg = rargs->argv[n];
836+
if (arg == 0) continue; // shell bug
837+
new = Append_Value(ser);
838+
Set_String(new, Copy_OS_Str(arg, (REBINT)LEN_STR(arg)));
839+
//if(arg[0]=='-') VAL_SET_LINE(new);
840+
}
841+
val = Get_System(SYS_OPTIONS, OPTIONS_ARGS);
842+
Set_Block(val, ser);
843+
#else
824844

825845
ser = Make_Block(3);
826846
n = 2; // skip first flag (ROF_EXT)
@@ -830,8 +850,11 @@ static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
830850
if (rargs->options & n) Append_Val(ser, val);
831851
n <<= 1;
832852
}
853+
// last value is always TRUE, so it's possible to use just *path* instead of `find`
854+
// like: `if system/options/flags/verbose [...]`
833855
val = Append_Value(ser);
834856
SET_TRUE(val);
857+
835858
val = Get_System(SYS_OPTIONS, OPTIONS_FLAGS);
836859
Set_Block(val, ser);
837860

@@ -846,16 +869,6 @@ static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
846869
Set_Option_File(OPTIONS_SCRIPT, (REBYTE*)rargs->script, FALSE);
847870
}
848871

849-
if (rargs->exe_path) {
850-
Set_Option_File(OPTIONS_BOOT, (REBYTE*)rargs->exe_path, FALSE);
851-
}
852-
853-
// Print("home: %s", rargs->home_dir);
854-
if (rargs->home_dir) {
855-
Set_Option_File(OPTIONS_HOME, (REBYTE*)rargs->home_dir, TRUE);
856-
OS_FREE(rargs->home_dir);
857-
}
858-
859872
n = Set_Option_Word(rargs->boot, OPTIONS_BOOT_LEVEL);
860873
if (n >= SYM_BASE && n <= SYM_MODS)
861874
PG_Boot_Level = n - SYM_BASE; // 0 - 3
@@ -867,7 +880,16 @@ static void Set_Option_File(REBCNT field, REBYTE* src, REBOOL dir )
867880
Set_Option_String(rargs->import, OPTIONS_IMPORT);
868881

869882
Set_Option_Word(rargs->secure, OPTIONS_SECURE);
883+
#endif
884+
if (rargs->exe_path) {
885+
Set_Option_File(OPTIONS_BOOT, (REBYTE*)rargs->exe_path, FALSE);
886+
}
870887

888+
// Print("home: %s", rargs->home_dir);
889+
if (rargs->home_dir) {
890+
Set_Option_File(OPTIONS_HOME, (REBYTE*)rargs->home_dir, TRUE);
891+
OS_FREE(rargs->home_dir);
892+
}
871893
if (NZ(data = OS_GET_LOCALE(0))) {
872894
val = Get_System(SYS_LOCALE, LOCALE_LANGUAGE);
873895
Set_String(val, Copy_OS_Str(data, (REBINT)LEN_STR(data)));

src/include/reb-args.h

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ typedef struct rebol_args {
4040
REBCHR *boot;
4141
REBCHR *exe_path;
4242
REBCHR *home_dir;
43+
#ifdef RAW_MAIN_ARGS
44+
REBCNT argc;
45+
REBCHR **argv;
46+
#endif
4347
} REBARGS;
4448

4549
// REBOL arg option flags:

src/mezz/sys-start.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ start: func [
7373
;-- Convert command line arg strings as needed:
7474
script-args: args ; save for below
7575
foreach [opt act] [
76-
args [parse args ""]
76+
;args [parse args ""]
7777
do-arg block!
7878
debug block!
7979
secure word!

src/os/host-args.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,29 @@ const struct arg_chr arg_chars2[] = {
197197
** Parse REBOL's command line arguments, setting options
198198
** and values in the provided args structure.
199199
**
200+
** If RAW_MAIN_ARGS is used, the arguments list is not being
201+
** parsed in this function, but instead will be converted to
202+
** block of strings and leaved on interpreter to process it.
203+
**
200204
***********************************************************************/
201205
{
206+
#ifdef RAW_MAIN_ARGS
207+
CLEARS(rargs);
208+
rargs->argc = argc;
209+
rargs->argv = argv;
210+
// First arg is path to executable (on most systems):
211+
if (argc > 0) rargs->exe_path = *argv;
212+
OS_Get_Current_Dir(&rargs->home_dir);
213+
#else
202214
int arg_buf_size=128;
203215

204216
REBCHR *arg;
205217
REBCHR *args = 0; // holds trailing args
206218
int flag;
207219
int i;
220+
int len;
221+
int size;
222+
REBCHR *tmp;
208223

209224
CLEARS(rargs);
210225

@@ -261,9 +276,6 @@ const struct arg_chr arg_chars2[] = {
261276
if (!rargs->script)
262277
rargs->script = arg;
263278
else {
264-
int len;
265-
int size;
266-
REBCHR *tmp;
267279
if (!args) {
268280
args = MAKE_STR(arg_buf_size);
269281
args[0] = 0;
@@ -289,6 +301,7 @@ const struct arg_chr arg_chars2[] = {
289301
args[LEN_STR(args)-1] = 0; // remove trailing space
290302
Get_Ext_Arg(RO_ARGS, rargs, args);
291303
}
304+
#endif
292305
}
293306

294307

0 commit comments

Comments
 (0)