Remove argv[0] from the arguments of main_symbol.

While the (command-line) in (scheme process-context) contains the
command name (argv[0]), SRFI 22 specifies that the interpreter passes
the command-line arguments except argv[0] to the script.

Fix #413.

Signed-off-by: Masanori Ogino <masanori.ogino@gmail.com>
This commit is contained in:
Masanori Ogino 2017-06-04 22:04:51 +09:00
parent b52711cac8
commit 361e8e6590
4 changed files with 17 additions and 18 deletions

View file

@ -522,4 +522,4 @@
(verbose? boolean (#\v "verbose"))))
,run-app))
(define (main args) (run-application app-spec args))
(define (main args) (run-application app-spec))

View file

@ -280,7 +280,6 @@
res))))
(define (main args)
(let ((args (cdr args)))
(cond
((equal? "t" (car args))
(for-each (lambda (f) (write-string f) (newline)) (tar-files (cadr args))))
@ -294,4 +293,4 @@
(write-string
(utf8->string (tar-extract-file (cadr args) (car (cddr args))))))
(else
(error "unknown tar command" (car args))))))
(error "unknown tar command" (car args)))))

2
main.c
View file

@ -597,7 +597,7 @@ sexp run_main (int argc, char **argv) {
sym = sexp_intern(ctx, main_symbol, -1);
tmp = sexp_env_ref(ctx, env, sym, SEXP_FALSE);
if (sexp_procedurep(tmp)) {
args = sexp_list1(ctx, args);
args = sexp_list1(ctx, sexp_cdr(args));
check_exception(ctx, sexp_apply(ctx, tmp, args));
} else {
fprintf(stderr, "couldn't find main binding: %s in %s\n", main_symbol, main_module ? main_module : argv[i]);

View file

@ -3,9 +3,9 @@
(begin
(define (main args)
(write-string "Hello, ")
(write-string (if (pair? (cdr args)) (cadr args) "world!"))
(write-string (if (pair? args) (car args) "world!"))
(newline))
(define (bye args)
(write-string "Goodbye, ")
(write-string (if (pair? (cdr args)) (cadr args) "world!"))
(write-string (if (pair? args) (car args) "world!"))
(newline))))