Blob


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