Include glade-2(1) --write-source support.
[macros.git] / glade-w.sh.in
diff --git a/glade-w.sh.in b/glade-w.sh.in
new file mode 100755 (executable)
index 0000000..313ebbf
--- /dev/null
@@ -0,0 +1,97 @@
+#! /bin/bash
+# $Id$
+# Try to run "glade" with write-source 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_GLADE@" != "x@PATH_GLADE$empty@"
+then
+       PATH_GLADE="@PATH_GLADE@"
+else
+       PATH_GLADE=glade-2
+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
+
+if [ "$1" != "${1#/}" ];then
+     abs="$1"
+else abs="$PWD/$1"
+fi
+$PATH_GLADE --disable-crash-dialog -w "$abs";r=$?
+
+if test "x$xpid" != "x"
+then
+       kill $xpid
+fi
+
+exit $r