Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
fca624550f | |||
b5b12171e1 | |||
7735cb2e71 | |||
16154393d0 |
3 changed files with 88 additions and 9 deletions
10
Changelog.md
10
Changelog.md
|
@ -2,6 +2,16 @@
|
|||
|
||||
## Upcoming Changes
|
||||
|
||||
## Version 1.7
|
||||
|
||||
Fix usage of indexing in `IF`.
|
||||
Note this is used like `{{{!IF SomeVar[2]==true}}}`.
|
||||
|
||||
## Version 1.6
|
||||
|
||||
Fix usage of `IF` with a `FOREACH` variable when the `IF` is nested in the
|
||||
`FOREACH` and is referring to a variable expanded by `FOREACH`.
|
||||
|
||||
## Version 1.5
|
||||
|
||||
Add flag `--generate-static-enable-overwrite`. This flag enables overwriting of
|
||||
|
|
|
@ -25,6 +25,41 @@ HTML='''
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2><a href="/inner">inner</a></h2><br>
|
||||
<h2>Test EachIf Expr</h2>
|
||||
|
||||
{{{!FOREACH EachIfTest_Array}}}
|
||||
{{{!IF EachIfTest_Array==true}}}
|
||||
EachIfTest_Array entry is <b>true</b>. <br>
|
||||
{{{!ELSE}}}
|
||||
EachIfTest_Array entry is <b>false</b>. <br>
|
||||
{{{!ENDIF}}}
|
||||
{{{!ENDFOREACH}}}
|
||||
|
||||
Again with IFs:<br>
|
||||
|
||||
{{{!IF EachIfTest_Array[0]==true}}}
|
||||
EachIfTest_Array entry is <b>true</b>. <br>
|
||||
{{{!ELSE}}}
|
||||
EachIfTest_Array entry is <b>false</b>. <br>
|
||||
{{{!ENDIF}}}
|
||||
{{{!IF EachIfTest_Array[1]==true}}}
|
||||
EachIfTest_Array entry is <b>true</b>. <br>
|
||||
{{{!ELSE}}}
|
||||
EachIfTest_Array entry is <b>false</b>. <br>
|
||||
{{{!ENDIF}}}
|
||||
{{{!IF EachIfTest_Array[2]==true}}}
|
||||
EachIfTest_Array entry is <b>true</b>. <br>
|
||||
{{{!ELSE}}}
|
||||
EachIfTest_Array entry is <b>false</b>. <br>
|
||||
{{{!ENDIF}}}
|
||||
{{{!IF EachIfTest_Array[3]==true}}}
|
||||
EachIfTest_Array entry is <b>true</b>. <br>
|
||||
{{{!ELSE}}}
|
||||
EachIfTest_Array entry is <b>false</b>. <br>
|
||||
{{{!ENDIF}}}
|
||||
|
||||
<br>
|
||||
<h2>Test IF/FOREACH Expr</h2>
|
||||
|
||||
Outer IF<br>
|
||||
|
@ -150,6 +185,11 @@ Each_FILE='''example_config/each_file_zero.html'''
|
|||
Each_FILE='''example_config/each_file_one.html'''
|
||||
Each_FILE='''example_config/each_file_two.html'''
|
||||
|
||||
EachIfTest_Array=false
|
||||
EachIfTest_Array=true
|
||||
EachIfTest_Array=false
|
||||
EachIfTest_Array=true
|
||||
|
||||
PATH=/inner
|
||||
HTML_FILE='''example_config/inner.html'''
|
||||
VAR_FILE='''example_config/var.html'''
|
||||
|
|
|
@ -180,6 +180,8 @@ int c_simple_http_internal_parse_if_expression(
|
|||
const char *var,
|
||||
const size_t var_offset,
|
||||
const size_t var_size,
|
||||
const uint64_t *for_state_idx,
|
||||
SDArchiverHashMap *array_vars,
|
||||
char **left_side_out,
|
||||
char **right_side_out,
|
||||
uint_fast8_t *is_equality_out,
|
||||
|
@ -227,10 +229,12 @@ int c_simple_http_internal_parse_if_expression(
|
|||
fprintf(stderr, "ERROR No closing \"]\"! %s\n", var);
|
||||
return 1;
|
||||
} else if (
|
||||
idx + 1 < var_size && var[idx] == '!' && var[idx + 1] == '=') {
|
||||
idx + 2 < var_size && var[idx + 1] == '!' && var[idx + 2] == '=') {
|
||||
++idx;
|
||||
break;
|
||||
} else if (
|
||||
idx + 1 < var_size && var[idx] == '=' && var[idx + 1] == '=') {
|
||||
idx + 2 < var_size && var[idx + 1] == '=' && var[idx + 2] == '=') {
|
||||
++idx;
|
||||
break;
|
||||
} else {
|
||||
fprintf(stderr, "ERROR Invalid expression after \"]\"! %s\n", var);
|
||||
|
@ -269,11 +273,31 @@ int c_simple_http_internal_parse_if_expression(
|
|||
simple_archiver_list_free(&var_parts);
|
||||
var_parts = simple_archiver_list_init();
|
||||
|
||||
C_SIMPLE_HTTP_ConfigValue *config_value =
|
||||
simple_archiver_hash_map_get(wrapped_hash_map->hash_map,
|
||||
var_buf,
|
||||
strlen(var_buf) + 1);
|
||||
if (!config_value || !config_value->value) {
|
||||
// At this point, var_buf contains the left-hand-side string that hasn't been
|
||||
// expanded yet.
|
||||
|
||||
// Check if ForEach variable.
|
||||
char *value = NULL;
|
||||
C_SIMPLE_HTTP_ConfigValue *config_value = NULL;
|
||||
if (for_state_idx != NULL) {
|
||||
if (var_index != -1) {
|
||||
fprintf(stderr,
|
||||
"ERROR Invalid indexing on expanded FOREACH variable! %s\n",
|
||||
var);
|
||||
return 1;
|
||||
}
|
||||
value = c_simple_http_internal_get_for_var(var_buf,
|
||||
*for_state_idx,
|
||||
array_vars);
|
||||
}
|
||||
if (!value) {
|
||||
// No ForEach variable, get as regular variable.
|
||||
config_value =
|
||||
simple_archiver_hash_map_get(wrapped_hash_map->hash_map,
|
||||
var_buf,
|
||||
strlen(var_buf) + 1);
|
||||
}
|
||||
if (!value && (!config_value || !config_value->value)) {
|
||||
fprintf(stderr, "ERROR Invalid VAR after \"IF/ELSEIF\"! %s\n", var);
|
||||
return 1;
|
||||
} else if (var_index >= 0) {
|
||||
|
@ -291,7 +315,8 @@ int c_simple_http_internal_parse_if_expression(
|
|||
uint64_t left_side_size = 0;
|
||||
if (c_simple_http_internal_ends_with_FILE(var_buf) == 0) {
|
||||
*left_side_out =
|
||||
c_simple_http_FILE_to_c_str(config_value->value, &left_side_size);
|
||||
c_simple_http_FILE_to_c_str(value ? value : config_value->value,
|
||||
&left_side_size);
|
||||
if (!*left_side_out || left_side_size == 0) {
|
||||
fprintf(stderr, "ERROR _FILE variable could not be read! %s\n", var);
|
||||
if (*left_side_out) {
|
||||
|
@ -304,7 +329,7 @@ int c_simple_http_internal_parse_if_expression(
|
|||
left_side_size = strlen(*left_side_out);
|
||||
c_simple_http_internal_set_out_insert(files_set_out, config_value->value);
|
||||
} else {
|
||||
*left_side_out = strdup(config_value->value);
|
||||
*left_side_out = strdup(value ? value : config_value->value);
|
||||
c_simple_http_trim_end_whitespace(*left_side_out);
|
||||
left_side_size = strlen(*left_side_out);
|
||||
}
|
||||
|
@ -599,6 +624,8 @@ int c_simple_http_internal_handle_inside_delimeters(
|
|||
var,
|
||||
1 + 3,
|
||||
var_size,
|
||||
(*state) & 0x4 ? &for_state_idx : NULL,
|
||||
array_vars,
|
||||
&left_side,
|
||||
&right_side,
|
||||
&is_equality,
|
||||
|
@ -673,6 +700,8 @@ int c_simple_http_internal_handle_inside_delimeters(
|
|||
var,
|
||||
1 + 7,
|
||||
var_size,
|
||||
(*state) & 0x4 ? &for_state_idx : NULL,
|
||||
array_vars,
|
||||
&left_side,
|
||||
&right_side,
|
||||
&is_equality,
|
||||
|
|
Loading…
Reference in a new issue