random-info-node

Thien-Thi Nguyen <[email protected]>
Newsgroups gmane.lisp.guile.user,gmane.lisp.guile.sources
Message-ID <[email protected]>
a small 5-minute toy while waiting for the hourly website update...
this will probably make it to http://www.glug.org/docbits/ at some point.

thi


____________________________________________________
#!/bin/sh
exec ${GUILE-guile} -s $0 "$@" # -*-scheme-*-
!#
;;; random-info-node
;;;
;;; Copyright (C) 2003 Thien-Thi Nguyen
;;; This program is released under the GNU GPL, v2 with ABSOLUTELY NO WARRANTY.
;;; See http://www.gnu.org/copyleft/gpl.txt for details.

;;; Commentary:

;; Usage: random-info-node [--list] [--sexp] INFO
;;
;; Display a random info node from INFO file to stdout.
;; Optional arg "--list" (or "-l") means to instead display a list of nodes.
;; Optional arg "--sexp" (or "-s") means to display the list as a sexp.

;;; Code:

(use-modules
 ((ice-9 rdelim) #:select (read-line))
 ((scripts PROGRAM) #:select (HVQC-MAIN))
 ((ice-9 regex) #:select (match:substring)))

(HVQC-MAIN (command-line)
           (lambda (qop)
             (set! *random-state* (seed->random-state (current-time)))
             (let ((rx (make-regexp (string-append
                                     "^Node: (.*)"
                                     (make-string 1 (integer->char 127)))))
                   (p (or (and (pair? (qop '()))
                               (open-input-file (car (qop '()))))
                          (error "No input file specified"))))
               (let loop ((line (read-line p)) (acc '()))
                 (cond ((eof-object? line)
                        (set! acc (reverse acc))
                        (cond ((qop 'sexp)
                               (format #t "~S\n" acc))
                              ((qop 'list)
                               (for-each write-line acc))
                              (else
                               (system
                                (format #f "info -o- -n '~A' -f ~A"
                                        (list-ref acc (random (length acc)))
                                        (car (qop '())))))))
                       ((regexp-exec rx line)
                        => (lambda (m)
                             (loop (read-line p)
                                   (cons (match:substring m 1) acc))))
                       (else
                        (loop (read-line p) acc))))))
           '(usage . commentary)
           '(version . "1.0")
           '(option-spec (list (single-char #\l))
                         (sexp (single-char #\s))))

;;; random-info-node ends here


_______________________________________________
Guile-user mailing list
[email protected]
http://mail.gnu.org/mailman/listinfo/guile-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.