X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fdarwin_specific.c;h=810bd1b27ae175a7935d64dddd90eff13edf6154;hb=532b014ad9c53a3ef32a74373fdb895726bde516;hp=baf214a77eaedad4b168b853e1576f95ca33eadf;hpb=3266cd725cf6b306c19cd24590b8caa4023775f1;p=vlc diff --git a/src/misc/darwin_specific.c b/src/misc/darwin_specific.c index baf214a77e..810bd1b27a 100644 --- a/src/misc/darwin_specific.c +++ b/src/misc/darwin_specific.c @@ -1,16 +1,19 @@ + /***************************************************************************** - * darwin_specific.c: Darwin specific features + * darwin_specific.m: Darwin specific features ***************************************************************************** - * Copyright (C) 2001 VideoLAN - * $Id: darwin_specific.c,v 1.13 2002/07/02 22:07:02 jlj Exp $ + * Copyright (C) 2001-2009 the VideoLAN team + * $Id$ * - * Authors: Samuel Hocevar + * Authors: Sam Hocevar + * Christophe Massiot + * Pierre d'Herbemont * * 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; either version 2 of the License, or * (at your option) any later version. - * + * * 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 @@ -18,28 +21,100 @@ * * 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, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include /* strdup() */ -#include /* free() */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -/***************************************************************************** - * Static vars - *****************************************************************************/ -static char * psz_program_path; +#include +#include "../libvlc.h" +#include /* *dir() */ +#include +#include +#include +#include + +#ifdef HAVE_LOCALE_H +# include +#endif + +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif /***************************************************************************** - * system_Init: fill in program path. + * system_Init: fill in program path & retrieve language *****************************************************************************/ -void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) { + VLC_UNUSED(p_this); char i_dummy; - char *p_char, *p_oldchar = &i_dummy; + char *p_char = NULL; + char *p_oldchar = &i_dummy; + unsigned int i; + (void)pi_argc; /* Get the full program path and name */ - p_char = psz_program_path = strdup( ppsz_argv[ 0 ] ); + /* First try to see if we are linked to the framework */ + for (i = 0; i < _dyld_image_count(); i++) + { + const char * psz_img_name = _dyld_get_image_name(i); + /* Check for "VLCKit.framework/Versions/Current/VLCKit", + * as well as "VLCKit.framework/Versions/A/VLCKit" and + * "VLC.framework/Versions/B/VLCKit" */ + if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) ) + { + /* Look for the next forward slash */ + p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */ + while( *p_char != '\0' && *p_char != '/') + p_char++; + + /* If the string ends with VLC then we've found a winner */ + if ( !strcmp( p_char, "/VLCKit" ) ) + { + p_char = strdup( psz_img_name ); + break; + } + else + p_char = NULL; + } + else + { + size_t len = strlen(psz_img_name); + /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't + * link to VLCKit. */ + if( !strcmp( psz_img_name + len - 3, "VLC") ) + { + p_char = strdup( psz_img_name ); + break; + } + } + } + if ( !p_char ) + { + /* We are not linked to the VLC.framework, let's use dladdr to figure + * libvlc path */ + Dl_info info; + if( dladdr(system_Init, &info) ) + p_char = strdup(dirname( info.dli_fname )); + } + if( !p_char ) + { + char path[MAXPATHLEN+1]; + uint32_t path_len = MAXPATHLEN; + if ( !_NSGetExecutablePath(path, &path_len) ) + p_char = strdup(path); + } + if( !p_char ) + { + /* We are not linked to the VLC.framework, return the executable path */ + p_char = strdup( ppsz_argv[ 0 ] ); + } + + free(psz_vlcpath); + psz_vlcpath = p_char; /* Remove trailing program name */ for( ; *p_char ; ) @@ -50,62 +125,58 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) *p_char = '\0'; p_oldchar = p_char; } - p_char++; } - /* Run the interface with a real-time priority too */ +#ifdef ENABLE_NLS + /* Check if $LANG is set. */ + if( NULL == getenv("LANG") ) { - struct sched_param param; - param.sched_priority = 10; - if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) + /* + Retrieve the preferred language as chosen in System Preferences.app + (note that CFLocaleCopyCurrent() is not used because it returns the + preferred locale not language) + */ + CFArrayRef all_locales, preferred_locales; + char psz_locale[50]; + + all_locales = CFLocaleCopyAvailableLocaleIdentifiers(); + + preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL ); + + if ( preferred_locales ) { - msg_Err( p_this, "pthread_setschedparam failed" ); + if ( CFArrayGetCount( preferred_locales ) ) + { + CFStringRef user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 ); + CFStringGetCString( user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8 ); + setenv( "LANG", psz_locale, 1 ); + } + CFRelease( preferred_locales ); } + CFRelease( all_locales ); } +#endif } /***************************************************************************** * system_Configure: check for system specific configuration options. *****************************************************************************/ -void system_Configure( vlc_t *p_this ) +void system_Configure( libvlc_int_t *p_this, + int i_argc, const char *const ppsz_argv[] ) { - + (void)p_this; + (void)i_argc; + (void)ppsz_argv; } /***************************************************************************** * system_End: free the program path. *****************************************************************************/ -void system_End( vlc_object_t *p_this ) -{ - free( psz_program_path ); -} - -/***************************************************************************** - * system_GetProgramPath: get the full path to the program. - *****************************************************************************/ -char * system_GetProgramPath( void ) +void system_End( libvlc_int_t *p_this ) { - return( psz_program_path ); + (void)p_this; + free( psz_vlcpath ); + psz_vlcpath = NULL; } -/***************************************************************************** - * strndup: returns a malloc'd copy of at most n bytes of string - * Does anyone know whether or not it will be present in Jaguar? - *****************************************************************************/ -char *strndup( const char *string, size_t n ) -{ - char *psz; - size_t len; - - len = __MIN( strlen( string ), n ); - psz = (char*)malloc( len + 1 ); - - if( psz != NULL ) - { - memcpy( (void*)psz, (const void*)string, len ); - psz[ len ] = 0; - } - - return( psz ); -}