URI: 
       tadict - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tadict (1601B)
       ---
            1 #!/usr/local/plan9/bin/rc
            2 
            3 . 9.rc
            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
           11         # $5 - eq0 beginning of expanded selection
           12         # $6 - eq1 end of expanded selection
           13         # $7 - flag
           14         # $8 - nr number of runes in $9
           15         # $9 - text
           16         # $10 - chorded argument
           17         # $11 - origin of chorded argument
           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)
           34                                 dictwin /adict/$9/ $9
           35                         if not
           36                                 dictwin /adict/$dict/$9 $dict $9
           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=$1
           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){
           80                 dict=`{dict -d'?' | 9 sed -n 's/^   ([^\[         ]+).*/\1/p' | sed 1q}
           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