]> Nishi Git Mirror - mandshurica.git/commitdiff
if/ifnot/endif works
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 08:42:41 +0000 (08:42 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 08:42:41 +0000 (08:42 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@53 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Mandshurica/template.c
Module/http.c
Webroot/bar.html

index e08c0d6983870fb6e6db0fdf2e807a315c023976..ce9ab9640bee7ab79e39c124c9dd73ab182312be 100644 (file)
@@ -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);
index ec404331cac6db616db4e53c751a4fdd118d719e..9550b6c395255e55642c8bab3fac7cf9fe0400c3 100644 (file)
@@ -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/");
index 0eb390466876598f681b4402d06ee4b4e084c7fd..08c3f66fbb246661b0f6706de5baef39fa35fd65 100644 (file)
@@ -1,3 +1,3 @@
 <hr>
-<a href="/">Home</a> <a href="/login">Login</a>
+<a href="/">Home</a> @ifnot login@<a href="/login">Login</a>@endif@
 <hr>