star-stl

Load STereo Lithography (StL) file format
git clone git://git.meso-star.fr/star-stl.git
Log | Files | Refs | README | LICENSE

commit 03c2c7eb393ce5f14445e2f7ff10cd0e91d20154
parent 1fa6b7110e44aefeb173713699fc85fc5742baab
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 30 Jan 2025 10:14:19 +0100

Fix log message type (error VS information) on read failure

In the case that an attempt to read a file as ASCII fails, the failure
log message type should depend on the fact that a further attempt to
read the file as BINARY is planed.
The message was always typed as error, regardless of the context. Now
fixed.

Diffstat:
Msrc/sstl.c | 24++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/sstl.c b/src/sstl.c @@ -38,6 +38,12 @@ #define OK(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 +enum allowed_load_steps { + TRY_READ_ASCII = 1, + TRY_READ_BINARY = 2, + TRY_READ_ALL = 3 +}; + struct solid { char* name; unsigned* indices; @@ -301,13 +307,15 @@ parse_solid_name char* line, const char* filename, const size_t iline, + int allowed, char** tok_ctx) { res_T res = RES_OK; ASSERT(sstl && solid && !solid->name); if(!line || strcmp(strtok_r(line, " \t", tok_ctx), "solid")) { - print_log(sstl, LOG_ERROR, + enum log_type lt = (allowed & TRY_READ_BINARY) ? LOG_OUTPUT : LOG_ERROR; + print_log(sstl, lt, "%s:%lu: missing the \"solid [NAME]\" directive.\n", filename, (unsigned long)iline); res = RES_BAD_ARG; @@ -433,7 +441,8 @@ static res_T load_ascii_stream (struct sstl* sstl, FILE* stream, - const char* stream_name) + const char* stream_name, + int allowed) { res_T res = RES_OK; struct streamer streamer; @@ -447,7 +456,8 @@ load_ascii_stream clear(sstl); line = streamer_read_line(&streamer, 1); - OK(parse_solid_name(sstl, &solid, line, streamer.name, streamer.iline, &tok_ctx)); + OK(parse_solid_name(sstl, &solid, line, streamer.name, streamer.iline, + allowed, &tok_ctx)); for(;;) { /* Parse the solid facets */ float normal[3]; @@ -624,12 +634,6 @@ error: #error Undefined FTELL macro #endif -enum allowed_load_steps { - TRY_READ_ASCII = 1, - TRY_READ_BINARY = 2, - TRY_READ_ALL = 3 -}; - static res_T load_stream (struct sstl* sstl, @@ -654,7 +658,7 @@ load_stream print_log(sstl, LOG_OUTPUT, "%s: attempt to read as ASCII file.\n", stream_name); } - res = load_ascii_stream(sstl, stream, stream_name); + res = load_ascii_stream(sstl, stream, stream_name, allowed); if(res == RES_OK) { if(log) print_log(sstl, LOG_OUTPUT, "Attempt successful.\n"); goto exit;