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 33e249c0b06de150e566a725887a64a5e4527d40
parent e5518528bf5673a6a41f74ccba4e8f847a7b0953
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Tue, 11 Feb 2025 15:53:03 +0100

Continue the implementation of sphin_volume parsing

Diffstat:
Msrc/sphin.h | 6++++++
Msrc/sphin_config.c | 25+++++++++----------------
Msrc/sphin_volume.c | 57+++++++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 64 insertions(+), 24 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -44,6 +44,12 @@ #define SPHIN(Func) sphin_##Func #endif +enum sphin_side { + SPHIN_BACK, /* 0 */ + SPHIN_FRONT, /* 1 */ + SPHIN_SIDE_NONE__ /* 2 */ +}; + struct sphin_create_args { struct logger* logger; /* May be NULL <=> default logger */ struct mem_allocator* allocator; /* NULL <=> use default allocator */ diff --git a/src/sphin_config.c b/src/sphin_config.c @@ -131,29 +131,18 @@ load_stream /* parse keyword */ token = strtok_r(str_get(&line), ":", &token_ptr); keyword = trim_keyword(token); - if (NULL == keyword){ - res = RES_BAD_ARG; - goto error; - } + if (NULL == keyword){ res = RES_BAD_ARG; goto error; } /* parse value (name) */ token = strtok_r(NULL, "", &token_ptr); + if(NULL != token){ res = RES_BAD_ARG; goto error; } name = trim_string(token); - if (NULL == name){ - res = RES_BAD_ARG; - goto error; - } + if (NULL == name){ res = RES_BAD_ARG; goto error; } if (0 == strcmp(keyword, "volume")){ - if (RES_OK != (res = txtrdr_read_line(txtrdr))) goto error; res = parse_volume(config, txtrdr, name); } - else if (0 == strcmp(keyword, "source")){ - if (RES_OK != (res = txtrdr_read_line(txtrdr))) goto error; - // res = parse_source(txtrdr, config, name); /* Not yet implemented */ - } else if (0 == strcmp(keyword, "surface")){ - if (RES_OK != (res = txtrdr_read_line(txtrdr))) goto error; // res = parse_surface(txtrdr, config, name); /* Not yet implemented */ } else { @@ -197,7 +186,9 @@ trim_keyword char* token_ptr = NULL; char* token = NULL; char* remaining_token = NULL; + ASSERT(NULL != str); + token = strtok_r(str, " \t", &token_ptr); /* If no token was found (empty string or invalid input) */ if (NULL == token) return NULL; @@ -210,14 +201,16 @@ trim_keyword return token; } -char* /* 'mon volume ' */ +char* trim_string - (char* str) /* ' erreur "mon volume " salut ' */ + (char* str) { char* a = NULL; char* b = NULL; size_t len = 0; + ASSERT(NULL != str); + a = strchr(str, '"'); /* find the first occurrence of " */ b = strrchr(str, '"'); /* find the last occurrence of " */ diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -39,7 +39,7 @@ struct sphin_volume { }; /******************************************************************************* - * Helper functions + * Helper functions ******************************************************************************/ static res_T volume_create @@ -63,19 +63,19 @@ volume_create ref_init(&volume->ref); SPHIN(ref_get(sphin)); volume->sphin = sphin; - + str_init(sphin->allocator, &volume->name); res = str_set(&volume->name, name); if (RES_OK != res) { goto error; } - + exit: *out_volume = volume; return res; error: if (NULL != volume) { - SPHIN(volume_ref_put(volume)); + SPHIN(volume_ref_put(volume)); volume = NULL; } goto exit; @@ -88,7 +88,7 @@ release_volume(ref_T* address) struct sphin* sphin = NULL; ASSERT(NULL != address); - + volume = CONTAINER_OF(address, struct sphin_volume, ref); str_release(&volume->name); sphin = volume->sphin; @@ -106,24 +106,65 @@ parse_volume const char* name) { struct sphin_volume* volume = NULL; + struct str line; + char* keyword = NULL; + char* token = NULL; + char* token_ptr = NULL; + char* value = NULL; res_T res = RES_OK; ASSERT(NULL != config); ASSERT(NULL != txtrdr); ASSERT(NULL != name); ASSERT('\0' != name[0]); /* Name can't be empty */ - + + str_init(config->sphin->allocator, &line); + res = volume_create(config->sphin, name, &volume); if (RES_OK != res) { goto error; } + res = txtrdr_read_line(txtrdr); + if (RES_OK != res) { + goto error; + } + + while (NULL != txtrdr_get_line(txtrdr)) { + res = str_set(&line, txtrdr_get_cline(txtrdr)); + if (RES_OK != res) { + goto error; + } + + /* parse keyword */ + token = strtok_r(str_get(&line), ":", &token_ptr); + if (NULL == token){ res = RES_BAD_ARG; goto error; } + keyword = trim_keyword(token); + if (NULL == keyword){ res = RES_BAD_ARG; goto error; } + + /* parse value */ + token = strtok_r(NULL, "", &token_ptr); + if (NULL == token){ res = RES_BAD_ARG; goto error; } + value = trim_string(token); + if (NULL == value){ res = RES_BAD_ARG; goto error; } + + if (0 == strcmp(keyword, "geometry")){ + // res = parse_geometry(volume, txtrdr, value); + } + else if (0 == strcmp(keyword, "ka")){ + // res = parse_ka(volume, txtrdr, value); + } + else { + break; + } + } exit: - return res; + str_release(&line); + return res; error: goto exit; } - + /******************************************************************************* * Exported functions ******************************************************************************/