window 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
  64. bind -b $dir /dev
  65. # toss geometry parameters to find command
  66. while(~ $1 -*)
  67. switch($1){
  68. case -dx -dy -minx -miny -maxx -maxy
  69. shift 2
  70. case -r
  71. shift 5
  72. case -hide
  73. shift
  74. }
  75. if(~ $#* 0) cmd = rc
  76. if not cmd = $*
  77. echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
  78. exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
  79. }
  80. }&
  81. }
  82. if not echo new -cd `{pwd} $* >> `{getwctl}