?? subreader.c.svn-base
字號:
return NULL; } // we do overlap if the user forced it (suboverlap_enable == 2) or // the user didn't forced no-overlapsub and the format is Jacosub or Ssa. // this is because usually overlapping subtitles are found in these formats, // while in others they are probably result of bad timing adjust_subs_time(first, 6.0, fps, 1, sub_num, uses_time);/*~6 secs AST*/ return_sub = first; if (return_sub == NULL) return NULL; subt_data = MALLOC(sizeof(sub_data)); subt_data->filename = STRDUP(filename);//strdup(filename); subt_data->sub_uses_time = uses_time; subt_data->sub_num = sub_num; subt_data->sub_errs = sub_errs; subt_data->subtitles = return_sub; subt_data->max = n_max; return subt_data;}static void strcpy_trim(RMascii *d, RMascii *s){ // skip leading whitespace while (*s && !isalnum(*s)) { s++; } for (;;) { // copy word while (*s && isalnum(*s)) { *d = tolower(*s); s++; d++; } if (*s == 0) break; // trim excess whitespace while (*s && !isalnum(*s)) { s++; } if (*s == 0) break; *d++ = ' '; } *d = 0;}static void strcpy_strip_ext(RMascii *d, RMascii *s){ RMascii *tmp = strrchr(s,'.'); if (!tmp) { strcpy(d, s); return; } else { strncpy(d, s, tmp-s); d[tmp-s] = 0; } while (*d) { *d = tolower(*d); d++; }}static void strcpy_get_ext(RMascii *d, RMascii *s){ RMascii *tmp = strrchr(s,'.'); if (!tmp) { strcpy(d, ""); return; } else { strcpy(d, tmp+1); }}static int whiteonly(RMascii *s){ while (*s) { if (isalnum(*s)) return 0; s++; } return 1;}typedef struct _subfn{ int priority; RMascii *fname;} subfn;static int compare_sub_priority(const void *a, const void *b){ if (((const subfn*)a)->priority > ((const subfn*)b)->priority) { return -1; } else if (((const subfn*)a)->priority < ((const subfn*)b)->priority) { return 1; } else { return strcoll(((const subfn*)a)->fname, ((const subfn*)b)->fname); }}RMascii** sub_filenames(const RMascii* path, RMascii *fname){ RMascii *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp, *tmp_sub_id; RMascii *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult; int len, pos, found, i, j; RMascii * sub_exts[] = { "utf", "utf8", "utf-8", "sub", "srt", "smi", "rt", "txt", "ssa", "aqt", "jss", "js", "ass", NULL}; subfn *result; RMascii **result2; int subcnt; FILE *f; DIR *d; struct dirent *de;// printf ("TEMP: check1\n"); len = (RMasciiLength(fname) > 256 ? RMasciiLength(fname) : 256) +(RMasciiLength(path) > 256 ? RMasciiLength(path) : 256)+2; f_dir = MALLOC(len); f_fname = MALLOC(len); f_fname_noext = MALLOC(len); f_fname_trim = MALLOC(len); tmp_fname_noext = MALLOC(len); tmp_fname_trim = MALLOC(len); tmp_fname_ext = MALLOC(len); tmpresult = MALLOC(len);// printf ("TEMP: check2\n"); result = MALLOC(sizeof(subfn)*MAX_SUBTITLE_FILES); RMMemset(result, 0, sizeof(subfn)*MAX_SUBTITLE_FILES);// printf ("TEMP: check3\n"); subcnt = 0; tmp = strrchr(fname,'/'); // extract filename & dirname from fname if (tmp) { RMCopyAscii(f_fname, tmp+1); pos = tmp - fname; RMNCopyAscii(f_dir, fname, pos+1); f_dir[pos+1] = 0; } else { RMCopyAscii(f_fname, fname); RMCopyAscii(f_dir, "./"); }// printf ("TEMP: check4 %s %s\n", f_dir, f_fname); strcpy_strip_ext(f_fname_noext, f_fname); strcpy_trim(f_fname_trim, f_fname_noext); tmp_sub_id = NULL; if (dvdsub_lang && !whiteonly(dvdsub_lang)) { tmp_sub_id = MALLOC(RMasciiLength(dvdsub_lang)+1); strcpy_trim(tmp_sub_id, dvdsub_lang); }// printf ("TEMP: check41\n"); // 0 = nothing // 1 = any subtitle file // 2 = any sub file containing movie name // 3 = sub file containing movie name and the lang extension for (j = 0; j <= 3; j++) { d = opendir(j == 0 ? f_dir : path);// printf ("TEMP: check42 %p\n", d); if (d) {// printf ("TEMP: wytre\n"); while ((de = readdir(d))) {// printf ("TEMP: neshto procheteno\n"); // retrieve various parts of the filename strcpy_strip_ext(tmp_fname_noext, de->d_name); strcpy_get_ext(tmp_fname_ext, de->d_name); strcpy_trim(tmp_fname_trim, tmp_fname_noext);// printf ("TEMP: %s %s\n", tmp_fname_noext, tmp_fname_ext); // does it end with a subtitle extension? found = 0; for (i = 0; sub_exts[i]; i++) { if (strcasecmp(sub_exts[i], tmp_fname_ext) == 0) { found = 1;// printf("found one\n"); break; } } // we have a (likely) subtitle file if (found) { int prio = 0;// printf("check prio\n"); if (!prio && tmp_sub_id) { sprintf(tmpresult, "%s %s", f_fname_trim, tmp_sub_id);// printf ("TEMP: check5 %s %s\n", f_fname_trim, tmp_sub_id); if (strcmp(tmp_fname_trim, tmpresult) == 0 && sub_match_fuzziness >= 1) { // matches the movie name + lang extension prio = 5; } }// printf ("TEMP: check51 %s %s\n", tmp_fname_trim, f_fname_trim); if (!prio && strcmp(tmp_fname_trim, f_fname_trim) == 0) { // matches the movie name prio = 4;// printf("prio 4\n"); } if (!prio && (tmp = strstr(tmp_fname_trim, f_fname_trim)) && (sub_match_fuzziness >= 1)) { // contains the movie name tmp += RMasciiLength(f_fname_trim); if (tmp_sub_id && strstr(tmp, tmp_sub_id)) { // with sub_id specified prefer localized subtitles prio = 3;// printf("prio 3\n"); } else if ((tmp_sub_id == NULL) && whiteonly(tmp)) { // without sub_id prefer "plain" name prio = 3;// printf("prio 31\n"); } else { // with no localized subs found, try any else instead prio = 2;// printf("prio 2\n"); } } if (!prio) { // doesn't contain the movie name // don't try in the mplayer subtitle directory if ((j == 0) && (sub_match_fuzziness >= 2)) { prio = 1;// printf("prio 1\n"); } } if (prio) { prio += prio; sprintf(tmpresult, "%s%s", j == 0 ? f_dir : path, de->d_name);// printf ("TEMP: check5 %s %s\n", j == 0 ? f_dir : path, de->d_name);// fprintf(stderr, "%s priority %d\n", tmpresult, prio); if ((f = fopen(tmpresult, "rt"))) { fclose(f); result[subcnt].priority = prio; result[subcnt].fname = STRDUP(tmpresult); subcnt++; } } } if (subcnt >= MAX_SUBTITLE_FILES) break; } closedir(d); } }// printf ("TEMP: check6 %p\n", d); if (tmp_sub_id) RFREE(tmp_sub_id); RFREE(f_dir); RFREE(f_fname); RFREE(f_fname_noext); RFREE(f_fname_trim); RFREE(tmp_fname_noext); RFREE(tmp_fname_trim); RFREE(tmp_fname_ext); RFREE(tmpresult); qsort(result, subcnt, sizeof(subfn), compare_sub_priority); result2 = MALLOC(sizeof(RMascii*)*(subcnt+1)); RMMemset(result2, 0, sizeof(RMascii*)*(subcnt+1)); for (i = 0; i < subcnt; i++) { result2[i] = result[i].fname;// printf ("TEMP: %s result[i].fname\n", result[i].fname); } result2[subcnt] = NULL; RFREE(result); return result2;}void sub_free( sub_data * subd ){ RMuint32 i, j; if ( !subd ) return; if (subd->subtitles) { for(j = 0; j < subd->sub_num; j ++) for (i=0; i < subd->subtitles[j].lines; i++) RFREE( subd->subtitles[j].text[i] ); RFREE( subd->subtitles ); } if (subd->filename) RFREE( subd->filename ); RFREE( subd ); if(subs.subs_path) { RFREE(subs.subs_path); subs.subs_path = NULL; }}void init_subs(void){ subs.data = NULL; subs.current_sub = 0; subs.nosub_range_start = 0; subs.nosub_range_end = 0; subs.vo_sub = NULL; subs.sub_size = 26; subs.alignment = ALIGN_CENTER; subs.vPos = 100; subs.osd = FALSE; subs.subs_path = NULL;}void clear_subs(void){ subs.vo_sub = NULL; if(subs.data) { sub_free(subs.data); subs.data = NULL; }}void find_sub(sub_data* subd,RMint32 key){ subtitle *sub; int i,j; if ( !subd || subd->sub_num == 0) return; sub = subd->subtitles; if(subs.vo_sub){ if(key>=(RMint32)subs.vo_sub->start && key<=(RMint32)subs.vo_sub->end) return; // OK! } else { if(key>(RMint32)subs.nosub_range_start && key<(RMint32)subs.nosub_range_end) return; // OK! } // sub changed! /* Tell the OSD subsystem that the OSD contents will change soon */ // vo_osd_changed(OSDTYPE_SUBTITLE); if(key<=0){ subs.vo_sub=NULL; // no sub here return; }// printf("\r---- sub changed ----\n"); // check next sub. if(subs.current_sub>=0 && (RMuint16)(subs.current_sub+1) < subd->sub_num){ if(key>(RMint32)sub[subs.current_sub].end && key<(RMint32)sub[subs.current_sub+1].start){ // no sub subs.nosub_range_start=sub[subs.current_sub].end; subs.nosub_range_end=sub[subs.current_sub+1].start; subs.vo_sub=NULL; return; } // next sub? subs.current_sub++; subs.vo_sub=&sub[subs.current_sub]; if(key>=(RMint32)subs.vo_sub->start && key<=(RMint32)subs.vo_sub->end) return; // OK! }// printf("\r---- sub log search... ----\n"); // use logarithmic search: i=0; j = subd->sub_num - 1;// printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); while(j>=i){ subs.current_sub=(i+j+1)/2; subs.vo_sub=&sub[subs.current_sub]; if(key<(RMint32)subs.vo_sub->start) j=subs.current_sub-1; else if(key>(RMint32)subs.vo_sub->end) i=subs.current_sub+1; else return; // found! }// if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! // check where are we... if(key<(RMint32)subs.vo_sub->start){ if(subs.current_sub<=0){ // before the first sub subs.nosub_range_start=key-1; // tricky subs.nosub_range_end=subs.vo_sub->start;// printf("FIRST... key=%d end=%d \n",key,vo_sub->start); subs.vo_sub=NULL; return; } subs.current_sub--; if(key>(RMint32)sub[subs.current_sub].end && key<(RMint32)sub[subs.current_sub+1].start){ // no sub subs.nosub_range_start=sub[subs.current_sub].end; subs.nosub_range_end=sub[subs.current_sub+1].start;// printf("No sub... 1 \n"); subs.vo_sub=NULL; return; } printf("HEH???? "); } else { if(key<=(RMint32)subs.vo_sub->end) printf("JAJJ! "); else if((RMuint16)(subs.current_sub+1) >= subd->sub_num){ // at the end? subs.nosub_range_start=subs.vo_sub->end; subs.nosub_range_end=0x7FFFFFFF; // MAXINT// printf("END!?\n"); subs.vo_sub=NULL; return; } else if(key>(RMint32)sub[subs.current_sub].end && key<(RMint32)sub[subs.current_sub+1].start){ // no sub subs.nosub_range_start=sub[subs.current_sub].end; subs.nosub_range_end=sub[subs.current_sub+1].start;// printf("No sub... 2 \n"); subs.vo_sub=NULL; return; } } subs.vo_sub=NULL; // no sub here}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -