#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <stdlib.h> /* free() */
-#ifdef HAVE_ASSERT
-# include <assert.h>
-#else
-# define assert( c ) ((void)0)
-#endif
#ifndef WIN32
# include <netinet/in.h> /* BSD: struct in_addr */
vlc_bool_t b_block, vlc_bool_t b_play,
int i_options, char **ppsz_options );
-static void LocaleInit( void );
-static void LocaleDeinit( void );
+void LocaleInit( vlc_object_t * );
+void LocaleDeinit( void );
static void SetLanguage ( char const * );
static int GetFilenames ( vlc_t *, int, char *[] );
static void Help ( vlc_t *, char const *psz_help_name );
static void Version ( void );
#ifdef WIN32
-static void ShowConsole ( void );
+static void ShowConsole ( vlc_bool_t );
static void PauseConsole ( void );
#endif
static int ConsoleWidth ( void );
libvlc.p_module_bank = NULL;
libvlc.b_ready = VLC_TRUE;
-
- /* UTF-8 convertor are initialized after the locale */
- libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
}
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_libvlc, "libvlc" );
* Global iconv, must be done after setlocale()
* so that vlc_current_charset() works.
*/
- LocaleInit();
+ LocaleInit( (vlc_object_t *)p_vlc );
/* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
/* Reset the default domain */
SetLanguage( psz_language );
- LocaleDeinit();
- LocaleInit();
+
+ /* Should not be needed (otherwise, fixes should rather be
+ * attempted on vlc_current_charset().
+ * Also, if the locale charset is overriden, anything that has been
+ * translated until now would have to be retranslated. */
+ /*LocaleDeinit();
+ LocaleInit( (vlc_object_t *)p_vlc );*/
/* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
{
#ifdef WIN32
- ShowConsole();
+ ShowConsole( VLC_FALSE );
/* Pause the console because it's destroyed when we exit */
fprintf( stderr, "The command line options couldn't be loaded, check "
"that they are valid.\n" );
return VLC_SUCCESS;
};
-static void LocaleInit( void )
-{
- char *psz_charset;
-
- if( !vlc_current_charset( &psz_charset ) )
- {
- char *psz_conv = psz_charset;
-
- /*
- * Still allow non-ASCII characters when the locale is not set.
- * Western Europeans are being favored for historical reasons.
- */
- psz_conv = strcmp( psz_charset, "ASCII" )
- ? psz_charset : "CP1252";
-
- vlc_mutex_init( p_libvlc, &libvlc.from_locale_lock );
- vlc_mutex_init( p_libvlc, &libvlc.to_locale_lock );
- libvlc.from_locale = vlc_iconv_open( "UTF-8", psz_charset );
- libvlc.to_locale = vlc_iconv_open( psz_charset, "UTF-8" );
- if( !libvlc.to_locale )
- {
- /* Not sure it is the right thing to do, but at least it
- doesn't make vlc crash with msvc ! */
- libvlc.to_locale = (vlc_iconv_t)(-1);
- }
- }
- else
- libvlc.from_locale = libvlc.to_locale = (vlc_iconv_t)(-1);
- free( psz_charset );
-}
-
-static void LocaleDeinit( void )
-{
- if( libvlc.to_locale != (vlc_iconv_t)(-1) )
- {
- vlc_mutex_destroy( &libvlc.from_locale_lock );
- vlc_mutex_destroy( &libvlc.to_locale_lock );
- vlc_iconv_close( libvlc.from_locale );
- vlc_iconv_close( libvlc.to_locale );
- }
-}
/*****************************************************************************
* SetLanguage: set the interface language.
/* many code paths assume that float numbers are formatted according
* to the US standard (ie. with dot as decimal point), so we keep
* C for LC_NUMERIC. */
- setlocale(LC_NUMERIC, "C" );
+ setlocale( LC_NUMERIC, "C" );
}
/* Specify where to find the locales for current domain */
}
/* Set the default domain */
- textdomain( PACKAGE_NAME );
bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
#endif
}
static void Help( vlc_t *p_this, char const *psz_help_name )
{
#ifdef WIN32
- ShowConsole();
+ ShowConsole( VLC_TRUE );
#endif
if( psz_help_name && !strcmp( psz_help_name, "help" ) )
{
- fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
+ utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
Usage( p_this, "help" );
Usage( p_this, "main" );
}
else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
{
- fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
+ utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
Usage( p_this, NULL );
}
else if( psz_help_name )
/* Print name of module */
if( strcmp( "main", p_parser->psz_object_name ) )
- fprintf( stdout, "\n %s\n", p_parser->psz_longname );
+ utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname );
b_help_module = !strcmp( "help", p_parser->psz_object_name );
case CONFIG_HINT_CATEGORY:
case CONFIG_HINT_USAGE:
if( !strcmp( "main", p_parser->psz_object_name ) )
- fprintf( stdout, "\n %s\n", p_item->psz_text );
+ utf8_fprintf( stdout, "\n %s\n", p_item->psz_text );
break;
case CONFIG_ITEM_STRING:
if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
{
- fprintf( stdout, psz_format, psz_short, p_item->psz_name,
+ utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
psz_prefix, p_item->psz_name, psz_bra, psz_type,
psz_ket, psz_spaces );
}
else
{
- fprintf( stdout, psz_format, psz_short, p_item->psz_name,
+ utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name,
"", "", psz_bra, psz_type, psz_ket, psz_spaces );
}
/* If the remaining text fits in a line, print it. */
if( i_end <= (size_t)i_width )
{
- fprintf( stdout, "%s\n", psz_text );
+ utf8_fprintf( stdout, "%s\n", psz_text );
break;
}
{
char c = psz_text[i_width];
psz_text[i_width] = '\0';
- fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
+ utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
psz_text += i_width;
psz_text[0] = c;
}
else
{
psz_word[-1] = '\0';
- fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
+ utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
psz_text = psz_word;
}
}
sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
b_description = VLC_FALSE;
psz_spaces = psz_spaces_longtext;
- fprintf( stdout, "%s", psz_spaces );
+ utf8_fprintf( stdout, "%s", psz_spaces );
goto description;
}
}
memset( psz_spaces, ' ', 22 );
#ifdef WIN32
- ShowConsole();
+ ShowConsole( VLC_TRUE );
#endif
/* List all modules */
if( i < 0 ) i = 0;
psz_spaces[i] = 0;
- fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
+ utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
psz_spaces, p_parser->psz_longname );
psz_spaces[i] = ' ';
static void Version( void )
{
#ifdef WIN32
- ShowConsole();
+ ShowConsole( VLC_TRUE );
#endif
- fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
- fprintf( stdout, _("Compiled by %s@%s.%s\n"),
+ utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() );
+ utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"),
VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() );
- fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
+ utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() );
if( strcmp( VLC_Changeset(), "exported" ) )
- fprintf( stdout, _("Based upon svn changeset [%s]\n"),
+ utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"),
VLC_Changeset() );
- fprintf( stdout, LICENSE_MSG );
+ utf8_fprintf( stdout, LICENSE_MSG );
#ifdef WIN32 /* Pause the console because it's destroyed when we exit */
PauseConsole();
* This function is useful only on Win32.
*****************************************************************************/
#ifdef WIN32 /* */
-static void ShowConsole( void )
+static void ShowConsole( vlc_bool_t b_dofile )
{
# ifndef UNDER_CE
FILE *f_help;
freopen( "CONOUT$", "w", stderr );
freopen( "CONIN$", "r", stdin );
- if( (f_help = fopen( "vlc-help.txt", "wt" )) )
+ if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) )
{
fclose( f_help );
freopen( "vlc-help.txt", "wt", stdout );
- fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
+ utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") );
}
else freopen( "CONOUT$", "w", stdout );
if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
- fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
+ utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
getchar();
fclose( stdout );
}
#endif
}
-
-/*****************************************************************************
- * FromLocale: converts a locale string to UTF-8
- *****************************************************************************/
-char *FromLocale( const char *locale )
-{
- if( locale == NULL )
- return NULL;
-
- if( libvlc.from_locale != (vlc_iconv_t)(-1) )
- {
- char *iptr = (char *)locale, *output, *optr;
- size_t inb, outb;
-
- /*
- * We are not allowed to modify the locale pointer, even if we cast it
- * to non-const.
- */
- inb = strlen( locale );
- /* FIXME: I'm not sure about the value for the multiplication
- * (for western people, multiplication by 3 (Latin9) is sufficient) */
- outb = inb * 6 + 1;
-
- optr = output = calloc( outb , 1);
-
- vlc_mutex_lock( &libvlc.from_locale_lock );
- vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
-
- while( vlc_iconv( libvlc.from_locale, &iptr, &inb, &optr, &outb )
- == (size_t)-1 )
- {
- *optr++ = '?';
- outb--;
- iptr++;
- inb--;
- vlc_iconv( libvlc.from_locale, NULL, NULL, NULL, NULL );
- }
- vlc_mutex_unlock( &libvlc.from_locale_lock );
-
- assert (inb == 0);
- assert (*iptr == '\0');
- assert (*optr == '\0');
- assert (strlen( output ) == (size_t)(optr - output));
- return realloc( output, optr - output + 1 );
- }
- return (char *)locale;
-}
-
-/*****************************************************************************
- * ToLocale: converts an UTF-8 string to locale
- *****************************************************************************/
-char *ToLocale( const char *utf8 )
-{
- if( utf8 == NULL )
- return NULL;
-
- if( libvlc.to_locale != (vlc_iconv_t)(-1) )
- {
- char *iptr = (char *)utf8, *output, *optr;
- size_t inb, outb;
-
- /*
- * We are not allowed to modify the locale pointer, even if we cast it
- * to non-const.
- */
- inb = strlen( utf8 );
- /* FIXME: I'm not sure about the value for the multiplication
- * (for western people, multiplication is not needed) */
- outb = inb * 2 + 1;
-
- optr = output = calloc( outb, 1 );
- vlc_mutex_lock( &libvlc.to_locale_lock );
- vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
-
- while( vlc_iconv( libvlc.to_locale, &iptr, &inb, &optr, &outb )
- == (size_t)-1 )
- {
- *optr++ = '?'; /* should not happen, and yes, it sucks */
- outb--;
- iptr++;
- inb--;
- vlc_iconv( libvlc.to_locale, NULL, NULL, NULL, NULL );
- }
- vlc_mutex_unlock( &libvlc.to_locale_lock );
-
- assert (inb == 0);
- assert (*iptr == '\0');
- assert (*optr == '\0');
- assert (strlen( output ) == (size_t)(optr - output));
- return realloc( output, optr - output + 1 );
- }
- return (char *)utf8;
-}
-
-void LocaleFree( const char *str )
-{
- if( ( str != NULL ) && ( libvlc.to_locale != (vlc_iconv_t)(-1) ) )
- free( (char *)str );
-}