diff options
Diffstat (limited to 'modules/document-viewer.tcl')
-rwxr-xr-x | modules/document-viewer.tcl | 54 |
1 files changed, 54 insertions, 0 deletions
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 <br> " +} + +append http::content [html::end] |