mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-27 02:00:41 +00:00
Cleanups/simplifications
This commit is contained in:
parent
ed4e7abeb1
commit
24287b1cce
@ -2000,7 +2000,7 @@ bool gfx_animation_line_ticker_smooth(gfx_animation_ctx_line_ticker_smooth_t *li
|
||||
gfx_animation_t *p_anim = &anim_st;
|
||||
const char *wideglyph_str = NULL;
|
||||
int wideglyph_width = 100;
|
||||
void (*word_wrap_func)(char *dst, size_t dst_size,
|
||||
size_t (*word_wrap_func)(char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines);
|
||||
|
||||
@ -2008,10 +2008,10 @@ bool gfx_animation_line_ticker_smooth(gfx_animation_ctx_line_ticker_smooth_t *li
|
||||
if (!line_ticker)
|
||||
return false;
|
||||
|
||||
if (!line_ticker->font ||
|
||||
string_is_empty(line_ticker->src_str) ||
|
||||
(line_ticker->field_width < 1) ||
|
||||
(line_ticker->field_height < 1))
|
||||
if ( !line_ticker->font
|
||||
|| string_is_empty(line_ticker->src_str)
|
||||
|| (line_ticker->field_width < 1)
|
||||
|| (line_ticker->field_height < 1))
|
||||
goto end;
|
||||
|
||||
/* Get font dimensions */
|
||||
|
@ -204,7 +204,7 @@ char *string_trim_whitespace(char *const s);
|
||||
* correctly any text containing so-called 'wide' Unicode
|
||||
* characters (e.g. CJK languages, emojis, etc.).
|
||||
**/
|
||||
void word_wrap(char *dst, size_t dst_size, const char *src, size_t src_len,
|
||||
size_t word_wrap(char *dst, size_t dst_size, const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines);
|
||||
|
||||
/**
|
||||
@ -241,7 +241,7 @@ void word_wrap(char *dst, size_t dst_size, const char *src, size_t src_len,
|
||||
* on-screen pixel width deviates greatly from the set
|
||||
* @wideglyph_width value.
|
||||
**/
|
||||
void word_wrap_wideglyph(
|
||||
size_t word_wrap_wideglyph(
|
||||
char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width,
|
||||
|
@ -43,47 +43,39 @@ static void media_zero_trailing_spaces(char *buf, size_t len)
|
||||
|
||||
static bool media_skip_spaces(const char **buf, size_t len)
|
||||
{
|
||||
bool found = false;
|
||||
unsigned i;
|
||||
|
||||
if (!buf || !*buf || !**buf)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (buf && *buf && **buf)
|
||||
{
|
||||
if ((*buf)[i] == ' ' || (*buf)[i] == '\t')
|
||||
continue;
|
||||
size_t i;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if ((*buf)[i] == ' ' || (*buf)[i] == '\t')
|
||||
continue;
|
||||
|
||||
*buf += i;
|
||||
found = true;
|
||||
break;
|
||||
*buf += i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Fill in "info" with detected CD info. Use this when you have a cue file and want it parsed to find the first data track and any pregap info. */
|
||||
bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
|
||||
{
|
||||
RFILE *file = NULL;
|
||||
char *line = NULL;
|
||||
char track_path[PATH_MAX_LENGTH] = {0};
|
||||
RFILE *file = NULL;
|
||||
char *line = NULL;
|
||||
char track_path[PATH_MAX_LENGTH] = {0};
|
||||
char track_abs_path[PATH_MAX_LENGTH] = {0};
|
||||
char track_mode[11] = {0};
|
||||
bool found_file = false;
|
||||
bool found_track = false;
|
||||
unsigned first_data_track = 0;
|
||||
uint64_t data_track_pregap_bytes = 0;
|
||||
char track_mode[11] = {0};
|
||||
bool found_file = false;
|
||||
bool found_track = false;
|
||||
unsigned first_data_track = 0;
|
||||
uint64_t data_track_pregap_bytes = 0;
|
||||
|
||||
if (string_is_empty(path) || !info)
|
||||
return false;
|
||||
|
||||
file = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0);
|
||||
|
||||
if (!file)
|
||||
if (!(file = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0)))
|
||||
{
|
||||
#ifdef MEDIA_CUE_PARSE_DEBUG
|
||||
printf("[MEDIA] Could not open cue path for reading: %s\n", path);
|
||||
@ -116,8 +108,8 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
|
||||
if (!string_is_empty(file))
|
||||
{
|
||||
const char *file_end = NULL;
|
||||
size_t file_len = 0;
|
||||
bool quoted = false;
|
||||
size_t file_len = 0;
|
||||
bool quoted = false;
|
||||
|
||||
if (file[0] == '"')
|
||||
{
|
||||
@ -198,7 +190,7 @@ bool media_detect_cd_info_cue(const char *path, media_detect_cd_info_t *info)
|
||||
if (!string_is_empty(pregap))
|
||||
{
|
||||
media_skip_spaces(&pregap, strlen(pregap));
|
||||
found_file = false;
|
||||
found_file = false;
|
||||
found_track = false;
|
||||
|
||||
if (first_data_track && !string_is_empty(track_mode))
|
||||
@ -273,9 +265,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
|
||||
if (string_is_empty(path) || !info)
|
||||
return false;
|
||||
|
||||
file = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0);
|
||||
|
||||
if (!file)
|
||||
if (!(file = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0)))
|
||||
{
|
||||
#ifdef MEDIA_CUE_PARSE_DEBUG
|
||||
printf("[MEDIA] Could not open path for reading: %s\n", path);
|
||||
@ -285,11 +275,11 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
|
||||
}
|
||||
|
||||
{
|
||||
unsigned offset = 0;
|
||||
unsigned offset = 0;
|
||||
unsigned sector_size = 0;
|
||||
unsigned buf_size = 17 * 2352;
|
||||
char *buf = (char*)calloc(1, buf_size);
|
||||
int64_t read_bytes = 0;
|
||||
unsigned buf_size = 17 * 2352;
|
||||
char *buf = (char*)calloc(1, buf_size);
|
||||
int64_t read_bytes = 0;
|
||||
|
||||
if (!buf)
|
||||
return false;
|
||||
@ -321,23 +311,14 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
|
||||
/* Assume track data contains all fields. */
|
||||
sector_size = 2352;
|
||||
|
||||
/* Assume Mode 2 formed (formless is rarely used) */
|
||||
if (buf[15] == 2)
|
||||
{
|
||||
/* assume Mode 2 formed (formless is rarely used) */
|
||||
offset = 24;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* assume Mode 1 */
|
||||
offset = 16;
|
||||
}
|
||||
offset = 24;
|
||||
else /* Assume Mode 1 */
|
||||
offset = 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Assume sectors only contain user data instead. */
|
||||
offset = 0;
|
||||
else /* Assume sectors only contain user data instead. */
|
||||
sector_size = 2048;
|
||||
}
|
||||
|
||||
if (!memcmp(buf + offset, "SEGADISCSYSTEM",
|
||||
STRLEN_CONST("SEGADISCSYSTEM")))
|
||||
@ -551,13 +532,11 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
|
||||
else if (!memcmp(buf + offset, "\x01\x5a\x5a\x5a\x5a\x5a\x01\x00\x00\x00\x00\x00", 12))
|
||||
{
|
||||
info->system_id = MEDIA_CD_SYSTEM_3DO;
|
||||
|
||||
strcpy_literal(info->system, "3DO");
|
||||
}
|
||||
else if (!memcmp(buf + offset + 0x950, "PC Engine CD-ROM SYSTEM", 23))
|
||||
{
|
||||
info->system_id = MEDIA_CD_SYSTEM_PC_ENGINE_CD;
|
||||
|
||||
strcpy_literal(info->system, "TurboGrafx-CD / PC-Engine CD");
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,7 @@ static bool fifo_initialize_internal(fifo_buffer_t *buf, size_t size)
|
||||
|
||||
bool fifo_initialize(fifo_buffer_t *buf, size_t size)
|
||||
{
|
||||
if (!buf)
|
||||
return false;
|
||||
return fifo_initialize_internal(buf, size);
|
||||
return (buf && fifo_initialize_internal(buf, size));
|
||||
}
|
||||
|
||||
void fifo_free(fifo_buffer_t *buffer)
|
||||
|
@ -28,12 +28,15 @@
|
||||
#include <compat/strl.h>
|
||||
#include <compat/posix_string.h>
|
||||
|
||||
static bool msg_queue_initialize_internal(msg_queue_t *queue, size_t size)
|
||||
bool msg_queue_initialize(msg_queue_t *queue, size_t size)
|
||||
{
|
||||
struct queue_elem **elems = (struct queue_elem**)calloc(size + 1,
|
||||
sizeof(struct queue_elem*));
|
||||
struct queue_elem **elems = NULL;
|
||||
|
||||
if (!elems)
|
||||
if (!queue)
|
||||
return false;
|
||||
|
||||
if (!(elems = (struct queue_elem**)
|
||||
calloc(size + 1, sizeof(struct queue_elem*))))
|
||||
return false;
|
||||
|
||||
queue->tmp_msg = NULL;
|
||||
@ -55,27 +58,18 @@ static bool msg_queue_initialize_internal(msg_queue_t *queue, size_t size)
|
||||
**/
|
||||
msg_queue_t *msg_queue_new(size_t size)
|
||||
{
|
||||
msg_queue_t *queue = (msg_queue_t*)malloc(sizeof(*queue));
|
||||
msg_queue_t *queue = (msg_queue_t*)malloc(sizeof(*queue));
|
||||
|
||||
if (!queue)
|
||||
return NULL;
|
||||
|
||||
if (!msg_queue_initialize_internal(queue, size))
|
||||
if (!msg_queue_initialize(queue, size))
|
||||
{
|
||||
free(queue);
|
||||
if (queue)
|
||||
free(queue);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
bool msg_queue_initialize(msg_queue_t *queue, size_t size)
|
||||
{
|
||||
if (!queue)
|
||||
return false;
|
||||
return msg_queue_initialize_internal(queue, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* msg_queue_free:
|
||||
* @queue : pointer to queue object
|
||||
@ -126,9 +120,7 @@ void msg_queue_push(msg_queue_t *queue, const char *msg,
|
||||
if (!queue || queue->ptr >= queue->size)
|
||||
return;
|
||||
|
||||
new_elem = (struct queue_elem*)malloc(
|
||||
sizeof(struct queue_elem));
|
||||
if (!new_elem)
|
||||
if (!(new_elem = (struct queue_elem*)malloc(sizeof(struct queue_elem))))
|
||||
return;
|
||||
|
||||
new_elem->duration = duration;
|
||||
@ -180,7 +172,7 @@ void msg_queue_clear(msg_queue_t *queue)
|
||||
queue->elems[i] = NULL;
|
||||
}
|
||||
}
|
||||
queue->ptr = 1;
|
||||
queue->ptr = 1;
|
||||
free(queue->tmp_msg);
|
||||
queue->tmp_msg = NULL;
|
||||
}
|
||||
@ -199,8 +191,6 @@ const char *msg_queue_pull(msg_queue_t *queue)
|
||||
struct queue_elem *front = NULL, *last = NULL;
|
||||
size_t tmp_ptr = 1;
|
||||
|
||||
(void)tmp_ptr;
|
||||
|
||||
/* Nothing in queue. */
|
||||
if (!queue || queue->ptr == 1)
|
||||
return NULL;
|
||||
|
@ -234,7 +234,7 @@ static void retro_task_regular_gather(void)
|
||||
if (task->finished)
|
||||
task_queue_put(&tasks_finished, task);
|
||||
else
|
||||
retro_task_regular_push_running(task);
|
||||
task_queue_put(&tasks_running, task);
|
||||
}
|
||||
|
||||
retro_task_internal_gather();
|
||||
@ -468,18 +468,14 @@ static void retro_task_threaded_retrieve(task_retriever_data_t *data)
|
||||
{
|
||||
/* Protect access to running tasks */
|
||||
slock_lock(running_lock);
|
||||
|
||||
/* Call regular retrieve function */
|
||||
retro_task_regular_retrieve(data);
|
||||
|
||||
/* Release access to running tasks */
|
||||
slock_unlock(running_lock);
|
||||
}
|
||||
|
||||
static void threaded_worker(void *userdata)
|
||||
{
|
||||
(void)userdata;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
retro_task_t *task = NULL;
|
||||
@ -734,16 +730,13 @@ void task_queue_cancel_task(void *task)
|
||||
|
||||
void *task_queue_retriever_info_next(task_retriever_info_t **link)
|
||||
{
|
||||
void *data = NULL;
|
||||
|
||||
/* Grab data and move to next link */
|
||||
if (*link)
|
||||
{
|
||||
data = (*link)->data;
|
||||
*link = (*link)->next;
|
||||
return (*link)->data;
|
||||
}
|
||||
|
||||
return data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void task_queue_retriever_info_free(task_retriever_info_t *list)
|
||||
|
@ -217,27 +217,24 @@ char *string_trim_whitespace(char *const s)
|
||||
* correctly any text containing so-called 'wide' Unicode
|
||||
* characters (e.g. CJK languages, emojis, etc.).
|
||||
**/
|
||||
void word_wrap(
|
||||
size_t word_wrap(
|
||||
char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines)
|
||||
{
|
||||
char *lastspace = NULL;
|
||||
char *last_space = NULL;
|
||||
unsigned counter = 0;
|
||||
unsigned lines = 1;
|
||||
const char *src_end = src + src_len;
|
||||
|
||||
/* Prevent buffer overflow */
|
||||
if (dst_size < src_len + 1)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
/* Early return if src string length is less
|
||||
* than line width */
|
||||
if (src_len < (size_t)line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
|
||||
while (*src != '\0')
|
||||
{
|
||||
@ -245,21 +242,18 @@ void word_wrap(
|
||||
counter++;
|
||||
|
||||
if (*src == ' ')
|
||||
lastspace = dst; /* Remember the location of the whitespace */
|
||||
last_space = dst; /* Remember the location of the whitespace */
|
||||
else if (*src == '\n')
|
||||
{
|
||||
/* If newlines embedded in the input,
|
||||
* reset the index */
|
||||
lines++;
|
||||
counter = 0;
|
||||
counter = 0;
|
||||
|
||||
/* Early return if remaining src string
|
||||
* length is less than line width */
|
||||
if (src_end - src <= line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
}
|
||||
|
||||
while (char_len--)
|
||||
@ -269,29 +263,27 @@ void word_wrap(
|
||||
{
|
||||
counter = 0;
|
||||
|
||||
if (lastspace && (max_lines == 0 || lines < max_lines))
|
||||
if (last_space && (max_lines == 0 || lines < max_lines))
|
||||
{
|
||||
/* Replace nearest (previous) whitespace
|
||||
* with newline character */
|
||||
*lastspace = '\n';
|
||||
*last_space = '\n';
|
||||
lines++;
|
||||
|
||||
src -= dst - lastspace - 1;
|
||||
dst = lastspace + 1;
|
||||
lastspace = NULL;
|
||||
src -= dst - last_space - 1;
|
||||
dst = last_space + 1;
|
||||
last_space = NULL;
|
||||
|
||||
/* Early return if remaining src string
|
||||
* length is less than line width */
|
||||
if (src_end - src < line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,7 +319,7 @@ void word_wrap(
|
||||
* on-screen pixel width deviates greatly from the set
|
||||
* @wideglyph_width value.
|
||||
**/
|
||||
void word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
size_t word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len, int line_width,
|
||||
int wideglyph_width, unsigned max_lines)
|
||||
{
|
||||
@ -363,10 +355,7 @@ void word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
/* Early return if src string length is less
|
||||
* than line width */
|
||||
if (src_end - src < line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
|
||||
while (*src != '\0')
|
||||
{
|
||||
@ -389,10 +378,7 @@ void word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
/* Early return if remaining src string
|
||||
* length is less than line width */
|
||||
if (src_end - src <= line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
}
|
||||
else if (char_len >= 3)
|
||||
{
|
||||
@ -424,10 +410,7 @@ void word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
/* Early return if remaining src string
|
||||
* length is less than line width */
|
||||
if (src_end - src <= line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
}
|
||||
else if (lastspace)
|
||||
{
|
||||
@ -442,15 +425,13 @@ void word_wrap_wideglyph(char *dst, size_t dst_size,
|
||||
/* Early return if remaining src string
|
||||
* length is less than line width */
|
||||
if (src_end - src < line_width)
|
||||
{
|
||||
strlcpy(dst, src, dst_size);
|
||||
return;
|
||||
}
|
||||
return strlcpy(dst, src, dst_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -589,7 +589,7 @@ typedef struct materialui_handle
|
||||
font_data_impl_t hint; /* ptr alignment */
|
||||
} font_data;
|
||||
|
||||
void (*word_wrap)(
|
||||
size_t (*word_wrap)(
|
||||
char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines);
|
||||
|
@ -468,7 +468,7 @@ struct ozone_handle
|
||||
font_data_impl_t sidebar;
|
||||
} fonts;
|
||||
|
||||
void (*word_wrap)(
|
||||
size_t (*word_wrap)(
|
||||
char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines);
|
||||
|
@ -319,7 +319,7 @@ typedef struct xmb_handle
|
||||
video_font_raster_block_t raster_block;
|
||||
video_font_raster_block_t raster_block2;
|
||||
|
||||
void (*word_wrap)(
|
||||
size_t (*word_wrap)(
|
||||
char *dst, size_t dst_size,
|
||||
const char *src, size_t src_len,
|
||||
int line_width, int wideglyph_width, unsigned max_lines);
|
||||
|
Loading…
Reference in New Issue
Block a user