stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit c19b7f6c6f29464d3893ce55af408c383e21eeb3
parent caaba0c6cc31d9c1fdefc9628f941646816d0f7d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 10 Apr 2020 17:21:48 +0200

Fix how to provide all-default to the -R option

Diffstat:
Mdoc/stardis.1.txt.in | 14+++++++++++++-
Msrc/stardis-parsing.c | 50++++++++++++++++++++++++--------------------------
2 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/doc/stardis.1.txt.in b/doc/stardis.1.txt.in @@ -135,7 +135,9 @@ EXCLUSIVE OPTIONS *-R* [__sub-option__:...]:: Render an infrared image of the system through a pinhole camera and write it - to _standard output_ in VTK format. Available sub-options are: + to _standard output_ in VTK format. One can use all-default sub-options by + simply providing the colon character (*:*) alone as an argument. Available + sub-options are: **fov=**_angle_;; Horizontal field of view of the camera in [30, 120] degrees. By default @@ -255,6 +257,16 @@ read from the 2 files *media.txt* and *bounds.txt*: $ stardis -M media.txt -M bounds.txt -m med05,100 +Render the system as described in *scene.txt* with default settings: + + $ stardis -M scene.txt -R : + +Render the system as described in *scene.txt* at *t=1000*, *spp=2*, +*img=800x600* and all other settings set to their default values: + + $ stardis -M scene.txt -R t=1000:spp=2:img=800x600 + + COPYRIGHT --------- Copyright &copy; 2018-2020 |Meso|Star>. License GPLv3+: GNU GPL diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -55,46 +55,51 @@ split_line const char a_delim) { char** result = 0; - size_t count = 0; + size_t chunks_count; char* tmp = a_str; - char* last_delim = a_str; char delim[2]; + char* tok_ctx = NULL; + + ASSERT(a_str); + delim[0] = a_delim; delim[1] = 0; - ASSERT(a_str); + /* if a_str starts with initial useless delimiters remove them */ + while(*a_str == a_delim) a_str++; + + /* if a_str ends with final useless delimiters remove them */ + tmp = a_str + strlen(a_str) - 1; + while(*tmp == a_delim && tmp >= a_str) { *tmp = '\0'; tmp--; } - /* Count how many elements will be extracted. */ + if(tmp >= a_str) chunks_count = 1; + else return NULL; + + tmp = a_str; while(*tmp) { - if(a_delim == *tmp) { - count++; - last_delim = tmp; - } + int delim_found = 0; + while(*tmp == a_delim) { delim_found = 1; tmp++; } + if(delim_found) chunks_count++; tmp++; } - /* Add space for trailing token. */ - count += last_delim < (a_str + strlen(a_str) - 1); - /* Add space for terminating null string so caller knows where the list of returned strings ends. */ - count++; - - result = malloc(sizeof(char*) * count); + result = malloc(sizeof(char*) * (1 + chunks_count)); if(result) { size_t idx = 0; - char* token = strtok(a_str, delim); + char* token = strtok_r(a_str, delim, &tok_ctx); while(token) { - ASSERT(idx < count); + ASSERT(idx <= chunks_count); #ifdef COMPILER_CL *(result + idx++) = _strdup(token); #else *(result + idx++) = strdup(token); #endif - token = strtok(0, delim); + token = strtok_r(NULL, delim, &tok_ctx); } - ASSERT(idx == count - 1); + ASSERT(idx == chunks_count); *(result + idx) = 0; } return result; @@ -457,26 +462,18 @@ parse_args size_t len = 0; const char option_list[] = "a:dD:f:F:ghm:M:n:p:P:r:R:s:S:tvV:"; char buf[128]; - static char empty_arg[1] = ""; res_T res = RES_OK; ASSERT(argv && args); opterr = 0; /* No default error messages */ while((opt = getopt(argc, argv, option_list)) != -1) { -re_switch: switch (opt) { case '?': /* Unreconised option */ { char* ptr = strchr(option_list, optopt); if(ptr && ptr[1] == ':') { - /* As a special case -R option can accept an empty argument */ - if(optopt == 'R') { - opt = optopt; - optarg = empty_arg; - goto re_switch; /* retry switch */ - } res = RES_BAD_ARG; logger_print(args->logger, LOG_ERROR, "Missing argument for option -%c\n", @@ -861,6 +858,7 @@ parse_camera for(i = 0; *(line + i); i++) { size_t len = 0; opt = split_line(line[i], '='); + ASSERT(opt[0] && opt[1] && !opt[2]); _strupr(opt[0]); if(strcmp(opt[0], "T") == 0) { ERR(cstr_to_double(opt[1], &cam->time));