diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-01 00:42:16 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-01 01:31:32 +0300 |
commit | 284a1ac48b35ef107979978fd443fbde6a6b4b12 (patch) | |
tree | 126db7b2837559bd678fb976f2cda43ccbac4e0a /scheme/idest/list-modules.scm | |
parent | 9a64ffcf42132cf27fdd5a59127985f1175234c3 (diff) | |
download | idest-284a1ac48b35ef107979978fd443fbde6a6b4b12.tar.gz idest-284a1ac48b35ef107979978fd443fbde6a6b4b12.tar.bz2 |
Finish the docs.
* doc/.gitignore: Update.
* doc/idest.texi: Document all new features.
* scheme/idest/batch/setlyrics.scm: Update --help output.
* scheme/idest/batch/setpic.scm: Likewise.
* scheme/idest/format/lyrics.scm: Likewise.
* scheme/idest/format/pic.scm: Likewise.
* scheme/idest/list-modules.scm: Implement the --which option.
* src/guile.c (%idest-package-site-dir)
(%idest-version-site-dir)
(%idest-guile-site-dir): New functions.
Diffstat (limited to 'scheme/idest/list-modules.scm')
-rw-r--r-- | scheme/idest/list-modules.scm | 154 |
1 files changed, 91 insertions, 63 deletions
diff --git a/scheme/idest/list-modules.scm b/scheme/idest/list-modules.scm index bd538ea..c69d331 100644 --- a/scheme/idest/list-modules.scm +++ b/scheme/idest/list-modules.scm @@ -31,70 +31,98 @@ (return #f)))) (define-public (idest-list-modules type) - (let ((saved-load-hook %load-hook) - ;; Collect a list of possible modules. List elements are conses: - ;; (basename . dir) - ;; where basename is the module name and dir is the directory where - ;; it is found. Make sure only one entry for each basename exists. - ;; Sort the list alphabetically on basename. - (candidates - (sort - (fold - (lambda (elt prev) - (catch 'misc-error - (lambda () - (let ((dir (string-append elt "/idest/" - (symbol->string type)))) - (if (and dir - (file-exists? dir) - (eq? (stat:type (stat dir)) 'directory)) - (let ((d (opendir dir))) - (let loop ((file (readdir d))) - (cond - ((not (eof-object? file)) - (if (eq? (stat:type - (stat (string-append dir "/" file))) - 'regular) - (let ((base (strip-suffix file))) - (if (and base - (not (assoc-ref prev base))) - (set! prev (cons (cons base dir) - prev))))) - (loop (readdir d))))))))) - (lambda (key . args) - #f)) - prev) - '() - %load-path) - (lambda (a b) - (string<? (car a) (car b)))))) + (let ((progname (car (command-line))) + (grammar `((which (single-char #\w)))) + (print-dir #f)) + (catch 'misc-error + (lambda () + (for-each + (lambda (x) + (case (car x) + ((which) + (set! print-dir #t)) + (else + (set-program-arguments (cons progname (cdr x)))))) + (getopt-long (command-line) grammar))) + (lambda (key . args) + (with-output-to-port + (current-error-port) + (lambda () + (format #t "~A: " progname) + (apply format #t (list-ref args 1) (list-ref args 2)) + (newline) + (exit 1))))) - ;; Try out each candidate and print ist name, directory and description - ;; if it happens to be a valid idest format module. - ;; Take care not to bail out on errors. Disable %load-hook as it migh - ;; clobber the output. - (set! %load-hook #f) - (for-each - (lambda (candidate) - (catch 'misc-error - (lambda () - (let ((mod (resolve-module - (list 'idest type - (string->symbol (car candidate)))))) - ; Check if it defines idest-main - (module-ref mod 'idest-main) - (format #t "~A (from ~A): ~A~%" - (car candidate) (cdr candidate) - (catch #t - (lambda () - (module-ref mod 'description)) - (lambda (key . args) - "no description"))))) - (lambda (key . args) - #f))) - candidates) - (newline) - (set! %load-hook saved-load-hook))) + (let ((saved-load-hook %load-hook) + ;; Collect a list of possible modules. List elements are conses: + ;; (basename . dir) + ;; where basename is the module name and dir is the directory where + ;; it is found. Make sure only one entry for each basename exists. + ;; Sort the list alphabetically on basename. + (candidates + (sort + (fold + (lambda (elt prev) + (catch 'misc-error + (lambda () + (let ((dir (string-append elt "/idest/" + (symbol->string type)))) + (if (and dir + (file-exists? dir) + (eq? (stat:type (stat dir)) 'directory)) + (let ((d (opendir dir))) + (let loop ((file (readdir d))) + (cond + ((not (eof-object? file)) + (if (eq? (stat:type + (stat + (string-append dir "/" file))) + 'regular) + (let ((base (strip-suffix file))) + (if (and base + (not (assoc-ref prev base))) + (set! prev (cons (cons base dir) + prev))))) + (loop (readdir d))))))))) + (lambda (key . args) + #f)) + prev) + '() + %load-path) + (lambda (a b) + (string<? (car a) (car b)))))) + + ;; Try out each candidate and print ist name, directory and description + ;; if it happens to be a valid idest format module. + ;; Take care not to bail out on errors. Disable %load-hook as it migh + ;; clobber the output. + (set! %load-hook #f) + (for-each + (lambda (candidate) + (catch 'misc-error + (lambda () + (let ((mod (resolve-module + (list 'idest type + (string->symbol (car candidate)))))) + ; Check if it defines idest-main + (module-ref mod 'idest-main) + ; Print module name + (display (car candidate)) + ; Its directory, if required + (if print-dir + (format #t " (~A)" (cdr candidate))) + ; A colon, and description (if any + (format #t ": ~A~%" + (catch #t + (lambda () + (module-ref mod 'description)) + (lambda (key . args) + "no description"))))) + (lambda (key . args) + #f))) + candidates) + (newline) + (set! %load-hook saved-load-hook)))) |