LJ Archive

Listing 3. Unix->DOS text file converter

#!/usr/bin/scm -f

;;; load in the line-oriented I/O package
(require `line-i/o)
(require `common-list-functions)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (main . argv)
  ;; read & write lines until EOF is reached
  (do ((line (read-line) (read-line)))
      ((eof-object? line) #t)
    (display (chomp line))
    (display #\return)
    (display #\newline)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; return #t if the character is either a carriage
;; return or a newline
;;
(define (lineterm? char)
  (case char
    ((#\newline #\return) #t)
    (else                 #f)))

[start block emphasis]

;; remove all carriage returns and newlines from
;; the end of a string and return the new string
;;
(define (chomp string)
  (list->string (remove-if lineterm? (string->list string))))

[end block emphasis]

(main)
(exit)
LJ Archive