diff --git a/src/classic.c b/src/classic.c index 8493df1..41c803c 100644 --- a/src/classic.c +++ b/src/classic.c @@ -17,7 +17,8 @@ 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"); @@ -129,7 +130,8 @@ 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) { @@ -139,8 +141,10 @@ 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; @@ -182,9 +186,11 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body free(nodes); } - if(sitesearch == NULL) sitesearch = "https://invalid.link"; + 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++) { @@ -197,14 +203,16 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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); @@ -214,7 +222,10 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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); } @@ -226,7 +237,8 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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) { @@ -236,14 +248,18 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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); } @@ -251,19 +267,28 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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) { @@ -282,7 +307,8 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body fprintf(out, "
\n"); fprintf(out, "
\n"); - fprintf(out, "
\n"); + fprintf(out, "
\n"); child = body->first_child; while(child != NULL) { @@ -295,30 +321,62 @@ void classic_body(FILE* out, const char* top, const char* title, xl_node_t* body 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"); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, " Example Co, Ltd\n"); - fprintf(f, " 2026\n"); + fprintf(f, " %d\n", 1900 + tm->tm_year); fprintf(f, " \n"); fprintf(f, " \n"); fprintf(f, "\n"); @@ -115,9 +129,12 @@ 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/site.c b/src/site.c index 9503729..4de1dcc 100644 --- a/src/site.c +++ b/src/site.c @@ -15,7 +15,8 @@ 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) { @@ -81,7 +82,8 @@ int action_site(int argc, char** argv) { io_mkdir("build", 0755); - if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || !xl_parse(skinconf)) { + if((skinconf = xl_open_file("site/skinconf.xml")) == NULL || + !xl_parse(skinconf)) { fprintf(stderr, "Failed to parse site/skinconf.xml!\n"); st = 1; goto cleanup; @@ -100,7 +102,8 @@ 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 fdae715..1c487f2 100644 --- a/src/taiga.h +++ b/src/taiga.h @@ -1,19 +1,19 @@ #ifndef __TAIGA_H__ #define __TAIGA_H__ -#include -#include -#include #include -#include -#include +#include +#include +#include #include +#include +#include #ifdef _WIN32 #include #include #else -#include #include +#include #endif #include @@ -67,9 +67,11 @@ 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); /* also create files here if you need one */ 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); /* 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 81ad1e8..dd4b205 100644 --- a/src/util.c +++ b/src/util.c @@ -8,14 +8,16 @@ 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; @@ -30,9 +32,12 @@ 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 */ }