comparison subreader.c @ 10354:18ad3cda99d4

sub_utf8 fiddling
author atlka
date Tue, 01 Jul 2003 08:49:14 +0000
parents ee46cdf03028
children 7b358cd956fd
comparison
equal deleted inserted replaced
10353:ee46cdf03028 10354:18ad3cda99d4
928 928
929 extern float sub_delay; 929 extern float sub_delay;
930 extern float sub_fps; 930 extern float sub_fps;
931 931
932 #ifdef USE_ICONV 932 #ifdef USE_ICONV
933 static iconv_t icdsc; 933 static iconv_t icdsc = (iconv_t)(-1);
934 934
935 void subcp_open (void) 935 void subcp_open (void)
936 { 936 {
937 char *tocp = "UTF-8"; 937 char *tocp = "UTF-8";
938 icdsc = (iconv_t)(-1);
939 938
940 if (sub_cp){ 939 if (sub_cp){
941 if ((icdsc = iconv_open (tocp, sub_cp)) != (iconv_t)(-1)){ 940 if ((icdsc = iconv_open (tocp, sub_cp)) != (iconv_t)(-1)){
942 mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: opened iconv descriptor.\n"); 941 mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: opened iconv descriptor.\n");
943 sub_utf8 = 2; 942 sub_utf8 = 2;
1176 rewind (fd); 1175 rewind (fd);
1177 1176
1178 #ifdef USE_ICONV 1177 #ifdef USE_ICONV
1179 sub_utf8_prev=sub_utf8; 1178 sub_utf8_prev=sub_utf8;
1180 { 1179 {
1181 int l; 1180 int l,k;
1181 k = -1;
1182 if ((l=strlen(filename))>4){ 1182 if ((l=strlen(filename))>4){
1183 int k; 1183 int k;
1184 char *exts[] = {".utf", ".utf8", ".utf-8" }; 1184 char *exts[] = {".utf", ".utf8", ".utf-8" };
1185 for (k=3;--k>=0;) 1185 for (k=3;--k>=0;)
1186 if (!strcasecmp(filename+(l - strlen(exts[k])), exts[k])){ 1186 if (!strcasecmp(filename+(l - strlen(exts[k])), exts[k])){
1187 sub_utf8 = 1; 1187 sub_utf8 = 1;
1188 fprintf(stderr,"UTF-8 detected\n");
1188 break; 1189 break;
1189 } 1190 }
1190 } 1191 }
1191 } 1192 if (k<0) subcp_open();
1192 if (!(sub_utf8 & 1)) subcp_open(); 1193 }
1193 #endif 1194 #endif
1194 1195
1195 sub_num=0;n_max=32; 1196 sub_num=0;n_max=32;
1196 first=(subtitle *)malloc(n_max*sizeof(subtitle)); 1197 first=(subtitle *)malloc(n_max*sizeof(subtitle));
1197 if(!first) return NULL; 1198 if(!first){
1199 #ifdef USE_ICONV
1200 subcp_close();
1201 sub_utf8=sub_utf8_prev;
1202 #endif
1203 return NULL;
1204 }
1198 1205
1199 #ifdef USE_SORTSUB 1206 #ifdef USE_SORTSUB
1200 sub = (subtitle *)malloc(sizeof(subtitle)); 1207 sub = (subtitle *)malloc(sizeof(subtitle));
1201 //This is to deal with those formats (AQT & Subrip) which define the end of a subtitle 1208 //This is to deal with those formats (AQT & Subrip) which define the end of a subtitle
1202 //as the beginning of the following 1209 //as the beginning of the following
1221 #endif 1228 #endif
1222 if ( sub == ERR ) 1229 if ( sub == ERR )
1223 { 1230 {
1224 #ifdef USE_ICONV 1231 #ifdef USE_ICONV
1225 subcp_close(); 1232 subcp_close();
1226 sub_utf8=sub_utf8_prev;
1227 #endif 1233 #endif
1228 if ( first ) free(first); 1234 if ( first ) free(first);
1229 return NULL; 1235 return NULL;
1230 } 1236 }
1231 // Apply any post processing that needs recoding first 1237 // Apply any post processing that needs recoding first