2 \ #
! /home
/ygrek
/work
/forth
/spf
/spf4
4 REQUIRE ATTACH ~pinka
/samples
/2005/lib
/append
-file
.f
5 REQUIRE USER
-TYPE ~ygrek
/lib
/typestr
.f
6 \
:NONAME
2DROP
; TO USER
-TYPE \ no stdout
8 REQUIRE XSLTmm ~ac
/lib
/lin
/xml
/xslt
.f
9 REQUIRE XHTML ~ygrek
/lib
/xhtml
/core
.f
10 REQUIRE DumpParams ~ac
/lib
/string
/get_params
.f
11 REQUIRE EQUAL ~pinka
/spf
/string
-equal
.f
12 REQUIRE NOT ~profit
/lib
/logic
.f
13 REQUIRE cat ~ygrek
/lib
/cat
.f
14 REQUIRE ALLOCATED ~pinka
/lib
/ext
/basics
.f
15 REQUIRE NUMBER ~ygrek
/lib
/parse
.f
16 REQUIRE DateTime
>PAD ~ygrek
/lib
/spec
/unixdate
.f
17 REQUIRE FileLines
=> ~ygrek
/lib
/filelines
.f
18 REQUIRE
READ-FILE
-EXACT ~pinka
/lib
/files
-ext
.f
19 \ REQUIRE CREATE
-ANON
-PIPE ~ygrek
/lib
/sys
/pipe
.f
29 S
" /bin/sh" DROP DUP
2 <( S
" -c" DROP R
> 0 )) execlp \ no
return
32 : sys
( a u
-- ) DROP
(sys
) DROP
;
34 : BACKSTRFREE
( s
--> s \
<-- ) PRO BACK STRFREE TRACKING RESTB CONT
;
35 : SEVALUATE BACKSTRFREE STR@ EVALUATE
;
37 : SAPPEND
( s s1
-- s
' ) OVER S+ ;
43 : <page> ( `title -- )
49 << `application/xhtml+xml;charset=utf-8 `content-type http-equiv >>
50 << `title tag ( `title ) TYPE >>
51 \ << `wiki.css link-stylesheet >>
57 : input ( `value `name `type -- ) %[ `type $$ `name $$ `value $$ ]% `input /atag ;
59 : render-edit ( a u -- )
60 \ << `h1 tag S" Nota bene: Editing is disabled ('save
' will ignore your changes)" TYPE >>
61 %[ `POST `method $$ S" " `action $$ ]% `form atag
65 %[ `content `name $$ `25 `rows $$ `80 `cols $$ ]% `textarea atag
69 `save `button `submit input
72 : GetParamInt ( `str -- n ) GetParam NUMBER NOT IF 0 THEN ;
74 20 1024 * CONSTANT limit
78 << `h2 tag S" Input" TYPE >>
79 DUP limit > IF DROP limit S" Input too long, truncated" TYPE CR THEN
80 << `pre tag 2DUP TYPE >>
82 (( S" sql" DROP 0x1FF )) mkdir DROP
83 ms@ { tick | src dst err }
84 tick " sql/{n}.in" -> src
85 tick " sql/{n}.out" -> dst
86 tick " sql/{n}.err" -> err
87 \ src STR@ TYPE CR dst STR@ TYPE CR err STR@ TYPE CR
89 err STR@ dst STR@ src STR@ " ./sqlgg.native {s} > {s} 2> {s}" STR@ sys
91 << `h2 tag S" Output" TYPE >>
94 err STR@ FILE DUP 0= IF 2DROP EXIT THEN
95 << `h2 tag S" Errors" TYPE >>
102 S" Input SQL statements terminated with semicolon (;) each. " TYPE
103 S" Use ? or @name for binding slots" TYPE
108 S" SQL to C++ code generator" 2DUP <page>
109 << `h1 tag `/p/sqlgg.html link-text >>
110 `content GetParam DUP 0= IF 2DROP ask-input ELSE process THEN
111 \ S" CREATE TABLE x (z INT);" process
117 : content:html S" Content-type: text/html" TYPE CR ;
118 : content:xhtml S" Content-type: application/xhtml+xml" TYPE CR ;
119 : content-length " Content-Length: {n}" STYPE CR ;
121 \ : comment PRO ." <!-- " CONT ." -->" ;
124 S" CONTENT_LENGTH" ENVIRONMENT? NOT IF EXIT THEN
125 NUMBER NOT IF EXIT THEN
126 ALLOCATED 2DUP H-STDIN READ-FILE-EXACT IF 2DROP ELSE GetParamsFromString THEN ;
127 \ ALLOCATED 2DUP H-STDIN READ-FILE . NIP 2DUP TYPE CR GetParamsFromString ;
130 S" QUERY_STRING" ENVIRONMENT? IF GetParamsFromString THEN ;
133 `REQUEST_METHOD ENVIRONMENT? NOT IF EXIT THEN
134 2DUP `POST CEQUAL IF 2DROP get_post_params EXIT THEN
135 2DUP `GET CEQUAL IF 2DROP get_get_params EXIT THEN
138 [UNDEFINED] WINAPI: [IF]
140 S" environ" symbol-lookup symbol-address @
144 DUP @ ASCIIZ> TYPE CR
150 WINAPI: GetEnvironmentStrings KERNEL32.DLL
153 GetEnvironmentStrings
164 : env ENVIRONMENT? NOT IF S" " THEN ;
170 TIME&DATE DateTime>PAD TYPE TAB
171 `REMOTE_ADDR env TYPE TAB
172 `REQUEST_METHOD env TYPE TAB
173 `SCRIPT_NAME env TYPE SPACE
174 `QUERY_STRING env TYPE TAB
175 `HTTP_USER_AGENT env TYPE
176 } TYPE>STR BACKSTRFREE STR@ `request.log ATTACH-LINE-CATCH DROP ;
180 \ S" Cache-Control: no-cache" TYPE CR
191 ['] content TYPE
>STR DUP STRLEN content
-length
196 \
: index headers CR content
;
198 \
: REQUEST_METHOD S
" GET" ;
199 \
: QUERY_STRING S
" page_name=MainPage" ;
201 \
' TYPE1 TO USER-TYPE
203 : save ['] index MAINX
! `sql
.cgi SAVE
;