Skip to content

Commit

Permalink
Small cleanups (Task_database_cue.c)
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Dec 28, 2024
1 parent 4297f02 commit 3e6486d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 103 deletions.
156 changes: 55 additions & 101 deletions tasks/task_database_cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ static void cue_append_multi_disc_suffix(char * str1, const char *filename)
}
}

static int64_t task_database_cue_get_token(intfstream_t *fd, char *token, uint64_t max_len)
static int64_t task_database_cue_get_token(intfstream_t *fd, char *s, uint64_t len)
{
char *c = token;
int64_t len = 0;
char *c = s;
int64_t _len = 0;
int in_string = 0;

for (;;)
Expand All @@ -151,32 +151,32 @@ static int64_t task_database_cue_get_token(intfstream_t *fd, char *token, uint64
case '\t':
case '\r':
case '\n':
if (c == token)
if (c == s)
continue;

if (!in_string)
{
*c = '\0';
return len;
return _len;
}
break;
case '\"':
if (c == token)
if (c == s)
{
in_string = 1;
continue;
}

*c = '\0';
return len;
return _len;
}

len++;
_len++;
c++;
if (len == (int64_t)max_len)
if (_len == (int64_t)len)
{
*c = '\0';
return len;
return _len;
}
}
}
Expand Down Expand Up @@ -456,7 +456,7 @@ int detect_psp_game(intfstream_t *fd, char *s, size_t len, const char *filename)
return false;
}

int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
size_t detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
{
char region_id;
char pre_game_id[20];
Expand All @@ -465,18 +465,18 @@ int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)

/* Load raw serial or quit */
if (intfstream_seek(fd, 0, SEEK_SET) < 0)
return false;
return 0;

if (intfstream_read(fd, raw_game_id, 4) <= 0)
return false;
return 0;

if ( string_is_equal_fast(raw_game_id, "RVZ", STRLEN_CONST("RVZ"))
|| string_is_equal_fast(raw_game_id, "WIA", STRLEN_CONST("WIA")))
{
if (intfstream_seek(fd, 0x0058, SEEK_SET) < 0)
return false;
return 0;
if (intfstream_read(fd, raw_game_id, 4) <= 0)
return false;
return 0;
}

raw_game_id[4] = '\0';
Expand All @@ -487,7 +487,7 @@ int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
#ifdef DEBUG
RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
#endif
return false;
return 0;
}

/** convert raw gamecube serial to redump serial.
Expand All @@ -498,15 +498,7 @@ int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
will not match redump.**/

/** insert prefix **/
pre_game_id[ _len] = 'D';
pre_game_id[++_len] = 'L';
pre_game_id[++_len] = '-';
pre_game_id[++_len] = 'D';
pre_game_id[++_len] = 'O';
pre_game_id[++_len] = 'L';
pre_game_id[++_len] = '-';
pre_game_id[++_len] = '\0';

_len = strlcpy(pre_game_id, "DL-DOL-", sizeof(pre_game_id));
/** add raw serial **/
strlcpy(pre_game_id + _len, raw_game_id, sizeof(pre_game_id) - _len);

Expand All @@ -520,74 +512,38 @@ int detect_gc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
switch (region_id)
{
case 'E':
s[ _len] = '-';
s[++_len] = 'U';
s[++_len] = 'S';
s[++_len] = 'A';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-USA", len - _len);
return _len;
case 'J':
s[ _len] = '-';
s[++_len] = 'J';
s[++_len] = 'P';
s[++_len] = 'N';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-JPN", len - _len);
return _len;
case 'P': /** NYI: P can also be P-UKV, P-AUS **/
case 'X': /** NYI: X can also be X-UKV, X-EUU **/
s[ _len] = '-';
s[++_len] = 'E';
s[++_len] = 'U';
s[++_len] = 'R';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-EUR", len - _len);
return _len;
case 'Y':
s[ _len] = '-';
s[++_len] = 'F';
s[++_len] = 'A';
s[++_len] = 'H';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-FAH", len - _len);
return _len;
case 'D':
s[ _len] = '-';
s[++_len] = 'N';
s[++_len] = 'O';
s[++_len] = 'E';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-NOE", len - _len);
return _len;
case 'S':
s[ _len] = '-';
s[++_len] = 'E';
s[++_len] = 'S';
s[++_len] = 'P';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-ESP", len - _len);
return _len;
case 'F':
s[ _len] = '-';
s[++_len] = 'F';
s[++_len] = 'R';
s[++_len] = 'A';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-FRA", len - _len);
return _len;
case 'I':
s[ _len] = '-';
s[++_len] = 'I';
s[++_len] = 'T';
s[++_len] = 'A';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-ITA", len - _len);
return _len;
case 'H':
s[ _len] = '-';
s[++_len] = 'H';
s[++_len] = 'O';
s[++_len] = 'L';
s[++_len] = '\0';
return true;
_len += strlcpy(s + _len, "-HOL", len - _len);
return _len;
default:
break;
}

return false;
return 0;
}

