From a3bdaf37b72013fe581f108c4798137e1ea267cd Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Sun, 30 Jun 2024 21:57:33 +1000 Subject: last commit of today; expanding on configuration and modules --- modules/document-viewer.tcl | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 modules/document-viewer.tcl (limited to 'modules') diff --git a/modules/document-viewer.tcl b/modules/document-viewer.tcl new file mode 100755 index 0000000..de8f0e7 --- /dev/null +++ b/modules/document-viewer.tcl @@ -0,0 +1,54 @@ +## Note that this code is leftover from the beginning of this project, +## which was originally a CGI document viewer that grew into a HTTP +## server instead, but I plan to implement this as a module. +## This is not at all supposed to be used right now. + +variable directories {articles test-one} + + + +### Content + +proc run {request_target} { + +} + + + + +append http::content [html::start Lame!] + +## If directory is not queried, +if { ([lsearch -exact [dict keys $query] "directory"] eq -1) || ([lsearch -exact $directories [dict get $query directory]] eq -1 )} { + append http::content "Utter failure." + append http::content [html::end] + http::respond + exit +} + +set directory [dict get $query directory] + + + +## If document is not queried, or does not exist in our directory, +set documents [exec ls -Q $directory] +if { ([lsearch -exact [dict keys $query] "document"] eq -1) || ([lsearch -exact $documents [dict get $query document]] eq -1 ) } { + foreach a $documents { + append http::content [html::link $a "?directory=$directory&document=$a"] + } + append http::content [html::end] + http::respond + exit +} + + + +## Open file +set file [open "$directory/[dict get $query document]" r] + +## Output lines +while {[gets $file line] != -1} { + append http::content "$line
" +} + +append http::content [html::end] -- cgit v1.2.3