openpgp: 7E25094870599135A83DD2C6C446E92ECE0D66B2
[www.jankratochvil.net.git] / dia-w.sh.in
1 #! /bin/bash
2 # $Id$
3 # Try to run "dia" with '-e' option, Xvnc wrapping if needed.
4 # Copyright (C) 2000,2003 Jan Kratochvil <project-macros@jankratochvil.net>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; exactly version 2 of June 1991 is required
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
20 empty=
21 if test "x@PATH_XVNC@" != "x@PATH_XVNC$empty@"
22 then
23         PATH_XVNC="@PATH_XVNC@"
24 fi
25 if test "x@PATH_BC@" != "x@PATH_BC$empty@"
26 then
27         PATH_BC="@PATH_BC@"
28 fi
29 if test "x@PATH_DIA@" != "x@PATH_DIA$empty@"
30 then
31         PATH_DIA="@PATH_DIA@"
32 else
33         PATH_DIA=dia
34 fi
35
36 unset xpid
37 if test "x$PATH_XVNC" != "x"
38 then
39         xport=$[($$%4096)+2000]
40         notdone=true
41         run=true
42         while $notdone
43         do
44                 if test -r /proc/net/tcp -a "x$PATH_BC" != "x"
45                 then
46                         loop=true
47                         while $loop
48                         do
49                                 hex="`echo "obase=16;$[$xport+5900]"|$PATH_BC`"
50                                 if grep -q ":`echo "000$hex"|tail -c5` " /proc/net/tcp
51                                 then
52                                         if $run
53                                         then
54                                                 xport=$[$xport+1]
55                                         else
56                                                 notdone=false
57                                                 loop=false
58                                         fi
59                                 else
60                                         if $run
61                                         then
62                                                 loop=false
63                                         else
64                                                 echo -n .
65                                                 sleep 1
66                                         fi
67                                 fi
68                         done
69                 else
70                         notdone=$run
71                 fi
72                 if $run
73                 then
74                         export DISPLAY=":$xport"
75                         $PATH_XVNC $DISPLAY & xpid=$!
76                         run=false
77                 fi
78         done
79 else
80         if test "x$DISPLAY" = "x"
81         then
82                 export DISPLAY=":0"
83         fi
84 fi
85
86 for opt in "--disable-crash-dialog" "";do
87         $PATH_DIA $opt "$@";r=$?
88
89         if test "x$xpid" != "x"
90         then
91                 kill $xpid
92         fi
93
94         if test $r = 0
95         then
96                 exit $r
97         fi
98 done
99
100 exit $r