summary refs log blame commit diff stats
path: root/osx/launcher.sh
blob: 4c21e56138791dd7a4a7e1e74d0d5a4d870c3739 (plain) (tree)























                                         
                           












                                                                      


                                                                             
 

                                                         

                                                   



































































































































                                                                                                                                                                                  
#!/bin/sh

if test "x$GTK_DEBUG_LAUNCHER" != x; then
    set -x
fi

if test "x$GTK_DEBUG_GDB" != x; then
    EXEC="gdb --args"
else
    EXEC=exec
fi

name=`basename "$0"`
tmp="$0"
tmp=`dirname "$tmp"`
tmp=`dirname "$tmp"`
bundle=`dirname "$tmp"`
bundle_contents="$bundle"/Contents
bundle_res="$bundle_contents"/Resources
bundle_lib="$bundle_res"/lib
bundle_bin="$bundle_res"/bin
bundle_data="$bundle_res"/share
bundle_etc="$bundle_res"/etc

export PREFIX="$bundle_res"
export DYLD_LIBRARY_PATH="$bundle_lib"
export XDG_CONFIG_DIRS="$bundle_etc"/xdg
export XDG_DATA_DIRS="$bundle_data"
export GTK_DATA_PREFIX="$bundle_res"
export GTK_EXE_PREFIX="$bundle_res"
export GTK_PATH="$bundle_res"

export GTK2_RC_FILES="$bundle_etc/gtk-2.0/gtkrc"
export GTK_IM_MODULE_FILE="$bundle_etc/gtk-2.0/gtk.immodules"
export GDK_PIXBUF_MODULE_FILE="$bundle_etc/gtk-2.0/gdk-pixbuf.loaders"
export PANGO_LIBDIR="$bundle_lib"
export PANGO_SYSCONFDIR="$bundle_etc"

export PYTHON="$bundle_contents/MacOS/python"
export PYTHONHOME="$bundle_res"
export PYTHONPATH="$bundle_lib/python2.7:$bundle_lib/python2.7/site-packages"

export OPENSSL_CONF="/System/Library/OpenSSL/openssl.cnf"

export HEXCHAT_LIBDIR="$bundle_lib/hexchat/plugins"

APP=name
I18NDIR="$bundle_data/locale"
# Set the locale-related variables appropriately:
unset LANG LC_MESSAGES LC_MONETARY LC_COLLATE

# Has a language ordering been set?
# If so, set LC_MESSAGES and LANG accordingly; otherwise skip it.
# 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.
APPLELANGUAGES=`defaults read .GlobalPreferences AppleLanguages | sed -En   -e 's/\-/_/' -e 's/Hant/TW/' -e 's/Hans/CN/' -e 's/[[:space:]]*\"?([[:alnum:]_]+)\"?,?/\1/p' `
if test "$APPLELANGUAGES"; then
    # A language ordering exists.
    # Test, item per item, to see whether there is an corresponding locale.
    for L in $APPLELANGUAGES; do
	#test for exact matches:
       if test -f "$I18NDIR/${L}/LC_MESSAGES/$APP.mo"; then
	    export LANG=$L
            break
        fi
	#This is a special case, because often the original strings are in US
	#English and there is no translation file.
	if test "x$L" == "xen_US"; then
	    export LANG=$L
	    break
	fi
	#OK, now test for just the first two letters:
        if test -f "$I18NDIR/${L:0:2}/LC_MESSAGES/$APP.mo"; then
	    export LANG=${L:0:2}
	    break
	fi
	#Same thing, but checking for any english variant.
	if test "x${L:0:2}" == "xen"; then
	    export LANG=$L
	    break
	fi;
    done  
fi
unset APPLELANGUAGES L

# If we didn't get a language from the language list, try the Collation preference, in case it's the only setting that exists.
APPLECOLLATION=`defaults read .GlobalPreferences AppleCollationOrder`
if test -z ${LANG} -a -n $APPLECOLLATION; then
    if test -f "$I18NDIR/${APPLECOLLATION:0:2}/LC_MESSAGES/$APP.mo"; then
	export LANG=${APPLECOLLATION:0:2}
    fi
fi
if test ! -z $APPLECOLLATION; then
    export LC_COLLATE=$APPLECOLLATION
