From a95002238c04f3be24a01174e96fa3bb9907858b Mon Sep 17 00:00:00 2001 From: the little girl Date: Fri, 21 Feb 2014 14:37:13 +0100 Subject: ehhh #i, marxupmagi --- wiki.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/wiki.c b/wiki.c index 4dea629..a6dc95d 100644 --- a/wiki.c +++ b/wiki.c @@ -37,6 +37,7 @@ void head(char *page, char *link, char *what) { printf("\n"); printf("%s · %s\n", title, page); printf("\n", base); + printf("\n", base); if(link && what && !strcmp(what, "rediger")) printf("

%s

\n", what, link, page); else if(link && what) @@ -172,7 +173,8 @@ int post(char *path) { return redirect(path); } -int list(char *raw, int dir) { +// gjør denne penere! +int list(char *raw, int dir, int inc) { int len = strlen(raw); char *pattern = malloc(len + 3); if(len > 0 && raw[len - 1] == '/') @@ -183,19 +185,24 @@ int list(char *raw, int dir) { snprintf(pattern, len + 1, "%s", raw); glob_t res; if(glob(pattern, GLOB_MARK, NULL, &res)) { - head("ingen treff", NULL, NULL); - foot(0); + if(!inc) { + head("ingen treff", NULL, NULL); + foot(0); + } return 0; } - head("treff", NULL, NULL); + if(!inc) + head("treff", NULL, NULL); char *path; printf(""); - foot(0); + if(!inc) + foot(0); free(pattern); return 0; } @@ -212,15 +219,38 @@ int text(char *path) { return 0; } +void include(FILE *out, char *path) { + struct stat s; + while(isspace(*path)) path++; + if(!legit(path)) return; + if(*path == '/') return; + stat(path, &s); + if(S_ISDIR(s.st_mode)) { + list(path, 1, 1); + return; + } + FILE *fp = fopen(path, "r"); + if(!fp) return; + marxup(fp, out, NULL); + fclose(fp); +} + +void magic(FILE *out, char *line) { + switch(*line++) { + case 'i': include(out, line); break; + default: fprintf(out, "WHAT: %s\n", line); return; + } +} + int view(char *path) { struct stat s; stat(path, &s); if(S_ISDIR(s.st_mode)) - return list(path, 1); + return list(path, 1, 0); FILE *fp = fopen(path, "r"); if(!fp) return redirect("?e"); writable(path) ? head(path, "?e", "rediger") : head(path, NULL, NULL); - marxup(fp, stdout, NULL); + marxup(fp, stdout, magic); foot(1); return 0; } @@ -240,7 +270,7 @@ int main(int argc, char **argv) { if(!base) base = strdup(dirname(strdup(script))); if(authenticate && !(id = authenticate())) return unauthorized(401); - if(!legit(page++)) return redirect("home"); + if(!legit(page++)) return redirect("hei"); setenv("MARXUP_HEADER", "2", 1); setenv("MARXUP_PREFIX", base, 1); @@ -250,7 +280,7 @@ int main(int argc, char **argv) { if(!strncmp(verb, "POST", 4)) return post(page); if(strchr(page, '*')) - return list(page, 0); + return list(page, 0, 0); while(qstr && *qstr) { switch(*qstr) { -- cgit v1.0