star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

commit 9825cb980cf9ce9177572e285083a9d1f29ee89a
parent 12592595753e58a2a7e2b492a16765e820ab4493
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue,  6 Sep 2022 11:04:26 +0200

Manage verbosity level

Diffstat:
Msrc/scad.c | 16++++++++++++----
Msrc/scad.h | 9++++++---
Msrc/scad_device.c | 21+++++++++++++++++++--
Msrc/scad_device.h | 20+++++++++++++++-----
4 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/src/scad.c b/src/scad.c @@ -68,7 +68,7 @@ write_ascii_stl f3_sub(edge2, vtx[2], vtx[0]); f3_cross(tmp, edge1, edge2); if(f3_eq(tmp, zero)) { - fprintf(stderr, "Error: nul triangle in exported geometry.\n"); + log_error(get_device(), "Error: nul triangle in exported geometry.\n"); res = RES_BAD_ARG; goto error; } @@ -92,7 +92,7 @@ exit: if(stl_file) fclose(stl_file); return res; error: - fprintf(stderr, "Error: could not export to STL file '%s': %s\n", + log_error(get_device(), "Error: could not export to STL file '%s': %s\n", filename, res_to_cstr(res)); goto exit; } @@ -160,7 +160,7 @@ exit: if(stl_file) fclose(stl_file); return res; error: - fprintf(stderr, "Error: could not export to STL file '%s': %s\n", + log_error(get_device(), "Error: could not export to STL file '%s': %s\n", filename, res_to_cstr(res)); goto exit; } @@ -191,6 +191,10 @@ scad_synchronize /* Cannot use check_device to avoid an infinite loop! */ if(!dev) { + /* No logger available for a message */ + fprintf(stderr, + "%s: cannot call API functions if star-cad in not initialized.\n", + FUNC_NAME); res = RES_BAD_ARG; goto error; } @@ -214,6 +218,10 @@ scad_run_ui(void) /* Cannot use check_device to avoid an infinite loop! */ if(!dev) { + /* No logger available for a message */ + fprintf(stderr, + "%s: cannot call API functions if star-cad in not initialized.\n", + FUNC_NAME); res = RES_BAD_ARG; goto error; } @@ -385,7 +393,7 @@ exit: if(dimTags) free(dimTags); return res; error: - fprintf(stderr, "%s: could not export to STL -- %s\n", + log_error(get_device(), "%s: could not export to STL -- %s\n", FUNC_NAME, res_to_cstr(res)); goto exit; } diff --git a/src/scad.h b/src/scad.h @@ -73,7 +73,11 @@ SCAD_API res_T scad_initialize (struct logger* logger, /* May be NULL <=> use default logger */ struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ - const int verbose); /* Define the level of verbosity */ + const int verbose); /* Define the level of verbosity: + 0 = no logs, + 1 = errors only, + 2 = errors and warnings, + 3 = errors, warnings, and informative messages */ SCAD_API res_T scad_finalize @@ -278,8 +282,7 @@ scad_geometry_rotate const double dir[3], const double angle); -/* Extrude the geometry `geom' using a translation along (`dx', `dy', - * `dz').*/ +/* Extrude the geometry `geom' using a translation along (`dx', `dy', `dz').*/ SCAD_API res_T scad_geometry_extrude (const struct scad_geometry* geom, diff --git a/src/scad_device.c b/src/scad_device.c @@ -61,7 +61,7 @@ log_error(struct scad_device* dev, const char* msg, ...) { va_list vargs_list; ASSERT(dev && msg); - + if(dev->verbose < 1) return; va_start(vargs_list, msg); log_msg(dev, LOG_ERROR, msg, vargs_list); va_end(vargs_list); @@ -72,12 +72,24 @@ log_warning(struct scad_device* dev, const char* msg, ...) { va_list vargs_list; ASSERT(dev && msg); - + if(dev->verbose < 2) return; va_start(vargs_list, msg); log_msg(dev, LOG_WARNING, msg, vargs_list); va_end(vargs_list); } + +void +log_message(struct scad_device* dev, const char* msg, ...) +{ + va_list vargs_list; + ASSERT(dev && msg); + if(dev->verbose < 3) return; + va_start(vargs_list, msg); + log_msg(dev, LOG_OUTPUT, msg, vargs_list); + va_end(vargs_list); +} + /******************************************************************************* * The unique device in scad-cad ******************************************************************************/ @@ -220,6 +232,11 @@ scad_initialize goto error; } + if(0 > verbose || verbose > 3) { + res = RES_BAD_ARG; + goto error; + } + gmshInitialize(0, NULL, 1, 0, &ierr); ERR(gmsh_err_to_res_T(ierr)); diff --git a/src/scad_device.h b/src/scad_device.h @@ -103,6 +103,18 @@ log_warning #endif ; +/* Conditionally log a message on the LOG_OUTPUT stream of the device logger, + * with respect to the device verbose flag */ +extern LOCAL_SYM void +log_message + (struct scad_device* dev, + const char* msg, + ...) +#ifdef COMPILER_GCC + __attribute((format(printf, 2, 3))) +#endif +; + static INLINE void log_msg (struct scad_device* dev, @@ -110,12 +122,10 @@ log_msg const char* msg, va_list vargs) { + res_T res; (void)res; ASSERT(dev && msg); - if(dev->verbose) { - res_T res; (void)res; - res = logger_vprint(dev->logger, stream, msg, vargs); - ASSERT(res == RES_OK); - } + res = logger_vprint(dev->logger, stream, msg, vargs); + ASSERT(res == RES_OK); } /*******************************************************************************