Commit e7061e86 authored by Sam Hocevar's avatar Sam Hocevar

* ./src/misc/iso_lang.c: code simplifications.

  * ./src/misc/iso_lang.c: the language prototypes now use the const keyword.
parent b651216e
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions * Collection of useful common types and macros definitions
***************************************************************************** *****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN * Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: common.h,v 1.107 2002/05/18 17:47:46 sam Exp $ * $Id: common.h,v 1.108 2002/05/20 22:36:42 sam Exp $
* *
* Authors: Samuel Hocevar <sam@via.ecp.fr> * Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr> * Vincent Seguin <seguin@via.ecp.fr>
...@@ -703,10 +703,10 @@ typedef struct module_symbols_s ...@@ -703,10 +703,10 @@ typedef struct module_symbols_s
void ( * CurrentPTS ) ( struct bit_stream_s *, mtime_t *, void ( * CurrentPTS ) ( struct bit_stream_s *, mtime_t *,
mtime_t * ); mtime_t * );
iso639_lang_t * ( * GetLang_1 ) ( const char * ); const iso639_lang_t * ( * GetLang_1 ) ( const char * );
iso639_lang_t * ( * GetLang_2T ) ( const char * ); const iso639_lang_t * ( * GetLang_2T ) ( const char * );
iso639_lang_t * ( * GetLang_2B ) ( const char * ); const iso639_lang_t * ( * GetLang_2B ) ( const char * );
char * ( * DecodeLanguage ) ( u16 ); const char * ( * DecodeLanguage ) ( u16 );
struct module_s * ( * module_Need ) ( int, char *, void * ); struct module_s * ( * module_Need ) ( int, char *, void * );
void ( * module_Unneed ) ( struct module_s * ); void ( * module_Unneed ) ( struct module_s * );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* iso_lang.h: function to decode language code (in dvd or a52 for instance). * iso_lang.h: function to decode language code (in dvd or a52 for instance).
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: iso_lang.h,v 1.4 2002/05/14 19:33:54 bozo Exp $ * $Id: iso_lang.h,v 1.5 2002/05/20 22:36:42 sam Exp $
* *
* Author: Stphane Borel <stef@via.ecp.fr> * Author: Stphane Borel <stef@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -32,10 +32,10 @@ struct iso639_lang_s ...@@ -32,10 +32,10 @@ struct iso639_lang_s
}; };
#ifndef __PLUGIN__ #ifndef __PLUGIN__
iso639_lang_t * GetLang_1( const char * psz_iso639_1 ); const iso639_lang_t * GetLang_1( const char * psz_iso639_1 );
iso639_lang_t * GetLang_2T( const char * psz_iso639_2T ); const iso639_lang_t * GetLang_2T( const char * psz_iso639_2T );
iso639_lang_t * GetLang_2B( const char * psz_iso639_2B ); const iso639_lang_t * GetLang_2B( const char * psz_iso639_2B );
char * DecodeLanguage( u16 ); const char * DecodeLanguage( u16 );
#else #else
# define GetLang_1 p_symbols->GetLang_1 # define GetLang_1 p_symbols->GetLang_1
# define GetLang_2T p_symbols->GetLang_2T # define GetLang_2T p_symbols->GetLang_2T
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* iso_lang.c: function to decode language code (in dvd or a52 for instance). * iso_lang.c: function to decode language code (in dvd or a52 for instance).
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2001 VideoLAN * Copyright (C) 1998-2001 VideoLAN
* $Id: iso_lang.c,v 1.4 2002/05/14 19:33:54 bozo Exp $ * $Id: iso_lang.c,v 1.5 2002/05/20 22:36:42 sam Exp $
* *
* Author: Stphane Borel <stef@via.ecp.fr> * Author: Stphane Borel <stef@via.ecp.fr>
* Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -35,77 +35,77 @@ ...@@ -35,77 +35,77 @@
* Local tables * Local tables
*****************************************************************************/ *****************************************************************************/
static iso639_lang_t p_iso_languages[] =
{
#define DEFINE_LANGUAGE_CODE(engName, nativeName, iso1, iso2T, iso2B) \ #define DEFINE_LANGUAGE_CODE(engName, nativeName, iso1, iso2T, iso2B) \
{ engName, nativeName, #iso1, #iso2T, #iso2B }, { engName, nativeName, #iso1, #iso2T, #iso2B },
{ "", "", "", "", "" },
static const iso639_lang_t p_languages[] =
{
#include "iso-639.def" #include "iso-639.def"
{ NULL, NULL, NULL, NULL, NULL }
}; };
static const iso639_lang_t unknown_language =
{ "Unknown", "Unknown", "??", "???", "???" };
/***************************************************************************** /*****************************************************************************
* DecodeLanguage: gives the long language name from the two-letters * DecodeLanguage: gives the long language name from the two-letter
* ISO-639 code * ISO-639 code
*****************************************************************************/ *****************************************************************************/
char * DecodeLanguage( u16 i_code ) const char * DecodeLanguage( u16 i_code )
{ {
u8 code[2]; const iso639_lang_t * p_lang;
iso639_lang_t * p_iso; u8 psz_code[3];
code[0] = i_code >> 8;
code[1] = i_code; psz_code[0] = i_code >> 8;
p_iso = GetLang_1( code ); psz_code[1] = i_code;
if( p_iso ) psz_code[2] = '\0';
for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
{ {
if( p_iso->psz_native_name[0] ) if( !strncmp( p_lang->psz_iso639_1, psz_code, 2 ) )
return p_iso->psz_native_name; {
else if( *p_lang->psz_native_name )
return p_iso->psz_eng_name; {
return p_lang->psz_native_name;
}
return p_lang->psz_eng_name;
}
} }
return p_iso_languages[sizeof( p_iso_languages ) /
sizeof( iso639_lang_t ) - 1].psz_native_name;
}
return "Unknown";
}
iso639_lang_t * GetLang_1( const char * psz_iso639_1 ) const iso639_lang_t * GetLang_1( const char * psz_code )
{ {
unsigned int i; const iso639_lang_t *p_lang;
for( i = 0; i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ); i++ )
{ for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
if( !strncmp( p_iso_languages[i].psz_iso639_1, psz_iso639_1, 2 ) ) if( !strncmp( p_lang->psz_iso639_1, psz_code, 2 ) )
break; return p_lang;
}
if( i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ) ) return &unknown_language;
return &p_iso_languages[i];
else
return NULL;
} }
iso639_lang_t * GetLang_2T( const char * psz_iso639_2T ) const iso639_lang_t * GetLang_2T( const char * psz_code )
{ {
unsigned int i; const iso639_lang_t *p_lang;
for( i = 0; i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ); i++ )
{ for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
if( !strncmp( p_iso_languages[i].psz_iso639_2T, psz_iso639_2T, 2 ) ) if( !strncmp( p_lang->psz_iso639_2T, psz_code, 3 ) )
break; return p_lang;
}
if( i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ) ) return &unknown_language;
return &p_iso_languages[i];
else
return NULL;
} }
iso639_lang_t * GetLang_2B( const char * psz_iso639_2B ) const iso639_lang_t * GetLang_2B( const char * psz_code )
{ {
unsigned int i; const iso639_lang_t *p_lang;
for( i = 0; i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ); i++ )
{ for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
if( !strncmp( p_iso_languages[i].psz_iso639_2B, psz_iso639_2B, 2 ) ) if( !strncmp( p_lang->psz_iso639_2B, psz_code, 3 ) )
break; return p_lang;
}
if( i < sizeof( p_iso_languages ) / sizeof( iso639_lang_t ) ) return &unknown_language;
return &p_iso_languages[i];
else
return NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment