home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / AWNP / AWNP-Docs / Demos / Dict-Thesar.rx < prev    next >
Encoding:
Text File  |  2000-11-12  |  14.1 KB  |  566 lines

  1. /*
  2. $VER: Online Dictionary and Thesaurus 2.5 (12.11.00)
  3. This script uses the Merriam-Webster site .
  4. www.m-w.com
  5. requires AWNP 2.52+
  6. */
  7.  
  8. if ~show('L','rexxsupport.library') then
  9. if ~addlib('rexxsupport.library',0,-30,0) then
  10. exit(20)
  11.  
  12. if show('P','DICTTHESAR') then do
  13.   address DICTTHESAR 'front'
  14.   exit
  15. end
  16.  
  17. rxPort = address()
  18. if abbrev(rxPort,'AWEB.') then do
  19.   'get screen var screen'
  20.   screen=' ps 'screen' '
  21. end
  22. else screen=''
  23.  
  24. nl='a'x
  25. delaybub=0
  26. call setdefaults()
  27. call buildgui()
  28. do while ~eof(ca)
  29.   call checkrx()
  30.   if delaybub>0 then do
  31.     delaybub=delaybub-1
  32.     if delaybub=0 then do
  33.       bubbleon=newbub
  34.       call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
  35.     end
  36.   end
  37.   call topipe('tick 50')
  38.   in= readln(ca)
  39.   parse var in in1 in2 in3 in4 in5 .
  40.   if (in1='help' & helpon~=0 ) then do
  41.     call bubble(in2)
  42.   end
  43.   if in1='active' then call bubble(0)
  44.   if in1='key' then call key()
  45.   if in1='gadget' then call gadget()
  46.   if in1='iconify' then call iconify(in2)
  47.   if in1='menu' then call menu()
  48.   if in1='close' then call windowclosed()
  49.   if in1='arexx' then call rxhst()
  50. end
  51. exit
  52.  
  53. key:
  54. scrpos=topipe('id 'txtgad)
  55. if (in2=77) then do
  56.   do i=0 for pcnt
  57.     if poslist.i>scrpos then break
  58.   end
  59.   if i=pcnt then i=i-1
  60.   call topipe('id 'txtgad' scroll -1')
  61.   call topipe('id 'txtgad' scroll' poslist.i)
  62. end
  63. if (in2=76) then do
  64.   do i=0 for pcnt
  65.     if scrpos<=poslist.i then break
  66.   end
  67.   if i>0 then i=i-1
  68.   call topipe('id 'txtgad' scroll' poslist.i)
  69. end
  70. return
  71.  
  72.  
  73. gadget:
  74. call bubble(0)
  75. if in2=wordgad then do
  76.   parse var in . . w
  77.   logon=1
  78.   call getword(w)
  79. end
  80. if in2=quitgad then exit
  81. if in2=levelgad then level=in3
  82. if in2=bookgad then book=in3
  83. if in2=cleargad then call clearlog()
  84. if in2=savegad then do
  85.   call writeln(ca,'id 'filegad' s 1 save 1 fn "'filename'"')
  86.   parse value readln(ca) with res1 '"' res2 '"'
  87.   if (res1>0) then do
  88.     filename=res2
  89.     call writeln(ca,'id 'txtgad' read')
  90.     len=readln(ca)
  91.     data=readch(ca,len)
  92.     if( open(out,res2,'W')) then do
  93.       call   writech(out,data)
  94.       call   close(out)
  95.     end
  96.   end
  97. end
  98. return
  99.  
  100. windowclosed:
  101. exit
  102. return
  103.  
  104. setdefaults:
  105. parse source . . called .
  106. logging=1
  107. oldpos=0
  108. poslist.0=0
  109. pcnt=1
  110. level=0
  111. book=0
  112. filename=''
  113. scrpos=''
  114. prono=''
  115. theno=''
  116. envname='onlinedictionary'
  117. call getenv()
  118. abouttx=' Online Dictionary & Thesaurus *nVers 2.5 *nArexx Host DICTTHESAR*nAuthor William Parker*nGUI by AWNPipe:'
  119. return
  120.  
  121. buildgui:
  122. call open(ca,"awnpipe:dict/-2052/xc")
  123. call topipe(screen 'it "Dict Thesa" "Online Dictionary & Thesaurus" sk v defg ig h state m a 'window' ii "'called'"' )
  124. lay1=topipe(' layout weih 0')
  125. call topipe(' label gt "_Word: " ua')
  126. wordgad=topipe('string chl lj')
  127. help.wordgad=' Enter word to look up '
  128. levelgad=topipe('chooser cl "First|Major|All" pu weiw 0')
  129. help.levelgad='Select look up depth*n First Entry*n Major Entries*n All Entries'
  130. bookgad=topipe('chooser cl "Dictionary|Thesaurus" pu weiw 0')
  131. help.Bookgad='Select book to search in*n Dictionary definition*n Thesaurus information'
  132. call topipe(' le')
  133. txtgad=topipe('textfield ro arrows')
  134. help.txtgad=' This area displays the retrieved definitions. It is read only *n but you may drag and copy the results to the clipboard. *n The cursor keys can be used to scroll the information.'
  135. lay2=topipe(' layout weih 0')
  136. abortgad=topipe('button pb gt "_Abort" dis 1')
  137. help.abortgad=' Abort multiple retrieval*navailable for major and all*noptions'
  138. savegad=topipe('button gt "_Save Log"')
  139. help.savegad=' Save retrieved definitions to a file '
  140. cleargad=topipe('button gt "_Clear Log"')
  141. help.cleargad=' Remove all retrieved definitions '
  142. quitgad=topipe('button gt "_Quit"')
  143. help.quitgad=' Quit the dictionary '
  144. call topipe(' layoutend')
  145. filegad=topipe('getfile save ua')
  146. men0gad= topipe('Menu gt "Project|Window|$@SSnapshot|$@UUnsnapshot|@AAbout|@H^&Bubble Help|-|@QQuit"')
  147. call pragma('W','N')
  148. if (showlist('A','MIAMI')|(showlist('P','MIAMI.1'))) then do
  149.   men1gad= topipe('Menu gt "Miami|Online|Offline|Status|Hide GUI|Show GUI|-|Quit Miami"')
  150.   miamifound=1
  151. end
  152. call pragma('W')
  153. call topipe("open")
  154. call open(rxfh,'awnpipe:rx/xc')
  155. call rxpipe('nowindow m')
  156. call rxpipe('ARexx gt "DICTTHESAR|front|quit|word|save|clear|book|level|iconify|logging"')
  157. call rxpipe("open")
  158. return
  159.  
  160. topipe:
  161. parse arg out
  162. call writeln(ca,out)
  163. res=readln(ca)
  164. parse var res res1 res2 res3
  165. if res1='ok' then return(res2)
  166. say 'error from: 'out
  167. say '  responce: ' in
  168. exit
  169. rxpipe:
  170. parse arg out
  171. call writeln(rxfh,out)
  172. res=readln(rxfh)
  173. parse var res res1 res2 res3
  174. if res1='ok' then return(res2)
  175. say 'error from: 'out
  176. say '  responce: ' in
  177. exit
  178.  
  179. trans:
  180. if testtcp() then return
  181. savetx='0a'x||'---------------'||'0a'x
  182. newword=w
  183. call topipe('id 0 s 8 gt " Connecting for *"'newword'*""')
  184. savew=w
  185. w=urlencode(w)
  186. if book=0 then t1='book=Dictionary&va='w
  187. else t1='book=Thesaurus&va='w
  188. t2=length(t1)
  189. t2='Content-Length: 't2
  190. if open(net,'tcp:www.m-w.com/80') then do
  191.   call topipe('id 0 s 8 gt " Getting information for *"'newword'*""')
  192.   call writeln(net,"POST /cgi-bin/dictionary HTTP/1.0")
  193.   call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by AWNPdictthing (2.5))")
  194.   call writeln(net,"Accept: */*;q=1")
  195.   call writeln(net,"Host: www.m-w.com")
  196.   call writeln(net,t2)
  197.   call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  198.   call writeln(net,"")
  199.   call writeln(net,t1)
  200.   call writeln(net,"")
  201.   def=''
  202.   do while ~eof(net)
  203.     if length(def)< 54000 then def=def||readch(net,10000)
  204.   end
  205.   call close(net)
  206.   savedef=def
  207.   call getdef()
  208. end
  209. else do
  210.   savetx=savetx||'0a'x||'Connect Failed for 'newword||'0a'x
  211.   call Showtx(0,"Could not connect to m-w.com")
  212. end
  213. return(0)
  214.  
  215. getdef:
  216. call topipe('id 0 s 8 gt " Parsing result for  *"'newword'*""')
  217. if book=0 then parse var def 'Main Entry:' thisword '0a'x d1 '</form>'
  218. else parse var def 'Entry Word:'  thisword '0a'x d1 '</form>'
  219. thisword=htmltotx(thisword)
  220. txt=htmltotx(d1)
  221. if txt='' then txt= 'not found'
  222. if book=0 then savetx=savetx||'0a'x||' (dict) >>>> 'newword' <<<<'||'0a0a'x||' Entry: '||thisword||txt||'0a0a'x
  223. else savetx=savetx||'0a'x||' (thes) >>>> 'newword' <<<<'||'0a0a'x||' Entry: '||thisword||txt||'0a'x
  224. if savedef~='' then call extradef()
  225. call topipe('id 0 s 8 gt " Online Dictionary & Thesaurus"')
  226. return
  227.  
  228. showtx:
  229. call open(ptx,'awnpipe:kctxt/xc')
  230. call writeln(ptx,screen 'db dg "D&T info" q cm v m a ')
  231. call writeln(ptx,'layout defn 2 weiw 10 si fpat="5555aaaa" cj v b 0'nl'space trans minh 2'nl'laYOUT DEFN 2 fpat="5555aaaa" cj b 0'nl'space trans minw 5'nl'layout weih 0 weiw 0 so'nl'label gt " *n'arg(2)'*n "')
  232. call writeln(ptx,'le'nl'space trans minw 5'nl'le'nl'button gt " OK " c weiw 0'nl'le'nl'open'nl)
  233. if arg(1)~=0 then call writeln(ptx,'tick 'arg(1))
  234. else call writeln(ptx,'m')
  235. call close(ptx)
  236. return(0)
  237.  
  238.  
  239. menu:
  240. if in2=1 then do
  241.   if ~show('P','MIAMI.1') then do
  242.     if in3=1 | in3=1 | in3=6 then do
  243.       call showtx(200,' Miami is not running ')
  244.       return()
  245.     end
  246.     address command 'Run >NIL: Miami:Miami '
  247.     do 5 while ~show('P','MIAMI.1')
  248.       address command 'waitforport MIAMI.1'
  249.     end
  250.     if rc=5 then return()
  251.   end
  252.   if in3=1 then address MIAMI.1 'OFFLINE'
  253.   if in3=6 then address MIAMI.1 'QUIT'
  254.   if in3=0  then address MIAMI.1 'ONLINE'
  255.   if in3=3 then address MIAMI.1 'HIDE'
  256.   if in3=4 then address MIAMI.1 'SHOW'
  257.   if in3=2 | in3=0 | in3=1 then do
  258.     address MIAMI.1 'ISONLINE'
  259.     if rc then call showtx(400,' Miami is online ')
  260.     else call showtx(400,' Miami is offline ')
  261.   end
  262. end
  263.  
  264. if in2=0 then do
  265.   if in3=0 then do
  266.     if in4=0 then call setenvarc()
  267.     if in4=1 then call unsetenvarc()
  268.   end
  269.   if in3=1 then call showtx(800,abouttx)
  270.   if in3=2 then do
  271.     helpon=in5
  272.     if helpon=0 then call bubble(0)
  273.   end
  274.   if in3=4 then  exit
  275. end
  276. return()
  277.  
  278. iconify:
  279. if arg(1)=1 then call topipe('id 0 s 32')
  280. else call topipe('id 0 s 64')
  281. call bubble(0)
  282. return
  283.  
  284. getenv:
  285. if(open(env,'env:'envname,'R')) then do
  286.   windows=readln(env)
  287.   filename=readln(env)
  288.   call close(env)
  289.   parse var windows wl wt ww wh .
  290.   window= 'top' wt 'left' wl 'width' ww 'height' wh
  291. end
  292. else window='tl width 400 height 200'
  293. return
  294.  
  295. setenv:
  296. call writeln(ca,'id 0 read')
  297. windowr=readln(ca)
  298. parse var windowr wl wt ww wh .
  299. if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then do
  300.   call open(env,'env:'envname,'W')
  301.   call writeln(env,windowr)
  302.   call writeln(env,filename)
  303.   call close(env)
  304. end
  305. return(0)
  306.  
  307. setenvarc:
  308. call setenv()
  309. address command 'copy env:'envname' envarc:'envname '>nil:'
  310. return
  311.  
  312. unsetenvarc:
  313. call setenv()
  314. if exists('envarc:'envname) then delete('envarc:'envname)
  315. if exists('env:'envname) then delete('env:'envname)
  316. return
  317.  
  318. testtcp:
  319. call pragma('W','N')
  320. if ~showlist(H,'TCP') then do
  321.   if miamifound=1 then call showtx(0,'You must be on line to use*n the dictionary or thesauris.*n *nYou can start Miami from the menus.')
  322.   else call showtx(0,'Can not find TCP device*n *nYou must be on line to use*n the dictionary or thesauris.')
  323.   savetx=''
  324.   call pragma('W')
  325.   return(1)
  326. end
  327. call pragma('W')
  328. if (showlist('P','MIAMI.1')) then do
  329.   address MIAMI.1 'ISONLINE'
  330.   if ~rc then do
  331.     call showtx(0,'Miami is not on line*n *nYou must be on line to use *n the dictionary or thesauris.*n *nYou can start Mimai from the menus.')
  332.     savetx=''
  333.     return(1)
  334.   end
  335.   return(0)
  336. end
  337. if (showlist('P','AMITCP')) then do
  338.   /*hmmm*/
  339. end
  340. return(0)
  341.  
  342. bubble:
  343. newbub=arg(1)
  344. if newbub=-1 then newbub=0
  345. if (bubbleon=newbub) then return()
  346. if bubbleon~=0 then call  topipe('bubble')
  347. if newbub=0 then delaybub=0
  348. else do
  349.   bubx=in3
  350.   buby=in4
  351.   delaybub=3
  352. end
  353. return
  354.  
  355. extradef:
  356. parse var savedef '<select name=jump size=3>' options '</select' . '<input type=hidden name=list value="' list '"'
  357. savedef=''
  358. if options='' then return(0)
  359. parse var options '>' newword '0a'x options
  360. do while options~=''
  361.   call writeln(ca,'read id 'abortgad)
  362.   if readln(ca)~=0 then do
  363.     savetx=savetx||'0a'x||' OPERATION ABORTED !'||'0a'x
  364.     return(0)
  365.   end
  366.   parse var options '>' newword '0a'x options
  367.   if (level=0 ||(right(newword,1)~=']' & level=1)) then savetx=savetx' * 'newword
  368.   else call transmore()
  369. end
  370. return(0)
  371.  
  372. transmore:
  373. if testtcp() then return
  374. call topipe('id 0 s 8 gt " Connecting for *"'newword'*""')
  375. if book=0 then t1='hdwd='savew'&book=Dictionary&jump='newword'&list='list
  376. else t1='hdwd='savew'&book=Thesaurus&jump='newword'&list='list
  377. t1=urlencode(t1)
  378. t2=length(t1)
  379. t2='Content-Length: 't2
  380. if open(net,'tcp:www.m-w.com/80') then do
  381.   call topipe('id 0 s 8 gt " Getting information for *"'newword'*""')
  382.   call writeln(net,"POST /cgi-bin/dictionary HTTP/1.0")
  383.   call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by AWNPdictthing (2.5 ))")
  384.   call writeln(net,"Accept: */*;q=1")
  385.   call writeln(net,"Host: www.m-w.com")
  386.   call writeln(net,t2)
  387.   call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  388.   call writeln(net,"")
  389.   call writeln(net,t1)
  390.   call writeln(net,"")
  391.   def=''
  392.   do while ~eof(net)
  393.     if length(def)< 54000 then def=def||readch(net,10000)
  394.   end
  395.   call close(net)
  396.   call getdef()
  397. end
  398. else do
  399.   savetx=savetx||'0a'x||'>>Connect Failed for 'newword'<<'||'0a'x
  400.   call Showtx(0,"Could not connect to m-w.com")
  401.   options=''
  402. end
  403. return(0)
  404.  
  405. urlencode:
  406. uin=translate(arg(1),'+',' ')
  407. do while index(uin,';')>0
  408.   parse var uin in1 ';' in2
  409.   uin=in1||'%3B'||in2
  410. end
  411. do while index(uin,'=')>0
  412.   parse var uin in1 '=' in2
  413.   uin=in1||'%3D'||in2
  414. end
  415. do while index(uin,'[')>0
  416.   parse var uin in1 '[' in2
  417.   uin=in1||'%5B'||in2
  418. end
  419. do while index(uin,']')>0
  420.   parse var uin in1 ']' in2
  421.   uin=in1||'%5D'||in2
  422. end
  423. do while index(uin,',')>0
  424.   parse var uin in1 ',' in2
  425.   uin=in1||'%2C'||in2
  426. end
  427. return(uin)
  428.  
  429. htmltotx:
  430. call open(fhz,"awnpipe:/xz")
  431. call open(fh,'awnpipe:dec/u/f','W')
  432. call writeln(fhz,arg(1));
  433. call writech(fh,readch(fhz,64000))
  434. call close(fhz);
  435. call close(fh)
  436. call open(fh,'awnpipe:dec','R')
  437. sel=readch(fh,64000)
  438. call close(fh)
  439. return(sel)
  440.  
  441. rxhst:
  442. rxcmd=readch(rxfh,rxin3)
  443. parse var rxcmd rx1 rx2
  444. rx2=strip(rx2)
  445. if rxin2>8 then call rxpipe("rc 10")
  446. if rxin2=0 then do
  447.   call topipe('id 0 s '2+64+2048)
  448.   call rxpipe('rc 0 result "Window brought to front"')
  449. end
  450. if rxin2=1 then do
  451.   if (upper(rx2)='AWEB') then do
  452.     if screen~='' then  do
  453.       call rxpipe('rc 0 result "aweb dict exiting"')
  454.       exit
  455.     end
  456.     else  call rxpipe('rc 0 result "not run from aweb"')
  457.   end
  458.   else do
  459.     call rxpipe('rc 0 result "exiting"')
  460.     exit
  461.   end
  462. end
  463. if rxin2=2 then do
  464.   if testtcp() then call rxpipe('rc 5')
  465.   else do
  466.     logon=logging
  467.     call getword(rx2)
  468.     if length(savetx)>60000 then call rxpipe('rc 6')
  469.     else do
  470.       call rxpipe('rc 0 bd result "'length(savetx)'"')
  471.       call writech(rxfh,savetx)
  472.     end
  473.   end
  474. end
  475. if rxin2=3 then do
  476.   call writeln(ca,'id 'txtgad' read')
  477.   len=readln(ca)
  478.   data=readch(ca,len)
  479.   if open(rxsfh,rx2,'W') then do
  480.     call writeln(rxsfh,data)
  481.     call rxpipe('rc 0 result "'length(data)'"')
  482.     call close(rxsfh)
  483.   end
  484.   else call rxpipe('rc 10')
  485. end
  486. if rxin2=4 then do
  487.   call rxpipe('rc 0 result "clearing log"')
  488.   call clearlog()
  489. end
  490. if rxin2=5 then do
  491.   if datatype(rx2,'W')then do
  492.     call rxpipe('rc 0 result "'book'"')
  493.     call  topipe('ref id 'bookgad' s 'rx2)
  494.     book=rx2
  495.   end
  496.   else call rxpipe('rc 10')
  497. end
  498. if rxin2=6 then do
  499.   if datatype(rx2,'W')then do
  500.     call rxpipe('rc 0 result "'level'"')
  501.     call  topipe('ref id 'levelgad' s 'rx2)
  502.     level=rx2
  503.   end
  504.   else call rxpipe('rc 10')
  505. end
  506. if rxin2=7 then do
  507.   if datatype(rx2,'W')then do
  508.     call rxpipe('rc 0')
  509.     call iconify(rx2)
  510.   end
  511.   else call rxpipe('rc 10')
  512. end
  513. if rxin2=8 then do
  514.   if datatype(rx2,'W')then do
  515.     call rxpipe('rc 0 result 'logging)
  516.     logging=rx2
  517.   end
  518.   else call rxpipe('rc 10')
  519. end
  520. return
  521.  
  522. getword:
  523.  
  524. w=strip(arg(1))
  525. call topipe('id 'lay1' dis 1 ref')
  526. call topipe('id 'lay2' dis 1 ref')
  527. if level>0 then call topipe('id 'abortgad' dis 0 ref')
  528. call trans()
  529. if logon>0 then do
  530.   call writeln(ca,'id 'txtgad' scroll -1 bd gt "'length(savetx)+1'"')
  531.   newpos=topipe(savetx)
  532.   poslist.pcnt=newpos
  533.   pcnt=pcnt+1
  534.   call topipe('id 'txtgad' scroll 'oldpos)
  535. end
  536. call topipe('id 'lay1' dis 0 ref')
  537. call topipe('id 'lay2' dis 0 ref')
  538. call topipe('id 'abortgad' s 0 dis 1 ref')
  539. oldpos=newpos
  540. return
  541.  
  542.  
  543. checkrx:
  544. call rxpipe('tick 0')
  545. do while 1
  546.   parse value readln(rxfh) with rxin1 rxin2 rxin3 .
  547.   if rxin1='arexx' then call rxhst()
  548.   else return()
  549. end
  550. return()
  551.  
  552. escapenl:
  553. call open(nlfh,'awnpipe:/x0')
  554. call writech(nlfh,'010a02'x||'*n')
  555. call writech(nlfh,arg(1))
  556. nlout=readch(nlfh,60000)
  557. call close(nlfh)
  558. return(nlout)
  559.  
  560. clearlog:
  561. oldpos=topipe('id 'txtgad' gt ""')
  562. pcnt=0
  563. return
  564.  
  565.  
  566.