1 ;;; punify --- Display Scheme code w/o unnecessary comments / whitespace
3 ;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public License
7 ;; as published by the Free Software Foundation; either version 3, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this software; see the file COPYING.LESSER. If
17 ;; not, write to the Free Software Foundation, Inc., 51 Franklin
18 ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;;; Author: Thien-Thi Nguyen
24 ;; Usage: punify FILE1 FILE2 ...
26 ;; Each file's forms are read and written to stdout.
27 ;; The effect is to remove comments and much non-essential whitespace.
28 ;; This is useful when installing Scheme source to space-limited media.
31 ;; $ wc ./punify ; ./punify ./punify | wc
32 ;; 89 384 3031 ./punify
35 ;; TODO: Read from stdin.
37 ;; Identifier punification.
41 (define-module (scripts punify)
44 (define %include-in-guild-list #f)
45 (define %summary "Strip comments and whitespace from a Scheme file.")
47 (define (write-punily form)
48 (cond ((and (list? form) (not (null? form)))
49 (let ((first (car form)))
52 (let loop ((ls (cdr form)) (last-was-list? (list? first)))
55 (let* ((new-first (car ls))
56 (this-is-list? (list? new-first)))
57 (and (not last-was-list?)
60 (write-punily new-first)
61 (loop (cdr ls) this-is-list?))))))
63 (let ((ls (string->list (symbol->string form))))
64 (and (char=? (car ls) #\:)
65 (not (memq #\space ls))
66 (list->string (cdr ls)))))
67 => (lambda (symbol-name-after-colon)
69 (display symbol-name-after-colon)))
72 (define (punify-one file)
73 (with-input-from-file file
75 (let ((toke (lambda () (read (current-input-port)))))
76 (let loop ((form (toke)))
77 (or (eof-object? form)
82 (define (punify . args)
83 (for-each punify-one args))