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,19 +232,16 @@ 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;
if (file != NULL) {
struct gmio_stream stream = gmio_stream_stdio(file);
struct gmio_stl_infos infos = {0}; struct gmio_stl_infos infos = {0};
gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL);
gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_ALL, NULL);
if (!already_exec) { if (!already_exec) {
printf("stl_infos_probe(ALL)\n" printf("stl_infos_probe(ALL)\n"
" File: %s\n" " File: %s\n"
" Size: %uKo\n" " Size: %uKo\n"
" Facets: %u\n", " Facets: %u\n",
(const char*)filepath, cfilepath,
infos.size / 1024, infos.size / 1024,
infos.facet_count); infos.facet_count);
if (infos.format == GMIO_STL_FORMAT_ASCII) if (infos.format == GMIO_STL_FORMAT_ASCII)
@ -253,32 +250,23 @@ void bmk_gmio_stl_infos_probe_all(const void* filepath)
printf(" [STLB]Header: %80.80s\n", infos.stlb_header.data); 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;
if (file != NULL) {
struct gmio_stream stream = gmio_stream_stdio(file);
struct gmio_stl_infos infos = {0}; struct gmio_stl_infos infos = {0};
gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_SIZE, NULL);
gmio_stl_infos_probe_file(&infos, cfilepath, GMIO_STL_INFO_FLAG_SIZE, NULL);
if (!already_exec) { if (!already_exec) {
printf("stl_infos_probe(SIZE)\n" printf("stl_infos_probe(SIZE)\n"
" File: %s\n" " File: %s\n"
" Size: %uKo\n", " Size: %uKo\n",
(const char*)filepath, cfilepath,
infos.size / 1024); 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");
if (file != NULL) {
struct gmio_stream stream = gmio_stream_stdio(file);
struct gmio_stl_infos infos = {0}; struct gmio_stl_infos infos = {0};
/* Retrieve STL informations, using default options(NULL) */ /* Retrieve STL informations, using default options(NULL) */
error = gmio_stl_infos_probe( const int error = gmio_stl_infos_probe_file(
&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL); &infos, filepath, GMIO_STL_INFO_FLAG_ALL, NULL);
printf("File: %s\n", filepath); printf("File: %s\n", filepath);
if (error == GMIO_ERROR_OK) if (error == GMIO_ERROR_OK)
print_stl_infos(&infos); print_stl_infos(&infos);
else else
fprintf(stderr, "gmio error: 0x%X\n", error); 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