Compare commits

..

No commits in common. "938fd7d41bdb6b5bac5034a85adf0e0b30aefe6e" and "7a24be4b9c2e0bbf6aa3a11bcbb585d11e94b71b" have entirely different histories.

View File

@ -4,43 +4,43 @@
(define (tsv-fields line) (define (tsv-fields line)
(reverse (reverse
(let iter ((len (string-length line)) (let iter ((len (string-length line))
(rem (string-copy line)) (rem (string-copy line))
(idx 0) (idx 0)
(res '())) (res '()))
(cond ((>= idx len) (cons rem res)) (cond ((>= idx len) (cons rem res))
((char=? #\tab (string-ref rem idx)) ((char=? #\tab (string-ref rem idx))
(iter (- len idx 1) (iter (- len idx 1)
(substring rem (+ idx 1) len) (substring rem (+ idx 1) len)
0 0
(cons (substring rem 0 idx) res))) (cons (substring rem 0 idx) res)))
(else (iter len rem (+ idx 1) res)))))) (else (iter len rem (+ idx 1) res))))))
(define (vcard name number) (define (vcard name number)
(with-output-to-string (with-output-to-string
(lambda () (lambda ()
(display "BEGIN:VCARD") (display "BEGIN:VCARD")
(newline) (newline)
(display "N:;") (display "N:;")
(display name) (display name)
(display ";;;") (display ";;;")
(newline) (newline)
(display "TEL;TYPE=cell:") (display "TEL;TYPE=cell:")
(display number) (display number)
(newline) (newline)
(display "END:VCARD") (display "END:VCARD")
(newline)))) (newline))))
(define (tsv-contact->vcard line) (define (tsv-contact->vcard line)
(let* ((fields (tsv-fields line)) (let* ((fields (tsv-fields line))
(number (list-ref fields 0)) (number (list-ref fields 0))
(name (list-ref fields 1))) (name (list-ref fields 1)))
(vcard name number))) (vcard name number)))
(define (foreach-line thunk) (define (foreach-line thunk)
(let loop () (let loop ()
(let ((line (get-line (current-input-port)))) (let ((line (get-line (current-input-port))))
(unless (eof-object? line) (when (not (eof-object? line))
(display (thunk line)) (display (thunk line))
(loop))))) (loop)))))
(foreach-line tsv-contact->vcard) (foreach-line tsv-contact->vcard)