update libretro-common

This commit is contained in:
Brad Parker 2019-07-04 23:17:34 -04:00
parent bb8f30f717
commit 2b46d1b1e9
2 changed files with 72 additions and 34 deletions

View File

@ -41,6 +41,7 @@ static retro_vfs_get_path_t filestream_get_path_cb = NULL;
static retro_vfs_open_t filestream_open_cb = NULL;
static retro_vfs_close_t filestream_close_cb = NULL;
static retro_vfs_size_t filestream_size_cb = NULL;
static retro_vfs_truncate_t filestream_truncate_cb = NULL;
static retro_vfs_tell_t filestream_tell_cb = NULL;
static retro_vfs_seek_t filestream_seek_cb = NULL;
static retro_vfs_read_t filestream_read_cb = NULL;
@ -67,6 +68,7 @@ void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info)
filestream_close_cb = NULL;
filestream_tell_cb = NULL;
filestream_size_cb = NULL;
filestream_truncate_cb = NULL;
filestream_seek_cb = NULL;
filestream_read_cb = NULL;
filestream_write_cb = NULL;
@ -84,6 +86,7 @@ void filestream_vfs_init(const struct retro_vfs_interface_info* vfs_info)
filestream_open_cb = vfs_iface->open;
filestream_close_cb = vfs_iface->close;
filestream_size_cb = vfs_iface->size;
filestream_truncate_cb = vfs_iface->truncate;
filestream_tell_cb = vfs_iface->tell;
filestream_seek_cb = vfs_iface->seek;
filestream_read_cb = vfs_iface->read;
@ -127,6 +130,21 @@ int64_t filestream_get_size(RFILE *stream)
return output;
}
int64_t filestream_truncate(RFILE *stream, int64_t length)
{
int64_t output;
if (filestream_truncate_cb != NULL)
output = filestream_truncate_cb(stream->hfile, length);
else
output = retro_vfs_file_truncate_impl((libretro_vfs_implementation_file*)stream->hfile, length);
if (output == vfs_error_return_value)
stream->error_flag = true;
return output;
}
/**
* filestream_open:
* @path : path to file
@ -197,37 +215,37 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
char buf[4096];
char subfmt[64];
va_list args;
const char * bufiter = buf;
int64_t startpos = filestream_tell(stream);
int ret = 0;
int64_t maxlen = filestream_read(stream, buf, sizeof(buf)-1);
buf[maxlen] = '\0';
va_start(args, format);
while (*format)
{
if (*format == '%')
{
int sublen;
char* subfmtiter = subfmt;
bool asterisk = false;
*subfmtiter++ = *format++; /* '%' */
/* %[*][width][length]specifier */
if (*format == '*')
{
asterisk = true;
*subfmtiter++ = *format++;
}
while (isdigit(*format)) *subfmtiter++ = *format++; /* width */
/* length */
if (*format == 'h' || *format == 'l')
{
@ -238,7 +256,7 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
{
*subfmtiter++ = *format++;
}
/* specifier - always a single character (except ]) */
if (*format == '[')
{
@ -246,11 +264,11 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
*subfmtiter++ = *format++;
}
else *subfmtiter++ = *format++;
*subfmtiter++ = '%';
*subfmtiter++ = 'n';
*subfmtiter++ = '\0';
if (sizeof(void*) != sizeof(long*)) abort(); /* all pointers must have the same size */
if (asterisk)
{
@ -260,7 +278,7 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
{
if (sscanf(bufiter, subfmt, va_arg(args, void*), &sublen) != 1) break;
}
ret++;
bufiter += sublen;
}
@ -277,10 +295,10 @@ int filestream_scanf(RFILE *stream, const char* format, ...)
format++;
}
}
va_end(args);
filestream_seek(stream, startpos+(bufiter-buf), RETRO_VFS_SEEK_POSITION_START);
return ret;
}
@ -305,7 +323,6 @@ int filestream_eof(RFILE *stream)
return stream->eof_flag;
}
int64_t filestream_tell(RFILE *stream)
{
int64_t output;
@ -592,3 +609,8 @@ char *filestream_getline(RFILE *stream)
newline[idx] = '\0';
return newline;
}
const libretro_vfs_implementation_file* filestream_get_vfs_handle(RFILE *stream)
{
return (const libretro_vfs_implementation_file*)stream->hfile;
}

View File

@ -82,6 +82,10 @@ char *string_replace_substring(const char *in,
outlen = strlen(in) - pattern_len*numhits + replacement_len*numhits;
out = (char *)malloc(outlen+1);
if (!out)
return NULL;
outat = out;
inat = in;
inprev = in;
@ -105,18 +109,17 @@ char *string_trim_whitespace_left(char *const s)
{
if(s && *s)
{
size_t len = strlen(s);
char *cur = s;
size_t len = strlen(s);
char *current = s;
while(*cur && isspace((unsigned char)*cur))
while(*current && isspace((unsigned char)*current))
{
++cur;
++current;
--len;
}
if(s != cur)
memmove(s, cur, len + 1);
if(s != current)
memmove(s, current, len + 1);
}
return s;
@ -127,16 +130,16 @@ char *string_trim_whitespace_right(char *const s)
{
if(s && *s)
{
size_t len = strlen(s);
char *cur = s + len - 1;
size_t len = strlen(s);
char *current = s + len - 1;
while(cur != s && isspace((unsigned char)*cur))
while(current != s && isspace((unsigned char)*current))
{
--cur;
--current;
--len;
}
cur[isspace((unsigned char)*cur) ? 0 : 1] = '\0';
current[isspace((unsigned char)*current) ? 0 : 1] = '\0';
}
return s;
@ -151,14 +154,16 @@ char *string_trim_whitespace(char *const s)
return s;
}
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode)
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode, unsigned max_lines)
{
unsigned i = 0;
unsigned len = (unsigned)strlen(string);
unsigned i = 0;
unsigned len = (unsigned)strlen(string);
unsigned lines = 1;
while (i < len)
{
unsigned counter;
int pos = (int)(&buffer[i] - buffer);
/* copy string until the end of the line is reached */
for (counter = 1; counter <= (unsigned)line_width; counter++)
@ -190,14 +195,21 @@ char *word_wrap(char* buffer, const char *string, int line_width, bool unicode)
/* check for newlines embedded in the original input
* and reset the index */
if (buffer[j] == '\n')
{
lines++;
counter = 1;
}
}
/* check for whitespace */
if (string[i] == ' ')
{
buffer[i] = '\n';
i++;
if ((max_lines == 0 || lines < max_lines))
{
buffer[i] = '\n';
i++;
lines++;
}
}
else
{
@ -206,14 +218,18 @@ char *word_wrap(char* buffer, const char *string, int line_width, bool unicode)
/* check for nearest whitespace back in string */
for (k = i; k > 0; k--)
{
if (string[k] != ' ')
if (string[k] != ' ' || (max_lines != 0 && lines >= max_lines))
continue;
buffer[k] = '\n';
/* set string index back to character after this one */
i = k + 1;
lines++;
break;
}
if (&buffer[i] - buffer == pos)
return buffer;
}
}