nendo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nendo CHANGED
@@ -1,7 +1,38 @@
1
- #!/usr/local/bin/ruby -W0
1
+ #!/usr/local/bin/ruby
2
2
  # -*- encoding: utf-8 -*-
3
3
  #
4
- # Nendo: "Nendo is a diarect of Lisp."
4
+ # nendo - "interpretter main program"
5
+ #
6
+ # Copyright (c) 2000-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
+ #
8
+ # Redistribution and use in source and binary forms, with or without
9
+ # modification, are permitted provided that the following conditions
10
+ # are met:
11
+ #
12
+ # 1. Redistributions of source code must retain the above copyright
13
+ # notice, this list of conditions and the following disclaimer.
14
+ #
15
+ # 2. Redistributions in binary form must reproduce the above copyright
16
+ # notice, this list of conditions and the following disclaimer in the
17
+ # documentation and/or other materials provided with the distribution.
18
+ #
19
+ # 3. Neither the name of the authors nor the names of its contributors
20
+ # may be used to endorse or promote products derived from this
21
+ # software without specific prior written permission.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ #
35
+ # $Id:
5
36
  #
6
37
  require 'nendo'
7
38
  require 'getoptlong'
@@ -4,32 +4,19 @@
4
4
 
5
5
  (load-library "text/html-lite")
6
6
  (load-library "text/tree")
7
+ (load-library "debug/syslog")
7
8
  (require "cgi")
8
9
  (require "RMagick")
9
10
 
10
- (define (response-dekamoji str pointsize)
11
- (let* ((font-dots pointsize)
12
- (margin (* pointsize 0.3))
13
- (image (Magick::Image.new (+ (* str.size font-dots) margin) (+ font-dots margin)))
14
- (imlist (Magick::ImageList.new))
15
- (dr (Magick::Draw.new)))
16
- (set! image.background_color "none")
17
- (set! image.format "PNG")
18
- (imlist.push image)
19
- ;;(set! dr.font "/Volumes/Macintosh HD/Library/Fonts/ホリデイMDJP03")
20
- ;;(set! dr.font "/Volumes/Macintosh HD/Library/Fonts/みかちゃん")
21
- ;;(set! dr.font "/Volumes/Macintosh HD/Library/Fonts/ヒラギノ丸ゴ ProN W4.otf")
22
- ;;(set! dr.font "/Volumes/Macintosh HD/Library/Fonts/ヒラギノ明朝 Pro W6.otf")
23
- (set! dr.font "/Volumes/Macintosh HD/Library/Fonts/ヒラギノ明朝 Pro W3.otf")
24
- (set! dr.pointsize pointsize)
25
- (set! dr.fill "#404040")
26
- (set! dr.stroke "#080808")
27
- (set! dr.font_weight Magick::BoldWeight)
28
- (set! dr.gravity Magick::CenterGravity)
29
- (dr.annotate imlist 0 0 0 0 str)
30
- (let1 blur (imlist.blur_image 1.0 1.0)
31
- (blur.to_blob))))
11
+ ;; ------ Please edit for your site -------
12
+ (define fontbase "/usr/local/lib/IPAfont-0302/")
13
+ ;; ----------------------------------------
32
14
 
