parse.ss
#lang scheme

(define (write-line ip l)
  (write-bytes l ip)
  (newline ip))

(define (is-c? l)
  (and (regexp-match #rx"^@-*@$" l)
       #t))

(define (split-port ip)
  (define-values (scheme-port send-to-scheme-port) (make-pipe))
  (define-values (c-port send-to-c-port) (make-pipe))
  
  (let loop ([seen-c? #f])
    (let ([l (read-bytes-line ip)])
      (cond
        [(eof-object? l)
         (close-output-port send-to-c-port)]
        [seen-c?
         (write-line send-to-c-port l)
         (loop #t)]
        [(is-c? l)
         (close-output-port send-to-scheme-port)
         (loop #t)]
        [else
         (write-line send-to-scheme-port l)
         (loop #f)])))
  
  (values scheme-port c-port))

(provide/contract
 [split-port (input-port? . -> . (values input-port? input-port?))])