mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
Avoid code duplication and excessively deep nesting in cue_find_bin
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30802 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
7d48f09b39
commit
2a6755e10d
@ -178,6 +178,7 @@ static int cue_getTrackinfo(char *Line, tTrack *track)
|
|||||||
* sure the sizes are in sync.
|
* sure the sizes are in sync.
|
||||||
*/
|
*/
|
||||||
static int cue_find_bin (char *firstline) {
|
static int cue_find_bin (char *firstline) {
|
||||||
|
const char *cur_name;
|
||||||
int i,j;
|
int i,j;
|
||||||
char s[256];
|
char s[256];
|
||||||
char t[256];
|
char t[256];
|
||||||
@ -213,67 +214,61 @@ static int cue_find_bin (char *firstline) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fd_bin = -1;
|
||||||
|
for (i = 0; fd_bin == -1 && i < 6; i++) {
|
||||||
|
switch (i) {
|
||||||
|
case 0:
|
||||||
/* now try to open that file, without path */
|
/* now try to open that file, without path */
|
||||||
fd_bin = open (bin_filename, O_RDONLY);
|
cur_name = bin_filename;
|
||||||
if (fd_bin == -1)
|
break;
|
||||||
{
|
case 1:
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS, MSGTR_MPDEMUX_CUEREAD_BinFilenameTested,
|
|
||||||
bin_filename);
|
|
||||||
|
|
||||||
/* now try to find it with the path of the cue file */
|
/* now try to find it with the path of the cue file */
|
||||||
snprintf(s,sizeof( s ),"%s/%s",bincue_path,bin_filename);
|
snprintf(s,sizeof( s ),"%s/%s",bincue_path,bin_filename);
|
||||||
fd_bin = open (s, O_RDONLY);
|
cur_name = s;
|
||||||
if (fd_bin == -1)
|
break;
|
||||||
{
|
case 2:
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS,
|
|
||||||
MSGTR_MPDEMUX_CUEREAD_BinFilenameTested, s);
|
|
||||||
/* now I would say the whole filename is shit, build our own */
|
/* now I would say the whole filename is shit, build our own */
|
||||||
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||||
s[strlen(cue_filename) - 3] = '\0';
|
s[strlen(cue_filename) - 3] = '\0';
|
||||||
strcat(s, "bin");
|
strcat(s, "bin");
|
||||||
fd_bin = open (s, O_RDONLY);
|
cur_name = s;
|
||||||
if (fd_bin == -1)
|
break;
|
||||||
{
|
case 3:
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS,
|
|
||||||
MSGTR_MPDEMUX_CUEREAD_BinFilenameTested, s);
|
|
||||||
|
|
||||||
/* ok try it with path */
|
/* ok try it with path */
|
||||||
snprintf(t, sizeof( t ), "%s/%s", bincue_path, s);
|
snprintf(t, sizeof( t ), "%s/%s", bincue_path, s);
|
||||||
fd_bin = open (t, O_RDONLY);
|
fd_bin = open (t, O_RDONLY);
|
||||||
if (fd_bin == -1)
|
cur_name = t;
|
||||||
{
|
break;
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS,
|
case 4:
|
||||||
MSGTR_MPDEMUX_CUEREAD_BinFilenameTested,t);
|
|
||||||
/* now I would say the whole filename is shit, build our own */
|
/* now I would say the whole filename is shit, build our own */
|
||||||
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
strncpy(s, cue_filename, strlen(cue_filename) - 3 );
|
||||||
s[strlen(cue_filename) - 3] = '\0';
|
s[strlen(cue_filename) - 3] = '\0';
|
||||||
strcat(s, "img");
|
strcat(s, "img");
|
||||||
fd_bin = open (s, O_RDONLY);
|
cur_name = s;
|
||||||
if (fd_bin == -1)
|
break;
|
||||||
{
|
case 5:
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS,
|
|
||||||
MSGTR_MPDEMUX_CUEREAD_BinFilenameTested, s);
|
|
||||||
/* ok try it with path */
|
/* ok try it with path */
|
||||||
snprintf(t, sizeof( t ), "%s/%s", bincue_path, s);
|
snprintf(t, sizeof( t ), "%s/%s", bincue_path, s);
|
||||||
fd_bin = open (t, O_RDONLY);
|
cur_name = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fd_bin = open(cur_name, O_RDONLY);
|
||||||
|
if (fd_bin == -1) {
|
||||||
|
mp_msg(MSGT_OPEN,MSGL_STATUS, MSGTR_MPDEMUX_CUEREAD_BinFilenameTested,
|
||||||
|
cur_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fd_bin == -1)
|
if (fd_bin == -1)
|
||||||
{
|
{
|
||||||
mp_msg(MSGT_OPEN,MSGL_STATUS,
|
|
||||||
MSGTR_MPDEMUX_CUEREAD_BinFilenameTested, s);
|
|
||||||
|
|
||||||
/* I'll give up */
|
/* I'll give up */
|
||||||
mp_msg(MSGT_OPEN,MSGL_ERR,
|
mp_msg(MSGT_OPEN,MSGL_ERR,
|
||||||
MSGTR_MPDEMUX_CUEREAD_CannotFindBinFile);
|
MSGTR_MPDEMUX_CUEREAD_CannotFindBinFile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else strcpy(bin_filename, t);
|
|
||||||
|
|
||||||
} else strcpy(bin_filename, s);
|
if (cur_name != bin_filename)
|
||||||
|
strcpy(bin_filename, cur_name);
|
||||||
} else strcpy(bin_filename, s);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_msg(MSGT_OPEN,MSGL_INFO,
|
mp_msg(MSGT_OPEN,MSGL_INFO,
|
||||||
MSGTR_MPDEMUX_CUEREAD_UsingBinFile, bin_filename);
|
MSGTR_MPDEMUX_CUEREAD_UsingBinFile, bin_filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user