Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

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