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) void bmk_gmio_stl_infos_probe_all(const void* filepath)
{ {
static bool already_exec = false; 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) { gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_ALL, NULL);
struct gmio_stream stream = gmio_stream_stdio(file); if (!already_exec) {
struct gmio_stl_infos infos = {0}; printf("stl_infos_probe(ALL)\n"
gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL); " File: %s\n"
" Size: %uKo\n"
if (!already_exec) { " Facets: %u\n",
printf("stl_infos_probe(ALL)\n" cfilepath,
" File: %s\n" infos.size / 1024,
" Size: %uKo\n" infos.facet_count);
" Facets: %u\n", if (infos.format == GMIO_STL_FORMAT_ASCII)
(const char*)filepath, printf(" [STLA]Solid name: %s\n", infos.stla_solidname);
infos.size / 1024, else if (infos.format & GMIO_STL_FORMAT_TAG_BINARY)
infos.facet_count); printf(" [STLB]Header: %80.80s\n", infos.stlb_header.data);
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;
} }
already_exec = true;
fclose(file);
} }
void bmk_gmio_stl_infos_probe_size(const void* filepath) void bmk_gmio_stl_infos_probe_size(const void* filepath)
{ {
static bool already_exec = false; 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) { gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_SIZE, NULL);
struct gmio_stream stream = gmio_stream_stdio(file); if (!already_exec) {
struct gmio_stl_infos infos = {0}; printf("stl_infos_probe(SIZE)\n"
gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_SIZE, NULL); " File: %s\n"
" Size: %uKo\n",
if (!already_exec) { cfilepath,
printf("stl_infos_probe(SIZE)\n" infos.size / 1024);
" File: %s\n"
" Size: %uKo\n",
(const char*)filepath,
infos.size / 1024);
}
already_exec = true;
} }
already_exec = true;
fclose(file);
} }
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -47,22 +47,15 @@ int main(int argc, char** argv)
int error = 0; int error = 0;
if (argc > 1) { if (argc > 1) {
const char* filepath = argv[1]; const char* filepath = argv[1];
FILE* file = fopen(filepath, "rb"); struct gmio_stl_infos infos = {0};
/* Retrieve STL informations, using default options(NULL) */
if (file != NULL) { const int error = gmio_stl_infos_probe_file(
struct gmio_stream stream = gmio_stream_stdio(file); &infos, filepath, GMIO_STL_INFO_FLAG_ALL, NULL);
struct gmio_stl_infos infos = {0}; printf("File: %s\n", filepath);
/* Retrieve STL informations, using default options(NULL) */ if (error == GMIO_ERROR_OK)
error = gmio_stl_infos_probe( print_stl_infos(&infos);
&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL); else
printf("File: %s\n", filepath); fprintf(stderr, "gmio error: 0x%X\n", error);
if (error == GMIO_ERROR_OK)
print_stl_infos(&infos);
else
fprintf(stderr, "gmio error: 0x%X\n", error);
fclose(file);
}
} }
return error; return error;
} }

View File

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

View File

@ -88,6 +88,22 @@ label_end:
return error; 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( gmio_streamsize_t gmio_stla_infos_probe_streamsize(
struct gmio_stream *stream, struct gmio_memblock *stream_memblock) struct gmio_stream *stream, struct gmio_memblock *stream_memblock)
{ {

View File

@ -139,6 +139,24 @@ GMIO_API int gmio_stl_infos_probe(
unsigned flags, unsigned flags,
const struct gmio_stl_infos_probe_options* options); 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 /*! 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 * It is a facade over gmio_stl_infos_probe() for gmio_stl_infos::size only