diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..beacb20 --- /dev/null +++ b/.clang-format @@ -0,0 +1,20 @@ +--- +Language: Cpp +UseTab: Always +TabWidth: 8 +AlignConsecutiveAssignments: + Enabled: true +AlignConsecutiveDeclarations: + Enabled: true +IndentWidth: 8 +PointerAlignment: Left +ColumnLimit: 0 +AllowShortIfStatementsOnASingleLine: Always +AllowShortBlocksOnASingleLine: Never +AllowShortFunctionsOnASingleLine: Empty +AllowShortLoopsOnASingleLine: true +SpaceBeforeParens: Never +AlignEscapedNewlines: DontAlign +SortIncludes: false +AllowShortEnumsOnASingleLine: false +#IndentPPDirectives: AfterHash diff --git a/external/xemil b/external/xemil index 178fe4a..750c295 160000 --- a/external/xemil +++ b/external/xemil @@ -1 +1 @@ -Subproject commit 178fe4aca775436db87de22765d5dcb52325981c +Subproject commit 750c29566540c46f5a480beb1e4abe032d6a0484 diff --git a/objs.mk b/objs.mk index 4e73336..d6602ae 100644 --- a/objs.mk +++ b/objs.mk @@ -59,6 +59,9 @@ src/src_process.o: src/process.c OBJS += src/src_seed.o src/src_seed.o: src/seed.c $(CC) $(CFLAGS) -c -o $@ src/seed.c +OBJS += src/src_simple.o +src/src_simple.o: src/simple.c + $(CC) $(CFLAGS) -c -o $@ src/simple.c OBJS += src/src_site.o src/src_site.o: src/site.c $(CC) $(CFLAGS) -c -o $@ src/site.c diff --git a/src/classic.c b/src/classic.c index 41c803c..7ac3ff6 100644 --- a/src/classic.c +++ b/src/classic.c @@ -17,8 +17,7 @@ void classic_stylesheet(FILE* out, const char* top) { free(nodes); } - if(breadcrumb_bgcolor == NULL) - breadcrumb_bgcolor = "#003366"; + if(breadcrumb_bgcolor == NULL) breadcrumb_bgcolor = "#003366"; fprintf(out, "body {\n"); fprintf(out, " padding: 0;\n"); @@ -130,8 +129,7 @@ void classic_stylesheet(FILE* out, const char* top) { void classic_head(FILE* out, const char* top, xl_node_t* header) { xl_node_t* child; - fprintf(out, " \n", - top); + fprintf(out, " \n", top); child = header->first_child; while(child != NULL) { @@ -141,10 +139,8 @@ void classic_head(FILE* out, const char* top, xl_node_t* header) { } } -void classic_body(FILE* out, const char* top, const char* title, - xl_node_t* body) { - char year[4 + 1 + 4 + - 1]; /* no one would use our software in year 10000... right? :) */ +void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body) { + char year[4 + 1 + 4 + 1]; /* no one would use our software in year 10000... right? :) */ char* holder = "Unknown people"; char* sitesearch = NULL; xl_node_t** nodes; @@ -189,8 +185,7 @@ void classic_body(FILE* out, const char* top, const char* title, if(sitesearch == NULL) sitesearch = "https://invalid.link"; - fprintf(out, " \n"); + fprintf(out, "
\n"); fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, "
\n"); for(i = 0; i < sizeof(images) / sizeof(images[0]); i++) { @@ -203,16 +198,14 @@ void classic_body(FILE* out, const char* top, const char* title, name = nodes[0]->text; free(nodes); } - if(name == NULL) - name = "Logo"; + if(name == NULL) name = "Logo"; sprintf(path, "%s.link", images[i]); if((nodes = xl_get_path(skinconf->root, path)) != NULL) { link = xl_get_attribute(nodes[0], "href"); free(nodes); } - if(link == NULL) - link = "https://invalid.link"; + if(link == NULL) link = "https://invalid.link"; link = u_path(top, link); @@ -222,10 +215,7 @@ void classic_body(FILE* out, const char* top, const char* title, if(text != NULL) { text = u_path(top, text); - fprintf(out, - " \"%s\"\n", - link, text, images[i + 1], name); + fprintf(out, " \"%s\"\n", link, text, images[i + 1], name); free(text); } @@ -237,8 +227,7 @@ void classic_body(FILE* out, const char* top, const char* title, fprintf(out, "
\n"); - fprintf(out, " \n"); + fprintf(out, "
\n"); fprintf(out, " \n"); fprintf(out, " \n"); - fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, "
\n"); if((nodes = xl_get_path(skinconf->root, "breadcrumb.link")) != NULL) { @@ -248,18 +237,14 @@ void classic_body(FILE* out, const char* top, const char* title, char* link = xl_get_attribute(nodes[i], "href"); char* name = xl_get_attribute(nodes[i], "name"); - if(link == NULL) - link = "https://invalid.link"; + if(link == NULL) link = "https://invalid.link"; link = u_path(top, link); - if(title == NULL) - title = link; + if(title == NULL) title = link; - if(i > 0) - fprintf(out, " |\n"); - fprintf(out, " %s\n", - link, name); + if(i > 0) fprintf(out, " |\n"); + fprintf(out, " %s\n", link, name); free(link); } @@ -267,28 +252,19 @@ void classic_body(FILE* out, const char* top, const char* title, free(nodes); } fprintf(out, " \n"); - fprintf(out, "
\n"); + fprintf(out, "
\n"); + fprintf(out, " \n"); fprintf(out, " Search\n"); - fprintf(out, - " \n", - sitesearch); - fprintf(out, " \n"); - fprintf(out, " \n"); + fprintf(out, " \n", sitesearch); + fprintf(out, " \n"); + fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, "
\n"); - fprintf(out, " \n"); + fprintf(out, "
\n"); fprintf(out, " \n"); - fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, "
\n"); + fprintf(out, " \n"); fprintf(out, "
\n"); if((nodes = xl_get_path(skinconf->root, "nav")) != NULL) { @@ -307,8 +283,7 @@ void classic_body(FILE* out, const char* top, const char* title, fprintf(out, "
\n"); fprintf(out, "
\n"); - fprintf(out, "
\n"); + fprintf(out, "
\n"); child = body->first_child; while(child != NULL) { @@ -321,62 +296,31 @@ void classic_body(FILE* out, const char* top, const char* title, fprintf(out, "
\n"); - fprintf(out, " \n"); + fprintf(out, "
\n"); fprintf(out, " \n"); - fprintf( - out, - " \n"); fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, "
\n"); - fprintf(out, - " Copyright © %s %s%s All " - "rights reserved.\n", - year, holder, - (strlen(holder) > 0 && holder[strlen(holder) - 1] == '.') ? "" : "."); + fprintf(out, " \n"); + fprintf(out, " Copyright © %s %s%s All rights reserved.\n", year, holder, (strlen(holder) > 0 && holder[strlen(holder) - 1] == '.') ? "" : "."); fprintf(out, " \n"); fprintf(out, "
\n"); - fprintf(out, - " \"Valid\n", - top); - fprintf(out, - " \"Valid\n", - top); + fprintf(out, " \"Valid\n", top); + fprintf(out, " \"Valid\n", top); fprintf(out, " \n"); fprintf(out, "
\n"); fprintf(out, " \n"); fprintf(f, "\n"); fprintf(f, " \n"); fprintf(f, " \n"); - fprintf(f, " \n"); - fprintf(f, " \n"); + fprintf(f, " \n"); + fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " Example Co, Ltd\n"); - fprintf( - f, - " Example Co, Ltd Description\n"); + fprintf(f, " Example Co, Ltd Description\n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " Example Project\n"); - fprintf( - f, - " Example Project Description\n"); + fprintf(f, " Example Project Description\n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " \n"); @@ -129,12 +117,9 @@ int action_seed(int argc, char** argv) { fprintf(f, " \n"); fprintf(f, "
\n"); fprintf(f, "

\n"); - fprintf(f, " You have successfully generated and " - "rendered a website using Taiga - static website generator.\n"); - fprintf(f, " This page is from the site template. " - "It is found in site/content/index.xml.\n"); - fprintf(f, " Please edit it and replace this text " - "with content of your own.\n"); + fprintf(f, " You have successfully generated and rendered a website using Taiga - static website generator.\n"); + fprintf(f, " This page is from the site template. It is found in site/content/index.xml.\n"); + fprintf(f, " Please edit it and replace this text with content of your own.\n"); fprintf(f, "

\n"); fprintf(f, "
\n"); fprintf(f, " \n"); diff --git a/src/simple.c b/src/simple.c new file mode 100644 index 0000000..2a5b17a --- /dev/null +++ b/src/simple.c @@ -0,0 +1,10 @@ +#include + +void simple_stylesheet(FILE* out, const char* top) { +} + +void simple_head(FILE* out, const char* top, xl_node_t* header) { +} + +void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body) { +} diff --git a/src/site.c b/src/site.c index 4de1dcc..fe3a31e 100644 --- a/src/site.c +++ b/src/site.c @@ -1,6 +1,9 @@ #include xemil_t* skinconf; +void (*site_stylesheet)(FILE* out, const char* top); /* also create files here if you need one */ +void (*site_head)(FILE* out, const char* top, xl_node_t* header); +void (*site_body)(FILE* out, const char* top, const char* title, xl_node_t* body); static int scan(const char* top, const char* path) { char* in = u_strvacat("site/content/", path, NULL); @@ -15,8 +18,7 @@ static int scan(const char* top, const char* path) { char* p; struct io_stat s; - if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) - continue; + if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) continue; p = u_strvacat(in, d->d_name, NULL); if(io_stat(p, &s) == 0) { @@ -76,12 +78,19 @@ static int scan(const char* top, const char* path) { return 1; } +#define USE_THEME(x) \ + site_stylesheet = x##_stylesheet; \ + site_head = x##_head; \ + site_body = x##_body; + int action_site(int argc, char** argv) { int st = 0; FILE* css; io_mkdir("build", 0755); + USE_THEME(simple); + if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !xl_parse(skinconf)) { fprintf(stderr, "Failed to parse site/skinconf.xml!\n"); @@ -93,7 +102,7 @@ int action_site(int argc, char** argv) { st = 1; goto cleanup; } - classic_stylesheet(css, "build/"); + site_stylesheet(css, "build/"); fclose(css); if(!scan("", "")) { @@ -102,8 +111,7 @@ int action_site(int argc, char** argv) { } cleanup:; - if(skinconf != NULL) - xl_close(skinconf); + if(skinconf != NULL) xl_close(skinconf); if(st == 0) { fprintf(stderr, "\nBuild successful\n"); diff --git a/src/taiga.h b/src/taiga.h index 1c487f2..f758770 100644 --- a/src/taiga.h +++ b/src/taiga.h @@ -49,6 +49,9 @@ void io_closedir(IO_DIR* dir); /* site.c */ extern xemil_t* skinconf; +extern void (*site_stylesheet)(FILE* out, const char* top); /* also create files here if you need one */ +extern void (*site_head)(FILE* out, const char* top, xl_node_t* header); +extern void (*site_body)(FILE* out, const char* top, const char* title, xl_node_t* body); int action_site(int argc, char** argv); @@ -67,11 +70,14 @@ char* u_path(const char* top, const char* path); int process(const char* top, const char* out, const char* full); /* classic.c */ -void classic_stylesheet( - FILE* out, const char* top); /* also create files here if you need one */ +void classic_stylesheet(FILE* out, const char* top); void classic_head(FILE* out, const char* top, xl_node_t* header); -void classic_body(FILE* out, const char* top, const char* title, - xl_node_t* body); +void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body); + +/* simple.c */ +void simple_stylesheet(FILE* out, const char* top); +void simple_head(FILE* out, const char* top, xl_node_t* header); +void simple_body(FILE* out, const char* top, const char* title, xl_node_t* body); /* default.c */ void default_head(FILE* out, const char* top, xl_node_t* element, int indent); diff --git a/src/util.c b/src/util.c index dd4b205..81ad1e8 100644 --- a/src/util.c +++ b/src/util.c @@ -8,16 +8,14 @@ char* u_strvacat(const char* str, ...) { len += strlen(str); va_start(va, str); - while((s = va_arg(va, const char*)) != NULL) - len += strlen(s); + while((s = va_arg(va, const char*)) != NULL) len += strlen(s); va_end(va); r = malloc(len + 1); strcpy(r, str); va_start(va, str); - while((s = va_arg(va, const char*)) != NULL) - strcat(r, s); + while((s = va_arg(va, const char*)) != NULL) strcat(r, s); va_end(va); return r; @@ -32,12 +30,9 @@ char* u_strdup(const char* str) { } char* u_path(const char* top, const char* path) { - if(strlen(path) > 3 && strstr(path, "://") != NULL) - return u_strdup(path); /* link - return as is */ - if(strlen(path) > 2 && memcmp(path, "./", 2) == 0) - return u_strdup(path); /* current directory - probably intended */ - if(strlen(path) > 3 && memcmp(path, "../", 2) == 0) - return u_strdup(path); /* parent directory - also probably intended */ + if(strlen(path) > 3 && strstr(path, "://") != NULL) return u_strdup(path); /* link - return as is */ + if(strlen(path) > 2 && memcmp(path, "./", 2) == 0) return u_strdup(path); /* current directory - probably intended */ + if(strlen(path) > 3 && memcmp(path, "../", 2) == 0) return u_strdup(path); /* parent directory - also probably intended */ return u_strvacat(top, path, NULL); /* otherwise, concat */ }