PennMUSH Community

Changeset 1201

Show
Ignore:
Timestamp:
01/08/08 22:21:26 (7 months ago)
Author:
shawnw
Message:

Make several of the scheme scripts in utils work with guile as well as chicken.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/utils/columnize.scm

    r1198 r1201  
    1 #!/usr/local/bin/csi -script  
     1#!/usr/local/bin/csi -script 
     2#| !# ; |# 
    23;;; Formats words in columns for inclusion in help files.  
     4 
     5;; Works with chicken or guile 
    36 
    47;; Reads from standard input, prints to standard output. Intended to 
     
    1114;; Something like :jfadskjfq423jram utils/columnize.scm 
    1215;; 
     16;; (Or, using guile instead of chicken: guile -s utils/columize.scm) 
     17;; 
    1318;; Compiled instead of interpeted: 
    1419;; csc -o columize -O2 utils/columnize.scm 
    15 ;; 
     20;;    (display "|") 
    1621;; This is similar to column(1) but that doesn't always work the way 
    1722;; we need. This does. 
     
    2631 ((and chicken csi) 
    2732  (use srfi-1 srfi-13 regex)) 
    28  (else #t)) 
     33 (guile 
     34  (use-modules (srfi srfi-1) (srfi srfi-13) (ice-9 regex) 
     35           (ice-9 rdelim)) 
     36  (define fx= =) 
     37  (define fx+ +) 
     38  (define fx< <) 
     39  (define fx> >) 
     40  (define fxmax max) 
     41  (define (read-lines) 
     42    (let loop ((line (read-line)) 
     43           (accum '())) 
     44      (if (eof-object? line) 
     45      (reverse accum) 
     46      (loop (read-line) (cons line accum))))) 
     47  (define-macro (define-constant sym val) 
     48    `(define ,sym ,val)) 
     49  (define (string-split-fields re str) 
     50    (map match:substring (list-matches re str))))) 
    2951 
    3052(define-constant line-width 78) 
     
    3961  (drop-while (lambda (w) (fx= (string-length w) 0)) 
    4062          (sort 
    41            (string-split-fields "\\s+" 
    42                     (string-join (read-lines) " ") #:infix
     63           (string-split-fields "[A-Za-z0-9_@()-]+" 
     64                    (string-join (read-lines) " ")
    4365           string-ci<?))) 
    4466(define max-word-length (fold (lambda (w len)  
     
    4971 
    5072(define (print-word word column) 
    51   (cond 
     73  (cond  
    5274   ((fx= column 1) 
    5375    (display "  ")  
     
    6284    1))) 
    6385 
    64 (unless (fx= (fold print-word 1 words) 1) (newline)) 
     86(if (fx> (fold print-word 1 words) 1) (newline)) 
    6587     
    6688 
  • 1.8.3/branches/devel/utils/typedefs.scm

    • Property svn:executable set to *
    r807 r1201  
    1 #!/usr/bin/env csi -script # -*-scheme-*- 
     1#!/usr/local/bin/csi -script 
     2#| !# ; |# 
     3 
    24; Print out a list of all typedefs in the src in a format suitable for 
    35; using in the indent rule for src/Makefile. Requires chicken scheme. 
    46; http://call-with-current-continuation.org or your package manager. 
    57; 
     8; Also works with guile 1.8 
     9; 
    610; Written by Raevnos <shawnw@speakeasy.org> for PennMUSH. 
    711; 
    8 ; Version 0.9.1. 
     12; Version 0.9.2 
    913; 
    1014; Usage: 
     
    1923; You can also use it as an interpreted script: 
    2024; % csi -script utils/typedefs.scm < src/TAGS > indent.defs 
     25; or 
     26; % guile -s utils/typedefs.scm < src/TAGS > indent.defs 
    2127; or 
    2228; % chmod +x typedefs.scm 
     
    5056  (require-extension srfi-1) 
    5157  (require-extension srfi-13)) 
    52  (else #f)) 
     58 (guile 
     59  (use-modules (srfi srfi-1) (srfi srfi-13) (ice-9 rdelim) 
     60           (ice-9 format)) 
     61  (define fx>= >=) 
     62  (define fx+ +) 
     63  (define fx= =) 
     64  (define signal throw) 
     65  (define (for-each-line f in-port) 
     66    (let loop ((line (read-line in-port))) 
     67      (if (not (eof-object? line)) 
     68      (begin 
     69        (f line) 
     70        (loop (read-line in-port)))))) 
     71  (define-macro (handle-exceptions exn handler body) 
     72    `(catch #t 
     73        (lambda () ,body) 
     74        (lambda (,exn) ,handler))) 
     75  (define-macro (printf fmtstr . args) 
     76    `(format #t ,fmtstr ,@args)) 
     77  (define-macro (define-constant sym val) 
     78    `(define ,sym ,val)))) 
    5379 
    5480 
     
    6894 
    6995; The special characters that mark the start and end of an identifier 
    70 (define-constant type-start #\x7F
    71 (define-constant type-end #\x01
     96(define-constant type-start (integer->char 127)
     97(define-constant type-end (integer->char 1))
    7298 
    7399; Either return a typedef name or a symbol : 'line-did-not-match or 
     
    142168; Control pretty-printing of the typedefs. 
    143169(define-constant max-column-width 75) 
    144 (define-constant tab-stop 8) 
     170(define-constant tab-stop 8)) 
    145171 
    146172; Print out one typedef to stdout, formated as indent args.