fork download
  1. ; file bundles
  2.  
  3. (define (read-line . port)
  4. (define (eat p c)
  5. (if (and (not (eof-object? (peek-char p)))
  6. (char=? (peek-char p) c))
  7. (read-char p)))
  8. (let ((p (if (null? port) (current-input-port) (car port))))
  9. (let loop ((c (read-char p)) (line '()))
  10. (cond ((eof-object? c) (if (null? line) c (list->string (reverse line))))
  11. ((char=? #\newline c) (eat p #\return) (list->string (reverse line)))
  12. ((char=? #\return c) (eat p #\newline) (list->string (reverse line)))
  13. (else (loop (read-char p) (cons c line)))))))
  14.  
  15. (define (write-header)
  16. (for-each (lambda (x) (display x) (newline))
  17. '("#! /usr/bin/petite --script"
  18. "(define (do-file f)"
  19. " (define (write-line x) (display x) (newline))"
  20. " (with-output-to-file (car f) (lambda ()"
  21. " (for-each write-line (cdr f)))))"
  22. "(for-each do-file '(")))
  23.  
  24. (define (do-file f)
  25. (display "(") (write f) (newline)
  26. (with-input-from-file f (lambda ()
  27. (do ((x (read-line) (read-line)))
  28. ((eof-object? x))
  29. (write x) (newline))))
  30. (display ")") (newline))
  31.  
  32. (define (bundle out-file . in-files)
  33. (with-output-to-file out-file (lambda ()
  34. (write-header)
  35. (for-each do-file in-files)
  36. (display "))") (newline))))
Success #stdin #stdout 0s 7272KB
stdin
Standard input is empty
stdout