diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f09c9d2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,15 @@ +--- +# $Id$ +Language: Cpp +UseTab: Always +TabWidth: 8 +IndentWidth: 8 +PointerAlignment: Left +ColumnLimit: 1024 +AllowShortIfStatementsOnASingleLine: Always +AllowShortBlocksOnASingleLine: Never +AllowShortLoopsOnASingleLine: true +SpaceBeforeParens: Never +AlignEscapedNewlines: DontAlign +SortIncludes: false +AllowShortEnumsOnASingleLine: false diff --git a/CGI/Makefile b/CGI/Makefile index b2ed835..1872b46 100644 --- a/CGI/Makefile +++ b/CGI/Makefile @@ -2,7 +2,7 @@ include $(PWD)/Platform/$(PLATFORM).mk -OBJS = main.o cgi.o util.o version.o +OBJS = main.o cgi.o util.o version.o man.o .PHONY: all clean .SUFFIXES: .c .o diff --git a/CGI/cgi.c b/CGI/cgi.c index 8e067c1..36e72c0 100644 --- a/CGI/cgi.c +++ b/CGI/cgi.c @@ -11,6 +11,7 @@ #include "kn_version.h" #include "kn_util.h" +#include "kn_man.h" struct q_entry { char* key; @@ -20,39 +21,38 @@ struct q_entry { bool no = false; bool showmain = false; struct q_entry** entries = NULL; +char* path; -char* kn_get_query(const char* key){ +char* kn_get_query(const char* key) { if(entries == NULL) return NULL; int i; - for(i = 0; entries[i] != NULL; i++){ - if(strcmp(entries[i]->key, key) == 0 ) return entries[i]->value; + for(i = 0; entries[i] != NULL; i++) { + if(strcmp(entries[i]->key, key) == 0) return entries[i]->value; } return NULL; } -char* kn_null(const char* a){ - return a == NULL ? "" : (char*)a; -} +char* kn_null(const char* a) { return a == NULL ? "" : (char*)a; } -void kn_parse_query(void){ +void kn_parse_query(void) { char* query = getenv("QUERY_STRING"); - if(query != NULL){ + if(query != NULL) { entries = malloc(sizeof(*entries)); entries[0] = NULL; int i; int incr = 0; - for(i = 0;; i++){ - if(query[i] == 0 || query[i] == '&'){ + for(i = 0;; i++) { + if(query[i] == 0 || query[i] == '&') { char* a = malloc(i - incr + 1); - memcpy(a, query + incr , i - incr); + memcpy(a, query + incr, i - incr); a[i - incr] = 0; char* key = a; char* value = ""; int j; - for(j = 0; key[j] != 0; j++){ - if(key[j] == '='){ + for(j = 0; key[j] != 0; j++) { + if(key[j] == '=') { key[j] = 0; value = key + j + 1; break; @@ -64,7 +64,8 @@ void kn_parse_query(void){ e->value = kn_strdup(value); struct q_entry** old = entries; - for(j = 0; old[j] != NULL; j++); + for(j = 0; old[j] != NULL; j++) + ; entries = malloc(sizeof(*entries) * (j + 2)); for(j = 0; old[j] != NULL; j++) entries[j] = old[j]; entries[j] = e; @@ -78,24 +79,30 @@ void kn_parse_query(void){ } } } - if(kn_get_query("page") == NULL){ + if(kn_get_query("page") == NULL) { printf("Status: 200 OK\n\n"); showmain = true; - }else{ - printf("Status: 404 Not Found\n\n"); - no = true; + } else { + if((path = kn_find(MANPAGE_DIR, kn_get_query("page"))) != NULL) { + printf("Status: 200 OK\n\n"); + } else { + printf("Status: 404 Not Found\n\n"); + no = true; + } } } -void kn_cgi(void){ +void kn_cgi(void) { printf("\n"); printf(" \n"); printf(" \n"); printf(" Keine - "); - if(no){ + if(no) { printf("Not found"); - }else if(showmain){ + } else if(showmain) { printf("Main"); + } else { + printf("%s", kn_get_query("page")); } printf("\n"); printf("