Index: openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl,v diff -u -r1.21 -r1.22 --- openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl 30 Mar 2013 19:07:24 -0000 1.21 +++ openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl 27 Oct 2014 16:40:12 -0000 1.22 @@ -15,7 +15,7 @@ ad_proc -public template::util::spellcheck { command args } { Dispatch procedure for the spellcheck object } { - eval template::util::spellcheck::$command $args + template::util::spellcheck::$command {*}$args } ad_proc -public template::util::spellcheck::merge_text { element_id } { @@ -61,7 +61,7 @@ # case 2, submission of the page showing errors: returns the corrected text. set merge_text [template::util::spellcheck::merge_text $element(id)] - if { [set richtext_p [string equal "richtext" $element(datatype)]] } { + if { [set richtext_p $element(datatype) eq "richtext"] } { # special treatment for the "richtext" datatype. set format [template::util::richtext::get_property format [lindex $values 0]] if { $merge_text ne "" } { @@ -161,13 +161,15 @@ -var_to_spellcheck:required {-language ""} -error_num_ref:required + {-no_abort:boolean 0} -formtext_to_display_ref:required {-just_the_errwords_ref ""} } { @param text The string to check for spelling errors. @param html_p Does the text have html in it? If so, we strip out html tags in the string we feed to ispell (or aspell). + @param no_abort_p Set this tue for testing purposes (e.g. aa_test). @param var_to_spellcheck The name of the text input type or textarea that holds this text (eg., "email_body") @@ -198,8 +200,25 @@ # the HOME environment set, and setting env(HOME) doesn't appear # to work from AOLserver. - set spelling_wrapper [file join [acs_root_dir] bin webspell] + set spelling_wrapper [file join $::acs::rootdir bin webspell] + if {![file executable $spelling_wrapper]} { + # + # In case no_abort is given we just return the error + # message. Otherwise an ad_return_error is raised and the + # script is ad_script_aborted. + # + if {!$no_abort_p} { + ad_return_error "Webspell could not be executed" \ + "Spell-checking is enabled but the spell-check wrapper\ + ($::acs::rootdir/bin/webspell) returns not be executed.\ + Check that the wrapper exists, and that its permissions are correct." + ad_script_abort + } else { + error $errmsg + } + } + set spellchecker_path [nsv_get spellchecker path] # @@ -213,44 +232,39 @@ append lang_and_enc " --lang=$language" } - # Caveat: The "open" arg must be a list (not a string) to allow the wrapper args to be the empty string - # (which $language will be when ispell is used, for instance) + #ns_log notice WRAPPER=[list |$spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] - if { [catch { set ispell_proc [open [list |$spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] r] } errmsg] } { - ad_return_error "Webspell could not be executed" "Spell-checking is enabled but the spell-check wrapper ([acs_root_dir]/bin/webspell) could not be executed. Check that the wrapper exists, and that its permissions are correct.

Here is the error message:

$errmsg
" - ad_script_abort + if {[catch { + set ispell_lines [exec $spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] + } errmsg]} { + #ns_log notice "errorMsg = $errmsg" + + # + # In case no_abort is given we just return the error + # message. Otherwise an ad_return_error is raised and the + # script is ad_script_aborted. + # + if {!$no_abort_p} { + ad_return_error "No dictionary found" \ + "Spell-checking is enabled but the spell-check dictionary\ + could not be reached. Check that the dictionary exists,\ + and that its permissions are correct.\ +

Here is the error message:

$errmsg
" + ad_script_abort + } else { + error $errmsg + } } - - # read will occasionally error out with "interrupted system call", - # so retry a few times in the hopes that it will go away. - set try 0 - set max_retry 10 - while { [catch { set ispell_text [read -nonewline $ispell_proc] } errmsg] - && $try < $max_retry } { - incr try - ns_log warning "template::util::spellcheck::get_element_formtext: spellchecker had a problem: $errmsg" - } - fconfigure $ispell_proc -blocking 0 - - if { [catch { close $ispell_proc } errmsg] } { - ad_return_error "No dictionary found" "Spell-checking is enabled but the spell-check dictionary could not be reached. Check that the dictionary exists, and that its permissions are correct.

Here is the error message:

$errmsg
" - ad_script_abort - } - file delete $tmpfile - if { $try == $max_retry } { - return -code error "webspell: Tried to execute spellchecker $max_retry times but it did not work out. Sorry!" - } - #### # # Ispell is done. Start manipulating the result string. # #### - set ispell_lines [split $ispell_text "\n"] + set ispell_lines [split $ispell_lines "\n"] # Remove the version line. if { [llength $ispell_lines] > 0 } { set ispell_lines [lreplace $ispell_lines 0 0] @@ -354,17 +368,17 @@ } { upvar $element_ref element - if { [empty_string_p [set spellcheck_value [ns_queryget $element(id).spellcheck]]] } { + if { [set spellcheck_value [ns_queryget $element(id).spellcheck]] eq "" } { # The user hasn't been able to state whether (s)he wants spellchecking to be performed or not. # That's either because spell-checking is disabled for this element, or we're not dealing with a submit. # Whichever it is, let's see if, and then how, we should render the spellcheck "sub widget". # Do the "cheap" checks first and then (if needed) read the parameter and do additional checks. - if { [string equal "display" $element(mode)] \ - || [info exists element(nospell)] \ - || [empty_string_p [nsv_get spellchecker path]] } { + if { $element(mode) eq "display" + || [info exists element(nospell)] + || [nsv_get spellchecker path] eq "" } { set spellcheck_p 0 } else { @@ -375,9 +389,11 @@ -parameter SpellcheckFormWidgets \ -default ""]] - set spellcheck_p [expr {[array size widget_info] \ - && ($element(widget) eq "richtext" || $element(widget) eq "textarea" || $element(widget) eq "text") \ - && [lsearch -exact [array names widget_info] $element(widget)] != -1}] + set spellcheck_p [expr {[array size widget_info] + && ($element(widget) eq "richtext" || + $element(widget) eq "textarea" || + $element(widget) eq "text") + && $element(widget) in [array names widget_info]}] }