Dropped the support of: $Options{"GetOptions_args"}
[macros.git] / glade-w.sh.in
1 #! /bin/bash
2 # $Id$
3 # Try to run "glade" with write-source 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_GLADE@" != "x@PATH_GLADE$empty@"
30 then
31         PATH_GLADE="@PATH_GLADE@"
32 else
33         PATH_GLADE=glade-2
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 if [ "$1" != "${1#/}" ];then
87      abs="$1"
88 else abs="$PWD/$1"
89 fi
90
91 while true;do
92         $PATH_GLADE --disable-crash-dialog -w "$abs";r=$?
93         if [ $r -eq 0 ];then
94                 break
95         fi
96         if [ "$DISPLAY" = ":0" ];then
97                 break
98         fi
99         export DISPLAY=":0"
100 done
101
102 if test "x$xpid" != "x"
103 then
104         kill $xpid
105 fi
106
107 exit $r