Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.102 -r1.103 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 21 Nov 2007 14:08:44 -0000 1.102 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 20 Jan 2008 19:31:37 -0000 1.103 @@ -4404,3 +4404,30 @@ } { return [regexp {[<>:\"|/@\#%&+\\ ]} $s1] } + +ad_proc -public util::which {prog} { + + @author Gustaf Neumann + + Use environment variable PATH to search for the specified executable + program. Replacement for UNIX command "which", avoiding exec. + + exec which: 3368.445 microseconds per iteration + ::util::which: 282.372 microseconds per iteration + + In addition of being more than 10 time faster than the + version via exec, this version is less platform dependent. + + @param prog name of the program to be located on the search path + @return fully qualified name including path, when specified program is found, + or otherwise empty string + +} { + foreach p [split $::env(PATH) :] { + set fullname [file join $p $prog] + if {[file executable $fullname]} { + return $fullname + } + } + return "" +} Index: openacs-4/packages/acs-templating/tcl/spellcheck-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/spellcheck-init.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/acs-templating/tcl/spellcheck-init.tcl 19 Jan 2008 20:36:33 -0000 1.14 +++ openacs-4/packages/acs-templating/tcl/spellcheck-init.tcl 20 Jan 2008 19:31:37 -0000 1.15 @@ -9,24 +9,10 @@ } # Find the aspell or, second best, the ispell binary. -# In case neither one is found, spell-checking will be disabled. - -# DRB: The original code here apparently was written under the delusion -# that using "catch" to guard calls to "exec" would allow one to safely use -# the same "exec" elsewhere in the same command, as though Tcl does short-circuit -# evaluation of exprs. I only mention this in case someone sees the clever (but wrong) -# code and decides they want to replace my fix with the clever (but wrong) version ... - -# DRB: And to top it off, OS/X (all BSD?) "which" doesn't return an error, just an -# error string, if the file doesn't exist, making the check even more fun to run. - -expr { ![catch {exec which aspell}] && ![string match "*no aspell*" [exec which aspell]] } -if { ![catch {exec which aspell}] && ![string match "*no aspell*" [exec which aspell]] } { - set bin [exec which aspell] -} elseif { ![catch {exec which ispell}] && ![string match "*no ispell*" [exec which ispell]] } { - set bin [exec which ispell] -} else { - set bin "" +# In case neither one is found, bin is empty and spell-checking will be disabled. +set bin [::util::which aspell] +if {$bin eq ""} { + set bin [::util::which ispell] } # Do we want dialect dictionaries (if available) or not? @@ -40,7 +26,7 @@ # aspell or ispell? set dicts "" set default_lang "" -if { [regexp aspell $bin] } { +if { [string match "*aspell" $bin] } { # aspell with_catch errmsg { set dicts [exec $bin dump dicts] @@ -55,7 +41,7 @@ ns_log Warning "Gettings dicts and default_lang for aspell failed with error message: \"$errmsg\"" ns_log Notice "You might want to upgrade to a more recent version of Aspell ... http://aspell.sourceforge.net/" } -} elseif { [regexp ispell $bin] } { +} elseif { [string match "*ispell" $bin] } { # ispell - if someone knows how to get the available dictionaries and the # default language from ispell, please add it here :-) set dicts ""