1 ;;;; "ppfile.scm". Pretty print a Scheme file.
2 ;Copyright (C) 1993, 1994 Aubrey Jaffer
4 ;Permission to copy this software, to redistribute it, and to use it
5 ;for any purpose is granted, subject to the following restrictions and
8 ;1. Any copy made of this software must include this copyright notice
11 ;2. I have made no warrantee or representation that the operation of
12 ;this software will be error-free, and I am under no obligation to
13 ;provide any services, by way of maintenance, update, or otherwise.
15 ;3. In conjunction with products arising from the use of this
16 ;material, there shall be no use of my name in any advertising,
17 ;promotional, or sales literature without prior written consent in
20 (require 'pretty-print)
22 (define (pprint-filter-file inport filter . optarg)
24 (if (input-port? inport)
26 (call-with-input-file inport fun)))
30 (if (null? optarg) (current-output-port) (car optarg))))
31 (if (output-port? outport)
33 (call-with-output-file outport fun))))
35 (let ((old-load-pathname *load-pathname*))
36 (set! *load-pathname* inport)
37 (letrec ((lp (lambda (c)
38 (cond ((eof-object? c))
40 (display (read-char port) export)
41 (lp (peek-char port)))
46 (cond ((eof-object? c))
48 (display (read-char port) export)
49 (lp (peek-char port)))
51 (display (read-char port) export)
52 (cmt (peek-char port))))))
54 (let ((o (read port)))
55 (cond ((eof-object? o))
57 (pretty-print (filter o) export)
58 ;; pretty-print seems to have extra newline
59 (let ((c (peek-char port)))
60 (cond ((eqv? #\newline c)
62 (set! c (peek-char port))))
64 (lp (peek-char port)))
65 (set! *load-pathname* old-load-pathname)))))))
67 (define (pprint-file ifile . optarg)
68 (pprint-filter-file ifile
70 (if (null? optarg) (current-output-port) (car optarg))))