commit ec938886fb5456883cdbc0ed91b12c5eb4acb8f4
parent a11874485c0f409fa00b1db4d361729e675e852c
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date: Sat, 4 Oct 2025 17:52:52 +0200
Change parsing logic for sphin_prop_rad name and type
prop_rads are declared in the input file as prop_rad: "name" TYPE.
Until now, a simple parsing strategy was used: the "name" TYPE part was
tokenized using spaces and tabs as separators. The first token was treated
as the name, and the last token as the type or radiative property. This
approach caused bugs when spaces were included in "name" (which is allowed
in the input file).
To address this issue, the parsing logic was replaced. Now, it first
uses the quotation marks (") as delimiters to extract the name, then
interprets the remaining part of the string as the prop_rad type. As
before, no characters other than spaces and tabs are allowed outside the
name and type.
Diffstat:
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/src/sphin_prop_rad.c b/src/sphin_prop_rad.c
@@ -102,14 +102,14 @@ parse_prop_rad
struct txtrdr* txtrdr,
char* value)
{
- char* tokens[2] = {NULL};
char* name = NULL;
+ char* name_start = NULL;
char* prop_rad_type_str = NULL;
char* token = NULL;
char* token_ptr = NULL;
- size_t token_count = 0;
enum sphin_prop_rad_type prop_rad_type = SPHIN_PROP_RAD_NONE__;
struct sphin_prop_rad* prop_rad = NULL;
+ size_t len = 0;
res_T res = RES_OK;
ASSERT(NULL != volume);
@@ -117,15 +117,23 @@ parse_prop_rad
if (NULL == value) { res = RES_BAD_ARG; goto error; }
- token = strtok_r(value, " \t", &token_ptr);
- while (token != NULL && token_count < 5) {
- tokens[token_count++] = trim_keyword(token);
- token = strtok_r(NULL, " \t", &token_ptr);
- }
+ /* Find first occurence of " in the value string */
+ name_start = strchr(value, '"');
+ if (NULL == name_start) { res = RES_BAD_ARG; goto error; }
- name = tokens[0];
+ /* Get the number of tabs and spaces (allowed characters) at the beginning
+ * of the string */
+ len = strspn(value, " \t");
+ if (value + len != name_start) {
+ /* There are characters before the first " other than spaces and tabs */
+ res = RES_BAD_ARG; goto error;
+ }
+ name = strtok_r(name_start, "\"", &token_ptr);
if (NULL == name) { res = RES_BAD_ARG; goto error; }
- prop_rad_type_str = tokens[1];
+
+ token = strtok_r(NULL, " \t", &token_ptr);
+ if (NULL == token) { res = RES_BAD_ARG; goto error; }
+ prop_rad_type_str = trim_keyword(token);
if (NULL == prop_rad_type_str) { res = RES_BAD_ARG; goto error; }
if (NULL == prop_rad_type_str) {
@@ -170,7 +178,6 @@ error:
goto exit;
}
-
/*******************************************************************************
* Exported functions
******************************************************************************/