From: nishi Date: Sat, 20 Apr 2024 08:42:41 +0000 (+0000) Subject: if/ifnot/endif works X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9f7eddbb20e295624eca6289ca0454d9ca23c0d8;p=mandshurica.git if/ifnot/endif works git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@53 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/template.c b/Mandshurica/template.c index e08c0d6..ce9ab96 100644 --- a/Mandshurica/template.c +++ b/Mandshurica/template.c @@ -53,6 +53,7 @@ char* mandshurica_parse_template(const char* data) { int start = 0; char* ret = malloc(1); ret[0] = 0; + bool skip = false; for(i = 0; data[i] != 0; i++) { cbuf[0] = data[i]; if(data[i] == '@') { @@ -75,7 +76,21 @@ char* mandshurica_parse_template(const char* data) { } } - if(strcmp(op, "include") == 0) { + if(strcmp(op, "endif") == 0) { + skip = false; + } else if(skip) { + } else if(strcmp(op, "if") == 0 || strcmp(op, "ifnot") == 0) { + bool result = false; + if(arg != NULL) { + if(mandshurica_strcaseequ(arg, "true")) { + result = true; + } else if(mandshurica_strcaseequ(arg, "false")) { + result = false; + } + } + if(strcmp(op, "ifnot") == 0) result = !result; + skip = !result; + } else if(strcmp(op, "include") == 0) { if(arg != NULL) { FILE* f = fopen(arg, "r"); if(f != NULL) { @@ -112,7 +127,7 @@ char* mandshurica_parse_template(const char* data) { free(tmpl); } - } else if(!template) { + } else if(!template && !skip) { char* tmp = ret; ret = mandshurica_strcat(tmp, cbuf); free(tmp); diff --git a/Module/http.c b/Module/http.c index ec40433..9550b6c 100644 --- a/Module/http.c +++ b/Module/http.c @@ -209,7 +209,7 @@ void http_handler(int sock) { uint64_t len; char* data = NULL; char* s; - + struct stat st; char* lastmod = NULL; const char* pth = mandshurica_strcat(webroot, "/login-fail/"); diff --git a/Webroot/bar.html b/Webroot/bar.html index 0eb3904..08c3f66 100644 --- a/Webroot/bar.html +++ b/Webroot/bar.html @@ -1,3 +1,3 @@
-Home Login +Home @ifnot login@Login@endif@