ppfile.out 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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)
  29. (current-output-port)
  30. (car optarg))))
  31. (if (output-port? outport)
  32. (fun outport)
  33. (call-with-output-file outport fun))))
  34. (lambda (export)
  35. (let ()
  36. (letrec ((lp (lambda (c)
  37. (cond ((eof-object? c))
  38. ((char-whitespace? c)
  39. (display (read-char port) export)
  40. (lp (peek-char port)))
  41. ((char=? #\; c) (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. (let ((c (peek-char port)))
  57. (cond ((eqv? #\newline c)
  58. (read-char port)
  59. (set! c (peek-char port))))
  60. (lp c))))))))
  61. (lp (peek-char port)))))))))
  62. (define (pprint-file
  63. ifile
  64. #!optional
  65. (oport (current-output-port)))
  66. (pprint-filter-file ifile (lambda (x) x) oport))