Fix off-by-one error in command-line argument handling.

Previously (command-line) did not include the script name, but did
include the executable name if no script was given.  Now if a script
is given its name will be the first element of the list returned by
(command-line) and will be the first element of the list passed to
(main).

This brings us into compliance with SRFI-22.  Our man page was already
correct on this point.
This commit is contained in:
Travis Cross 2011-12-31 09:03:21 +00:00
parent 904ae5743e
commit 7b23858d86
6 changed files with 16 additions and 13 deletions

View file

@ -27,7 +27,7 @@
(define (print . args) (for-each display args) (newline))
(define (main args)
(let* ((n (string->number (car args)))
(let* ((n (string->number (cadr args)))
(min-depth 4)
(max-depth (max (+ min-depth 2) n))
(stretch-depth (+ max-depth 1)))

View file

@ -101,7 +101,7 @@
(spell (apply + (map car results)))
(newline))))
(let ((n (command-line #:args (n) (string->number n))))
(let ((n (string->number (cadr (command-line)))))
(go n '(blue red yellow))
(go n '(blue red yellow red yellow blue red yellow red blue))
(newline))

2
main.c
View file

@ -442,7 +442,7 @@ void run_main (int argc, char **argv) {
if (! quit) {
load_init();
if (i < argc)
for (j=argc-1; j>i; j--)
for (j=argc-1; j>=i; j--)
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[j],-1), args);
else
args = sexp_cons(ctx, tmp=sexp_c_string(ctx,argv[0],-1), args);

View file

@ -664,16 +664,17 @@ div#footer {padding-bottom: 50px}
(define (main args)
(case (length args)
((0)
((0 1)
(convert (current-input-port)))
((1)
(cond
((equal? "-" (car args))
(convert (current-input-port)))
((file-exists? (car args))
(call-with-input-file (car args) convert))
(else
(extract (map (lambda (x) (or (string->number x) (string->symbol x)))
(string-split (car args) #\.))))))
((2)
(let ((name (cadr args)))
(cond
((equal? "-" name)
(convert (current-input-port)))
((file-exists? name)
(call-with-input-file name convert))
(else
(extract (map (lambda (x) (or (string->number x) (string->symbol x)))
(string-split name #\.)))))))
(else
(error "usage: chibi-doc [<file-or-module-name>]"))))

View file

@ -1358,6 +1358,7 @@
;; main
(define (main args)
(if (not (null? args)) (set! args (cdr args)))
(let* ((compile? (and (pair? args) (member (car args) '("-c" "--compile"))))
(args (if compile? (cdr args) args))
(cflags (if (and (pair? args) (member (car args) '("-f" "--flags")))

View file

@ -150,6 +150,7 @@
(display " },\n"))
(define (main args)
(if (not (null? args)) (set! args (cdr args)))
(find-c-libs
(if (and (pair? args) (member (car args) '("-x" "--exclude")))
(map (lambda (m)