fi
unset APPLECOLLATION

# Continue by attempting to find the Locale preference.
APPLELOCALE=`defaults read .GlobalPreferences AppleLocale`

if test -f "$I18NDIR/${APPLELOCALE:0:5}/LC_MESSAGES/$APP.mo"; then
    if test -z $LANG; then 
        export LANG="${APPLELOCALE:0:5}"
    fi

elif test -z $LANG -a -f "$I18NDIR/${APPLELOCALE:0:2}/LC_MESSAGES/$APP.mo"; then
    export LANG="${APPLELOCALE:0:2}"
fi

#Next we need to set LC_MESSAGES. If at all possilbe, we want a full
#5-character locale to avoid the "Locale not supported by C library"
#warning from Gtk -- even though Gtk will translate with a
#two-character code.
if test -n $LANG; then 
#If the language code matches the applelocale, then that's the message
#locale; otherwise, if it's longer than two characters, then it's
#probably a good message locale and we'll go with it.
    if test $LANG == ${APPLELOCALE:0:5} -o $LANG != ${LANG:0:2}; then
	export LC_MESSAGES=$LANG
#Next try if the Applelocale is longer than 2 chars and the language
#bit matches $LANG
    elif test $LANG == ${APPLELOCALE:0:2} -a $APPLELOCALE > ${APPLELOCALE:0:2}; then
	export LC_MESSAGES=${APPLELOCALE:0:5}
#Fail. Get a list of the locales in $PREFIX/share/locale that match
#our two letter language code and pick the first one, special casing
#english to set en_US
    elif test $LANG == "en"; then
	export LC_MESSAGES="en_US"
    else
	LOC=`find $PREFIX/share/locale -name $LANG???`
	for L in $LOC; do 
	    export LC_MESSAGES=$L
	done
    fi
else
#All efforts have failed, so default to US english
    export LANG="en_US"
    export LC_MESSAGES="en_US"
fi
CURRENCY=`echo $APPLELOCALE |  sed -En 's/.*currency=([[:alpha:]]+).*/\1/p'`
if test "x$CURRENCY" != "x"; then 
#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.
    if test -f /usr/local/share/$LC_MESSAGES/LC_MONETARY; then
	if test -a `cat /usr/local/share/$LC_MESSAGES/LC_MONETARY` == $CURRENCY; then
	    export LC_MONETARY=$LC_MESSAGES
	fi
    fi
    if test -z "$LC_MONETARY"; then 
	FILES=`find /usr/share/locale -name LC_MONETARY -exec grep -H $CURRENCY {} \;`
	if test -n "$FILES"; then 
	    export LC_MONETARY=`echo $FILES | sed -En 's%/usr/share/locale/([[:alpha:]_]+)/LC_MONETARY.*%\1%p'`
	fi
    fi
fi
#No currency value means that the AppleLocale governs:
if test -z "$LC_MONETARY"; then
    LC_MONETARY=${APPLELOCALE:0:5}
fi
#For Gtk, which only looks at LC_ALL:
export LC_ALL=$LC_MESSAGES

unset APPLELOCALE FILES LOC

if test -f "$bundle_lib/charset.alias"; then
    export CHARSETALIASDIR="$bundle_lib"
fi

# Extra arguments can be added in environment.sh.
EXTRA_ARGS=
if test -f "$bundle_res/environment.sh"; then
  source "$bundle_res/environment.sh"
fi

# Strip out the argument added by the OS.
if /bin/expr "x$1" : '^x-psn_' > /dev/null; then
    shift 1
fi

