star-meshtool

Mesh transformation
git clone git://git.meso-star.fr/star-meshtool.git
Log | Files | Refs | README | LICENSE

commit c7b3656e27de08966ebab27230599a0cbfa76e7e
parent 26126138b5f832f7b57d4197ba5f9566fb65b21c
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 14 Mar 2025 15:48:10 +0100

Code simplification

Avoid manipulating files when it can be done by star-stl

Diffstat:
Msrc/mtool.c | 27++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/src/mtool.c b/src/mtool.c @@ -36,7 +36,6 @@ main(int argc, char** argv) int allocator_initialized = 0; int logger_initialized = 0; int wbin; - FILE *fin = NULL, *fout = NULL; ERR(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); allocator_initialized = 1; @@ -70,16 +69,8 @@ main(int argc, char** argv) /* Create SSTL device and load data */ ERR(sstl_create(&logger, &allocator, ctx.V, &sstl)); - if(ctx.i != NULL) { - fin = fopen(ctx.i, "r"); - if(!fin) { - logger_print(&logger, LOG_ERROR, "Cannot open file: '%s'.\n", ctx.i); - res = RES_IO_ERR; - goto error; - } - ERR(sstl_load_stream(sstl, fin)); - fclose(fin); - fin = NULL; + if(ctx.in != NULL) { + ERR(sstl_load(sstl, ctx.in)); } else { ERR(sstl_load_stream(sstl, stdin)); } @@ -95,24 +86,14 @@ main(int argc, char** argv) ERR(sstl_pack_write_data(sstl, &data)); /* Write data */ - if(ctx.o != NULL) { - fout = fopen(ctx.o, "w"); - if(!fout) { - logger_print(&logger, LOG_ERROR, "Cannot open file: '%s'.\n", ctx.o); - res = RES_IO_ERR; - goto error; - } - ERR(sstl_write_stream(&data, wbin, fout)); - fclose(fout); - fout = NULL; + if(ctx.in != NULL) { + ERR(sstl_write(&data, wbin, ctx.out)); } else { ERR(sstl_write_stream(&data, wbin, stdout)); } end: release_ctx(&ctx); - if(fin) fclose(fin); - if(fout) fclose(fout); if(sstl) sstl_ref_put(sstl); if(logger_initialized) logger_release(&logger); if(allocator_initialized) {