diff --git a/benchmarks/benchmark_gmio/main.c b/benchmarks/benchmark_gmio/main.c index 178343b..e10afec 100644 --- a/benchmarks/benchmark_gmio/main.c +++ b/benchmarks/benchmark_gmio/main.c @@ -232,53 +232,41 @@ static void bmk_gmio_stl_readwrite_conv(const void* filepath) void bmk_gmio_stl_infos_probe_all(const void* filepath) { static bool already_exec = false; - FILE* file = fopen(filepath, "rb"); + const char* cfilepath = (const char*)filepath; + struct gmio_stl_infos infos = {0}; - if (file != NULL) { - struct gmio_stream stream = gmio_stream_stdio(file); - struct gmio_stl_infos infos = {0}; - gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL); - - if (!already_exec) { - printf("stl_infos_probe(ALL)\n" - " File: %s\n" - " Size: %uKo\n" - " Facets: %u\n", - (const char*)filepath, - infos.size / 1024, - infos.facet_count); - if (infos.format == GMIO_STL_FORMAT_ASCII) - printf(" [STLA]Solid name: %s\n", infos.stla_solidname); - else if (infos.format & GMIO_STL_FORMAT_TAG_BINARY) - printf(" [STLB]Header: %80.80s\n", infos.stlb_header.data); - } - already_exec = true; + gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_ALL, NULL); + if (!already_exec) { + printf("stl_infos_probe(ALL)\n" + " File: %s\n" + " Size: %uKo\n" + " Facets: %u\n", + cfilepath, + infos.size / 1024, + infos.facet_count); + if (infos.format == GMIO_STL_FORMAT_ASCII) + printf(" [STLA]Solid name: %s\n", infos.stla_solidname); + else if (infos.format & GMIO_STL_FORMAT_TAG_BINARY) + printf(" [STLB]Header: %80.80s\n", infos.stlb_header.data); } - - fclose(file); + already_exec = true; } void bmk_gmio_stl_infos_probe_size(const void* filepath) { static bool already_exec = false; - FILE* file = fopen(filepath, "rb"); + const char* cfilepath = (const char*)filepath; + struct gmio_stl_infos infos = {0}; - if (file != NULL) { - struct gmio_stream stream = gmio_stream_stdio(file); - struct gmio_stl_infos infos = {0}; - gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_SIZE, NULL); - - if (!already_exec) { - printf("stl_infos_probe(SIZE)\n" - " File: %s\n" - " Size: %uKo\n", - (const char*)filepath, - infos.size / 1024); - } - already_exec = true; + gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_SIZE, NULL); + if (!already_exec) { + printf("stl_infos_probe(SIZE)\n" + " File: %s\n" + " Size: %uKo\n", + cfilepath, + infos.size / 1024); } - - fclose(file); + already_exec = true; } int main(int argc, char** argv) diff --git a/examples/stl_get_infos.c b/examples/stl_get_infos.c index 618caf8..818a6ee 100644 --- a/examples/stl_get_infos.c +++ b/examples/stl_get_infos.c @@ -47,22 +47,15 @@ int main(int argc, char** argv) int error = 0; if (argc > 1) { const char* filepath = argv[1]; - FILE* file = fopen(filepath, "rb"); - - if (file != NULL) { - struct gmio_stream stream = gmio_stream_stdio(file); - struct gmio_stl_infos infos = {0}; - /* Retrieve STL informations, using default options(NULL) */ - error = gmio_stl_infos_probe( - &infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL); - printf("File: %s\n", filepath); - if (error == GMIO_ERROR_OK) - print_stl_infos(&infos); - else - fprintf(stderr, "gmio error: 0x%X\n", error); - - fclose(file); - } + struct gmio_stl_infos infos = {0}; + /* Retrieve STL informations, using default options(NULL) */ + const int error = gmio_stl_infos_probe_file( + &infos, filepath, GMIO_STL_INFO_FLAG_ALL, NULL); + printf("File: %s\n", filepath); + if (error == GMIO_ERROR_OK) + print_stl_infos(&infos); + else + fprintf(stderr, "gmio error: 0x%X\n", error); } return error; } diff --git a/src/gmio_stl/stl_global.h b/src/gmio_stl/stl_global.h index 3b8bfd5..788bfa3 100644 --- a/src/gmio_stl/stl_global.h +++ b/src/gmio_stl/stl_global.h @@ -81,6 +81,7 @@ * * Infos on contents * gmio_stl_infos_probe()
+ * gmio_stl_infos_probe_file()
* gmio_stla_infos_probe_streamsize() * gmio_stl_infos
* gmio_stl_infos_probe_options diff --git a/src/gmio_stl/stl_infos.c b/src/gmio_stl/stl_infos.c index 228addd..3dfdeb0 100644 --- a/src/gmio_stl/stl_infos.c +++ b/src/gmio_stl/stl_infos.c @@ -88,6 +88,22 @@ label_end: return error; } +int gmio_stl_infos_probe_file( + struct gmio_stl_infos *infos, + const char *filepath, + unsigned flags, + const struct gmio_stl_infos_probe_options *options) +{ + FILE* file = fopen(filepath, "rb"); + if (file != NULL) { + struct gmio_stream stream = gmio_stream_stdio(file); + const int error = gmio_stl_infos_probe(infos, &stream, flags, options); + fclose(file); + return error; + } + return GMIO_ERROR_STDIO; +} + gmio_streamsize_t gmio_stla_infos_probe_streamsize( struct gmio_stream *stream, struct gmio_memblock *stream_memblock) { diff --git a/src/gmio_stl/stl_infos.h b/src/gmio_stl/stl_infos.h index a258f61..5f6d9bb 100644 --- a/src/gmio_stl/stl_infos.h +++ b/src/gmio_stl/stl_infos.h @@ -139,6 +139,24 @@ GMIO_API int gmio_stl_infos_probe( unsigned flags, const struct gmio_stl_infos_probe_options* options); +/*! Finds informations about STL contents from a file + * + * This is just a facility function over gmio_stl_infos_probe(). The internal + * object is created to read file at \p filepath. + * + * \pre infos != NULL + * \pre filepath != \c NULL \n + * The file is opened with \c fopen() so \p filepath shall follow the file + * name specifications of the running environment + * + * \sa gmio_stl_infos_probe(), gmio_stream_stdio(FILE*) + */ +GMIO_API int gmio_stl_infos_probe_file( + struct gmio_stl_infos* infos, + const char* filepath, + unsigned flags, + const struct gmio_stl_infos_probe_options* options); + /*! Returns the size(in bytes) of the next STL ascii solid in \p stream * * It is a facade over gmio_stl_infos_probe() for gmio_stl_infos::size only