15
+ (define font-list `(
16
+ ("1" "ゴシック" ,(+ fontbase "ipagp.ttf"))
17
+ ("2" "明朝" ,(+ fontbase "ipamp.ttf"))
18
+ ))
19
+ (define default-fonttype 2)
33
20
 
34
21
  (define default-wording "デカ文字")
35
22
  (define default-size 2)
@@ -40,16 +27,45 @@
40
27
  (4 . "サイズ特大")
41
28
  ))
42
29
 
30
+ (define (response-dekamoji str pointsize fontpath)
31
+ (let* ((font-dots pointsize)
32
+ (margin (* pointsize 0.3))
33
+ (tmp-image (Magick::Image.new 1 1))
34
+ (dr (Magick::Draw.new)))
35
+ (set! dr.font fontpath)
36
+ (set! dr.pointsize pointsize)
37
+ (set! dr.font_weight Magick::BoldWeight)
38
+ (set! dr.gravity Magick::CenterGravity)
39
+ (let* ((metrics (dr.get_multiline_type_metrics tmp-image str))
40
+ (image1 (Magick::Image.new (+ metrics.width 30) (+ metrics.height 30))))
41
+ (set! image1.format "PNG")
42
+ (set! dr.fill "#777799")
43
+ (set! dr.stroke "#8888AA")
44
+ (dr.annotate image1 0 0 5 5 str)
45
+ (let* ((image2 (image1.blur_channel 0 3 Magick::AllChannels)))
46
+ (set! dr.fill "#111111")
47
+ (set! dr.stroke "#606060")
48
+ (dr.annotate image2 0 0 0 0 str)
49
+ (image2.to_blob)))))
50
+
43
51
 
44
52
  (define (top-page params)
53
+ (define (calc-limit min val max)
54
+ (let* ((val (if (< val min) min val))
55
+ (val (if (< max val) max val)))
56
+ val))
57
+
45
58
  (let* ((size (if (hash-table-exist? params "size")
46
59
  (to-i (car (to-list (hash-table-get params "size"))))
47
60
  default-size))
48
61
  (wording (if (hash-table-exist? params "w")
49
62
  (car (to-list (hash-table-get params "w")))
50
- default-wording)))
51
- (let* ((size (if (> 1 size) 1 size))
52
- (size (if (< (length size-list) size) (length size-list) size)))
63
+ default-wording))
64
+ (fonttype (if (hash-table-exist? params "type")
65
+ (to-i (car (to-list (hash-table-get params "type"))))
66
+ default-fonttype)))
67
+ (let* ((size (calc-limit 1 size (length size-list)))
68
+ (fonttype (calc-limit 1 fonttype (length font-list))))
53
69
  `(
54
70
  ,(html-doctype)
55
71
  ,(html:head
@@ -60,9 +76,10 @@
60
76
  (html:p
61
77
  "下記に文章を入れて『画像化』ボタンを押して下さい")
62
78
  (html:form
63
- :method "GET"
79
+ :method "POST"
64
80
  :action "./dekamoji.cgi"
65
- (html:input :name "w" :type "text" :cols 140 :value wording)
81
+ (html:input :name "w" :type "text" :size 60 :value wording)
82
+ (html:br)
66
83
  (map
67
84
  (lambda (x)
68
85
  (list
@@ -72,29 +89,47 @@
72
89
  (cdr x)))
73
90
  size-list)
74
91
  (html:br)
92
+ (map
93
+ (lambda (x)
94
+ (list
95
+ (html:input :name "type" :type "radio"
96
+ :value (car x)
97
+ :CHECKED (eq? (to-i (car x)) fonttype))
98
+ (second x)))
99
+ font-list)
100
+ (html:br)
75
101
  (html:input :type "submit" :value "画像化"))
76
102
  (html:hr)
77
- (html:img :src (sprintf "./dekamoji.cgi?img=1&size=%d&w=%s" size wording))
103
+ (html:img :src (sprintf "./dekamoji.cgi?img=1&size=%d&type=%s&w=%s" size fonttype wording))
78
104
  (html:hr)))))))
79
105
 
80
106
  (define fontsize-alist '(
81
107
  ("1" . 40)
82
108
  ("2" . 80)
83
109
  ("3" . 160)
84
- ("4" . 260)
110
+ ("4" . 320)
85
111
  ))
86
112
 
