diff options
author | neonloop | 2021-08-27 00:30:47 +0000 |
---|---|---|
committer | neonloop | 2021-08-27 00:30:47 +0000 |
commit | 3f527c7426cbbdbd04962545b801c944434a0377 (patch) | |
tree | f9ba8499e54dcafb2fea259522fd4ff1b9f66f2b /util.c | |
parent | 0060a16ad707c1d6f2013947821ff55e377ceb92 (diff) | |
download | picoarch-3f527c7426cbbdbd04962545b801c944434a0377.tar.gz picoarch-3f527c7426cbbdbd04962545b801c944434a0377.tar.bz2 picoarch-3f527c7426cbbdbd04962545b801c944434a0377.zip |
Adds a standalone multi-emulator mode
When starting without arguments, can select a core in the current
directory and some content (a game). Allows loading a different game
from the in-game menu.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -1,5 +1,58 @@ +#include <stdlib.h> +#include <string.h> #include "util.h" +struct string_list *string_split(const char *string, char delim) { + const char *loc = string; + int size = 2; /* rest of string, NULL terminator */ + int index = 0; + char delims[2] = {0}; + char *saveptr = NULL; + struct string_list *list = calloc(1, sizeof(struct string_list)); + + if (!list) + goto finish; + + list->source = strdup(string); + if (!list->source) + goto finish; + + while((loc = strchr(loc, delim))) { + size++; + while (*loc && *loc == delim) loc++; + } + + list->list = calloc(size, sizeof(char *)); + if (!list->list) + goto finish; + + delims[0] = delim; + + while((loc = strtok_r(index == 0 ? list->source : NULL, delims, &saveptr))) { + list->list[index++] = loc; + if (index >= size) + break; + } + +finish: + return list; +} + +void string_list_free(struct string_list *list) { + if (list) { + if (list->list) { + free(list->list); + list->list = NULL; + } + if (list->source) { + free(list->source); + list->source = NULL; + } + + free(list); + } +} + void string_truncate(char *string, size_t max_len) { size_t len = strlen(string) + 1; if (len <= max_len) return; |