From c8cc283e5811d344cbcef4e9eaa3312b1ff529d1 Mon Sep 17 00:00:00 2001 From: bnnm Date: Fri, 23 Aug 2024 21:26:33 +0200 Subject: [PATCH] cleanup: api renames --- cli/api_example.c | 24 ++++++++++++------------ src/base/api_internal.h | 2 +- src/base/api_libsf.c | 20 ++++++++++---------- src/base/api_tags.c | 4 ++-- src/base/streamfile_api.c | 12 ++++++------ src/libvgmstream.h | 4 ++-- src/libvgmstream_streamfile.h | 13 +++++++------ 7 files changed, 40 insertions(+), 39 deletions(-) diff --git a/cli/api_example.c b/cli/api_example.c index fbc036cf..d043fa9b 100644 --- a/cli/api_example.c +++ b/cli/api_example.c @@ -25,7 +25,7 @@ static FILE* get_output_file(const char* filename) { return outfile; } -static libvgmstream_streamfile_t* get_streamfile(const char* filename) { +static libstreamfile_t* get_streamfile(const char* filename) { return libvgmstream_streamfile_open_from_stdio(filename); } @@ -199,10 +199,10 @@ static void test_lib_extensions() { assert(exts == NULL); } -static libvgmstream_streamfile_t* test_libsf_open() { +static libstreamfile_t* test_libsf_open() { VGM_STEP(); - libvgmstream_streamfile_t* libsf = NULL; + libstreamfile_t* libsf = NULL; libsf = libvgmstream_streamfile_open_from_stdio("api.bin_wrong"); assert(libsf == NULL); @@ -214,7 +214,7 @@ static libvgmstream_streamfile_t* test_libsf_open() { } -static void test_libsf_read(libvgmstream_streamfile_t* libsf) { +static void test_libsf_read(libstreamfile_t* libsf) { VGM_STEP(); int read; @@ -233,7 +233,7 @@ static void test_libsf_read(libvgmstream_streamfile_t* libsf) { } } -static void test_libsf_seek_read(libvgmstream_streamfile_t* libsf) { +static void test_libsf_seek_read(libstreamfile_t* libsf) { VGM_STEP(); int read, res; @@ -255,27 +255,27 @@ static void test_libsf_seek_read(libvgmstream_streamfile_t* libsf) { assert(read == 0); } -static void test_libsf_size(libvgmstream_streamfile_t* libsf) { +static void test_libsf_size(libstreamfile_t* libsf) { VGM_STEP(); int64_t size = libsf->get_size(libsf->user_data); assert(size == 0x20000); } -static void test_libsf_name(libvgmstream_streamfile_t* libsf) { +static void test_libsf_name(libstreamfile_t* libsf) { VGM_STEP(); const char* name = libsf->get_name(libsf->user_data); assert(strcmp(name, "api.bin") == 0); } -static void test_libsf_reopen(libvgmstream_streamfile_t* libsf) { +static void test_libsf_reopen(libstreamfile_t* libsf) { VGM_STEP(); uint8_t buf[0x20]; int read; - libvgmstream_streamfile_t* newsf = NULL; + libstreamfile_t* newsf = NULL; newsf = libsf->open(libsf->user_data, "api2.bin_wrong"); assert(newsf == NULL); @@ -290,7 +290,7 @@ static void test_libsf_reopen(libvgmstream_streamfile_t* libsf) { newsf->close(newsf); } -static void test_libsf_apisf(libvgmstream_streamfile_t* libsf) { +static void test_libsf_apisf(libstreamfile_t* libsf) { VGM_STEP(); STREAMFILE* sf = open_api_streamfile(libsf); @@ -316,7 +316,7 @@ static void test_libsf_apisf(libvgmstream_streamfile_t* libsf) { static void test_lib_streamfile() { VGM_STEP(); - libvgmstream_streamfile_t* libsf = test_libsf_open(); + libstreamfile_t* libsf = test_libsf_open(); test_libsf_read(libsf); test_libsf_seek_read(libsf); test_libsf_size(libsf); @@ -331,7 +331,7 @@ static void test_lib_streamfile() { static void test_lib_tags() { VGM_STEP(); - libvgmstream_streamfile_t* libsf = NULL; + libstreamfile_t* libsf = NULL; libvgmstream_tags_t* tags = NULL; bool more = false; diff --git a/src/base/api_internal.h b/src/base/api_internal.h index fec1035f..f18be045 100644 --- a/src/base/api_internal.h +++ b/src/base/api_internal.h @@ -57,7 +57,7 @@ typedef struct { void libvgmstream_priv_reset(libvgmstream_priv_t* priv, bool reset_buf); -STREAMFILE* open_api_streamfile(libvgmstream_streamfile_t* libsf); +STREAMFILE* open_api_streamfile(libstreamfile_t* libsf); #endif #endif diff --git a/src/base/api_libsf.c b/src/base/api_libsf.c index c2318bd7..b9b60ae8 100644 --- a/src/base/api_libsf.c +++ b/src/base/api_libsf.c @@ -1,9 +1,9 @@ #include "api_internal.h" #if LIBVGMSTREAM_ENABLE -static libvgmstream_streamfile_t* libvgmstream_streamfile_from_streamfile(STREAMFILE* sf); +static libstreamfile_t* libvgmstream_streamfile_from_streamfile(STREAMFILE* sf); -/* libvgmstream_streamfile_t for external use, as a default implementation calling some internal SF */ +/* libstreamfile_t for external use, as a default implementation calling some internal SF */ typedef struct { int64_t offset; @@ -71,7 +71,7 @@ static const char* libsf_get_name(void* user_data) { return data->name; } -struct libvgmstream_streamfile_t* libsf_open(void* user_data, const char* filename) { +struct libstreamfile_t* libsf_open(void* user_data, const char* filename) { libsf_data_t* data = user_data; if (!data || !data->inner_sf) return NULL; @@ -80,7 +80,7 @@ struct libvgmstream_streamfile_t* libsf_open(void* user_data, const char* filena if (!sf) return NULL; - libvgmstream_streamfile_t* libsf = libvgmstream_streamfile_from_streamfile(sf); + libstreamfile_t* libsf = libvgmstream_streamfile_from_streamfile(sf); if (!libsf) { close_streamfile(sf); return NULL; @@ -89,7 +89,7 @@ struct libvgmstream_streamfile_t* libsf_open(void* user_data, const char* filena return libsf; } -static void libsf_close(struct libvgmstream_streamfile_t* libsf) { +static void libsf_close(struct libstreamfile_t* libsf) { if (!libsf) return; @@ -101,14 +101,14 @@ static void libsf_close(struct libvgmstream_streamfile_t* libsf) { free(libsf); } -static libvgmstream_streamfile_t* libvgmstream_streamfile_from_streamfile(STREAMFILE* sf) { +static libstreamfile_t* libvgmstream_streamfile_from_streamfile(STREAMFILE* sf) { if (!sf) return NULL; - libvgmstream_streamfile_t* libsf = NULL; + libstreamfile_t* libsf = NULL; libsf_data_t* data = NULL; - libsf = calloc(1, sizeof(libvgmstream_streamfile_t)); + libsf = calloc(1, sizeof(libstreamfile_t)); if (!libsf) goto fail; libsf->read = libsf_read; @@ -132,12 +132,12 @@ fail: } -LIBVGMSTREAM_API libvgmstream_streamfile_t* libvgmstream_streamfile_open_from_stdio(const char* filename) { +LIBVGMSTREAM_API libstreamfile_t* libvgmstream_streamfile_open_from_stdio(const char* filename) { STREAMFILE* sf = open_stdio_streamfile(filename); if (!sf) return NULL; - libvgmstream_streamfile_t* libsf = libvgmstream_streamfile_from_streamfile(sf); + libstreamfile_t* libsf = libvgmstream_streamfile_from_streamfile(sf); if (!libsf) { close_streamfile(sf); return NULL; diff --git a/src/base/api_tags.c b/src/base/api_tags.c index 48a9b0bc..ed1ed1b2 100644 --- a/src/base/api_tags.c +++ b/src/base/api_tags.c @@ -3,11 +3,11 @@ typedef struct { VGMSTREAM_TAGS* vtags; - libvgmstream_streamfile_t* libsf; + libstreamfile_t* libsf; STREAMFILE* sf_tags; } libvgmstream_tags_priv_t; -LIBVGMSTREAM_API libvgmstream_tags_t* libvgmstream_tags_init(libvgmstream_streamfile_t* libsf) { +LIBVGMSTREAM_API libvgmstream_tags_t* libvgmstream_tags_init(libstreamfile_t* libsf) { if (!libsf) return NULL; diff --git a/src/base/streamfile_api.c b/src/base/streamfile_api.c index 2acd440c..1e23f74a 100644 --- a/src/base/streamfile_api.c +++ b/src/base/streamfile_api.c @@ -1,15 +1,15 @@ #include "api_internal.h" #if LIBVGMSTREAM_ENABLE -/* STREAMFILE for internal use, that bridges calls to external libvgmstream_streamfile_t */ +/* STREAMFILE for internal use, that bridges calls to external libstreamfile_t */ -static STREAMFILE* open_api_streamfile_internal(libvgmstream_streamfile_t* libsf, bool external_libsf); +static STREAMFILE* open_api_streamfile_internal(libstreamfile_t* libsf, bool external_libsf); typedef struct { STREAMFILE vt; - libvgmstream_streamfile_t* libsf; + libstreamfile_t* libsf; bool external_libsf; //TODO: improve } API_STREAMFILE; @@ -46,7 +46,7 @@ static void api_get_name(API_STREAMFILE* sf, char* name, size_t name_size) { } static STREAMFILE* api_open(API_STREAMFILE* sf, const char* filename, size_t buf_size) { - libvgmstream_streamfile_t* libsf = sf->libsf->open(sf->libsf->user_data, filename); + libstreamfile_t* libsf = sf->libsf->open(sf->libsf->user_data, filename); STREAMFILE* new_sf = open_api_streamfile_internal(libsf, false); if (!new_sf) { @@ -63,7 +63,7 @@ static void api_close(API_STREAMFILE* sf) { free(sf); } -static STREAMFILE* open_api_streamfile_internal(libvgmstream_streamfile_t* libsf, bool external_libsf) { +static STREAMFILE* open_api_streamfile_internal(libstreamfile_t* libsf, bool external_libsf) { API_STREAMFILE* this_sf = NULL; if (!libsf) @@ -87,7 +87,7 @@ static STREAMFILE* open_api_streamfile_internal(libvgmstream_streamfile_t* libsf return &this_sf->vt; } -STREAMFILE* open_api_streamfile(libvgmstream_streamfile_t* libsf) { +STREAMFILE* open_api_streamfile(libstreamfile_t* libsf) { return open_api_streamfile_internal(libsf, true); } diff --git a/src/libvgmstream.h b/src/libvgmstream.h index 3ac947eb..038db0a6 100644 --- a/src/libvgmstream.h +++ b/src/libvgmstream.h @@ -201,7 +201,7 @@ LIBVGMSTREAM_API void libvgmstream_setup(libvgmstream_t* lib, libvgmstream_confi /* configures how vgmstream opens the format */ typedef struct { - libvgmstream_streamfile_t* libsf; // custom IO streamfile that provides reader info for vgmstream + libstreamfile_t* libsf; // custom IO streamfile that provides reader info for vgmstream // ** not needed after _open and should be closed, as vgmstream re-opens its own SFs internally as needed int subsong_index; // target subsong (1..N) or 0 = default/first @@ -345,7 +345,7 @@ typedef struct { * - libsf should point to a !tags.m3u file * - unlike libvgmstream_open, sf tagfile must be valid during the tag extraction process. */ -LIBVGMSTREAM_API libvgmstream_tags_t* libvgmstream_tags_init(libvgmstream_streamfile_t* libsf); +LIBVGMSTREAM_API libvgmstream_tags_t* libvgmstream_tags_init(libstreamfile_t* libsf); /* Finds tags for a new filename. Must be called first before extracting tags. */ diff --git a/src/libvgmstream_streamfile.h b/src/libvgmstream_streamfile.h index 809765f4..548d334e 100644 --- a/src/libvgmstream_streamfile.h +++ b/src/libvgmstream_streamfile.h @@ -19,7 +19,8 @@ enum { //LIBVGMSTREAM_STREAMFILE_SEEK_GET_SIZE = 5, }; -typedef struct libvgmstream_streamfile_t { +// maybe libvgmstream_streamfile_t but it was getting unwieldly +typedef struct libstreamfile_t { //uint32_t flags; // info flags for vgmstream void* user_data; // any internal structure @@ -44,23 +45,23 @@ typedef struct libvgmstream_streamfile_t { /* open another streamfile from filename (may be some path/protocol, or same as current get_name = reopen) * - vgmstream opens stuff based on current get_name (relative), so there shouldn't be need to transform this path */ - struct libvgmstream_streamfile_t* (*open)(void* user_data, const char* filename); + struct libstreamfile_t* (*open)(void* user_data, const char* filename); /* free current SF (needed for copied streamfiles) */ - void (*close)(struct libvgmstream_streamfile_t* libsf); + void (*close)(struct libstreamfile_t* libsf); -} libvgmstream_streamfile_t; +} libstreamfile_t; /* helper */ -static inline void libvgmstream_streamfile_close(libvgmstream_streamfile_t* libsf) { +static inline void libvgmstream_streamfile_close(libstreamfile_t* libsf) { if (!libsf || !libsf->close) return; libsf->close(libsf); } -LIBVGMSTREAM_API libvgmstream_streamfile_t* libvgmstream_streamfile_open_from_stdio(const char* filename); +LIBVGMSTREAM_API libstreamfile_t* libvgmstream_streamfile_open_from_stdio(const char* filename); #endif #endif