Created
October 4, 2015 14:30
-
-
Save snmsts/5abde1792c14c8a36e6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#|-*- mode:lisp -*-|# | |
#| | |
exec ros -Q -- $0 "$@" | |
|# | |
(defvar *filters* '(/line)) | |
(defvar *results* '()) | |
(defun /line (output error) | |
(values | |
(lambda (input) | |
(loop :for line := (read-line input nil nil) | |
:while line | |
:do (funcall output line))) | |
error)) | |
(defun to-stream (stream) | |
(lambda (x) | |
(typecase x | |
(string (format stream "~A~%" x)) | |
((simple-array (unsigned-byte 8) (*)) | |
(write-sequence x stream)) | |
(t (format stream "~S~%" x))))) | |
(defun main (&rest argv) | |
(declare (ignorable argv)) | |
(loop | |
:with output := (let ((output (to-stream *standard-output*))) | |
(lambda (input) (funcall output input))) | |
:with error := (let ((output (to-stream *error-output*))) | |
(lambda (input) (funcall output input))) | |
:for f :in *filters* | |
:do (multiple-value-setq (output error) | |
(funcall f output error)) | |
:finally (funcall output *standard-input*)) | |
(mapc #'funcall *results*)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment