diff options
Diffstat (limited to 'src/h_script.c')
-rw-r--r-- | src/h_script.c | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/h_script.c b/src/h_script.c index f719953..541e379 100644 --- a/src/h_script.c +++ b/src/h_script.c @@ -37,13 +37,14 @@ #include "h_bash.h" #include "haserl.h" -/* HTML, RUN, INCLUDE, EVAL NOOP }; */ +/* HTML, RUN, INCLUDE, EVAL, COMMENT, NOOP }; */ const char *g_tag[] = { "", "", "in", "=", + "#", "" }; @@ -185,10 +186,51 @@ free_token_list (token_t * tokenlist) #ifndef JUST_LUACSHELL +/* return the point in a script where the "comment" ends */ +char * +skip_comment (char *startbuf, char *endbuf) +{ + unsigned int c_lev = 1; + char *s_tag, *e_tag; + + startbuf += 2; + while (startbuf < endbuf) + { + s_tag = strstr (startbuf, open_tag); + e_tag = strstr (startbuf, close_tag); + + if (!e_tag) + { + break; + } + + if ((s_tag) && (s_tag < e_tag)) + { + c_lev++; + startbuf = s_tag + 2; + continue; + } + /* otherwise, we have an end tag first */ + c_lev--; + startbuf = e_tag; + if (c_lev == 0) + { + return (startbuf); + } + startbuf += 2; + + } + return NULL; +} + /* build a tokenchain from a script. This step just * splits a script buf into parts that are separated - * by <? ?>. If the <? ?> are out of order, then it + * by <% %>. If the <% %> are out of order, then it * flags that, but doesn't try to do anything else. + * + * For nesting comments, this function IS aware of + * the comment tag, and will try accomodate commented + * tags. Commented script never enters the token list */ token_t * build_token_list (script_t * scriptbuf, token_t * tokenlist) @@ -197,7 +239,6 @@ build_token_list (script_t * scriptbuf, token_t * tokenlist) char *start, *end, *curpos, *endpos; token_t *curtoken, *firsttoken; - curtoken = tokenlist; firsttoken = tokenlist; @@ -209,6 +250,17 @@ build_token_list (script_t * scriptbuf, token_t * tokenlist) start = strstr (curpos, open_tag); end = strstr (curpos, close_tag); + /* if this is a comment tag, the end is at the end of the comment */ + if ((start) && (memcmp (start + 2, g_tag[COMMENT], 1) == 0)) + { + end = skip_comment (start, endpos); + if (end) + { + curpos = end + 2; + continue; + } + } + if (start && !end) die_with_message (scriptbuf, start, g_err_msg[E_NO_END_MARKER], open_tag[1]); @@ -221,7 +273,6 @@ build_token_list (script_t * scriptbuf, token_t * tokenlist) && (strstr (start + 1, open_tag) < end))) die_with_message (scriptbuf, start, g_err_msg[E_NO_END_MARKER], open_tag[1]); - if (end) { /* push curpos to the start of the token */ @@ -234,7 +285,6 @@ build_token_list (script_t * scriptbuf, token_t * tokenlist) push_token_on_list (curtoken, scriptbuf, start, end - start); if (firsttoken == NULL) firsttoken = curtoken; - /* push start of token to end of token */ curpos = end + 2; } else |