gmio_stl: add "overload" function gmio_stl_infos_probe_file()

GitHub issue #4
This commit is contained in:
Hugues Delorme 2016-07-13 12:30:30 +02:00
parent 941a015bfb
commit 1bc3a98c5c
5 changed files with 70 additions and 54 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -81,6 +81,7 @@
* <tr>
* <td>Infos on contents</td>
* <td>gmio_stl_infos_probe()<br/>
* gmio_stl_infos_probe_file()<br/>
* gmio_stla_infos_probe_streamsize()</td>
* <td>gmio_stl_infos<br/>
* gmio_stl_infos_probe_options</td>

View File

@ -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)
{

View File

@ -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 <tt> infos != NULL </tt>
* \pre <tt> filepath != \c NULL </tt>\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