git: Line endings of README.txt
[projects/chimara/chimara.git] / bundle / launcher.sh
1 #!/bin/sh
2
3 if test "x$GTK_DEBUG_LAUNCHER" != x; then
4     set -x
5 fi
6
7 if test "x$GTK_DEBUG_GDB" != x; then
8     EXEC="gdb --args"
9 else
10     EXEC=exec
11 fi
12
13 name=`basename "$0"`
14 tmp="$0"
15 tmp=`dirname "$tmp"`
16 tmp=`dirname "$tmp"`
17 bundle=`dirname "$tmp"`
18 bundle_contents="$bundle"/Contents
19 bundle_res="$bundle_contents"/Resources
20 bundle_lib="$bundle_res"/lib
21 bundle_bin="$bundle_res"/bin
22 bundle_data="$bundle_res"/share
23 bundle_etc="$bundle_res"/etc
24
25 export DYLD_LIBRARY_PATH="$bundle_lib"
26 export XDG_CONFIG_DIRS="$bundle_etc"/xdg
27 export XDG_DATA_DIRS="$bundle_data"
28 export GTK_DATA_PREFIX="$bundle_res"
29 export GTK_EXE_PREFIX="$bundle_res"
30 export GTK_PATH="$bundle_res"
31
32 export GTK2_RC_FILES="$bundle_etc/gtk-2.0/gtkrc"
33 export GTK3_RC_FILES="$bundle_etc/gtk-3.0/gtkrc"
34 export GTK_IM_MODULE_FILE="$bundle_etc/gtk-3.0/gtk.immodules"
35 export GDK_PIXBUF_MODULE_FILE="$bundle_etc/gtk-3.0/gdk-pixbuf.loaders"
36 export PANGO_RC_FILE="$bundle_etc/pango/pangorc"
37
38 APP=name
39 I18NDIR="$bundle_data/locale"
40 # Set the locale-related variables appropriately:
41 unset LANG LC_MESSAGES LC_MONETARY LC_COLLATE
42
43 # Has a language ordering been set?
44 # If so, set LC_MESSAGES and LANG accordingly; otherwise skip it.
45 # First step uses sed to clean off the quotes and commas, to change - to _, and change the names for the chinese scripts from "Hans" to CN and "Hant" to TW.
46 APPLELANGUAGES=`defaults read .GlobalPreferences AppleLanguages | sed -En   -e 's/\-/_/' -e 's/Hant/TW/' -e 's/Hans/CN/' -e 's/[[:space:]]*\"?([[:alnum:]_]+)\"?,?/\1/p' `
47 if test "$APPLELANGUAGES"; then
48     # A language ordering exists.
49     # Test, item per item, to see whether there is an corresponding locale.
50     for L in $APPLELANGUAGES; do
51         #test for exact matches:
52        if test -f "$I18NDIR/${L}/LC_MESSAGES/$APP.mo"; then
53             export LANG=$L
54             break
55         fi
56         #This is a special case, because often the original strings are in US
57         #English and there is no translation file.
58         if test "x$L" == "xen_US"; then
59             export LANG=$L
60             break
61         fi
62         #OK, now test for just the first two letters:
63         if test -f "$I18NDIR/${L:0:2}/LC_MESSAGES/$APP.mo"; then
64             export LANG=${L:0:2}
65             break
66         fi
67         #Same thing, but checking for any english variant.
68         if test "x${L:0:2}" == "xen"; then
69             export LANG=$L
70             break
71         fi;
72     done  
73 fi
74 unset APPLELANGUAGES L
75
76 # If we didn't get a language from the language list, try the Collation preference, in case it's the only setting that exists.
77 APPLECOLLATION=`defaults read .GlobalPreferences AppleCollationOrder`
78 if test -z ${LANG} -a -n $APPLECOLLATION; then
79     if test -f "$I18NDIR/${APPLECOLLATION:0:2}/LC_MESSAGES/$APP.mo"; then
80         export LANG=${APPLECOLLATION:0:2}
81     fi
82 fi
83 if test ! -z $APPLECOLLATION; then
84     export LC_COLLATE=$APPLECOLLATION
85 fi
86 unset APPLECOLLATION
87
88 # Continue by attempting to find the Locale preference.
89 APPLELOCALE=`defaults read .GlobalPreferences AppleLocale`
90
91 if test -f "$I18NDIR/${APPLELOCALE:0:5}/LC_MESSAGES/$APP.mo"; then
92     if test -z $LANG; then 
93         export LANG="${APPLELOCALE:0:5}"
94     fi
95
96 elif test -z $LANG -a -f "$I18NDIR/${APPLELOCALE:0:2}/LC_MESSAGES/$APP.mo"; then
97     export LANG="${APPLELOCALE:0:2}"
98 fi
99
100 #Next we need to set LC_MESSAGES. If at all possilbe, we want a full
101 #5-character locale to avoid the "Locale not supported by C library"
102 #warning from Gtk -- even though Gtk will translate with a
103 #two-character code.
104 if test -n $LANG; then 
105 #If the language code matches the applelocale, then that's the message
106 #locale; otherwise, if it's longer than two characters, then it's
107 #probably a good message locale and we'll go with it.
108     if test $LANG == ${APPLELOCALE:0:5} -o $LANG != ${LANG:0:2}; then
109         export LC_MESSAGES=$LANG
110 #Next try if the Applelocale is longer than 2 chars and the language
111 #bit matches $LANG
112     elif test $LANG == ${APPLELOCALE:0:2} -a $APPLELOCALE > ${APPLELOCALE:0:2}; then
113         export LC_MESSAGES=${APPLELOCALE:0:5}
114 #Fail. Get a list of the locales in $PREFIX/share/locale that match
115 #our two letter language code and pick the first one, special casing
116 #english to set en_US
117     elif test $LANG == "en"; then
118         export LC_MESSAGES="en_US"
119     else
120         LOC=`find $PREFIX/share/locale -name $LANG???`
121         for L in $LOC; do 
122             export LC_MESSAGES=$L
123         done
124     fi
125 else
126 #All efforts have failed, so default to US english
127     export LANG="en_US"
128     export LC_MESSAGES="en_US"
129 fi
130 CURRENCY=`echo $APPLELOCALE |  sed -En 's/.*currency=([[:alpha:]]+).*/\1/p'`
131 if test "x$CURRENCY" != "x"; then 
132 #The user has set a special currency. Gtk doesn't install LC_MONETARY files, but Apple does in /usr/share/locale, so we're going to look there for a locale to set LC_CURRENCY to.
133     if test -f /usr/local/share/$LC_MESSAGES/LC_MONETARY; then
134         if test -a `cat /usr/local/share/$LC_MESSAGES/LC_MONETARY` == $CURRENCY; then
135             export LC_MONETARY=$LC_MESSAGES
136         fi
137     fi
138     if test -z "$LC_MONETARY"; then 
139         FILES=`find /usr/share/locale -name LC_MONETARY -exec grep -H $CURRENCY {} \;`
140         if test -n "$FILES"; then 
141             export LC_MONETARY=`echo $FILES | sed -En 's%/usr/share/locale/([[:alpha:]_]+)/LC_MONETARY.*%\1%p'`
142         fi
143     fi
144 fi
145 #No currency value means that the AppleLocale governs:
146 if test -z "$LC_MONETARY"; then
147     LC_MONETARY=${APPLELOCALE:0:5}
148 fi
149 #For Gtk, which only looks at LC_ALL:
150 export LC_ALL=$LC_MESSAGES
151
152 unset APPLELOCALE FILES LOC
153
154 if test -f "$bundle_lib/charset.alias"; then
155     export CHARSETALIASDIR="$bundle_lib"
156 fi
157
158 # Extra arguments can be added in environment.sh.
159 EXTRA_ARGS=
160 if test -f "$bundle_res/environment.sh"; then
161   source "$bundle_res/environment.sh"
162 fi
163
164 # Strip out the argument added by the OS.
165 if /bin/expr "x$1" : '^x-psn_' > /dev/null; then
166     shift 1
167 fi
168
169 $EXEC "$bundle_contents/MacOS/$name-bin" "$@" $EXTRA_ARGS