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