From 1639ad0ba33e310ce3f796ac6281b273921b046a Mon Sep 17 00:00:00 2001 From: atlka Date: Tue, 1 Jul 2003 08:49:14 +0000 Subject: sub_utf8 fiddling git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10355 b3059339-0415-0410-9bf9-f77b7e298cf2 --- subreader.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'subreader.c') diff --git a/subreader.c b/subreader.c index e8d24630ff..ab72a05314 100644 --- a/subreader.c +++ b/subreader.c @@ -930,12 +930,11 @@ extern float sub_delay; extern float sub_fps; #ifdef USE_ICONV -static iconv_t icdsc; +static iconv_t icdsc = (iconv_t)(-1); void subcp_open (void) { char *tocp = "UTF-8"; - icdsc = (iconv_t)(-1); if (sub_cp){ if ((icdsc = iconv_open (tocp, sub_cp)) != (iconv_t)(-1)){ @@ -1178,23 +1177,31 @@ sub_data* sub_read_file (char *filename, float fps) { #ifdef USE_ICONV sub_utf8_prev=sub_utf8; { - int l; + int l,k; + k = -1; if ((l=strlen(filename))>4){ int k; char *exts[] = {".utf", ".utf8", ".utf-8" }; for (k=3;--k>=0;) if (!strcasecmp(filename+(l - strlen(exts[k])), exts[k])){ sub_utf8 = 1; + fprintf(stderr,"UTF-8 detected\n"); break; } } + if (k<0) subcp_open(); } - if (!(sub_utf8 & 1)) subcp_open(); #endif sub_num=0;n_max=32; first=(subtitle *)malloc(n_max*sizeof(subtitle)); - if(!first) return NULL; + if(!first){ +#ifdef USE_ICONV + subcp_close(); + sub_utf8=sub_utf8_prev; +#endif + return NULL; + } #ifdef USE_SORTSUB sub = (subtitle *)malloc(sizeof(subtitle)); @@ -1223,7 +1230,6 @@ sub_data* sub_read_file (char *filename, float fps) { { #ifdef USE_ICONV subcp_close(); - sub_utf8=sub_utf8_prev; #endif if ( first ) free(first); return NULL; -- cgit v1.2.3