diff --git a/brmsaptool.scm b/brmsaptool.scm index b4015f4..cf2b17e 100644 --- a/brmsaptool.scm +++ b/brmsaptool.scm @@ -50,6 +50,10 @@ (members-base-tests!) (newline) +;; Command-line options and configurable parameters +(define *members-directory* (make-parameter "members")) + +;; Arguments parsing (command-line print-help (-h () "This help" @@ -58,9 +62,13 @@ (print-help) (newline) (exit 0)) + (-MB (dir) "Members base directory" (*members-directory* dir)) (-mfkw () "Member-File invalid Key Warning" (*member-file-check-syntax* 'warning)) (-mfkq () "Member-File invalid Key Quiet" (*member-file-check-syntax* 'quiet)) (-mfec (n) "Member-File parser Error Context (lines)" (*member-file-context* (string->number n)))) -(load-members "members" #t) +;; Load the members database (required for everything anyway) +(define MB (load-members "members" #t)) +;; ... +(void) diff --git a/dictionary.scm b/dictionary.scm index f6672f6..b221df8 100644 --- a/dictionary.scm +++ b/dictionary.scm @@ -34,6 +34,7 @@ dict-keys dict-map dict-filter + dict-reduce dictionary-tests! ) @@ -117,6 +118,16 @@ (cons (car d) r) r))))) + ;; Reduce over dictinary, the reducing procedure gets accumulator, + ;; key and value as its three arguments. + (define (dict-reduce init proc d) + (let loop ((d d) + (acc init)) + (if (null? d) + acc + (loop (cdr d) + (proc acc (caar d) (cdar d)))))) + ;; Performs self-tests of the dictionary module. (define (dictionary-tests!) (run-tests @@ -144,6 +155,9 @@ '((a . 1) (b . 2))) '((a . 1))) + (test-eq? dict-reduce + (dict-reduce 0 (lambda (a k v) (+ a v)) '((a . 1) (b . 2))) + 3) )) ) diff --git a/members-base.scm b/members-base.scm index 187b9b5..8a086c9 100644 --- a/members-base.scm +++ b/members-base.scm @@ -117,6 +117,15 @@ #t (loop (cdr lst)))))) + ;; Returns the first 4-digit symbol from the list. + (define (get-4digit-symbol-from-list lst) + (let loop ((lst lst)) + (if (null? lst) + #f + (if (is-4digit-symbol? (car lst)) + (car lst) + (loop (cdr lst)))))) + ;; Returns dictionary containing only records with either 4-digit ;; name or one of its aliases being 4-digit. (define (files-dictionary-filter-4digit-symbols d) @@ -138,7 +147,8 @@ (make-pathname mdir fname))))) ;; Loads members database, if the second argument is true, shows - ;; progress. + ;; progress. Members database is a dictionary with id being the key + ;; (number) and member record being the value. (define (load-members dn . opts) (let ((progress? (and (not (null? opts)) (car opts)))) @@ -147,17 +157,33 @@ (let* ((fss (files-dictionary-filter-4digit-symbols (files+symlinks->files-dictionary (get-files+symlinks dn)))) - (mb (dict-map + (mb0 (dict-map (lambda (symfn symlinks) (when progress? (display ".")) (members-base-load-member dn (symbol->string symfn) symlinks)) - fss))) + fss)) + (mb (dict-reduce (make-dict) + (lambda (acc key val) + #f) + mb0))) (when progress? (print " ok.")) - mb))) + mb0))) + + (define (find-member-by-id mb id) + #f) + + (define (find-member-by-nick mb nick) + #f) + + (define (list-members-ids mb) + #f) + + (define (list-members-nicks mb) + #f) ;; Performs self-tests of this module. (define (members-base-tests!) @@ -181,6 +207,9 @@ (test-false is-4digit-symbol? (is-4digit-symbol? '|ABC|)) (test-true list-contains-4digit-symbol? (list-contains-4digit-symbol? '(|0000| abc |666|))) (test-false list-contains-4digit-symbol? (list-contains-4digit-symbol? '(|00000| abc |666|))) + (test-eq? get-4digit-symbol-from-list + (get-4digit-symbol-from-list '(|000| abc |6666| qwer)) + '|6666|) )) )