87
- (let1 cgi (CGI.new)
88
- (cond ((hash-table-exist? cgi.params "img")
89
- (cgi.print
90
- (cgi.header "image/png"))
91
- (cgi.print
92
- (response-dekamoji
93
- (car (to-list (hash-table-get cgi.params "w")))
94
- (assv-ref (car (to-list (hash-table-get cgi.params "size"))) fontsize-alist))))
95
- (else
96
- (cgi.print
97
- (cgi.header))
98
- (cgi.print
99
- (tree->string
100
- (top-page cgi.params))))))
113
+ (if #f
114
+ ;; testing
115
+ (display
116
+ (response-dekamoji
117
+ "デカ文字"
118
+ 80
119
+ (+ fontbase "/IPAfont00302/ipam.ttf")))
120
+ ;; release
121
+ (let1 cgi (CGI.new)
122
+ (cond ((hash-table-exist? cgi.params "img")
123
+ (cgi.print
124
+ (cgi.header "image/png"))
125
+ (cgi.print
126
+ (response-dekamoji
127
+ (car (to-list (hash-table-get cgi.params "w")))
128
+ (assv-ref (car (to-list (hash-table-get cgi.params "size"))) fontsize-alist)
129
+ (second (assv-ref (car (to-list (hash-table-get cgi.params "type"))) font-list)))))
130
+ (else
131
+ (cgi.print
132
+ (cgi.header))
133
+ (cgi.print
134
+ (tree->string
135
+ (top-page cgi.params)))))))
@@ -0,0 +1,42 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;;
3
+ ;;; debug/syslog.nnd - #?= debug message output to syslog
4
+ ;;;
5
+ ;;;
6
+ ;;; Copyright (c) 2000-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
+ ;;;
8
+ ;;; Redistribution and use in source and binary forms, with or without
9
+ ;;; modification, are permitted provided that the following conditions
10
+ ;;; are met:
11
+ ;;;
12
+ ;;; 1. Redistributions of source code must retain the above copyright
13
+ ;;; notice, this list of conditions and the following disclaimer.
14
+ ;;;
15
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
16
+ ;;; notice, this list of conditions and the following disclaimer in the
17
+ ;;; documentation and/or other materials provided with the distribution.
18
+ ;;;
19
+ ;;; 3. Neither the name of the authors nor the names of its contributors
20
+ ;;; may be used to endorse or promote products derived from this
21
+ ;;; software without specific prior written permission.
22
+ ;;;
23
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ ;;;
35
+ ;;; $Id:
36
+ ;;;
37
+ (require "syslog")
38
+
39
+ (define (debug-print-output-func str)
40
+ (Syslog.open)
41
+ (Syslog.log Syslog::LOG_WARNING "%s" (+ "Nendo: " str))
42
+ (Syslog.close))
@@ -0,0 +1,53 @@
1
+
2
+ callProcedure( 'require',
3
+ begin
4
+ if @global_lisp_binding.has_key?('_require') then
5
+ @_require
6
+ else raise NameError.new( "Error: undefined variable _require", "_require" ) end
7
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:37"] + __e.backtrace ) ; raise __e
8
+ end ,
9
+ Cell.new(
10
+ "syslog"
11
+ ))
12
+ #--------------------
13
+
14
+ begin
15
+ @global_lisp_binding['_debug_MIMARKprint_MIMARKoutput_MIMARKfunc'] = true
16
+ @_debug_MIMARKprint_MIMARKoutput_MIMARKfunc =
17
+ Proc.new { |_str|
18
+ begin
19
+ Syslog.open(
20
+ )
21
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:40"] + __e.backtrace ) ; raise __e
22
+ end
23
+ begin
24
+ Syslog.log(
25
+ begin
26
+ Syslog::LOG_WARNING
27
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
28
+ end ,
29
+ "%s" ,
30
+ callProcedure( '+',
31
+ begin
32
+ if @global_lisp_binding.has_key?('__PLMARK') then
33
+ @__PLMARK
34
+ else raise NameError.new( "Error: undefined variable __PLMARK", "__PLMARK" ) end
35
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
36
+ end ,
37
+ Cell.new(
38
+ "Nendo: " ,Cell.new(
39
+ begin
40
+ _str
41
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
42
+ end
43
+ )))
44
+ )
45
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
46
+ end
47
+ begin
48
+ Syslog.close(
49
+ )
50
+ rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:42"] + __e.backtrace ) ; raise __e
51
+ end
52
+ }
53
+ end
data/lib/init.nnd CHANGED
@@ -1,4 +1,38 @@
1
1
  ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;;
3
+ ;;; init.nnd - Nendo's init file.
4
+ ;;;
5
+ ;;; Copyright (c) 2000-2010 Kiyoka Nishiyama <kiyoka@sumibi.org>
6
+ ;;;
7
+ ;;; Redistribution and use in source and binary forms, with or without
8
+ ;;; modification, are permitted provided that the following conditions
9
+ ;;; are met:
10
+ ;;;
11
+ ;;; 1. Redistributions of source code must retain the above copyright
12
+ ;;; notice, this list of conditions and the following disclaimer.
13
+ ;;;
14
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;;; notice, this list of conditions and the following disclaimer in the
16
+ ;;; documentation and/or other materials provided with the distribution.
17
+ ;;;
18
+ ;;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;;; may be used to endorse or promote products derived from this
20
+ ;;; software without specific prior written permission.
21
+ ;;;
22
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ ;;;
34
+ ;;; $Id:
35
+ ;;;
2
36
 
3
37
  ;; ----------------------------------------
