blob: c744c56044b70bb2a9ff294a32789d6a21a25ab5 [file] [log] [blame]
rsc2b85f702005-01-11 20:58:13 +00001#!/usr/local/plan9/bin/rc
rsc474ef692005-01-07 19:12:32 +00002
rsc9bbe4592005-01-14 05:55:09 +00003. 9.rc
rsc474ef692005-01-07 19:12:32 +00004. $PLAN9/lib/acme.rc
5
6fn event {
7 # $1 - c1 origin of event
8 # $2 - c2 type of action
9 # $3 - q0 beginning of selection
10 # $4 - q1 end of selection
rsc886f1212005-01-07 19:17:58 +000011 # $5 - eq0 beginning of expanded selection
12 # $6 - eq1 end of expanded selection
13 # $7 - flag
14 # $8 - nr number of runes in $7
15 # $9 - text
16 # $10 - chorded argument
17 # $11 - origin of chorded argument
rsc474ef692005-01-07 19:12:32 +000018
19 switch($1$2){
20 case E* # write to body or tag
21 case F* # generated by ourselves; ignore
22 case K* # type away we do not care
23 case Mi # mouse: text inserted in tag
24 case MI # mouse: text inserted in body
25 case Md # mouse: text deleted from tag
26 case MD # mouse: text deleted from body
27
28 case Mx MX # button 2 in tag or body
29 winwriteevent $*
30
31 case Ml ML # button 3 in tag or body
32 {
33 if(~ $dict NONE)
rsc886f1212005-01-07 19:17:58 +000034 dictwin /adict/$9/ $9
rsc474ef692005-01-07 19:12:32 +000035 if not
rsc886f1212005-01-07 19:17:58 +000036 dictwin /adict/$dict/$9 $dict $9
rsc474ef692005-01-07 19:12:32 +000037 } &
38 }
39}
40
41fn dictwin {
42 newwindow
43 winname $1
44 switch($#*){
45 case 1
46 dict -d '?' >[2=1] | sed 1d | winwrite body
47 case 2
48 dict=$2
49 case 3
50 dict=$2
51 dict -d $dict $3 >[2=1] | winwrite body
52 }
53 winctl clean
54 wineventloop
55}
56
57dict=NONE
58if(~ $1 -d){
59 shift
60 dict=$2
61 shift
62}
63if(~ $1 -d*){
64 dict=`{echo $1 | sed 's/-d//'}
65 shift
66}
67if(~ $1 -*){
68 echo 'usage: adict [-d dict] [word...]' >[1=2]
69 exit usage
70}
71
72switch($#*){
73case 0
74 if(~ $dict NONE)
75 dictwin /adict/
76 if not
77 dictwin /adict/$dict/ $dict
78case *
79 if(~ $dict NONE){
rsc2b85f702005-01-11 20:58:13 +000080 dict=`{dict -d'?' | 9 sed -n 's/^ ([^\[ ]+).*/\1/p' | sed 1q}
rsc474ef692005-01-07 19:12:32 +000081 if(~ $#dict 0){
82 echo 'no dictionaries present on this system' >[1=2]
83 exit nodict
84 }
85 }
86 for(i)
87 dictwin /adict/$dict/$i $dict $i
88}
89