From fae3f9ddeabccae4851ff451fb2aaf05a02e44e3 Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 13 Mar 2023 10:35:32 +0100 Subject: [PATCH] stop run-time option processing after "--" --- library.scm | 21 +++++++++++---------- manual/Module (chicken process-context) | 4 ++-- manual/Using the compiler | 3 ++- runtime.c | 6 ++++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/library.scm b/library.scm index 9fc663e0..451f1d4f 100644 --- a/library.scm +++ b/library.scm @@ -6031,17 +6031,18 @@ static C_word C_fcall C_setenv(C_word x, C_word y) { (define command-line-arguments (make-parameter - (let ([args (argv)]) + (let ((args (argv))) (if (pair? args) - (let loop ([args (##sys#slot args 1)]) - (if (null? args) - '() - (let ([arg (##sys#slot args 0)] - [r (##sys#slot args 1)] ) - (if (and (fx>= (##sys#size arg) 3) - (string=? "-:" (##sys#substring arg 0 2))) - (loop r) - (cons arg (loop r)) ) ) ) ) + (let loop ((args (##sys#slot args 1))) + (cond ((null? args) '()) + ((string=? "--" (car args)) args) + (else + (let ((arg (##sys#slot args 0)) + (r (##sys#slot args 1)) ) + (if (and (fx>= (##sys#size arg) 3) + (string=? "-:" (##sys#substring arg 0 2))) + (loop r) + (cons arg (loop r)) ) ) ) )) args) ) (lambda (x) (##sys#check-list x 'command-line-arguments) diff --git a/manual/Module (chicken process-context) b/manual/Module (chicken process-context) index 5299905e..6b8f8c48 100644 --- a/manual/Module (chicken process-context) +++ b/manual/Module (chicken process-context) @@ -29,8 +29,8 @@ the host-shell whether arguments are expanded ('globbed') or not. (command-line-arguments) Contains the list of arguments passed to this program, with the name of -the program and any runtime options (all options starting with {{-:}}) -removed. +the program and any runtime options (options starting with {{-:}}) +removed. Note that the latter will still be included when following {{--}}. ==== executable-pathname diff --git a/manual/Using the compiler b/manual/Using the compiler index 51cd9ffc..fd9e14c1 100644 --- a/manual/Using the compiler +++ b/manual/Using the compiler @@ -223,7 +223,8 @@ After successful compilation a C source file is generated and can be compiled with a C compiler. Executables generated with CHICKEN (and the compiler itself) accept a small set of runtime options. These are filtered out by the startup code and will not be contained in the result of -{{(command-line-arguments)}}. +{{(command-line-arguments)}}. An occurrence of {{--}} will prevent any +further run-time option processing. ; {{-:?}} : Shows a list of the available runtime options and exits the program. diff --git a/runtime.c b/runtime.c index 76f0e12c..5d097ddb 100644 --- a/runtime.c +++ b/runtime.c @@ -1349,8 +1349,9 @@ void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *st *stack = DEFAULT_STACK_SIZE; *symbols = DEFAULT_SYMBOL_TABLE_SIZE; - for(i = 1; i < C_main_argc; ++i) - if(!strncmp(C_main_argv[ i ], C_text("-:"), 2)) { + for(i = 1; i < C_main_argc; ++i) { + if(!C_strcmp(C_main_argv[ i ], C_text("--"))) break; + else if(!C_strncmp(C_main_argv[ i ], C_text("-:"), 2)) { for(ptr = &C_main_argv[ i ][ 2 ]; *ptr != '\0';) { switch(*(ptr++)) { case '?': @@ -1504,6 +1505,7 @@ void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *st next:; } + } } -- 2.33.0