Annotation of OpenXM/src/kan96xx/Doc/httpd-asir.sm1, Revision 1.4
1.4 ! takayama 1: %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-asir.sm1,v 1.3 2001/04/21 08:18:03 takayama Exp $
1.1 takayama 2: %% http server by sm1
1.2 takayama 3:
4: /httpd.port 1200 def
1.4 ! takayama 5: /httpd.initialization
! 6: %% Put initialization codes here.
! 7: [
! 8: ("Risa/Asir web version 0.80. "+
! 9: " Risa/Asir oxasir version "+rtostr(version());)
! 10: ] cat
! 11: def
1.1 takayama 12: [(parse) (oxasir.sm1) pushfile] extension
13: (oxasir.started) boundp {
14: } {
15: [(x^2-1) (x)] fctr pop
16: } ifelse
17:
1.2 takayama 18: /httpd_startserver {
19: [(sm1.socket) (open) [httpd.port (localhost)]] extension
20: /server.fdAndPort set
1.1 takayama 21: (sm1.socket.open returns ) messagen server.fdAndPort message
22: [(sm1.socket) (accept) [server.fdAndPort 0 get]] extension
23: /server.fd set
24: (connected.) message
25: (sm1.socket.accept returns ) messagen server.fd message
26: } def
27:
1.2 takayama 28: /httpd_stopserver {
1.1 takayama 29: [(sm1.socket) (close) server.fd ] extension message
30: } def
31:
1.3 takayama 32: /send_packet {
1.1 takayama 33: /arg1 set
34: [(sm1.socket) (write) [server.fd 0 get arg1]] extension message
35: } def
36:
37: /sendln {
1.2 takayama 38: /arg1 set
39: [/in-sendln /mmm] pushVariables
40: [ arg1 /mmm set
1.1 takayama 41: mmm tag 5 eq {
42: [mmm 10 (string) dc] cat /mmm set
43: }{
44: 10 (string) dc /mmm set
45: } ifelse
46: [(sm1.socket) (write) [server.fd 0 get mmm]] extension message
1.2 takayama 47: ] pop
48: popVariables
1.1 takayama 49: } def
50:
51: /httpd {
1.4 ! takayama 52: /httpd.serial 0 def
1.3 takayama 53: /httpd.history [ ] def
1.1 takayama 54: {
1.2 takayama 55: httpd_startserver ;
56: httpd_action ;
57: httpd_stopserver ;
1.1 takayama 58: (5 sleep) system
1.3 takayama 59: httpd.serial 1 add /httpd.serial set
1.1 takayama 60: } loop
61: } def
62:
1.2 takayama 63: /httpd_action {
1.3 takayama 64: [/in-httpd /httpd.com.old /ff /httpd.com /httpd.result
65: ] pushVariables
1.2 takayama 66: [
1.1 takayama 67: {
68: /httpd.com.old ( ) def
69: [(sm1.socket) (select) [server.fd 0 get -1]] extension
70: %% wait for ever
71: [(sm1.socket) (read) [server.fd 0 get ]] extension /ff set
72: ff length 0 eq {
73: (connection is closed.) message
74: }
1.4 ! takayama 75: {
1.1 takayama 76: (------------ start ----------------------) message
77: ff message
78: (-----------------------------------------) message
79: ff removeGET webstringToAscii /httpd.com set
80: httpd.com message
81: (------------ end ----------------------) message
82: ( ) message
1.4 ! takayama 83: httpd.serial 0 eq {
! 84: /httpd.com httpd.initialization def
! 85: } { } ifelse
1.3 takayama 86: httpd.com metaCommand {
87: /httpd.history httpd.history httpd.com append def
88: oxasir.ccc
89: [(if (1) {) httpd.com (};)] cat
90: oxexecutestring ;
91: oxasir.ccc oxpopstring /httpd.result set
92: /httpd.com.old httpd.com def
93: (------------- result -------------) message
94: httpd.result message
95: (----------------------------------) message
96: ( ) message
1.4 ! takayama 97: [httpd.serial 0 eq { } {
! 98: (<title> asirweb </title> )
! 99: (<font color="blue"> Input-) httpd.serial toString
! 100: (: </font> )
! 101: (<pre> ) httpd.com (</pre>) (<br>)
! 102: } ifelse
1.3 takayama 103: (<font color="green"> Output-) httpd.serial toString
104: (: </font> )
105: (<pre>) httpd.result (</pre>)
106: ] cat
107: send-page-3 exit
1.4 ! takayama 108: } { } ifelse %% metaCommand
1.1 takayama 109: } ifelse
110: } loop
1.2 takayama 111: ] pop
112: popVariables
1.1 takayama 113: } def
114:
115:
1.3 takayama 116: /send-page-bye {
1.1 takayama 117: (HTTP/0.9 200 OK) sendln
118: %% (Date: Sun, 18 Mar 2001 02:54:50 GMT) sendln
119: %% (Server: sm1/0.1 (Unix)) sendln
120: %% (Last-Modified: Wed, 23 Aug 2000 11:19:27 GMT) sendln
121: %% (ETag: "1f8f-5df-39a3b33f") sendln
122: %% (Accept-Ranges: bytes) sendln
123: %% (Content-Length: 10) sendln
124: (Connection: close) sendln
1.3 takayama 125: % (Content-Type: text/plain) sendln
126: (Content-Type: text/html) sendln
1.1 takayama 127: 0 sendln
1.3 takayama 128: (<html>) sendln
129: (Shutdown the engine. <br>) sendln
130: (See you! <a href="http://www.openxm.org"> asirweb </a>) sendln
131: (</html>) sendln
1.1 takayama 132: 0 sendln
133: [(flush)] extension
134: } def
135:
136: /send-page-2 {
137: (HTTP/0.9 200 OK) sendln
138: %% (Content-Length: 10) sendln
139: (Connection: close) sendln
140: (Content-Type: text/html) sendln
141: 0 sendln
142: (<FORM NAME="myFORM">) sendln
143: (<INPUT TYPE="TEXT" NAME="Num">) sendln
144: (</FORM>) sendln
145: 0 sendln
146: [(flush)] extension
147: } def
148:
149: /send-page-3 {
150: /arg1 set
151: [/in-send-page-3 /result] pushVariables
152: [
153: /result arg1 def
154: (HTTP/0.9 200 OK) sendln
155: (Connection: close) sendln
156: (Content-Type: text/html) sendln
157: 0 sendln
158: %% (<FORM NAME="myFORM" METHOD="POST">) sendln
159: result sendln
160: (<FORM NAME="myFORM">) sendln
161: (<INPUT TYPE=submit VALUE="submit">) sendln
1.2 takayama 162: (<textarea name=msg rows=10 cols="80" wrap="soft"></textarea>) sendln
1.1 takayama 163: (</FORM>) sendln
1.3 takayama 164: send-menu-1
1.1 takayama 165: 0 sendln
166: [(flush)] extension
167: ] pop
168: popVariables
169: } def
170:
1.3 takayama 171: /httpd.asirman
172: ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.1.3/doc/asir2000/html-jp/man_toc.html")
173: def
174: /httpd.asirman.index
175: ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.1.3/doc/asir2000/html-jp/man_262.html#SEC262")
176: def
1.4 ! takayama 177: /httpd.asir.intro
! 178: ("http://www.math.sci.kobe-u.ac.jp/~taka/asir-book-html/main")
! 179: def
1.3 takayama 180: /send-menu-1 {
181:
1.4 ! takayama 182: (FILE:) sendln
1.3 takayama 183: [$<a href="http://localhost:$ httpd.port toString
1.4 ! takayama 184: $/?msg=httpdAsirMeta+quit"> Shutdown the asir server. </a>, $
1.3 takayama 185: ] cat sendln
1.4 ! takayama 186: ( <spacer type=horizontal size=80> ) sendln
1.3 takayama 187:
1.4 ! takayama 188: (HELP:) sendln
1.3 takayama 189: [(<font color="red">
1.4 ! takayama 190: <a href=) httpd.asirman ( > AsirManual (Ja) </a> </font>, )] cat sendln
1.3 takayama 191: [(<font color="purple">
1.4 ! takayama 192: <a href=) httpd.asirman.index ( > Index (Ja) </a> </font>, )] cat sendln
! 193: [(<font color="blue">
! 194: <a href=) httpd.asir.intro ( > Intro (Ja) </a> </font>, )] cat sendln
1.3 takayama 195: } def
1.1 takayama 196:
197: /stopclient {
198: [(sm1.socket) (close) [client.fdAndPort 0 get] ] extension message
199: } def
200:
201:
202: /fromHex {
203: /arg1 set
204: [/in-fromHex /s1 /s2 /c /c2] pushVariables
205: [
206: arg1 0 get /s1 set
207: arg1 1 get /s2 set
208:
209: 48 s1 le s1 57 le and { % 0, ..., 9
210: s1 48 sub /c set
211: }{ } ifelse
212: 65 s1 le s1 70 le and { % A, ..., F
213: s1 65 sub 10 add /c set
214: }{ } ifelse
215: 97 s1 le s1 102 le and { % a, ..., f
216: s1 97 sub 10 add /c set
217: }{ } ifelse
218: c 16 mul /c set
219:
220: 48 s2 le s2 57 le and { % 0, ..., 9
221: s2 48 sub /c2 set
222: }{ } ifelse
223: 65 s2 le s2 70 le and { % A, ..., F
224: s2 65 sub 10 add /c2 set
225: }{ } ifelse
226: 97 s2 le s2 102 le and { % a, ..., f
227: s2 97 sub 10 add /c2 set
228: }{ } ifelse
229: c c2 add /arg1 set
230: ] pop
231: popVariables
232: arg1
233: } def
234:
235: /removeGET {
236: /arg1 set
237: [/in-removeGET /s /s2 /i /j] pushVariables
238: [
239: /s arg1 def
240: s 1 copy /s2 set
241: s (array) dc /s set
242: /j 0 def
243: 10 1 s length 1 sub {
244: /i set
245: s2 j << s i get (string) dc >> put
246: j 1 add /j set
247: } for
248: /arg1 s2 def
249: ] pop
250: arg1
251: } def
252:
253: /webstringToAscii {
254: /arg1 set
255: [/in-webstringToAscii /s /i /j /c /n] pushVariables
256: [
257: /s arg1 def
258: s (array) dc /s set
259: /j 0 def /n s length def
260: /i 0 def
261: {
262: s i get /c set
263: c 32 eq { exit } { } ifelse
264: c 37 eq { % c == %
265: [s i 1 add get s i 2 add get] fromHex /c set
266: s j c put
267: j 1 add /j set
268: i 3 add /i set
269: } {
270: c 43 eq { % c == +
271: s j 32 put
272: j 1 add /j set
273: i 1 add /i set
274: } {
275: c 13 eq { % c == 0xd
276: i 1 add /i set
277: } {
278: s j c put
279: j 1 add /j set
280: i 1 add /i set
281: } ifelse
282: } ifelse
283: } ifelse
284: i n ge { exit } { } ifelse
285: } loop
286: s j carN /s set
287: s { (string) dc } map cat /arg1 set
288: ] pop
289: popVariables
290: arg1
1.3 takayama 291: } def
292:
293: /metaCommand {
294: /arg1 set
295: [/in-metaCommand /msg /result] pushVariables
296: [
297: /msg arg1 def
298: /result 1 def
299: msg (httpdAsirMeta quit) eq {
300: send-page-bye
301: quit
302: /result 0 def
303: } { } ifelse
304: /arg1 result def
305: ] pop
306: popVariables
307: arg1
308: } def
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>