#!/usr/bin/tclsh
# (find-angg "TCL/httpwiki")
#
# (find-fline "/usr/lib/tcl8.0/")
# (find-fline "/usr/lib/tcl8.0/http1.0/")
# (find-fline "/usr/lib/tcl8.0/http1.0/http.tcl" "proc http_formatQuery")
# (find-fline "/usr/lib/tcl8.0/http1.0/http.tcl" "proc http_get")
# (find-es "tcl" "wiki_scripts")
# (find-es "wiki" "wiki_extracting_pages")
# (find-wiscritag "cgi_quote_html")
# (find-wiscrifile "")
# (find-wiscrifile "usecgi.tcl")
# (find-wiscrifile "usecgi.tcl" "generate an edit page")
# (find-wiscrifile "wikit.tcl" "GetPage")
# (find-wiscritag "cgi_textarea")
# (find-wiscritag "cgi_quote_html")
# (find-es "wiki" "httpwiki")
# (find-angg ".emacs" "wiki")
package require http 1.0
# Global variables:
# wikinames
# wikiname
# wikiurl
# pagenum
# pagehtml (as got from http://.../@nnn or from http://.../nnn.html)
# pagetitle
# pagetext
set wikinames {
ewiki-l http://127.0.0.1/cgi-bin/ewiki
ewiki http://angg.twu.net/cgi-bin/ewiki
wikit-l http://127.0.0.1/cgi-bin/wikit
wikit http://mini.net/cgi-bin/wikit
}
proc wikiname_to_url {wikiname} {
global wikinames
foreach {short long} $wikinames {
if {"$wikiname"=="$short"} {
return $long
}
}
return $wikiname
}
proc get_page_as_html {wikiurl n} {
return [http_data [http_get $wikiurl/${n}@]]
}
proc get_page_elements {wikiurl n} {
global pagetitle pagetext
set pagehtml [get_page_as_html $wikiurl $n]
regexp {
} $pagehtml \
-> n pagetitle
regexp "\n" $pagehtml \
-> text
regsub -all {\"} $text {"} text
regsub -all {\<} $text {<} text
regsub -all {\>} $text {>} text
regsub -all {\&} $text {&} text
set pagetext $text
}
# sendpage:
# Send the new text to a wiki using the "save" button of an
# "edit page xxx" (i.e., http://.../nnn@) page; the "action"
# field of its form points to http://.../nnn.html.
# (find-wiscrifile "usecgi.tcl" "quote_html $C")
# (find-wiscrifile "usecgi.tcl" "C=[GetPage]")
#
proc sendpage {wikiurl N text} {
global pagehtml pagetitle
set pagehtml [http_data [http_get $wikiurl/$N.html \
-query [http_formatQuery C $text]]]
regexp {([^<]+)} $pagehtml \
-> pagetitle
}
proc writefile {fname str} {
if {$fname=="-"} { puts -nonewline $str; return }
set ch [open $fname w]; puts -nonewline $ch $str; close $ch
}
proc setvars {wname n} {
global wikiname wikiurl pagenum
set wikiname $wname
set wikiurl [wikiname_to_url $wname]
set pagenum $n
}
proc setvars_read {wname n} {
global wikiurl pagetitle
setvars $wname $n
get_page_elements $wikiurl $n
puts stderr "Got page $n: $pagetitle"
}
proc setvars_write {wname n text} {
global wikiurl pagetext pagetitle
setvars $wname $n
set pagetext $text
sendpage $wikiurl $n $text
puts stderr "Wrote page $n: $pagetitle"
if {$pagetitle=="Search"} {
puts stderr "\aError: getting \"Search\" here\
means that that page does not exist."
exit 1
}
}
proc emacs_page {} {
global wikiname wikiurl pagenum pagetitle pagetext
return ";
; [exec date "+%Y%b%d %T" | tr A-Z a-z]
; Title: $pagetitle
; lynx $wikiurl/${pagenum}.html
; (getwikipage \"$wikiname\" $pagenum)
; (sendwikipage \"$wikiname\" $pagenum)
$pagetext"
}
proc get {wname n destfile} {
global pagetitle pagetext
setvars_read $wname $n
writefile $destfile $pagetext
}
proc eget {wname n destfile} {
setvars_read $wname $n
writefile $destfile [emacs_page]
}
proc send {wname n textfile {htmlfile ""}} {
global pagehtml
setvars_write $wname $n [exec cat $textfile]
if {$htmlfile!=""} { writefile $htmlfile $pagehtml }
}
if {$argv==""} {
puts \
"Usage: $argv0 get
$argv0 eget
$argv0 send []"
exit 1
}
eval $argv