]> git.sesse.net Git - vlc/blob - src/misc/darwin_specific.m
Avoid flags duplication when configure cache not present
[vlc] / src / misc / darwin_specific.m
1 /*****************************************************************************
2  * darwin_specific.m: Darwin specific features
3  *****************************************************************************
4  * Copyright (C) 2001-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sam Hocevar <sam@zoy.org>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #include <string.h>                                              /* strdup() */
25 #include <stdlib.h>                                                /* free() */
26
27 #include <vlc/vlc.h>
28
29 #include <Cocoa/Cocoa.h>
30 #include <CoreFoundation/CFString.h>
31
32 #ifdef HAVE_LOCALE_H
33 #   include <locale.h>
34 #endif
35
36 /*****************************************************************************
37  * system_Init: fill in program path & retrieve language
38  *****************************************************************************/
39 static int FindLanguage( const char * psz_lang )
40 {
41     const char ** ppsz_parser;
42     const char * ppsz_all[] =
43     {
44         "Catalan", "ca",
45         "Czech", "cs",
46         "Danish", "da",
47         "German", "de",
48         "British", "en_GB",
49         "English", "en",
50         "Spanish", "es",
51         "French", "fr",
52         "Galician", "gl",
53         "Hebrew", "he",
54         "Hungarian", "hu",
55         "Italian", "it",
56         "Japanese", "ja",
57         "Korean", "ko",
58         "Georgian", "ka",
59         "Malay", "ms",
60         "Dutch", "nl",
61         "Occitan", "oc",
62         "Brazilian Portuguese", "pt_BR",
63         "Romanian", "ro",
64         "Russian", "ru",
65         "Slovak", "sk",
66         "Swedish", "sv",
67         "Turkish", "tr",
68         "Simplified Chinese", "zh_CN",
69         "Chinese Traditional", "zh_TW",
70         NULL
71     };
72
73     for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 )
74     {
75         if( !strcmp( psz_lang, ppsz_parser[0] )
76              || !strcmp( psz_lang, ppsz_parser[1] ) )
77         {
78             setenv( "LANG", ppsz_parser[1], 1 );
79             return 1;
80         }
81     }
82
83     return 0;
84 }
85
86 void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
87 {
88     char i_dummy;
89     char *p_char, *p_oldchar = &i_dummy;
90
91     /* Get the full program path and name */
92     p_char = p_this->p_libvlc_global->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
93
94     /* Remove trailing program name */
95     for( ; *p_char ; )
96     {
97         if( *p_char == '/' )
98         {
99             *p_oldchar = '/';
100             *p_char = '\0';
101             p_oldchar = p_char;
102         }
103
104         p_char++;
105     }
106
107     /* Check if $LANG is set. */
108     if ( (p_char = getenv("LANG")) == NULL )
109     {
110         NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
111
112         /* Retrieve user's preferences. */
113         NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults];
114         NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"];
115         NSEnumerator * o_enumerator = [o_languages objectEnumerator];
116         NSString * o_lang;
117
118         while ( (o_lang = [o_enumerator nextObject]) )
119         {
120             const char * psz_string = [o_lang lossyCString];
121             if ( FindLanguage( psz_string ) )
122             {
123                 break;
124             }
125         }
126
127         [o_pool release];
128     }
129
130     vlc_mutex_init( p_this, &p_this->p_libvlc_global->iconv_lock );
131     p_this->p_libvlc_global->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
132 }
133
134 /*****************************************************************************
135  * system_Configure: check for system specific configuration options.
136  *****************************************************************************/
137 void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] )
138 {
139
140 }
141
142 /*****************************************************************************
143  * system_End: free the program path.
144  *****************************************************************************/
145 void system_End( libvlc_int_t *p_this )
146 {
147     free( p_this->p_libvlc_global->psz_vlcpath );
148
149     if ( p_this->p_libvlc_global->iconv_macosx != (vlc_iconv_t)-1 )
150         vlc_iconv_close( p_this->p_libvlc_global->iconv_macosx );
151     vlc_mutex_destroy( &p_this->p_libvlc_global->iconv_lock );
152 }
153