# -*- tcl -*-
# Helper rules for the creation of the memchan website from the .exp files.
# General formatting instructions ...
proc state {} [list return [file join [pwd] state]]
proc use_bg {} {
set c [bgcolor]
#puts stderr "using $c"
if {$c == {}} {return ""}
return bgcolor=$c
}
proc nbsp {} {return " "}
proc p {} {return
}
proc ptop {} {return "
"}
proc td {} {return "
"}
proc trtop {} {return " | "}
proc tr {} {return "
"}
proc sect {s} {return "$s
"}
proc link {text url} {return "$text"}
proc table {} {return ""}
proc btable {} {return ""}
proc stable {} {return ""}
proc tcl_cmd {cmd} {return "\[$cmd]"}
proc wget {url} {exec /usr/bin/wget -q -O - $url 2>/dev/null}
proc url {tag text url} {
set body {
switch -exact -- $what {
link {return {%text%}}
text {return {%text%}}
url {return {%url%}}
}
}
proc $tag {{what link}} [string map [list %text% $text %url% $url] $body]
}
proc img {tag alt img} {
proc $tag {} [list return "
"]
}
proc header {title} {
proc pagetitle {} [list return $title]
return "[sfproject] @ SourceForge : $title"
}
proc trailer {} {
return "
[table][tr][copyright][me] | Last update at [clock format [clock seconds]] |
"
}
proc protect {text} {return [string map [list & "&" < "<" > ">"] $text]}
proc get_changelog {} {
set cl [exec [file join [here] .. changelog_to_list] [file join [pwd] .. memchan ChangeLog]]
proc get_changelog {} [list return $cl]
return $cl
}
proc changelog {} {
set cl [get_changelog]
set html ""
foreach chunk $cl {
foreach {date person items} $chunk break ; # lassign
append html "
[protect $date][protect $person] ...
[p][changelog_items $items][p]\n"
}
return $html
}
proc changelog_items {items} {
set dlopen 0
set onlykey 0
set html ""
foreach item $items {
set key [set com {}]
foreach {key com} $item break
if {$key != {}} {
if {!$dlopen} {
if {$onlykey} {
append html [p]
set onlykey 0
}
append html \n
}
set dlopen 1
append html - [protect $key]
if {$com != {}} {
append html - [protect $com]
\n
}
} else {
if {$com != {}} {
if {$dlopen} {append html
[p]\n}
set dlopen 0
append html [protect $com]
set onlykey 1
}
}
}
if {$dlopen} {append html \n}
return $html
}
proc news {} {
set nfile [file join [state] news]
set data [read [set fh [open $nfile r]]][close $fh]
return [string trim $data]\n
}
proc stats {} {
set nfile [file join [state] statistics]
set data [read [set fh [open $nfile r]]][close $fh]
set data [string trim $data]
regsub -all {BGCOLOR="[^"]*"} $data "[use_bg]" data
regsub -all {bgcolor="[^"]*"} $data "[use_bg]" data
return [string trim $data]\n
}