Commit | Line | Data |
---|---|---|
28c31342 TTN |
1 | #!/bin/sh |
2 | # aside from this initial boilerplate, this is actually -*- scheme -*- code | |
3 | main='(module-ref (resolve-module '\''(scripts punify)) '\'main')' | |
4 | exec ${GUILE-guile} -c "(apply $main (cdr (command-line)))" "$@" | |
5 | !# | |
6 | ;;; punify --- Display Scheme code w/o unnecessary comments / whitespace | |
7 | ||
8 | ;; Copyright (C) 2001 Free Software Foundation, Inc. | |
9 | ;; | |
10 | ;; This program is free software; you can redistribute it and/or | |
11 | ;; modify it under the terms of the GNU General Public License as | |
12 | ;; published by the Free Software Foundation; either version 2, or | |
13 | ;; (at your option) any later version. | |
14 | ;; | |
15 | ;; This program is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | ;; General Public License for more details. | |
19 | ;; | |
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with this software; see the file COPYING. If not, write to | |
22 | ;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
23 | ;; Boston, MA 02111-1307 USA | |
24 | ||
e8cd769d TTN |
25 | ;;; Author: Thien-Thi Nguyen |
26 | ||
28c31342 TTN |
27 | ;;; Commentary: |
28 | ||
29 | ;; Usage: punify FILE1 FILE2 ... | |
30 | ;; | |
31 | ;; Each file's forms are read and written to stdout. | |
32 | ;; The effect is to remove comments and much non-essential whitespace. | |
33 | ;; This is useful when installing Scheme source to space-limited media. | |
34 | ;; | |
35 | ;; Example: | |
36 | ;; $ wc ./punify ; ./punify ./punify | wc | |
37 | ;; 81 355 2622 ./punify | |
38 | ;; 0 34 694 | |
39 | ;; | |
40 | ;; TODO: Read from stdin. | |
41 | ;; Handle vectors. | |
42 | ;; Identifier punification. | |
28c31342 TTN |
43 | |
44 | ;;; Code: | |
45 | ||
46 | (define-module (scripts punify) | |
47 | :export (punify)) | |
48 | ||
49 | (define (write-punily form) | |
50 | (if (and (list? form) (not (null? form))) | |
51 | (let ((first (car form))) | |
52 | (display "(") | |
53 | (write-punily first) | |
54 | (let loop ((ls (cdr form)) (last-was-list? (list? first))) | |
55 | (if (null? ls) | |
56 | (display ")") | |
57 | (let* ((new-first (car ls)) | |
58 | (this-is-list? (list? new-first))) | |
59 | (and (not last-was-list?) | |
60 | (not this-is-list?) | |
61 | (display " ")) | |
62 | (write-punily new-first) | |
63 | (loop (cdr ls) this-is-list?))))) | |
64 | (write form))) | |
65 | ||
66 | (define (punify-one file) | |
67 | (with-input-from-file file | |
68 | (lambda () | |
69 | (let ((toke (lambda () (read (current-input-port))))) | |
70 | (let loop ((form (toke))) | |
71 | (or (eof-object? form) | |
72 | (begin | |
73 | (write-punily form) | |
74 | (loop (toke))))))))) | |
75 | ||
76 | (define (punify . args) | |
77 | (for-each punify-one args)) | |
78 | ||
79 | (define main punify) | |
80 | ||
81 | ;;; punify ends here |