star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit 40932ba184f3c2ab60ed913f45383590295195c7
parent 2ea9346dfa6a1c4c404e996c23084e15eeb2588a
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Thu, 23 Jan 2025 12:14:52 +0100

Implemented trim_keyword and updated parsing

Diffstat:
Msrc/sphin.c | 6+++---
Msrc/sphin_config.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/src/sphin.c b/src/sphin.c @@ -22,8 +22,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "sphin.h" -#include "sphin_c.h" +#include "sphin.h" /* !! Public declarations */ +#include "sphin_c.h" /* Private declarations */ #include <rsys/logger.h> #include <rsys/mem_allocator.h> @@ -69,7 +69,7 @@ sphin_create struct sphin* sphin = NULL; res_T res = RES_OK; - if (out_sphin == NULL) { + if (NULL == out_sphin) { res = RES_BAD_ARG; goto error; } diff --git a/src/sphin_config.c b/src/sphin_config.c @@ -43,6 +43,23 @@ struct sphin_config { /******************************************************************************* * Helper functions ******************************************************************************/ +static char* +trim_keyword + (char* str) +{ + char* token_ptr = NULL; + char* token = NULL; + char* remaining_token = NULL; + + token = strtok_r(str, " ", &token_ptr); + if (NULL == token) return NULL; + + remaining_token = strtok_r(NULL, " ", &token_ptr); + if (NULL != remaining_token) return NULL; + + return token; +} + static res_T config_create (struct sphin* sphin, @@ -97,6 +114,9 @@ load_stream { struct sphin_config* config = NULL; struct txtrdr* txtrdr = NULL; + char* keyword = NULL; + char* token = NULL; + char* token_ptr = NULL; res_T res = RES_OK; ASSERT(NULL != sphin); @@ -120,6 +140,37 @@ load_stream } while (NULL != txtrdr_get_line(txtrdr)) { + const char* line = txtrdr_get_cline(txtrdr); + /* TODO copy line in local string */ + + /* volume : "Mon volume"\0 */ + /* volume \0 "Mon volume"\0 */ + /* volume\0\0 "Mon volume"\0 */ + + token = strtok_r(txtrdr_get_line(txtrdr), ":", &token_ptr); + keyword = trim_keyword(token); + if (NULL == keyword){ + res = RES_BAD_ARG; + } + else if (0 == strcmp(keyword, "volume")){ + res = parse_volume(txtrdr, config) /* Not yet implemented */ + } + else if (0 == strcmp(keyword, "source")){ + res = parse_source(txtrdr, config) /* Not yet implemented */ + } + else if (0 == strcmp(keyword, "surface")){ + res = parse_surface(txtrdr, config) /* Not yet implemented */ + } + else { + res = RES_BAD_ARG; + } + if (res != RES_OK) { + ERROR + (sphin, + "%s: %lu: Bad keyword\n", + txtrdr_get_name(txtrdr), txtrdr_get_line_num(txtrdr)); + goto error; + } /* TODO */ }