ppfile.scm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ;;;; "ppfile.scm". Pretty print a Scheme file.
  2. ;Copyright (C) 1993, 1994 Aubrey Jaffer
  3. ;
  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
  6. ;understandings.
  7. ;
  8. ;1. Any copy made of this software must include this copyright notice
  9. ;in full.
  10. ;
  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.
  14. ;
  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
  18. ;each case.
  19. (require 'pretty-print)
  20. (define (pprint-filter-file inport filter . optarg)
  21. ((lambda (fun)
  22. (if (input-port? inport)
  23. (fun inport)
  24. (call-with-input-file inport fun)))
  25. (lambda (port)
  26. ((lambda (fun)
  27. (let ((outport
  28. (if (null? optarg) (current-output-port) (car optarg))))
  29. (if (output-port? outport)
  30. (fun outport)
  31. (call-with-output-file outport fun))))
  32. (lambda (export)
  33. (let () ;; ((old-load-pathname *load-pathname*))
  34. ;;(set! *load-pathname* inport) ;; FIXME
  35. (letrec ((lp (lambda (c)
  36. (cond ((eof-object? c))
  37. ((char-whitespace? c)
  38. (display (read-char port) export)
  39. (lp (peek-char port)))
  40. ((char=? #\; c)
  41. (cmt c))
  42. (else (sx)))))
  43. (cmt (lambda (c)
  44. (cond ((eof-object? c))
  45. ((char=? #\newline c)
  46. (display (read-char port) export)
  47. (lp (peek-char port)))
  48. (else
  49. (display (read-char port) export)
  50. (cmt (peek-char port))))))
  51. (sx (lambda ()
  52. (let ((o (read port)))
  53. (cond ((eof-object? o))
  54. (else
  55. (pretty-print (filter o) export)
  56. ;; pretty-print seems to have extra newline
  57. (let ((c (peek-char port)))
  58. (cond ((eqv? #\newline c)
  59. (read-char port)
  60. (set! c (peek-char port))))
  61. (lp c))))))))
  62. (lp (peek-char port)))
  63. ;;(set! *load-pathname* old-load-pathname)
  64. ))))))
  65. (define (pprint-file ifile #!optional (oport (current-output-port)))
  66. (pprint-filter-file ifile
  67. (lambda (x) x)
  68. oport))