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 NOT ~profit
/lib
/logic
.f
11 REQUIRE DateTime
>PAD ~ygrek
/lib
/spec
/unixdate
.f
12 REQUIRE FileLines
=> ~ygrek
/lib
/filelines
.f
13 REQUIRE BACKSTRFREE ~ygrek
/lib
/backstr
.f
14 REQUIRE StartAppWait ~ygrek
/lib
/linux
/process
.f
15 REQUIRE content
:html ~ygrek
/lib
/net
/cgi
.f
21 : <page
> ( `title
-- )
27 << `application
/xhtml
+xml
;charset
=utf
-8 `content
-type http
-equiv
>>
28 << `title tag
( `title
) TYPE
>>
29 \
<< `wiki
.css link
-stylesheet
>>
35 : input
( `value `name `type
-- ) %[ `type $$ `name $$ `value $$
]% `input
/atag
;
37 : render
-edit
( a u
-- )
38 \
<< `h1 tag S
" Nota bene: Editing is disabled ('save' will ignore your changes)" TYPE
>>
39 %[ `post `method $$ S
" " `action $$
]% `form atag
43 %[ `content `name $$ `
25 `rows $$ `
80 `cols $$
]% `textarea atag
51 %[ `gen `name $$
]% `select atag
52 << %[ `cxx `value $$ `selected
2DUP $$
]% `option atag `C
++ TYPE
>>
53 << %[ `caml `value $$
]% `option atag `OCaml TYPE
>>
56 S
" generate code " `button `submit input
60 20 1024 * CONSTANT limit
65 << `h2 tag S
" Input" TYPE
>>
66 DUP limit
> IF DROP limit S
" Input too long, truncated" TYPE CR
THEN
67 << `pre tag
2DUP TYPE
>>
69 (( S
" sql" DROP
0x1FF )) mkdir DROP
70 ms@
{ tick | src dst err gen
}
71 `gen GetParam S
" caml" CEQUAL
IF S
" caml" ELSE S
" cxx" THEN >STR
TO gen
72 tick
" sql/{n}.in" -> src
73 tick
" sql/{n}.out" -> dst
74 tick
" sql/{n}.err" -> err
75 \ src STR@ TYPE CR dst STR@ TYPE CR err STR@ TYPE CR
77 err STR@ dst STR@ src STR@ gen STR@
78 " ./sqlgg.native -gen {s} {s} > {s} 2> {s}" STR@ StartAppWait DROP
80 << `h2 tag S
" Output" TYPE
>>
83 err STR@ FILE DUP
0= IF 2DROP EXIT
THEN
84 << `h2 tag S
" Errors" TYPE
>>
91 S
" Input SQL statements terminated with semicolon (;) each. " TYPE
92 S
" Use ? or @name for binding slots" TYPE
97 S
" SQL Guided (code) generator" 2DUP
<page
>
98 << `h1 tag `
/p
/sqlgg
.html link
-text
>>
99 `content GetParam DUP
0= IF 2DROP ask
-input
ELSE process
THEN
100 \ S
" CREATE TABLE x (z INT);" process
106 : env ENVIRONMENT? NOT
IF S
" " THEN ;
114 TIME
&DATE DateTime
>PAD TYPE TAB
115 `REMOTE_ADDR env TYPE TAB
116 `REQUEST_METHOD env TYPE TAB
117 `SCRIPT_NAME env TYPE SPACE
118 `QUERY_STRING env TYPE TAB
119 `HTTP_USER_AGENT env TYPE
120 } TYPE
>STR BACKSTRFREE STR@ `request
.log ATTACH
-LINE
-CATCH DROP
;
124 \ S
" Cache-Control: no-cache" TYPE CR
135 ['] content TYPE>STR DUP STRLEN content-length
142 \ : index headers CR content ;
144 \ : REQUEST_METHOD S" GET" ;
145 \ : QUERY_STRING S" page_name=MainPage" ;
147 \ ' TYPE1
TO USER
-TYPE
149 : save
['] index MAINX ! `sql.cgi SAVE ;