Revert "(task_database.c) Style nits"

This reverts commit 0f46d42c267cef80c634eef8f66dad68cc19e705.
This commit is contained in:
twinaphex 2016-02-04 10:17:54 +01:00
parent 24adcc8e68
commit 16ba94b531

View File

@ -90,7 +90,7 @@ static int zlib_compare_crc32(const char *name, const char *valid_exts,
static int database_info_iterate_start(database_info_handle_t *db, static int database_info_iterate_start(database_info_handle_t *db,
const char *name) const char *name)
{ {
char msg[128]; char msg[128] = {0};
#ifdef _WIN32 #ifdef _WIN32
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
@ -125,7 +125,7 @@ static int iso_get_serial(database_state_handle_t *db_state,
database_info_handle_t *db, const char *name, char* serial) database_info_handle_t *db, const char *name, char* serial)
{ {
int rv; int rv;
int32_t offset = 0; int32_t offset = 0;
const char* system_name = NULL; const char* system_name = NULL;
if ((rv = detect_system(name, offset, &system_name)) < 0) if ((rv = detect_system(name, offset, &system_name)) < 0)
@ -152,8 +152,7 @@ static int cue_get_serial(database_state_handle_t *db_state,
{ {
char track_path[PATH_MAX_LENGTH]; char track_path[PATH_MAX_LENGTH];
int32_t offset = 0; int32_t offset = 0;
int rv = find_first_data_track( int rv = find_first_data_track(name, &offset, track_path, PATH_MAX_LENGTH);
name, &offset, track_path, PATH_MAX_LENGTH);
if (rv < 0) if (rv < 0)
{ {
@ -170,8 +169,8 @@ static int database_info_iterate_playlist(
database_state_handle_t *db_state, database_state_handle_t *db_state,
database_info_handle_t *db, const char *name) database_info_handle_t *db, const char *name)
{ {
char parent_dir[PATH_MAX_LENGTH];
uint32_t extension_hash = 0; uint32_t extension_hash = 0;
char parent_dir[PATH_MAX_LENGTH] = {0};
path_parent_dir(parent_dir); path_parent_dir(parent_dir);
@ -202,23 +201,20 @@ static int database_info_iterate_playlist(
default: default:
{ {
ssize_t ret; ssize_t ret;
int read_from = retro_read_file(name, (void**)&db_state->buf, &ret);
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
const struct file_archive_file_backend *stream_backend = const struct file_archive_file_backend *stream_backend =
file_archive_get_default_file_backend(); file_archive_get_default_file_backend();
#endif #endif
if (
retro_read_file(name, (void**)&db_state->buf, &ret) != 1)
return 0;
if (ret <= 0) if (read_from != 1 || ret <= 0)
return 0; return 0;
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
db_state->crc = db_state->crc = stream_backend->stream_crc_calculate(0, db_state->buf, ret);
stream_backend->stream_crc_calculate(0, db_state->buf, ret);
#endif #endif
db->type = DATABASE_TYPE_CRC_LOOKUP; db->type = DATABASE_TYPE_CRC_LOOKUP;
} }
break; break;
} }
@ -226,8 +222,7 @@ static int database_info_iterate_playlist(
return 1; return 1;
} }
static int database_info_list_iterate_end_no_match( static int database_info_list_iterate_end_no_match(database_state_handle_t *db_state)
database_state_handle_t *db_state)
{ {
/* Reached end of database list, CRC match probably didn't succeed. */ /* Reached end of database list, CRC match probably didn't succeed. */
db_state->list_index = 0; db_state->list_index = 0;
@ -247,8 +242,7 @@ static int database_info_iterate_next(database_info_handle_t *db)
return -1; return -1;
} }
static int database_info_list_iterate_new( static int database_info_list_iterate_new(database_state_handle_t *db_state, const char *query)
database_state_handle_t *db_state, const char *query)
{ {
const char *new_database = db_state->list->elems[db_state->list_index].data; const char *new_database = db_state->list->elems[db_state->list_index].data;
#if 0 #if 0
@ -267,10 +261,10 @@ static int database_info_list_iterate_found_match(
const char *zip_name const char *zip_name
) )
{ {
char db_crc[PATH_MAX_LENGTH]; char db_crc[PATH_MAX_LENGTH] = {0};
char db_playlist_path[PATH_MAX_LENGTH]; char db_playlist_path[PATH_MAX_LENGTH] = {0};
char db_playlist_base_str[PATH_MAX_LENGTH]; char db_playlist_base_str[PATH_MAX_LENGTH] = {0};
char entry_path_str[PATH_MAX_LENGTH]; char entry_path_str[PATH_MAX_LENGTH] = {0};
content_playlist_t *playlist = NULL; content_playlist_t *playlist = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *db_path = db_state->list->elems[db_state->list_index].data; const char *db_path = db_state->list->elems[db_state->list_index].data;
@ -312,8 +306,7 @@ static int database_info_list_iterate_found_match(
if(!content_playlist_entry_exists(playlist, entry_path_str, db_crc)) if(!content_playlist_entry_exists(playlist, entry_path_str, db_crc))
{ {
content_playlist_push(playlist, entry_path_str, content_playlist_push(playlist, entry_path_str,
db_info_entry->name, "DETECT", "DETECT", db_info_entry->name, "DETECT", "DETECT", db_crc, db_playlist_base_str);
db_crc, db_playlist_base_str);
} }
content_playlist_write_file(playlist); content_playlist_write_file(playlist);
@ -348,23 +341,20 @@ static int database_info_iterate_crc_lookup(
const char *zip_entry) const char *zip_entry)
{ {
if (!db_state->list || if (!db_state->list || (unsigned)db_state->list_index == (unsigned)db_state->list->size)
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
return database_info_list_iterate_end_no_match(db_state); return database_info_list_iterate_end_no_match(db_state);
if (db_state->entry_index == 0) if (db_state->entry_index == 0)
{ {
char query[50] = {0}; char query[50] = {0};
snprintf(query, sizeof(query), snprintf(query, sizeof(query), "{crc: b\"%08X\"}", swap_if_big32(db_state->crc));
"{crc: b\"%08X\"}", swap_if_big32(db_state->crc));
database_info_list_iterate_new(db_state, query); database_info_list_iterate_new(db_state, query);
} }
if (db_state->info) if (db_state->info)
{ {
database_info_t *db_info_entry = database_info_t *db_info_entry = &db_state->info->list[db_state->entry_index];
&db_state->info->list[db_state->entry_index];
if (db_info_entry && db_info_entry->crc32) if (db_info_entry && db_info_entry->crc32)
{ {
@ -373,8 +363,7 @@ static int database_info_iterate_crc_lookup(
db_state->crc, db_info_entry->crc32, db_info_entry->name); db_state->crc, db_info_entry->crc32, db_info_entry->name);
#endif #endif
if (db_state->crc == db_info_entry->crc32) if (db_state->crc == db_info_entry->crc32)
return database_info_list_iterate_found_match( return database_info_list_iterate_found_match(db_state, db, zip_entry);
db_state, db, zip_entry);
} }
} }
@ -402,16 +391,17 @@ static int database_info_iterate_playlist_zip(
bool returnerr = true; bool returnerr = true;
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
if (db_state->crc != 0) if (db_state->crc != 0)
return database_info_iterate_crc_lookup( return database_info_iterate_crc_lookup(db_state, db, db_state->zip_name);
db_state, db, db_state->zip_name); else
{
if (file_archive_parse_file_iterate(&db->state,
&returnerr, name, NULL, zlib_compare_crc32,
(void*)db_state) != 0)
return 0;
if (file_archive_parse_file_iterate(&db->state, if (db_state->crc)
&returnerr, name, NULL, zlib_compare_crc32, file_archive_parse_file_iterate_stop(&db->state);
(void*)db_state) != 0) }
return 0;
if (db_state->crc)
file_archive_parse_file_iterate_stop(&db->state);
#endif #endif
return 1; return 1;
@ -421,15 +411,13 @@ static int database_info_iterate_serial_lookup(
database_state_handle_t *db_state, database_state_handle_t *db_state,
database_info_handle_t *db, const char *name) database_info_handle_t *db, const char *name)
{ {
if (!db_state->list || if (!db_state->list || (unsigned)db_state->list_index == (unsigned)db_state->list->size)
(unsigned)db_state->list_index == (unsigned)db_state->list->size)
return database_info_list_iterate_end_no_match(db_state); return database_info_list_iterate_end_no_match(db_state);
if (db_state->entry_index == 0) if (db_state->entry_index == 0)
{ {
char query[50]; char query[50];
char *serial_buf = char *serial_buf = bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
bin_to_hex_alloc((uint8_t*)db_state->serial, 10 * sizeof(uint8_t));
if (!serial_buf) if (!serial_buf)
return 1; return 1;
@ -442,8 +430,7 @@ static int database_info_iterate_serial_lookup(
if (db_state->info) if (db_state->info)
{ {
database_info_t *db_info_entry = database_info_t *db_info_entry = &db_state->info->list[db_state->entry_index];
&db_state->info->list[db_state->entry_index];
if (db_info_entry && db_info_entry->serial) if (db_info_entry && db_info_entry->serial)
{ {
@ -473,13 +460,9 @@ static int database_info_iterate_serial_lookup(
return 0; return 0;
} }
static int database_info_iterate(database_state_handle_t *db_state, static int database_info_iterate(database_state_handle_t *db_state, database_info_handle_t *db)
database_info_handle_t *db)
{ {
const char *name = NULL; const char *name = db ? db->list->elems[db->list_ptr].data : NULL;
if (db)
db = (database_info_handle_t*)db->list->elems[db->list_ptr].data;
if (!db || !db->list) if (!db || !db->list)
return -1; return -1;
@ -489,6 +472,8 @@ static int database_info_iterate(database_state_handle_t *db_state,
switch (db->type) switch (db->type)
{ {
case DATABASE_TYPE_NONE:
break;
case DATABASE_TYPE_ITERATE: case DATABASE_TYPE_ITERATE:
return database_info_iterate_playlist(db_state, db, name); return database_info_iterate_playlist(db_state, db, name);
case DATABASE_TYPE_ITERATE_ZIP: case DATABASE_TYPE_ITERATE_ZIP:
@ -497,16 +482,11 @@ static int database_info_iterate(database_state_handle_t *db_state,
return database_info_iterate_serial_lookup(db_state, db, name); return database_info_iterate_serial_lookup(db_state, db, name);
case DATABASE_TYPE_CRC_LOOKUP: case DATABASE_TYPE_CRC_LOOKUP:
return database_info_iterate_crc_lookup(db_state, db, NULL); return database_info_iterate_crc_lookup(db_state, db, NULL);
case DATABASE_TYPE_NONE:
default:
break;
} }
return 0; return 0;
} }
static void rarch_main_data_db_cleanup_state( static void rarch_main_data_db_cleanup_state(database_state_handle_t *db_state)
database_state_handle_t *db_state)
{ {
if (!db_state) if (!db_state)
return; return;
@ -518,13 +498,10 @@ static void rarch_main_data_db_cleanup_state(
static void rarch_dbscan_task_handler(rarch_task_t *task) static void rarch_dbscan_task_handler(rarch_task_t *task)
{ {
db_handle_t *db = (db_handle_t*)task->state; db_handle_t *db = (db_handle_t*)task->state;
database_info_handle_t *dbinfo = db->handle; database_info_handle_t *dbinfo = db->handle;
database_state_handle_t *dbstate = &db->state; database_state_handle_t *dbstate = &db->state;
const char *name = NULL; const char *name = dbinfo ? dbinfo->list->elems[dbinfo->list_ptr].data : NULL;
if (dbinfo)
name = dbinfo->list->elems[dbinfo->list_ptr].data;
if (!dbinfo || task->cancelled) if (!dbinfo || task->cancelled)
goto task_finished; goto task_finished;
@ -533,8 +510,7 @@ static void rarch_dbscan_task_handler(rarch_task_t *task)
{ {
case DATABASE_STATUS_ITERATE_BEGIN: case DATABASE_STATUS_ITERATE_BEGIN:
if (dbstate && !dbstate->list) if (dbstate && !dbstate->list)
dbstate->list = dir_list_new_special( dbstate->list = dir_list_new_special(NULL, DIR_LIST_DATABASES, NULL);
NULL, DIR_LIST_DATABASES, NULL);
dbinfo->status = DATABASE_STATUS_ITERATE_START; dbinfo->status = DATABASE_STATUS_ITERATE_START;
break; break;
case DATABASE_STATUS_ITERATE_START: case DATABASE_STATUS_ITERATE_START:
@ -587,8 +563,7 @@ task_finished:
free(db); free(db);
} }
bool rarch_task_push_dbscan(const char *fullpath, bool rarch_task_push_dbscan(const char *fullpath, bool directory, rarch_task_callback_t cb)
bool directory, rarch_task_callback_t cb)
{ {
rarch_task_t *t = (rarch_task_t*)calloc(1, sizeof(*t)); rarch_task_t *t = (rarch_task_t*)calloc(1, sizeof(*t));
db_handle_t *db = (db_handle_t*)calloc(1, sizeof(db_handle_t)); db_handle_t *db = (db_handle_t*)calloc(1, sizeof(db_handle_t));