diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-25 16:21:55 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-25 16:21:55 +0300 |
commit | 39e1ad85f7fb63156621112a28a876265d9fa1f0 (patch) | |
tree | 3607cb92f570680bb6c2016018e373834edd8b3d /scheme/idest/list-modules.scm | |
parent | c6230a46e93e9fb1525d5a036074aa7b5ff8a76e (diff) | |
download | idest-39e1ad85f7fb63156621112a28a876265d9fa1f0.tar.gz idest-39e1ad85f7fb63156621112a28a876265d9fa1f0.tar.bz2 |
Implement --batch option (a generalization of --format).
* NEWS: Update
* doc/idest.texi: Update.
* scheme/Makefile.am (EXTRA_DIST,site_DATA): Add batch.scm
(dist-hook): Exclude backup files.
* scheme/batch.scm: New file.
* scheme/idest/batch/help.scm: New file.
* scheme/idest/format/help.scm: Use list-modules.
* scheme/idest/format/shortlist.scm: Fix typo.
* scheme/idest/list-modules.scm: New file (from scheme/idest/format/help.scm).
* src/cmdline.opt: Remove the --function option.
New option --batch.
* src/guile.c (guile_function,guile_script): Remove.
(load_closure): Remove struct.
(load_handler,load_handler_path): data points to char **.
(guile_load): Change signature: filename is superfluous, use argv[0]
instead. All callers updated.
* src/idest.h (ed_list,guile_script,guile_function): Remove.
* src/main.c (dry_run_option,batch_name): New variables.
(set_guile_argv): New function.
(main): Handle batch_name and dry_run_option.
Diffstat (limited to 'scheme/idest/list-modules.scm')
-rw-r--r-- | scheme/idest/list-modules.scm | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/scheme/idest/list-modules.scm b/scheme/idest/list-modules.scm new file mode 100644 index 0000000..bd538ea --- /dev/null +++ b/scheme/idest/list-modules.scm @@ -0,0 +1,100 @@ +;; This file is part of Idest +;; Copyright (C) 2011 Sergey Poznyakoff +;; +;; Idest is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; Idest is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with Idest. If not, see <http://www.gnu.org/licenses/>. + +(define-module (idest list-modules)) + +(use-modules (ice-9 getopt-long) + (srfi srfi-1)) + +(define (strip-suffix name) + (call-with-current-continuation + (lambda (return) + (for-each + (lambda (suf) + (if (and (not (string-null? suf)) (string-suffix? suf name)) + (return + (substring name 0 (- (string-length name) (string-length suf)))))) + %load-extensions) + (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)))))) + + ;; 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))) + + + |