aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe little girl <yui@blekksprut.net>2014-02-21 14:37:13 +0100
committerthe little girl <yui@blekksprut.net>2014-02-21 14:37:13 +0100
commita95002238c04f3be24a01174e96fa3bb9907858b (patch)
treeaba4c85f4e5d7c074ca87a9533394032dbaffb53
parentd50bab21d036edcc1d7b54b913cb422c3c2143e9 (diff)
downloadukulele-a95002238c04f3be24a01174e96fa3bb9907858b.tar.xz
ehhh #i, marxupmagi
-rw-r--r--wiki.c48
1 files 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("<!doctype html>\n");
printf("<title>%s · %s</title>\n", title, page);
printf("<link rel='stylesheet' href='%s/wiki.css'>\n", base);
+ printf("<script src='%s/wiki.js'></script>\n", base);
if(link && what && !strcmp(what, "rediger"))
printf("<h1><a data-text='%s' href='%s'>%s</a></h1>\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("<ul class='glob'>");
for(int i = 0; i < res.gl_pathc; i++) {
path = res.gl_pathv[i];
+ if(*path == '.' && *path + 1 == '/') path += 2;
printf("<li><a href='%s/%s'>%s</a>", script, path, path);
}
printf("</ul>");
- 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) {