File: embed.scm

package info (click to toggle)
scmail 1.3-4.1
  • links: PTS
  • area: main
  • in suites: bullseye, forky, sid, trixie
  • size: 592 kB
  • sloc: lisp: 1,535; sh: 178; makefile: 145
file content (30 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(use gauche.regexp)
(use gauche.charconv)

(define (escape str)
  (set! str (regexp-replace-all #/&/ str "&"))
  (set! str (regexp-replace-all #/</ str "&lt;"))
  (set! str (regexp-replace-all #/\"/ str "&quot;"))
  (set! str (regexp-replace-all #/@/ str "&#64;"))
  (set! str (regexp-replace-all #/>/ str "&gt;"))
  str)

(define (read-file-and-escape file)
  (call-with-input-file file
    (lambda (in)
      (escape (port->string in)))
    :encoding 'utf-8))

(define (main args)
  (call-with-input-file (cadr args)
    (lambda (in)
      (let* ((content (port->string in))
             (content (regexp-replace-all #/#\{(.*?)\}/ content
                                          (lambda (m)
                                            (string-append 
                                             "<pre>\n"
                                             (read-file-and-escape (rxmatch-substring m 1))
                                             "</pre>\n")))))
        (display content)))
    :encoding 'eucjp)
  0)