You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

#! /usr/bin/env sh
2 years ago
exec guile -e main -s "$0" "$@"
!#
2 years ago
(use-modules (bible-tools bible-tools)
(bible-tools count-words)
(srfi srfi-1)
(srfi srfi-26))
2 years ago
(define (show t)
(define (tabs w) (if (< (string-length (car w)) 7) "\t\t" "\t"))
(define (to-str w) (string-append (car w) ":" (tabs w)
(number->string (cdr w)) "\n"))
2 years ago
(for-each (compose display to-str) (count-words (map text t))))
(define (help)
2 years ago
(display "Usage: word-counter [book] [-c chapter]")
2 years ago
(display " [-h] [-v] [--bible b]\n")
(display "\t-c chapter count the words in this chapter\n")
(display "\t-h display this help message\n")
2 years ago
(display "\t-v display the current version\n")
(display "\t--bible b use this bible\n"))
(define (main args)
2 years ago
(define version "word-counter v1.0.0\n")
(define flag? (cut member <> args))
(define get (compose cadr flag?))
2 years ago
(let-syntax ((conf (syntax-rules (else)
((_ (f e)... (else g)) (cond ((flag? f) e)...
(else g))))))
(let ((bible (if (flag? "--bible") (get "--bible") "elb1871")))
(with-bible bible
(conf ("-h" (help))
("-v" (display version))
("-c"
(call-with-chapter (cadr args) (get "-c")
show))
(else (if (< (length args) 2) (help)
(call-with-book (cadr args)
show))))))))