## Set your variables here. namespace eval http { # The directory which files are searched for. variable srv {/home/aleksei/www/files/} namespace eval cache { variable precache { {/fonts/} } } namespace eval module { variable targets {}; source modules/template.tcl } } proc temp {} { # Run through and bring in all targets foreach i [namespace children ::http::module] { set ::http::module::targets [concat $::http::module::targets $i::targets] # If there are duplicate elements, then error. if [expr [llength [lsort -unique $::http::module::targets]] != [llength $::http::module::targets]] { error "A duplicate target coming from $i." } } } ## Validate configuration variables. ## Especially file exists content ## Especially validate the existence of necessary components in $content set config [open /etc/tcl-httpd.conf] ## Configure the server, whilst verifying options. namespace eval temp { set error_state 0; set error_message "Invalid lines:"; set line_number 1; namespace eval verify { proc srv {s} { } proc module_path } namespace eval actions { proc @MODULE {v} { if [info exists ::http::configure::module_path] { set path [string cat $::http::configure::module_path $v ".tcl"] if { [file exists $path] && [file isFile $path] } { namespace eval [string cat "::http::module::" $v] { source $path } } else { error "Fatal Error: While trying to import module '$b', file $path' doesn't exist." } } else { error "Fatal Error: Tried to import module '$b' without a module_path" } } proc @PRECACHE {a b} { ::http::cache::add $b } } while {[gets $config line] != -1} { if [regexp {^[[:lower:]_]+=[[:alnum:][:punct:]]+$} $line] { set n [string first "=" $line] set a [string range start [expr n-1]] set b [string range [expr n+1] end] # RUN VERIFICATION namespace eval ::http::configure "variable $a $b" } elseif [regexp {^@[[:upper:]]+ [[:alnum:][:punct:]]+$} $line] { set n [string first " " $line] set a [string range start [expr n-1]] set b [string range [expr n+1] end] # PERFORM ACTION } else { append error_message " $line_number" set error_state 1; } incr line_number; } if $error_state { error "ERROR: There were multiple errors in your configuration.\n$error_message" } } ## Delete the namespace afterwards. namespace delete temp;