modperl branch collapsed back to MAIN trunk, man!
[www.jankratochvil.net.git] / dia-w.sh.in
diff --git a/dia-w.sh.in b/dia-w.sh.in
new file mode 100755 (executable)
index 0000000..899f18c
--- /dev/null
@@ -0,0 +1,93 @@
+#! /bin/bash
+# $Id$
+# Try to run "dia" with '-e' option, Xvnc wrapping if needed.
+# Copyright (C) 2000,2003 Jan Kratochvil <project-macros@jankratochvil.net>
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; exactly version 2 of June 1991 is required
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+empty=
+if test "x@PATH_XVNC@" != "x@PATH_XVNC$empty@"
+then
+       PATH_XVNC="@PATH_XVNC@"
+fi
+if test "x@PATH_BC@" != "x@PATH_BC$empty@"
+then
+       PATH_BC="@PATH_BC@"
+fi
+if test "x@PATH_DIA@" != "x@PATH_DIA$empty@"
+then
+       PATH_DIA="@PATH_DIA@"
+else
+       PATH_DIA=dia
+fi
+
+unset xpid
+if test "x$PATH_XVNC" != "x"
+then
+       xport=$[($$%4096)+2000]
+       notdone=true
+       run=true
+       while $notdone
+       do
+               if test -r /proc/net/tcp -a "x$PATH_BC" != "x"
+               then
+                       loop=true
+                       while $loop
+                       do
+                               hex="`echo "obase=16;$[$xport+5900]"|$PATH_BC`"
+                               if grep -q ":`echo "000$hex"|tail -c5` " /proc/net/tcp
+                               then
+                                       if $run
+                                       then
+                                               xport=$[$xport+1]
+                                       else
+                                               notdone=false
+                                               loop=false
+                                       fi
+                               else
+                                       if $run
+                                       then
+                                               loop=false
+                                       else
+                                               echo -n .
+                                               sleep 1
+                                       fi
+                               fi
+                       done
+               else
+                       notdone=$run
+               fi
+               if $run
+               then
+                       export DISPLAY=":$xport"
+                       $PATH_XVNC $DISPLAY & xpid=$!
+                       run=false
+               fi
+       done
+else
+       if test "x$DISPLAY" = "x"
+       then
+               export DISPLAY=":0"
+       fi
+fi
+
+$PATH_DIA --disable-crash-dialog "$@";r=$?
+
+if test "x$xpid" != "x"
+then
+       kill $xpid
+fi
+
+exit $r