From 0ac7b141f833296e229f0daabe5b4274adf681f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Apr 2022 19:03:55 +0200 Subject: Rewrote script get-config. Now works with new config system. Also outputs result as an ini-file. --- scripts/get-config.scm | 80 +++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 49 deletions(-) (limited to 'scripts') diff --git a/scripts/get-config.scm b/scripts/get-config.scm index f1088c8e..7d6abfcd 100755 --- a/scripts/get-config.scm +++ b/scripts/get-config.scm @@ -9,61 +9,43 @@ (add-to-load-path "module") +(add-to-load-path "scripts") (use-modules (hnh util) (ice-9 ftw) (ice-9 match) (srfi srfi-1) - ) - -(define (read-multiple) - (let loop ((done '())) - (let ((sexp (read))) - (if (eof-object? sexp) - (reverse done) - (loop (cons sexp done)))))) - -(define remove-stat - (match-lambda - ((name state) name) - ((name stat children ...) - (cons name (map remove-stat children))))) + (srfi srfi-88) -(define (f tree) - (let loop ((rem tree) (path '())) - (cond [(string? rem) - (string-join (reverse (cons rem path)) "/" 'infix)] - [(null? rem) - '()] - [else - (map (lambda (branch) - (loop branch (cons (car rem) path))) - (cdr rem))]))) + (all-modules) + (module-introspection) + ((calp translation) + :select (translate)) + ) -((@ (ice-9 pretty-print) pretty-print) - (filter - (lambda (form) - (and (list? form) (not (null? form)) - (eq? 'define-config (car form)))) - (concatenate - (map (lambda (filename) (with-input-from-file filename read-multiple)) - (flatten (f (remove-stat (file-system-tree "module")))))))) - -;; expected result => -#; -((config debug) - (config edit-mode) - (config summary-filter) - (config description-filter) - (config - tz-dir - "Directory in which zoneinfo files can be found") - (config - tz-list - "List of default zoneinfo files to be parsed") - (config default-week-start "First day of week") - (config - calendar-files - "Which files to parse. Takes a list of paths or a single string which will be globbed.")) +;; TODO split this into separate read and write stages +;; TODO and add texinfo output (besides ini output) +(for (filename module-name) + in (all-files-and-modules-under-directory "module") + (define forms (call-with-input-file filename get-forms)) + (define configurations + (filter (lambda (form) + (and (list? form) (not (null? form)) + (eq? 'define-config (car form)))) + forms)) + (unless (null? configurations) + (format #t "~%[~{~a~^ ~}]" module-name) + (for-each (match-lambda + (('define-config name default kvs ...) + (cond ((memv description: kvs) + => (match-lambda + ((description: ('_ desc) rest ...) + (format #t "~%; ~a" + (gettext desc "calp"))) + ((description: desc rest ...) + (format #t "~%; ~a" desc))))) + (format #t "~%~a = ~s~%" + name default))) + configurations))) -- cgit v1.2.3