#!/local/gauche/bin/gosh (define attrs (make-hash-table 'string=?)) (define (dosomething) (hash-table-for-each attrs (lambda (key value) (cond ((string=? key "starts") (print "Got starts")) ((string=? key "ends") (print "Got ends")) ((string=? key "hardware") (if (string=? (car value) "ethernet") (print "Ethernet address: " (cadr value)) (print "Unknown hardware type: " (car value)))))))) (define (gobble-lease-text) (port-for-each (lambda (line) (if (string=? line "}") (dosomething) (let ((items (string-split (string-scan line ";" 'before) #\space))) (hash-table-put! attrs (car items) (cdr items))))) read-line)) (define (parse-leases ip) (call/cc (lambda (leave-loop) (port-for-each (lambda (line) (rxmatch-if (rxmatch #/^lease (\d+.\d+.\d+.\d+)\s+\{/ line) (#f tip) (if (string=? ip tip) (begin (gobble-lease-text) (leave-loop))) #f)) read-line)))) (define (main args) (if (null? (cdr args)) (print "usage: " (car args) " ip-address") (parse-leases (cadr args))))