#!/usr/local/bin/tclsh set SourceDir /home/wilbert/devel/www/linux set DestDir /home/wilbert/www/linux set Template [exec cat [file join $SourceDir Template]] set Contents [exec cat [file join $SourceDir Contents]] set Contents_en [exec cat [file join $SourceDir Contents-en ]] set debug 0 set me $argv0 set version 1.0 proc ProcessFile file { global SourceDir DestDir global Template global Contents Contents_en global debug me if $debug {puts stdout $me: Processing $file} set Sfile [file join $SourceDir $file] set Dfile [file join $DestDir $file] #Get header and body of document set f [open $Sfile] regexp -nocase {(.*?).*?(.*)(|\Z)} [read $f] {} HEAD BODY close $f #English file? if {[regexp -- {-en.html$} $file]} { set PFIX {-en} set DATE "Last modified: [clock format [file mtime $Sfile]]" set FLAG "g/du-flag.png" set LANG Nederlands regsub -- {-en.html$} $file {.html} LINK upvar "#0" Contents_en CONTENTS } else { set PFIX {} set DATE "Laatst gewijzigd: [clock format [file mtime $Sfile]]" set FLAG "g/en-flag.png" set LANG English regsub -- {.html$} $file {-en.html} LINK upvar "#0" Contents CONTENTS } set f [open $Dfile w] puts $f [subst $Template] close $f } proc ProcessAll {} { foreach f [glob *.html] { ProcessFile $f } } proc ProcessNL {} { foreach f [glob *.html] { if {![regexp -- {-en.html$} $f]} { ProcessFile $f } } } proc ProcessEN {} { foreach f [glob *-en.html] { ProcessFile $f } } #Main Script cd $SourceDir set o stderr puts $o "$me $version running..." if {![file exists [file join $DestDir index.html]]} { puts $o "$me: No index.html. Processing all files" ProcessAll } elseif {[file mtime [file join $DestDir index.html]] < [file mtime Template]} { puts $o "$me: Template has changed. Processing all files" ProcessAll } elseif {[file mtime [file join $DestDir index.html]] < [file mtime [file join $SourceDir $me]]} { puts $o "$me: Myself changed. Processing all files" ProcessAll } else { if {[file mtime [file join $DestDir index.html]] < [file mtime Contents]} { puts $o "$me: Dutch contents have changed. Processing Dutch files" ProcessNL } if {[file mtime [file join $DestDir index-en.html]] < [file mtime Contents-en]} { puts $o "$me: English contents have changed. Processing English files" ProcessEN } foreach f [glob *.html] { if {![file exists [file join $DestDir $f]]} { puts $o "$me: New file: $f" ProcessFile $f } elseif {[file mtime [file join $DestDir $f]] < [file mtime $f]} { puts $o "$me: Changed file: $f" ProcessFile $f } } } puts $o "$me finished."