read a lone - as stdin
getopt-long read it as an option it did not know, and died.
This commit is contained in:
13
sexc.scm
13
sexc.scm
@@ -121,6 +121,12 @@
|
||||
(loop (cddr as) (cons "--output=-" acc)))
|
||||
(else (loop (cdr as) (cons (car as) acc))))))
|
||||
|
||||
;;; ...and a lone `-' left after that is the input, which is stdin: one
|
||||
;;; getopt-long would read as an option it did not know, so it is taken
|
||||
;;; out before
|
||||
(define (stdin-dash? argv)
|
||||
(and (member "-" argv) #t))
|
||||
|
||||
(define (get-rest-args args)
|
||||
(cdr (assoc '@ args)))
|
||||
|
||||
@@ -250,14 +256,13 @@ status, which is ours to pass on."
|
||||
|
||||
(define (main)
|
||||
(let* ((argv (command-line-arguments))
|
||||
(raw-args (args-before-separator argv))
|
||||
(raw-args (spell-stdout-output (args-before-separator argv)))
|
||||
(cc-args (args-after-separator argv))
|
||||
(args (getopt-long (spell-stdout-output raw-args)
|
||||
opts-grammar))
|
||||
(args (getopt-long (delete "-" raw-args) opts-grammar))
|
||||
(output (get-arg args 'output 'default))
|
||||
(help (help-arg? args))
|
||||
|
||||
(input (get-input-file args))
|
||||
(input (if (stdin-dash? raw-args) 'stdin (get-input-file args)))
|
||||
(current-dir (current-directory)))
|
||||
(call/cc
|
||||
(lambda (return)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken file)
|
||||
(chicken io)
|
||||
(chicken pathname)
|
||||
(chicken process)
|
||||
(chicken process-context)
|
||||
@@ -33,6 +34,18 @@
|
||||
(define out (make-pathname scratch "out"))
|
||||
(set-environment-variable! "TMPDIR" scratch)
|
||||
|
||||
;;; (status stdout stderr) of sexc run with ARGS, and INPUT, when one
|
||||
;;; is given, on its stdin
|
||||
(define (sexc-run input . args)
|
||||
(let ((proc (process* sexc args)))
|
||||
(when input (display input (process-input-port proc)))
|
||||
(close-output-port (process-input-port proc))
|
||||
(let* ((text (lambda (s) (if (eof-object? s) "" s)))
|
||||
(out (text (read-string #f (process-output-port proc))))
|
||||
(err (text (read-string #f (process-error-port proc)))))
|
||||
(process-wait proc)
|
||||
(list (process-exit-status proc) out err))))
|
||||
|
||||
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
||||
(define (sexc-succeeds? . args)
|
||||
(zero? (system (string-append (string-intersperse (map qs (cons sexc args)))
|
||||
@@ -52,6 +65,12 @@
|
||||
(sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))
|
||||
|
||||
(define hello (make-pathname (current-directory) "hello.sex"))
|
||||
(define hello-source (call-with-input-file hello (lambda (p) (read-string #f p))))
|
||||
|
||||
;;; getopt-long read a lone `-' as an option it did not know, and died
|
||||
(test-assert "- is stdin"
|
||||
(let ((run (sexc-run hello-source "-" "-C" "-o" "-")))
|
||||
(and (zero? (car run)) (substring-index "main" (cadr run)) #t)))
|
||||
(change-directory scratch)
|
||||
|
||||
(test "-o - is refused for an executable" #f
|
||||
|
||||
Reference in New Issue
Block a user