All pastes #803250 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-01 00:53 UTC
rendered paste body
dialog sc {
  title "Spell Check"
  size -1 -1 96 78
  option dbu
  edit "", 1, 2 3 92 10, autohs
  button "Check", 2, 63 14 28 12
  text "Spelled Correct:", 3, 6 17 39 8, hide
  text "", 4, 46 17 8 8, hide
  list 6, 0 28 96 50, size hsbar vsbar
}
on *:DIALOG:sc:init:*:{ 
  did -f sc 1
  did -t sc 2
}
on *:DIALOG:sc:sclick:2:{
  if ($did(1)) {
    if ($sock(spell)) {
      if ($input(The Spell Check socket is already connected $+ $crlf $+ $crlf $+ Close the socket and continue search?,yw,Connected)) {
        sockclose spell
        goto end
      }
      halt
    }
    :end
    did -r sc 6
    did -h sc 3,4
    sockopen spell www.spellcheck.net 80
  }
  else { noop $input(Supply a word/phrase to spell check,ow,Supply) }
}
on *:DIALOG:sc:dclick:6:{
  if ($did(6).seltext) {
    if (!$dialog(define)) { dialog -md define define }
    if ($sock(def)) {
      if ($input(The definition socket is already open $+ $crlf $+ $crlf $+ Close socket and continue?,wy,Already connected)) {
        sockclose def
        goto end
      }
      else {
        dialog -x define
        halt
      }
    }
    :end
    did -ra define 1 $did(6).seltext
    did -r define 3
    did -a define 3 Searching for $qt($did(6).seltext) $+ ...
    did -z define 3
    sockopen def wordnet.princeton.edu 80
  }
}
on *:SOCKOPEN:spell:{
  sockwrite -n $sockname GET /cgi-bin/spell.exe?action=CHECKWORD&string= $+ $replace($did(sc,1),$chr(32),+) HTTP/1.1
  sockwrite -n $sockname Host: www.spellcheck.net
  sockwrite -n $sockname $+($crlf,$crlf)
}
on *:SOCKREAD:spell:{
  if ($sockerr) { did -ra sc 6 Socket Error $qt($sockerr) }
  else {
    var %read
    sockread %read
    if (</BLOCKQUOTE> isin %read) {
      sockmark spell
      sockclose spell
    }
    if ($sock(spell).mark == continue) {
      did -a sc 6 $remove(%read,<BR>)
      did -z sc 6
    }
    if (*<BR><BR><font color=#006600><B>"*" is spelled correctly.</B></font><P><BR>* iswm %read) {
      did -v sc 3,4
      did -ra sc 4 Yes
      did -a sc 6 $did(sc,1)
      did -z sc 6
      sockclose spell
    }
    if (*<BR><font color=#990033><B>"*" is misspelled.</B></font>* iswm %read) {
      did -v sc 3,4
      did -ra sc 4 No
    }
    if (*<P><B>Here are some suggestions:</B><BLOCKQUOTE>* iswm %read) { sockmark spell continue }
    if (*</html>* iswm %read) { sockclose spell }
  }
}
dialog define {
  title "Word Definitions"
  size -1 -1 144 73
  option dbu
  edit "", 1, 2 3 75 10
  button "Lookup", 2, 79 2 27 12
  list 3, 0 16 144 58, size hsbar vsbar
}
on *:DIALOG:define:init:*:{ 
  did -f define 1
  did -t define 2 
}
on *:DIALOG:define:sclick:2:{
  if ($did(1)) {
    if ($sock(def)) {
      if ($input(The definition socket is already open $+ $crlf $+ $crlf $+ Close socket and continue?,wy,Already connected)) {
        sockclose def
        goto end
      }
      halt
    }
    :end
    did -r define 3
    did -a define 3 Searching for $qt($did(1)) $+ ...
    did -z define 3
    sockopen def wordnet.princeton.edu 80
  }
  else { noop $input(Supply a word/phrase to search for,wo,Nothing supplied) }
}
on *:SOCKOPEN:def:{
  sockwrite -n $sockname GET /perl/webwn?s= $+ $replace($did(define,1),$chr(32),+) HTTP/1.1
  sockwrite -n $sockname Host: wordnet.princeton.edu
  sockwrite -n $sockname $+($crlf,$crlf)
}
on *:SOCKREAD:def:{
  if ($sockerr) {
    did -a define 3 Socket Error $qt($sockerr)
    did -z define 3
  }
  else {
    var %read
    sockread %read
    if (*<h3>Your search did not return any results.</h3>* iswm %read) {
      did -r define 3
      did -a define 3 No results for $qt($did(define,1))
      did -z define 3
    }
    if (*<ul><a name="c"></a><li><a href="webwn?o2=&amp;o0=1&amp;o7=&amp;o5=&amp;o1=1&amp;o6=&amp;o4=&amp;o3=&amp;s=*&amp;i=0&amp;h=*>*</a><a class="pos">*</li>* iswm %read) {  
      did -r define 3
      did -a define 3 $remove($nohtml(%read),S:,W:)
      did -z define 3
    }
    elseif (*<li><a href="webwn?o2=&amp;o0=1&amp;o7=&amp;o5=&amp;o1=1&amp;o6=&amp;o4=&amp;o3=&amp;s=*&amp;i=*&amp;h=*>*</a><a class="pos">*</li>* iswm %read) { 
      did -a define 3 $remove($nohtml(%read),S:,W:)
      did -z define 3
    }
    if (*</html>* iswm %read) { sockclose def }
  }
}
alias -l nohtml { return $remove($regsubex($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null),&nbsp;,$chr(09)) }