This splits a string into an array of strings, which is useful for splitting the string returned by eglQueryString(EGL_EXTENSIONS).
Signed-off-by: Chad Versace <[email protected]> --- tests/util/piglit-util-gl-common.c | 23 +---------------------- tests/util/piglit-util.c | 30 ++++++++++++++++++++++++++++++ tests/util/piglit-util.h | 3 +++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c index f4b7f29..35d233d 100644 --- a/tests/util/piglit-util-gl-common.c +++ b/tests/util/piglit-util-gl-common.c @@ -64,32 +64,11 @@ int piglit_get_gl_version(void) return 10*major+minor; } -static const char** split_string(const char *string) -{ - char **strings, *string_copy; - int i, length, max_words; - - length = strlen(string); - max_words = length / 2; - strings = malloc ((sizeof(char*) * (max_words + 1)) + - (sizeof(char) * (length + 1))); - assert (strings != NULL); - - string_copy = (char*) &strings[max_words + 1]; - strcpy(string_copy, string); - - strings[0] = strtok(string_copy, " "); - for (i = 0; strings[i] != NULL; ++i) - strings[i + 1] = strtok(NULL, " "); - - return (const char**) strings; -} - static const char** gl_extension_array_from_getstring() { const char *gl_extensions_string; gl_extensions_string = (const char *) glGetString(GL_EXTENSIONS); - return split_string(gl_extensions_string); + return piglit_split_string_to_array(gl_extensions_string, " "); } #if defined(PIGLIT_USE_OPENGL) diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c index 71d55a7..7dd770e 100644 --- a/tests/util/piglit-util.c +++ b/tests/util/piglit-util.c @@ -101,6 +101,36 @@ int asprintf(char **strp, const char *fmt, ...) #endif /* _WIN32 */ +/** + * \brief Split \a string into an array of strings. + * + * The null-terminated string \a separators is a list of characters at + * which to perform the splits. For example, if separators is " ,", then + * the function will split the string at each occurence of ' ' and ','. + */ +const char** +piglit_split_string_to_array(const char *string, const char *separators) +{ + char **strings, *string_copy; + int i, length, max_words; + + length = strlen(string); + max_words = length / 2; + strings = malloc((sizeof(char*) * (max_words + 1)) + + (sizeof(char) * (length + 1))); + assert(strings != NULL); + + string_copy = (char*) &strings[max_words + 1]; + strcpy(string_copy, string); + + strings[0] = strtok(string_copy, separators); + for (i = 0; strings[i] != NULL; ++i) { + strings[i + 1] = strtok(NULL, separators); + } + + return (const char**) strings; +} + bool piglit_is_extension_in_array(const char **haystack, const char *needle) { if (needle[0] == 0) diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h index 52f053e..0aee833 100644 --- a/tests/util/piglit-util.h +++ b/tests/util/piglit-util.h @@ -174,6 +174,9 @@ piglit_source_dir(void); size_t piglit_join_paths(char buf[], size_t buf_size, int n, ...); +const char** +piglit_split_string_to_array(const char *string, const char *separators); + #ifdef __cplusplus } /* end extern "C" */ #endif -- 1.8.3.1 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
