Last active
July 20, 2017 15:38
-
-
Save b4284/fc75ad396e670161592eba4dc13601bb to your computer and use it in GitHub Desktop.
Mimic GNU yes' behavior of cmdline arguments.
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
| (use-modules (ice-9 binary-ports) | |
| (rnrs bytevectors)) | |
| (define (build-string s n) | |
| (let* ((s2 (string-append s "\n")) | |
| (s2len (string-length s2))) | |
| (let A ((s3 (string-copy s2)) | |
| (s3len s2len)) | |
| (if (> (+ s3len s2len) n) | |
| s3 | |
| (A (string-append s3 s2) (+ s3len s2len)))))) | |
| (define (yes args) | |
| (let ((args-str | |
| (let ((t (cdr args))) | |
| (if (null? t) "y" (string-join t " "))))) | |
| (let ((stdout (current-output-port)) | |
| (yyy (string->utf8 (build-string args-str 8192)))) | |
| (setvbuf stdout 'block 8192) | |
| (let A () | |
| (put-bytevector stdout yyy) | |
| (A))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment