@@ 53,6 53,7 @@
(let ((x (with-input-from-pipe "hg log -r . --template \"{latesttag}{sub('^-0-.*', '', '-{latesttagdistance}-{node|short}')}\" 2>/dev/null" read-line)))
(if (string? x) x "(egg)"))))
+(: exit-status (#!optional fixnum -> fixnum))
(define exit-status
(make-parameter 0))
@@ 61,6 62,7 @@
(let ((ports (map (lambda (x) (if (string? x) (open-input-string x) x)) args)))
(apply make-concatenated-port ports)))
+(: make-rewindable-input-port (output-port #!optional input-port -> input-port))
(define (make-multiplexed-input-port output-port #!optional (port (current-input-port)))
(make-input-port
(lambda ()
@@ 76,6 78,7 @@
(begin0-let* ((x (read-line port n)))
(when (string? x) (write-line x output-port))))))
+(: make-rewindable-input-port (#!optional input-port -> input-port (-> number number)))
(define (make-location-tracking-input-port #!optional (port (current-input-port)))
(let ((line 1)
(column 0))
@@ 94,11 97,13 @@
(lambda () (peek-char port)))
(lambda () (values line column)))))
+(: make-rewindable-input-port (#!optional input-port -> input-port (-> input-port)))
(define (make-rewindable-input-port #!optional (port (current-input-port)))
(let ((buffer (open-output-string)))
(values (make-multiplexed-input-port buffer port)
(lambda () (make-concatenated-port* (get-output-string buffer) port)))))
+(: process-start! ((-> any) -> number input-port output-port))
(define (process-start! thunk)
(let*-values (((c-i p-o) (create-pipe))
((p-i c-o) (create-pipe))
@@ 113,11 118,13 @@
(file-close c-o)
(values pid (open-input-file* p-i) (open-output-file* p-o))))
+(: thread-waiter (input-port #!optional keyword -> (-> undefined)))
(define (thread-waiter port #!optional (mode #:all))
(condition-case (let ((fd (port->fileno port)))
(lambda () (thread-wait-for-i/o! fd #:input)))
((exn type) void)))
+(: copy-port* (input-port output-port #!optional (input-port -> any) (any output-port -> any) -> undefined))
(define (copy-port* input output #!optional (reader read-char) (writer write-char))
(let ((thread-wait-for-input! (thread-waiter input #:input)))
(copy-port
@@ 134,6 141,7 @@
(json-write x port)
(newline port))
+(: proxy (input-port output-port -> undefined))
(define (proxy input output)
(let-values (((input* rewind) (make-rewindable-input-port input)))
(handle-exceptions e
@@ 158,12 166,15 @@
((integer? x) (loop))
(else (signal 'scheme)))))))))
+(: proxy-scheme (input-port output-port -> undefined))
(define (proxy-scheme input output)
(copy-port* input output read json-write*))
+(: proxy-json (input-port output-port -> undefined))
(define (proxy-json input output)
(copy-port* input output json-read pretty-print))
+(: proxy-string (input-port output-port -> undefined))
(define (proxy-string input output)
(copy-port*
input
@@ 171,12 182,15 @@
(lambda (p) (read-string 65535 p))
(lambda (x p) (write-string x 65535 p))))
+(: syntax-error? (any -> boolean))
(define syntax-error?
(condition-predicate 'syntax))
+(: ->string* (any -> string))
(define (->string* x)
(with-output-to-string (lambda () (write x))))
+(: error-message (any (-> number number) -> string))
(define (error-message e location)
(format "~a: ~a~a~n"
(if (json-error? e) "parse error" "error")
@@ 191,6 205,7 @@
(string)
(string-append ": " (string-intersperse (map ->string* (arguments e)) ", ")))))
+(: process-input ((list-of string) (list-of pair) -> undefined))
(define (process-input args opts)
(let-values (((port location) (make-location-tracking-input-port)))
(handle-exceptions e
@@ 230,6 245,7 @@
(close-input-port input)
(signal 'ok))))))
+(: main ((list-of string) -> undefined))
(define (main args)
(let* ((opts (parse-command-line args options))
(args* (alist-ref '-- opts)))