#!/usr/bin/tclsh.docsrc source [file dirname [info script]]/document_header.tcl # Decode an HTTP %-encoded string # proc percent_decode {str} { # rewrite "+" back to space # protect \ and [ and ] by quoting with '\' set str [string map [list + { } "\\" "\\\\" \[ \\\[ \] \\\]] $str] # prepare to process all %-escapes regsub -all -- {%([A-Fa-f][A-Fa-f0-9])%([A-Fa-f89][A-Fa-f0-9])} \ $str {[encoding convertfrom utf-8 [binary decode hex \1\2]]} str regsub -all -- {%([0-7][A-Fa-f0-9])} $str {\\u00\1} str # process %-escapes return [subst -novar $str] } #========================================================================= # This proc is called to parse the arguments passed to this invocation of # the CGI program (via either the GET or POST method). It returns a # key/value list containing the arguments suitable for passing to [array # set]. For example, if the CGI is invoked via a GET request on the URI: # # http://www.sqlite.org/search?query=fts3+table&results=10 # # then the returned list value is: # # {query {fts3 table} results 10} # proc cgi_parse_args {} { global env A if {$env(REQUEST_METHOD) == "GET"} { foreach q [split $env(QUERY_STRING) &] { if {[regexp {([a-z0-9]*)=(.*)} $q all var value]} { set A($var) [percent_decode $value] } } } elseif {$env(REQUEST_METHOD) == "POST"} { set qstring [read stdin $env(CONTENT_LENGTH)] foreach q [split $qstring &] { if {[regexp {([a-z0-9]*)=(.*)} $q all var value]} { set A($var) [percent_decode $value] } } } else { error "Unrecognized method: $env(REQUEST_METHOD)" } } #========================================================================= # The argument contains a key value list. The values in the list are # transformed to an HTTP query key value list. For example: # # % cgi_encode_args {s "search string" t "search \"type\""} # s=search+string&t=search+%22type%22 # proc cgi_encode_args {list} { set reslist [list] foreach {key value} $list { set value [string map { \x20 + \x21 %21 \x2A %2A \x22 %22 \x27 %27 \x28 %28 \x29 %29 \x3B %3B \x3A %3A \x40 %40 \x26 %26 \x3D %3D \x2B %2B \x24 %24 \x2C %2C \x2F %2F \x3F %3F \x25 %25 \x23 %23 \x5B %5B \x5D %5D } $value] lappend reslist "$key=$value" } join $reslist & } proc htmlize {str} { string map {< < > >} $str } proc attrize {str} { string map {< < > > \x22 "} $str } #========================================================================= proc cgi_env_dump {} { set ret "
[htmlize $key] | [htmlize $value]" } append ret " |
[htmlize $key] | [htmlize $value]" } append ret " |
Powered by FTS5. |
$s_title1
($url)
$s_apis
$s_content
|
}]
}
append ret {
for {set i 0} {$i < 10 && ($i*10)<$nRes} {incr i} { append ret [subst { [expr $i+1] }] } append ret
Page generated in $t." return $doc # return [cgi_env_dump] } #========================================================================= source [file dirname [info script]]/document_header.tcl if {![info exists env(REQUEST_METHOD)]} { set env(REQUEST_METHOD) GET set env(QUERY_STRING) rebuild=1 set ::HEADER "" #set env(QUERY_STRING) {q="one+two+three+four"+eleven} set env(QUERY_STRING) {q=windows} set ::HEADER "" } if {0==[catch main res]} { set title "Search SQLite Documentation" if {[info exists ::A(q)]} { set initsearch [attrize $::A(q)] append title " - [htmlize $::A(q)]" } else { set initsearch {} } set document [document_header $title "" $initsearch] append document $res } else { set document "
" append document "Error: $res\n\n" append document $::errorInfo append document "" } puts "Content-type: text/html" puts "Content-Length: [string length $document]" puts "" puts $document puts "" flush stdout close stdout exit