mirror of
https://github.com/libretro/RetroArch
synced 2025-03-10 07:14:13 +00:00
Create string_separate_noalloc
This commit is contained in:
parent
1898a4bec5
commit
044209bc5a
@ -139,13 +139,14 @@ enum slang_texture_semantic slang_name_to_texture_semantic_array(
|
|||||||
bool glslang_read_shader_file(const char *path,
|
bool glslang_read_shader_file(const char *path,
|
||||||
struct string_list *output, bool root_file)
|
struct string_list *output, bool root_file)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
char tmp[PATH_MAX_LENGTH];
|
char tmp[PATH_MAX_LENGTH];
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
size_t i;
|
|
||||||
const char *basename = NULL;
|
const char *basename = NULL;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
int64_t buf_len = 0;
|
int64_t buf_len = 0;
|
||||||
struct string_list *lines = NULL;
|
struct string_list lines = {0};
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
tmp[0] = '\0';
|
tmp[0] = '\0';
|
||||||
attr.i = 0;
|
attr.i = 0;
|
||||||
@ -173,7 +174,8 @@ bool glslang_read_shader_file(const char *path,
|
|||||||
|
|
||||||
/* Split into lines
|
/* Split into lines
|
||||||
* (Blank lines must be included) */
|
* (Blank lines must be included) */
|
||||||
lines = string_separate((char*)buf, "\n");
|
string_list_initialize(&lines);
|
||||||
|
ret = string_separate_noalloc(&lines, (char*)buf, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Buffer is no longer required - clean up */
|
/* Buffer is no longer required - clean up */
|
||||||
@ -181,17 +183,17 @@ bool glslang_read_shader_file(const char *path,
|
|||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (!lines)
|
if (!ret)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (lines->size < 1)
|
if (lines.size < 1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* If this is the 'parent' shader file, ensure that first
|
/* If this is the 'parent' shader file, ensure that first
|
||||||
* line is a 'VERSION' string */
|
* line is a 'VERSION' string */
|
||||||
if (root_file)
|
if (root_file)
|
||||||
{
|
{
|
||||||
const char *line = lines->elems[0].data;
|
const char *line = lines.elems[0].data;
|
||||||
|
|
||||||
if (strncmp("#version ", line, STRLEN_CONST("#version ")))
|
if (strncmp("#version ", line, STRLEN_CONST("#version ")))
|
||||||
{
|
{
|
||||||
@ -217,10 +219,10 @@ bool glslang_read_shader_file(const char *path,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Loop through lines of file */
|
/* Loop through lines of file */
|
||||||
for (i = root_file ? 1 : 0; i < lines->size; i++)
|
for (i = root_file ? 1 : 0; i < lines.size; i++)
|
||||||
{
|
{
|
||||||
unsigned push_line = 0;
|
unsigned push_line = 0;
|
||||||
const char *line = lines->elems[i].data;
|
const char *line = lines.elems[i].data;
|
||||||
|
|
||||||
/* Check for 'include' statements */
|
/* Check for 'include' statements */
|
||||||
if (!strncmp("#include ", line, STRLEN_CONST("#include ")))
|
if (!strncmp("#include ", line, STRLEN_CONST("#include ")))
|
||||||
@ -276,15 +278,12 @@ bool glslang_read_shader_file(const char *path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string_list_free(lines);
|
string_list_deinitialize(&lines);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
string_list_deinitialize(&lines);
|
||||||
if (lines)
|
|
||||||
string_list_free(lines);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,9 @@ bool string_split_noalloc(struct string_list *list,
|
|||||||
*/
|
*/
|
||||||
struct string_list *string_separate(char *str, const char *delim);
|
struct string_list *string_separate(char *str, const char *delim);
|
||||||
|
|
||||||
|
bool string_separate_noalloc(struct string_list *list,
|
||||||
|
char *str, const char *delim);
|
||||||
|
|
||||||
bool string_list_deinitialize(struct string_list *list);
|
bool string_list_deinitialize(struct string_list *list);
|
||||||
|
|
||||||
bool string_list_initialize(struct string_list *list);
|
bool string_list_initialize(struct string_list *list);
|
||||||
|
@ -411,6 +411,39 @@ error:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool string_separate_noalloc(
|
||||||
|
struct string_list *list,
|
||||||
|
char *str, const char *delim)
|
||||||
|
{
|
||||||
|
char *token = NULL;
|
||||||
|
char **str_ptr = NULL;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
if (!str || string_is_empty(delim) || !list)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
str_ptr = &str;
|
||||||
|
token = string_tokenize(str_ptr, delim);
|
||||||
|
|
||||||
|
while (token)
|
||||||
|
{
|
||||||
|
union string_list_elem_attr attr;
|
||||||
|
|
||||||
|
attr.i = 0;
|
||||||
|
|
||||||
|
if (!string_list_append(list, token, attr))
|
||||||
|
{
|
||||||
|
free(token);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(token);
|
||||||
|
token = string_tokenize(str_ptr, delim);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string_list_find_elem:
|
* string_list_find_elem:
|
||||||
* @list : pointer to string list
|
* @list : pointer to string list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user