rsc | 2b85f70 | 2005-01-11 20:58:13 +0000 | [diff] [blame] | 1 | #!/usr/local/plan9/bin/rc |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 2 | |
rsc | 9bbe459 | 2005-01-14 05:55:09 +0000 | [diff] [blame] | 3 | . 9.rc |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 4 | . $PLAN9/lib/acme.rc |
| 5 | |
| 6 | fn 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 |
rsc | 886f121 | 2005-01-07 19:17:58 +0000 | [diff] [blame] | 11 | # $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 |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 18 | |
| 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) |
rsc | 886f121 | 2005-01-07 19:17:58 +0000 | [diff] [blame] | 34 | dictwin /adict/$9/ $9 |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 35 | if not |
rsc | 886f121 | 2005-01-07 19:17:58 +0000 | [diff] [blame] | 36 | dictwin /adict/$dict/$9 $dict $9 |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 37 | } & |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | fn 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 | |
| 57 | dict=NONE |
| 58 | if(~ $1 -d){ |
| 59 | shift |
| 60 | dict=$2 |
| 61 | shift |
| 62 | } |
| 63 | if(~ $1 -d*){ |
| 64 | dict=`{echo $1 | sed 's/-d//'} |
| 65 | shift |
| 66 | } |
| 67 | if(~ $1 -*){ |
| 68 | echo 'usage: adict [-d dict] [word...]' >[1=2] |
| 69 | exit usage |
| 70 | } |
| 71 | |
| 72 | switch($#*){ |
| 73 | case 0 |
| 74 | if(~ $dict NONE) |
| 75 | dictwin /adict/ |
| 76 | if not |
| 77 | dictwin /adict/$dict/ $dict |
| 78 | case * |
| 79 | if(~ $dict NONE){ |
rsc | 2b85f70 | 2005-01-11 20:58:13 +0000 | [diff] [blame] | 80 | dict=`{dict -d'?' | 9 sed -n 's/^ ([^\[ ]+).*/\1/p' | sed 1q} |
rsc | 474ef69 | 2005-01-07 19:12:32 +0000 | [diff] [blame] | 81 | 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 | |