4
38
  ;; define
@@ -72,7 +106,10 @@
72
106
  ;; ----------------------------------------
73
107
  ;; Utility functions
74
108
  ;; ----------------------------------------
75
- (define list? pair?)
109
+ (define (list? arg)
110
+ (if (pair? arg)
111
+ (list? (cdr arg))
112
+ (null? arg)))
76
113
  (define (even? n) (= (% n 2) 0))
77
114
  (define (odd? n) (not (= (% n 2) 0)))
78
115
  (define (zero? n) (= n 0))
@@ -244,8 +281,8 @@
244
281
  (else (if (zero? level)
245
282
  (cond ((eq? (car form) 'unquote) (car (cdr form)))
246
283
  ((eq? (car form) 'unquote-splicing)
247
- (error "Unquote-splicing wasn't in a list:"
248
- form))
284
+ (raise RuntimeError (+ "Error: Unquote-splicing wasn't in a list: " (write-to-string form))
285
+ (sprintf "%s:%s outside list." (*FILE*) (*LINE*))))
249
286
  ((and (pair? (car form))
250
287
  (eq? (car (car form)) 'unquote-splicing))
251
288
  (mappend form (car (cdr (car form)))
@@ -264,11 +301,12 @@
264
301
 
265
302
  (define unquote
266
303
  (macro (lst)
267
- (error "unquote appeared outside quasiquote")))
304
+ (raise RuntimeError "Error: unquote appeared outside quasiquote" (sprintf "%s:%s outside quasiquote" (*FILE*) (*LINE*)))))
305
+
268
306
 
269
307
  (define unquote-splicing
270
308
  (macro (lst)
271
- (error "unquote-splicing appeared outside quasiquote")))
309
+ (raise RuntimeError "Error: unquote-splicing appeared outside quasiquote" (sprintf "%s:%s outside quasiquote" (*FILE*) (*LINE*)))))
272
310
 
273
311
 
274
312
  (define when
@@ -563,11 +601,11 @@
563
601
  ,@(cddr lst))))))))
564
602
  (cond
565
603
  ((> 2 (length lst))
566
- (raise ArgumentError ". dot-operator requires 2+ arguments."))
604
+ (raise ArgumentError ". dot-operator requires 2+ arguments." (sprintf "%s:%s in dot-operator" (*FILE*) (*LINE*))))
567
605
  (else
568
606
  (if (symbol? (second lst))
569
607
  (generate-method-call-form lst)
570
- (raise TypeError ". dot-operator requires method name as symbol.")))))))
608
+ (raise TypeError ". dot-operator requires method name as symbol." (sprintf "%s:%s in dot-operator" (*FILE*) (*LINE*)))))))))
571
609
 
572
610
 
573
611
  (define (with-open filename pred . lst)
@@ -631,6 +669,12 @@
631
669
  (define (hash-table-delete! h key)
632
670
  (h.delete key))
633
671
 
672
+ (define (hash-table-push! ht key value)
673
+ (hash-table-put!
674
+ ht
675
+ key
676
+ (cons value (hash-table-get ht key '()))))
677
+
634
678
  (define (hash-table-keys h)
635
679
  (to-list (h.keys)))
636
680
 
@@ -647,7 +691,7 @@
647
691
 
648
692
  (define (hash-table->alist h)
649
693
  (if (not (h.is_a? Hash))
650
- (raise TypeError "Error: hash-table->alist expects Hash instance.")
694
+ (error "Error: hash-table->alist expects Hash instance.")
651
695
  (let1 keys (hash-table-keys h)
652
696
  (map
653
697
  (lambda (key)
@@ -656,7 +700,7 @@
656
700
 
657
701
  (define (alist->hash-table alist)
658
702
  (if (not (list? alist))
659
- (raise TypeError "Error: alist->hash-table expects alist.")
703
+ (error "Error: alist->hash-table expects alist.")
660
704
  (apply hash-table alist)))
661
705
 
662
706
  ;; ----------------------------------------
@@ -736,3 +780,11 @@
736
780
  (pp-list s 0 #f)
737
781
  (write s))
738
782
  (newline))
783
+
784
+
785
+ ;; ----------------------------------------
786
+ ;; global variables
787
+ ;; ----------------------------------------
788
+ (define *nendo-version*
789
+ "0.3.1" ;;NENDO-VERSION
790
+ )