1: # Copyright 2002-2004 The Apache Software Foundation 2: 3: # Licensed under the Apache License, Version 2.0 (the "License"); 4: # you may not use this file except in compliance with the License. 5: # You may obtain a copy of the License at 6: 7: # http://www.apache.org/licenses/LICENSE-2.0 8: 9: # Unless required by applicable law or agreed to in writing, software 10: # distributed under the License is distributed on an "AS IS" BASIS, 11: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12: # See the License for the specific language governing permissions and 13: # limitations under the License. 14: 15: package provide RivetTcl 1.1 16: 17: namespace eval ::Rivet { 18: 19: ### 20: ## This routine gets called each time a new request comes in. 21: ## It sets up the request namespace and creates a global command 22: ## to replace the default global. This ensures that when a user 23: ## uses global variables, they're actually contained within the 24: ## namespace. So, everything gets deleted when the request is finished. 25: ### 26: proc initialize_request {} { 27: catch { namespace delete ::request } 28: 29: namespace eval ::request { } 30: 31: proc ::request::global {args} { 32: foreach arg $args { 33: uplevel "::global ::request::$arg" 34: } 35: } 36: } 37: 38: ### 39: ## The default error handler for Rivet. Any time a page runs into an 40: ## error, this routine will be called to handle the error information. 41: ## If an ErrorScript has been specified, this routine will not be called. 42: ### 43: proc handle_error {} { 44: global errorInfo 45: global errorOutbuf 46: 47: puts <PRE> 48: puts "<HR>$errorInfo<HR>" 49: puts "<P><B>OUTPUT BUFFER:</B></P>" 50: puts $errorOutbuf 51: puts </PRE> 52: } 53: 54: ### 55: ## This routine gets called each time a request is finished. Any kind 56: ## of special cleanup can be placed here. 57: ### 58: proc cleanup_request {} { 59: } 60: 61: ### 62: ## The main initialization procedure for Rivet. 63: ### 64: proc init {} { 65: global auto_path 66: global server 67: 68: ## Add the rivet-tcl directory to Tcl's auto search path. 69: ## We insert it at the head of the list because we want any of 70: ## our procs named the same as Tcl's procs to be overridden. 71: ## Example: parray 72: set tclpath [file join [file dirname [info script]] rivet-tcl] 73: set auto_path [linsert $auto_path 0 $tclpath] 74: 75: ## Add the packages directory to the auto_path. 76: ## If we have a packages$tcl_version directory 77: ## (IE: packages8.3, packages8.4) append that as well. 78: set pkgpath [file join [file dirname [info script]] packages] 79: lappend auto_path $pkgpath 80: lappend auto_path ${pkgpath}-local 81: 82: if { [file exists ${pkgpath}$::tcl_version] } { 83: lappend auto_path ${pkgpath}$::tcl_version 84: } 85: 86: ## This will allow users to create proc libraries and tclIndex files 87: ## in the local directory that can be autoloaded. 88: lappend auto_path . 89: } 90: 91: } ;## namespace eval ::Rivet 92: 93: ## Initialize Rivet. 94: ::Rivet::init |