dtstyle: Coverity 89011
[oweals/cde.git] / cde / util / scripts / xon.sh
1 #!/bin/sh
2 # $XConsortium: xon.sh /main/2 1995/07/19 18:06:13 drk $
3 # start up xterm (or any other X command) on the specified host
4 # Usage: xon host [arguments] [command]
5 case $# in
6 0)
7         echo "Usage: $0 <hostname> [-user user] [-name window-name] [-debug]"
8         echo "[-screen screen-number] [command ...]"
9         exit 1
10         ;;
11 esac
12 target=$1
13 shift
14 label=$target
15 resource=xterm-$label
16 rcmd="rsh $target"
17 case $DISPLAY in
18 unix:*)
19         DISPLAY=`echo $DISPLAY | sed 's/unix//'`
20         ;;
21 esac
22 case $DISPLAY in
23 :*)
24         fullname=`hostname`
25         hostname=`echo $fullname | sed 's/\..*$//'`
26         if [ $hostname = $target -o $fullname = $target ]; then
27                 DISPLAY=$DISPLAY
28                 rcmd="sh -c"
29         else
30                 DISPLAY=$fullname$DISPLAY
31         fi
32         ;;
33 esac
34 username=
35 xauth=
36 case x$XUSERFILESEARCHPATH in
37 x)
38         xpath='HOME=${HOME-`pwd`} '
39         ;;
40 *)
41         xpath='HOME=${HOME-`pwd`} XUSERFILESEARCHPATH=${XUSERFILESEARCHPATH-"'"$XUSERFILESEARCHPATH"'"} '
42         ;;
43 esac
44 redirect=" < /dev/null > /dev/null 2>&1 &"
45 command=
46 ls=-ls
47 continue=:
48 while $continue; do
49         case $1 in
50         -user)
51                 shift
52                 username="-l $1"
53                 label="$target $1"
54                 rcmd="rsh $target $username"
55                 shift
56                 case x$XAUTHORITY in
57                 x)
58                         XAUTHORITY="$HOME/.Xauthority"
59                         ;;
60                 esac
61                 case x$XUSERFILESEARCHPATH in
62                 x)
63                         ;;
64                 *)
65                         xpath="XUSERFILESEARCHPATH=$XUSERFILESEARCHPATH "
66                         ;;
67                 esac
68                 ;;
69         -access)
70                 shift
71                 xhost +$target
72                 ;;
73         -name)
74                 shift
75                 label="$1"
76                 resource="$1"
77                 shift
78                 ;;
79         -nols)
80                 shift
81                 ls=
82                 ;;
83         -debug)
84                 shift
85                 redirect=
86                 ;;
87         -screen)
88                 shift
89                 DISPLAY=`echo $DISPLAY | sed 's/:\\([0-9][0-9]*\\)\\.[0-9]/:\1/'`.$1
90                 shift
91                 ;;
92         *)
93                 continue=false
94                 ;;
95         esac
96 done
97 case x$XAUTHORITY in
98 x)
99         ;;
100 x*)
101         xauth="XAUTHORITY=$XAUTHORITY "
102         ;;
103 esac
104 vars="$xpath$xauth"DISPLAY="$DISPLAY"
105 case $# in
106 0)
107         $rcmd 'sh -c '"'$vars"' xterm '$ls' -name "'"$resource"'" -T "'"$label"'" -n "'"$label"'" '"$redirect'"
108         ;;
109 *)
110         $rcmd 'sh -c '"'$vars"' '"$*$redirect'"
111         ;;
112 esac