mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 16:09:47 +00:00
Move strftime_am_pm to libretro-common and get rid of duplicated
function
This commit is contained in:
parent
b2ff445531
commit
b951a010fd
@ -24,6 +24,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@ -68,6 +69,31 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Time format strings with AM-PM designation require special
|
||||||
|
* handling due to platform dependence */
|
||||||
|
void strftime_am_pm(char *s, size_t len, const char* format,
|
||||||
|
const void *ptr)
|
||||||
|
{
|
||||||
|
char *local = NULL;
|
||||||
|
const struct tm *timeptr = (const struct tm*)ptr;
|
||||||
|
|
||||||
|
/* Ensure correct locale is set
|
||||||
|
* > Required for localised AM/PM strings */
|
||||||
|
setlocale(LC_TIME, "");
|
||||||
|
|
||||||
|
strftime(s, len, format, timeptr);
|
||||||
|
#if !(defined(__linux__) && !defined(ANDROID))
|
||||||
|
if ((local = local_to_utf8_string_alloc(s)))
|
||||||
|
{
|
||||||
|
if (!string_is_empty(local))
|
||||||
|
strlcpy(s, local, len);
|
||||||
|
|
||||||
|
free(local);
|
||||||
|
local = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new linked list with one node in it
|
* Create a new linked list with one node in it
|
||||||
* The path on this node will be set to NULL
|
* The path on this node will be set to NULL
|
||||||
|
@ -664,6 +664,11 @@ bool path_mkdir(const char *dir);
|
|||||||
*/
|
*/
|
||||||
bool path_is_directory(const char *path);
|
bool path_is_directory(const char *path);
|
||||||
|
|
||||||
|
/* Time format strings with AM-PM designation require special
|
||||||
|
* handling due to platform dependence */
|
||||||
|
void strftime_am_pm(char *s, size_t len, const char* format,
|
||||||
|
const void* timeptr);
|
||||||
|
|
||||||
bool path_is_character_special(const char *path);
|
bool path_is_character_special(const char *path);
|
||||||
|
|
||||||
int path_stat(const char *path);
|
int path_stat(const char *path);
|
||||||
|
@ -20,9 +20,8 @@
|
|||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
#include <retro_timers.h>
|
#include <retro_timers.h>
|
||||||
|
#include <file/file_path.h>
|
||||||
#include <lists/dir_list.h>
|
#include <lists/dir_list.h>
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
#include <compat/strcasestr.h>
|
#include <compat/strcasestr.h>
|
||||||
@ -676,32 +675,6 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
|
|||||||
return match_found;
|
return match_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Time format strings with AM-PM designation require special
|
|
||||||
* handling due to platform dependence */
|
|
||||||
static void strftime_am_pm(char *s, size_t len, const char* format,
|
|
||||||
const struct tm* timeptr)
|
|
||||||
{
|
|
||||||
char *local = NULL;
|
|
||||||
|
|
||||||
/* Ensure correct locale is set
|
|
||||||
* > Required for localised AM/PM strings */
|
|
||||||
setlocale(LC_TIME, "");
|
|
||||||
|
|
||||||
strftime(s, len, format, timeptr);
|
|
||||||
#if !(defined(__linux__) && !defined(ANDROID))
|
|
||||||
local = local_to_utf8_string_alloc(s);
|
|
||||||
if (local)
|
|
||||||
{
|
|
||||||
if (!string_is_empty(local))
|
|
||||||
strlcpy(s, local, len);
|
|
||||||
|
|
||||||
free(local);
|
|
||||||
local = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Display the date and time - time_mode will influence how
|
/* Display the date and time - time_mode will influence how
|
||||||
* the time representation will look like.
|
* the time representation will look like.
|
||||||
* */
|
* */
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
@ -62,11 +61,9 @@ static bool RtlJSONObjectMemberHandler(void *ctx, const char *s, size_t len)
|
|||||||
{
|
{
|
||||||
RtlJSONContext *p_ctx = (RtlJSONContext*)ctx;
|
RtlJSONContext *p_ctx = (RtlJSONContext*)ctx;
|
||||||
|
|
||||||
|
/* Something went wrong */
|
||||||
if (p_ctx->current_entry_val)
|
if (p_ctx->current_entry_val)
|
||||||
{
|
|
||||||
/* something went wrong */
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (len)
|
if (len)
|
||||||
{
|
{
|
||||||
@ -74,7 +71,7 @@ static bool RtlJSONObjectMemberHandler(void *ctx, const char *s, size_t len)
|
|||||||
p_ctx->current_entry_val = &p_ctx->runtime_string;
|
p_ctx->current_entry_val = &p_ctx->runtime_string;
|
||||||
else if (string_is_equal(s, "last_played"))
|
else if (string_is_equal(s, "last_played"))
|
||||||
p_ctx->current_entry_val = &p_ctx->last_played_string;
|
p_ctx->current_entry_val = &p_ctx->last_played_string;
|
||||||
/* ignore unknown members */
|
/* Ignore unknown members */
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -91,8 +88,8 @@ static bool RtlJSONStringHandler(void *ctx, const char *s, size_t len)
|
|||||||
|
|
||||||
*p_ctx->current_entry_val = strdup(s);
|
*p_ctx->current_entry_val = strdup(s);
|
||||||
}
|
}
|
||||||
/* ignore unknown members */
|
|
||||||
|
|
||||||
|
/* Ignore unknown members */
|
||||||
p_ctx->current_entry_val = NULL;
|
p_ctx->current_entry_val = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -104,6 +101,7 @@ static bool RtlJSONStringHandler(void *ctx, const char *s, size_t len)
|
|||||||
* Does nothing if log file does not exist. */
|
* Does nothing if log file does not exist. */
|
||||||
static void runtime_log_read_file(runtime_log_t *runtime_log)
|
static void runtime_log_read_file(runtime_log_t *runtime_log)
|
||||||
{
|
{
|
||||||
|
rjson_t* parser;
|
||||||
unsigned runtime_hours = 0;
|
unsigned runtime_hours = 0;
|
||||||
unsigned runtime_minutes = 0;
|
unsigned runtime_minutes = 0;
|
||||||
unsigned runtime_seconds = 0;
|
unsigned runtime_seconds = 0;
|
||||||
@ -116,8 +114,6 @@ static void runtime_log_read_file(runtime_log_t *runtime_log)
|
|||||||
unsigned last_played_second = 0;
|
unsigned last_played_second = 0;
|
||||||
|
|
||||||
RtlJSONContext context = {0};
|
RtlJSONContext context = {0};
|
||||||
rjson_t* parser;
|
|
||||||
|
|
||||||
/* Attempt to open log file */
|
/* Attempt to open log file */
|
||||||
RFILE *file = filestream_open(runtime_log->path,
|
RFILE *file = filestream_open(runtime_log->path,
|
||||||
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
||||||
@ -129,8 +125,7 @@ static void runtime_log_read_file(runtime_log_t *runtime_log)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise JSON parser */
|
/* Initialise JSON parser */
|
||||||
parser = rjson_open_rfile(file);
|
if (!(parser = rjson_open_rfile(file)))
|
||||||
if (!parser)
|
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to create JSON parser.\n");
|
RARCH_ERR("Failed to create JSON parser.\n");
|
||||||
goto end;
|
goto end;
|
||||||
@ -212,7 +207,6 @@ static void runtime_log_read_file(runtime_log_t *runtime_log)
|
|||||||
runtime_log->last_played.second = last_played_second;
|
runtime_log->last_played.second = last_played_second;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
|
||||||
/* Clean up leftover strings */
|
/* Clean up leftover strings */
|
||||||
if (context.runtime_string)
|
if (context.runtime_string)
|
||||||
free(context.runtime_string);
|
free(context.runtime_string);
|
||||||
@ -247,17 +241,17 @@ runtime_log_t *runtime_log_init(
|
|||||||
content_name[0] = '\0';
|
content_name[0] = '\0';
|
||||||
core_name[0] = '\0';
|
core_name[0] = '\0';
|
||||||
|
|
||||||
if ( string_is_empty(dir_runtime_log) &&
|
if ( string_is_empty(dir_runtime_log)
|
||||||
string_is_empty(dir_playlist))
|
&& string_is_empty(dir_playlist))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Runtime log directory is undefined - cannot save"
|
RARCH_ERR("Runtime log directory is undefined - cannot save"
|
||||||
" runtime log files.\n");
|
" runtime log files.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( string_is_empty(core_path) ||
|
if ( string_is_empty(core_path)
|
||||||
string_is_equal(core_path, "builtin") ||
|
|| string_is_equal(core_path, "builtin")
|
||||||
string_is_equal(core_path, "DETECT"))
|
|| string_is_equal(core_path, "DETECT"))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Get core info:
|
/* Get core info:
|
||||||
@ -375,9 +369,7 @@ runtime_log_t *runtime_log_init(
|
|||||||
|
|
||||||
/* Phew... If we get this far then all is well.
|
/* Phew... If we get this far then all is well.
|
||||||
* > Create 'runtime_log' object */
|
* > Create 'runtime_log' object */
|
||||||
runtime_log = (runtime_log_t*)
|
if (!(runtime_log = (runtime_log_t*)malloc(sizeof(*runtime_log))))
|
||||||
malloc(sizeof(*runtime_log));
|
|
||||||
if (!runtime_log)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* > Populate default values */
|
/* > Populate default values */
|
||||||
@ -441,13 +433,11 @@ void runtime_log_set_runtime_hms(runtime_log_t *runtime_log,
|
|||||||
void runtime_log_set_runtime_usec(
|
void runtime_log_set_runtime_usec(
|
||||||
runtime_log_t *runtime_log, retro_time_t usec)
|
runtime_log_t *runtime_log, retro_time_t usec)
|
||||||
{
|
{
|
||||||
if (!runtime_log)
|
if (runtime_log)
|
||||||
return;
|
runtime_log_convert_usec2hms(usec,
|
||||||
|
&runtime_log->runtime.hours,
|
||||||
runtime_log_convert_usec2hms(usec,
|
&runtime_log->runtime.minutes,
|
||||||
&runtime_log->runtime.hours,
|
&runtime_log->runtime.seconds);
|
||||||
&runtime_log->runtime.minutes,
|
|
||||||
&runtime_log->runtime.seconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adds specified hours, minutes, seconds value to current runtime */
|
/* Adds specified hours, minutes, seconds value to current runtime */
|
||||||
@ -647,29 +637,6 @@ void runtime_log_get_last_played_time(runtime_log_t *runtime_log,
|
|||||||
mktime(time_info);
|
mktime(time_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runtime_last_played_strftime(
|
|
||||||
char *s, size_t len, const char *format,
|
|
||||||
const struct tm *timeptr)
|
|
||||||
{
|
|
||||||
char *local = NULL;
|
|
||||||
|
|
||||||
/* Ensure correct locale is set */
|
|
||||||
setlocale(LC_TIME, "");
|
|
||||||
|
|
||||||
/* Generate string */
|
|
||||||
strftime(s, len, format, timeptr);
|
|
||||||
#if !(defined(__linux__) && !defined(ANDROID))
|
|
||||||
if ((local = local_to_utf8_string_alloc(s)))
|
|
||||||
{
|
|
||||||
if (!string_is_empty(local))
|
|
||||||
strlcpy(s, local, len);
|
|
||||||
|
|
||||||
free(local);
|
|
||||||
local = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool runtime_last_played_human(runtime_log_t *runtime_log,
|
static bool runtime_last_played_human(runtime_log_t *runtime_log,
|
||||||
char *str, size_t len)
|
char *str, size_t len)
|
||||||
{
|
{
|
||||||
@ -877,7 +844,7 @@ void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
|
|||||||
/* Get time */
|
/* Get time */
|
||||||
struct tm time_info;
|
struct tm time_info;
|
||||||
runtime_log_get_last_played_time(runtime_log, &time_info);
|
runtime_log_get_last_played_time(runtime_log, &time_info);
|
||||||
runtime_last_played_strftime(tmp, sizeof(tmp), format_str, &time_info);
|
strftime_am_pm(tmp, sizeof(tmp), format_str, &time_info);
|
||||||
str[_len ] = ' ';
|
str[_len ] = ' ';
|
||||||
str[_len+1] = '\0';
|
str[_len+1] = '\0';
|
||||||
strlcat(str, tmp, len);
|
strlcat(str, tmp, len);
|
||||||
|
Loading…
Reference in New Issue
Block a user