rngrd

Describe a surface and its physical properties
git clone git://git.meso-star.fr/rngrd.git
Log | Files | Refs | README | LICENSE

commit 8ba095e887f8436e13a9be41029794a7b53e636f
parent 607b5dad5e949fac57c4755a712631f782f2d156
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 21 Sep 2022 09:17:30 +0200

Rely on the RNSL library to load the list of materials

Diffstat:
MREADME.md | 1+
Mcmake/CMakeLists.txt | 6++++--
Ddoc/rnml.5.scd | 59-----------------------------------------------------------
Msrc/rngrd_properties.c | 118++++++++++++++-----------------------------------------------------------------
Msrc/test_rngrd.c | 6+++---
5 files changed, 28 insertions(+), 162 deletions(-)

diff --git a/README.md b/README.md @@ -12,6 +12,7 @@ This library is compatible with 64-bits POSIX systems. It relies the [RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. It also depends on the [MruMtl](https://gitlab.com/meso-star/mrumtl), +[RNSL](htpps://gitlab.com/meso-star/rnsl), [RSys](https://gitlab.com/vaplv/rsys/), [Star-3D](https://gitlab.com/meso-star/star-3d), [Star-Buffer](https://gitlab.com/meso-star/star-buffer), and diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -30,6 +30,7 @@ option(NO_TEST "Do not build tests" OFF) ################################################################################ find_package(MruMtl 0.1 REQUIRED) find_package(RCMake 0.4 REQUIRED) +find_package(RNSL REQUIRED) find_package(RSys 0.9 REQUIRED) find_package(Star3D 0.8 REQUIRED) find_package(StarMesh REQUIRED) @@ -41,6 +42,7 @@ include(rcmake_runtime) include_directories( ${MruMtl_INCLUDE_DIR} + ${RNSL_INCLUDE_DIR} ${RSys_INCLUDE_DIR} ${Star3D_INCLUDE_DIR} ${StarMesh_INCLUDE_DIR} @@ -72,7 +74,7 @@ rcmake_prepend_path(RNGRD_FILES_INC_API ${RNGRD_SOURCE_DIR}) rcmake_prepend_path(RNGRD_FILES_DOC ${PROJECT_SOURCE_DIR}/../) add_library(rngrd SHARED ${RNGRD_FILES_SRC} ${RNGRD_FILES_INC} ${RNGRD_FILES_INC_API}) -target_link_libraries(rngrd MruMtl RSys Star3D StarBuffer StarMesh) +target_link_libraries(rngrd MruMtl RNSL RSys Star3D StarBuffer StarMesh) if(CMAKE_COMPILER_IS_GNUCC) target_link_libraries(rngrd m) @@ -113,7 +115,7 @@ if(NOT SCDOC) "The `scdoc' program is missing. " "The Rad Net GRounD man page cannot be generated.") else() - set(_man_names rnml.5 rnsp.5) + set(_man_names rnsp.5) foreach(_man IN LISTS _man_names) set(_src ${PROJECT_SOURCE_DIR}/../doc/${_man}.scd) diff --git a/doc/rnml.5.scd b/doc/rnml.5.scd @@ -1,59 +0,0 @@ -rnml(5) - -; Copyright (C) 2022 Centre National de la Recherche Scientifique -; Copyright (C) 2022 Institut de Physique du Globe de Paris -; Copyright (C) 2022 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2022 Université de Reims Champagne-Ardenne -; Copyright (C) 2022 Université de Versaille Saint-Quentin -; Copyright (C) 2022 Université Paul Sabatier (contact@laplace.univ-tlse.fr) -; -; This program is free software: you can redistribute it and/or modify -; it under the terms of the GNU General Public License as published by -; the Free Software Foundation, either version 3 of the License, or -; (at your option) any later version. -; -; This program is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this program. If not, see <http://www.gnu.org/licenses/>. - -# NAME - -rnml - Rad-Net Materials List file format - -# DESCRIPTION - -*rnml* is a text file format that lists the filenames of materials saved in the -*mrumtl*(5) file format. The material filenames are expanded before they are -loaded and therefore can be composed of variables (e.g. _"${MY_PATH}/mtl.mrumtl"_) - -Characters behind the hash mark (#) are considered comments and are therefore -ignored, as well as empty lines, i.e. lines without characters or composed -only of spaces and tabs. - -# GRAMMAR - -``` -<rnml> ::= <materials-count> - <material-filename> - [ <material-filename> ... ] - -<materials-count> ::= INTGER -<material-filename> ::= STRING -``` - -# EXEMPLE - -``` -3 -mtl_000.dat -mtl_001.dat -mtl_002.dat -``` - -# SEE ALSO - -*mrumtl*(5) diff --git a/src/rngrd_properties.c b/src/rngrd_properties.c @@ -18,22 +18,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _POSIX_C_SOURCE 200112L /* strtok_r and wordexp */ - #include "rngrd.h" #include "rngrd_c.h" #include "rngrd_log.h" #include <modradurb/mrumtl.h> +#include <rad-net/rnsl.h> #include <star/sbuf.h> #include <rsys/cstr.h> #include <rsys/text_reader.h> -#include <string.h> -#include <wordexp.h> - /******************************************************************************* * Helper functions ******************************************************************************/ @@ -62,73 +58,26 @@ check_sbuf_desc } static res_T -parse_mtl(struct rngrd* ground, struct txtrdr* txtrdr, struct mrumtl** out_mtl) +load_mtl(struct rngrd* ground, const char* filename, struct mrumtl** out_mtl) { - wordexp_t wexp; - char* tk = NULL; - char* tk_ctx = NULL; struct mrumtl_create_args args = MRUMTL_CREATE_ARGS_DEFAULT; struct mrumtl* mtl = NULL; - int wexp_is_allocated = 1; res_T res = RES_OK; - int err = 0; - ASSERT(ground && txtrdr && out_mtl); - - res = txtrdr_read_line(txtrdr); - if(res != RES_OK) { - log_err(ground, "%s: can't read the line `%lu' -- %s\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), - res_to_cstr(res)); - goto error; - } - - if(!txtrdr_get_cline(txtrdr)) { - const size_t nexpect = darray_mtl_size_get(&ground->mtls); - const size_t nparsed = (size_t)(out_mtl - darray_mtl_cdata_get(&ground->mtls)); - log_err(ground, - "%s:%lu: missing a material filename. " - "Expecting %lu material%s while %lu %s parsed.\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), - (unsigned long)nexpect, nexpect == 1 ? " " : "s ", - (unsigned long)nparsed, nparsed > 1 ? "were" : "was"); - res = RES_BAD_ARG; - goto error; - } - - tk = strtok_r(txtrdr_get_line(txtrdr), "", &tk_ctx); - ASSERT(tk); - - err = wordexp(tk, &wexp, 0/*flags*/); - if(err) { - log_err(ground, "%s:%lu: unable to expand material filename\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr)); - res = RES_BAD_ARG; - goto error; - } - wexp_is_allocated = 1; - ASSERT(wexp.we_wordc != 0); + ASSERT(ground && filename && out_mtl); args.verbose = ground->verbose; args.logger = ground->logger; args.allocator = ground->allocator; res = mrumtl_create(&args, &mtl); if(res != RES_OK) { - log_err(ground, "%s:%lu: could not create the MruMtl data structure\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr)); + log_err(ground, "%s: could not create the MruMtl data structure\n", filename); goto error; } - res = mrumtl_load(mtl, wexp.we_wordv[0]); + res = mrumtl_load(mtl, filename); if(res != RES_OK) goto error; - if(wexp.we_wordc > 1) { - log_warn(ground, "%s:%lu: unexpected text `%s'\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), - wexp.we_wordv[1]); - } - exit: - if(wexp_is_allocated) wordfree(&wexp); *out_mtl = mtl; return res; error: @@ -139,68 +88,41 @@ error: static res_T parse_mtllst(struct rngrd* ground, const struct rngrd_create_args* args) { - struct txtrdr* txtrdr = NULL; - char* tk = NULL; - char* tk_ctx = NULL; - size_t imtl = 0; - unsigned long nmtls = 0; + struct rnsl_create_args rnsl_args = RNSL_CREATE_ARGS_DEFAULT; + struct rnsl* rnsl = NULL; + size_t imtl, nmtls; res_T res = RES_OK; - ASSERT(ground && args); - res = txtrdr_file(ground->allocator, args->mtllst_filename, '#', &txtrdr); + rnsl_args.logger = ground->logger; + rnsl_args.allocator = ground->allocator; + rnsl_args.verbose = ground->verbose; + res = rnsl_create(&rnsl_args, &rnsl); if(res != RES_OK) { - log_err(ground, "Could not create text reader to parse file `%s' -- %s\n", + log_err(ground, "Could not create loader for the material list `%s' -- %s\n", args->mtllst_filename, res_to_cstr(res)); goto error; } - res = txtrdr_read_line(txtrdr); - if(res != RES_OK) { - log_err(ground, "%s: can't read the line %lu --%s\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), - res_to_cstr(res)); - goto error; - } - - if(!txtrdr_get_cline(txtrdr)) { - log_err(ground, "%s: file cannot be empty\n", txtrdr_get_name(txtrdr)); - res = RES_BAD_ARG; - goto error; - } - - tk = strtok_r(txtrdr_get_line(txtrdr), " \t", &tk_ctx); - ASSERT(tk); - - res = cstr_to_ulong(tk, &nmtls); - if(res == RES_OK && nmtls == 0) res = RES_BAD_ARG; - if(res != RES_OK) { - log_err(ground, "%s:%lu: invalid number of materials %lu\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), - nmtls); - goto error; - } + res = rnsl_load(rnsl, args->mtllst_filename); + if(res != RES_OK) goto error; + nmtls = rnsl_get_strings_count(rnsl); res = darray_mtl_resize(&ground->mtls, nmtls); if(res != RES_OK) { log_err(ground, "%s: could not allocate the list of %lu materials -- %s\n", - txtrdr_get_name(txtrdr), nmtls, res_to_cstr(res)); + args->mtllst_filename, nmtls, res_to_cstr(res)); goto error; } - tk = strtok_r(NULL, " \t", &tk_ctx); - if(tk) { - log_warn(ground, "%s:%lu: unexpected text `%s'\n", - txtrdr_get_name(txtrdr), (unsigned long)txtrdr_get_line_num(txtrdr), tk); - } - FOR_EACH(imtl, 0, nmtls) { struct mrumtl** mtl = darray_mtl_data_get(&ground->mtls)+imtl; - res = parse_mtl(ground, txtrdr, mtl); + const char* filename = rnsl_get_string(rnsl, imtl); + res = load_mtl(ground, filename, mtl); if(res != RES_OK) goto error; } exit: - if(txtrdr) txtrdr_ref_put(txtrdr); + if(rnsl) RNSL(ref_put(rnsl)); return res; error: darray_mtl_clear(&ground->mtls); diff --git a/src/test_rngrd.c b/src/test_rngrd.c @@ -45,13 +45,13 @@ print_help(const char* cmd) printf( " -h display this help and exit\n"); printf( -" -M matlst path toward the list of ground materials\n"); +" -M matlst path toward the list of ground materials (rnsl(5))\n"); printf( -" -m mesh path toward the ground mesh\n"); +" -m mesh path toward the ground mesh (smsh(5))\n"); printf( " -n name ground name\n"); printf( -" -p props path toward the ground properties\n"); +" -p props path toward the ground properties (rnsp(5))\n"); printf( " -V validate data\n"); printf(