window 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/rc
  2. fn checkwsys{
  3. if(~ $wsys ''){
  4. echo 'window: $wsys not defined'
  5. exit bad
  6. }
  7. }
  8. # original version used mount to do the work
  9. fn oldway{
  10. switch($#*){
  11. case 0 1
  12. echo usage: window '''minx miny maxx maxy''' cmd args ...
  13. exit usage
  14. }
  15. checkwsys
  16. dir = /mnt/wsys
  17. srv = $wsys
  18. rfork ne
  19. {
  20. if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
  21. shift
  22. bind -b $dir /dev
  23. echo -n `{basename $1} > /dev/label >[2] /dev/null
  24. exec $* < /dev/cons > /dev/cons >[2] /dev/cons
  25. }
  26. }&
  27. }
  28. # if argument is of form '100 100 200 200' or '100,100,200,200' use old way
  29. if(~ $1 *[0-9][' ,'][0-9]*){
  30. oldway $*
  31. exit
  32. }
  33. # geometry parameters are:
  34. # -r 0 0 100 100
  35. # -dx n
  36. # -dy n
  37. # -minx n
  38. # -miny n
  39. # -maxx n
  40. # -maxy n
  41. # where n can be a number, to set the value, or +number or -number to change it
  42. # find wctl file
  43. fn getwctl{
  44. if(~ $wctl ''){
  45. if(test -f /dev/wctl) echo /dev/wctl
  46. if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
  47. if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
  48. if not {
  49. echo window: '$wctl' not defined >[1=2]
  50. exit usage
  51. }
  52. }
  53. if not echo $wctl
  54. }
  55. # use mount to make local window
  56. if(~ $1 -m){
  57. shift
  58. checkwsys
  59. dir = /mnt/wsys
  60. srv = $wsys
  61. rfork ne
  62. {
  63. unmount /mnt/acme /dev >[2]/dev/null
  64. if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
  65. bind -b $dir /dev
  66. # toss geometry parameters to find command
  67. while(~ $1 -*)
  68. switch($1){
  69. case -dx -dy -minx -miny -maxx -maxy
  70. shift 2
  71. case -r
  72. shift 5
  73. case -hide
  74. shift
  75. }
  76. if(~ $#* 0) cmd = rc
  77. if not cmd = $*
  78. echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
  79. exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
  80. }
  81. }&
  82. }
  83. if not echo new -cd `{pwd} $* >> `{getwctl}