guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

random-info-node


From: Thien-Thi Nguyen
Subject: random-info-node
Date: Thu, 23 Oct 2003 22:51:19 +0200

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]