int detect_scd_game(intfstream_t *fd, char *s, size_t len, const char *filename)
Expand Down Expand Up @@ -989,32 +945,32 @@ int detect_dc_game(intfstream_t *fd, char *s, size_t len, const char *filename)
return false;
}

int detect_wii_game(intfstream_t *fd, char *s, size_t len, const char *filename)
size_t detect_wii_game(intfstream_t *fd, char *s, size_t len, const char *filename)
{
char raw_game_id[15];

/* Load raw serial or quit */
if (intfstream_seek(fd, 0x0000, SEEK_SET) < 0)
return false;
return 0;

if (intfstream_read(fd, raw_game_id, 6) <= 0)
return false;
return 0;

if (string_is_equal_fast(raw_game_id, "WBFS", STRLEN_CONST("WBFS")))
{
if (intfstream_seek(fd, 0x0200, SEEK_SET) < 0)
return false;
return 0;
if (intfstream_read(fd, raw_game_id, 6) <= 0)
return false;
return 0;
}

if ( string_is_equal_fast(raw_game_id, "RVZ", STRLEN_CONST("RVZ"))
|| string_is_equal_fast(raw_game_id, "WIA", STRLEN_CONST("WIA")))
{
if (intfstream_seek(fd, 0x0058, SEEK_SET) < 0)
return false;
return 0;
if (intfstream_read(fd, raw_game_id, 6) <= 0)
return false;
return 0;
}
raw_game_id[6] = '\0';

Expand All @@ -1025,12 +981,11 @@ int detect_wii_game(intfstream_t *fd, char *s, size_t len, const char *filename)
#ifdef DEBUG
RARCH_LOG("[Scanner]: Scrubbing: %s\n", filename);
#endif
return false;
return 0;
}

cue_append_multi_disc_suffix(s, filename);
strlcpy(s, raw_game_id, len);
return true;
return strlcpy(s, raw_game_id, len);
}

#if 0
Expand Down Expand Up @@ -1135,22 +1090,23 @@ static int64_t intfstream_get_file_size(const char *path)

static bool update_cand(int64_t *cand_index, int64_t *last_index,
uint64_t *largest, char *last_file, uint64_t *offset,
size_t *size, char *track_path, uint64_t max_len)
size_t *size, char *s, size_t len)
{
if (*cand_index != -1)
{
if ((uint64_t)(*last_index - *cand_index) > *largest)
{
size_t _len;
*largest = *last_index - *cand_index;
strlcpy(track_path, last_file, (size_t)max_len);
_len = strlcpy(s, last_file, len);
*offset = *cand_index;
*size = (size_t)*largest;
*cand_index = -1;
return true;
return _len;
}
*cand_index = -1;
}
return false;
return 0;
}

int cue_find_track(const char *cue_path, bool first,
Expand Down Expand Up @@ -1206,7 +1162,7 @@ int cue_find_track(const char *cue_path, bool first,
/* We're changing files since the candidate, update it */
if (update_cand(&cand_index, &last_index,
&largest, last_file, offset,
size, track_path, max_len))
size, track_path, (size_t)max_len))
{
rv = 0;
if (first)
Expand Down Expand Up @@ -1250,7 +1206,7 @@ int cue_find_track(const char *cue_path, bool first,
&& (track != cand_track)
&& update_cand(&cand_index, &last_index, &largest,
last_file, offset,
size, track_path, max_len))
size, track_path, (size_t)max_len))
{
rv = 0;
if (first)
Expand All @@ -1273,7 +1229,7 @@ int cue_find_track(const char *cue_path, bool first,

if (update_cand(&cand_index, &last_index,
&largest, last_file, offset,
size, track_path, max_len))
size, track_path, (size_t)max_len))
rv = 0;

clean:
Expand All @@ -1294,17 +1250,15 @@ bool cue_next_file(intfstream_t *fd,
const char *cue_path, char *s, uint64_t len)
{
char tmp_token[MAX_TOKEN_LEN];
char cue_dir[DIR_MAX_LENGTH];
cue_dir[0] = '\0';

fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));

tmp_token[0] = '\0';

while (task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token)) > 0)
{
if (string_is_equal_noncase(tmp_token, "FILE"))
{
char cue_dir[DIR_MAX_LENGTH];
fill_pathname_basedir(cue_dir, cue_path, sizeof(cue_dir));
task_database_cue_get_token(fd, tmp_token, sizeof(tmp_token));
fill_pathname_join_special(s, cue_dir, tmp_token, (size_t)len);
return true;
Expand Down
4 changes: 2 additions & 2 deletions tasks/task_database_cue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ int detect_ps2_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_psp_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_gc_game(intfstream_t *fd, char *s, size_t len,
size_t detect_gc_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_scd_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_sat_game(intfstream_t *fd,
char *s, size_t len, const char *filename);
int detect_dc_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_wii_game(intfstream_t *fd, char *s, size_t len,
size_t detect_wii_game(intfstream_t *fd, char *s, size_t len,
const char *filename);
int detect_system(intfstream_t *fd, const char **system_name,
const char * filename);
Expand Down

0 comments on commit 3e6486d

Please sign in to comment.