$EXEC "$bundle_contents/MacOS/$name-bin" "$@" $EXTRA_ARGS
y_ask (char *name, char *networks); void fe_text_clear (struct session *sess, int lines); void fe_close_window (struct session *sess); void fe_progressbar_start (struct session *sess); void fe_progressbar_end (struct server *serv); void fe_print_text (struct session *sess, char *text, time_t stamp, gboolean no_activity); void fe_userlist_insert (struct session *sess, struct User *newuser, gboolean sel); int fe_userlist_remove (struct session *sess, struct User *user); void fe_userlist_rehash (struct session *sess, struct User *user); void fe_userlist_update (struct session *sess, struct User *user); void fe_userlist_numbers (struct session *sess); void fe_userlist_clear (struct session *sess); void fe_userlist_set_selected (struct session *sess); void fe_uselect (session *sess, char *word[], int do_clear, int scroll_to); void fe_dcc_add (struct DCC *dcc); void fe_dcc_update (struct DCC *dcc); void fe_dcc_remove (struct DCC *dcc); int fe_dcc_open_recv_win (int passive); int fe_dcc_open_send_win (int passive); int fe_dcc_open_chat_win (int passive); void fe_clear_channel (struct session *sess); void fe_session_callback (struct session *sess); void fe_server_callback (struct server *serv); void fe_url_add (const char *text); void fe_pluginlist_update (void); void fe_buttons_update (struct session *sess); void fe_dlgbuttons_update (struct session *sess); void fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive); void fe_set_channel (struct session *sess); void fe_set_title (struct session *sess); void fe_set_nonchannel (struct session *sess, int state); void fe_set_nick (struct server *serv, char *newnick); void fe_ignore_update (int level); void fe_beep (session *sess); void fe_lastlog (session *sess, session *lastlog_sess, char *sstr, gtk_xtext_search_flags flags); void fe_set_lag (server *serv, long lag); void fe_set_throttle (server *serv); void fe_set_away (server *serv); void fe_serverlist_open (session *sess); void fe_get_bool (char *title, char *prompt, void *callback, void *userdata); void fe_get_str (char *prompt, char *def, void *callback, void *ud); void fe_get_int (char *prompt, int def, void *callback, void *ud); #define FRF_WRITE 1 /* save file */ #define FRF_MULTIPLE 2 /* multi-select */ #define FRF_RECENTLYUSED 4 /* let gtk decide start dir instead of our config */ #define FRF_CHOOSEFOLDER 8 /* choosing a folder only */ #define FRF_FILTERISINITIAL 16 /* filter is initial directory */ #define FRF_NOASKOVERWRITE 32 /* don't ask to overwrite existing files */ #define FRF_EXTENSIONS 64 /* specify file extensions to be displayed */ #define FRF_MIMETYPES 128 /* specify file mimetypes to be displayed */ void fe_get_file (const char *title, char *initial, void (*callback) (void *userdata, char *file), void *userdata, int flags); typedef enum { FE_GUI_HIDE, FE_GUI_SHOW, FE_GUI_FOCUS, FE_GUI_FLASH, FE_GUI_COLOR, FE_GUI_ICONIFY, FE_GUI_MENU, FE_GUI_ATTACH, FE_GUI_APPLY, } fe_gui_action; void fe_ctrl_gui (session *sess, fe_gui_action action, int arg); int fe_gui_info (session *sess, int info_type); void *fe_gui_info_ptr (session *sess, int info_type); void fe_confirm (const char *message, void (*yesproc)(void *), void (*noproc)(void *), void *ud); char *fe_get_inputbox_contents (struct session *sess); int fe_get_inputbox_cursor (struct session *sess); void fe_set_inputbox_contents (struct session *sess, char *text); void fe_set_inputbox_cursor (struct session *sess, int delta, int pos); void fe_open_url (const char *url); void fe_menu_del (menu_entry *); char *fe_menu_add (menu_entry *); void fe_menu_update (menu_entry *); #define FE_SE_CONNECT 0 #define FE_SE_LOGGEDIN 1 #define FE_SE_DISCONNECT 2 #define FE_SE_RECONDELAY 3 #define FE_SE_CONNECTING 4 void fe_server_event (server *serv, int type, int arg); /* pass NULL filename2 for default HexChat icon */ void fe_tray_set_flash (const char *filename1, const char *filename2, int timeout); /* pass NULL filename for default HexChat icon */ void fe_tray_set_file (const char *filename); typedef enum { FE_ICON_NORMAL = 0, FE_ICON_MESSAGE = 2, FE_ICON_HIGHLIGHT = 5, FE_ICON_PRIVMSG = 8, FE_ICON_FILEOFFER = 11 } feicon; void fe_tray_set_icon (feicon icon); void fe_tray_set_tooltip (const char *text); void fe_open_chan_list (server *serv, char *filter, int do_refresh); const char *fe_get_default_font (void); #endif