This commit is contained in:
parent
8ecf8eb8f5
commit
930fa5dbad
5 changed files with 100 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
|||
*.o
|
||||
*.exe
|
||||
/taiga
|
||||
/build
|
||||
/site
|
||||
|
|
|
|||
3
objs.mk
3
objs.mk
|
|
@ -26,3 +26,6 @@ src/src_seed.o: src/seed.c
|
|||
OBJS += src/src_site.o
|
||||
src/src_site.o: src/site.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/site.c
|
||||
OBJS += src/src_util.o
|
||||
src/src_util.o: src/util.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/util.c
|
||||
|
|
|
|||
33
src/seed.c
33
src/seed.c
|
|
@ -1,5 +1,38 @@
|
|||
#include <taiga.h>
|
||||
|
||||
static void describe(const char* path, const char* what){
|
||||
char space[64];
|
||||
int i;
|
||||
|
||||
memset(space, 0, sizeof(space));
|
||||
for(i = 0; i < (32 - strlen(path)); i++) space[i] = ' ';
|
||||
|
||||
printf("%s%s# %s\n", path, space, what);
|
||||
}
|
||||
|
||||
int action_seed(int argc, char** argv){
|
||||
FILE* f;
|
||||
|
||||
io_mkdir("site", 0755);
|
||||
io_mkdir("site/content", 0755);
|
||||
|
||||
if((f = fopen("site/skinconf.xml", "w")) == NULL){
|
||||
fprintf(stderr, "Failed to open site/skinconf.xml\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(f, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(f, "<skinconfig>\n");
|
||||
fprintf(f, " <search domain=\"example.com\" />\n");
|
||||
fprintf(f, " <vendor>Example Co, Ltd.</vendor>\n");
|
||||
fprintf(f, " <year>2026</vendor>\n");
|
||||
fprintf(f, " <copyright-link>https://example.com</copyright-link>\n");
|
||||
fprintf(f, "</skinconfig>\n");
|
||||
fclose(f);
|
||||
|
||||
printf("Template project created!\n");
|
||||
printf("\n");
|
||||
printf("Here is an outline of the generated files:\n");
|
||||
describe("site/skinconf.xml", "Skin configuration");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
34
src/site.c
34
src/site.c
|
|
@ -1,5 +1,39 @@
|
|||
#include <taiga.h>
|
||||
|
||||
static void scan(const char* path){
|
||||
char* in = u_strvacat("site/content/", path, NULL);
|
||||
char* out = u_strvacat("build/", path, NULL);
|
||||
IO_DIR* dir;
|
||||
|
||||
if((dir = io_opendir(in)) != NULL){
|
||||
struct io_dirent* d;
|
||||
|
||||
while((d = io_readdir(dir)) != NULL){
|
||||
char* p;
|
||||
struct io_stat s;
|
||||
|
||||
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){
|
||||
if(IO_S_ISDIR(s.st_mode)){
|
||||
scan(p);
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
io_closedir(dir);
|
||||
}
|
||||
|
||||
free(out);
|
||||
free(in);
|
||||
}
|
||||
|
||||
int action_site(int argc, char** argv){
|
||||
io_mkdir("build", 0755);
|
||||
|
||||
scan("");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
28
src/taiga.h
28
src/taiga.h
|
|
@ -4,10 +4,35 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define io_mkdir(x,y) _mkdir(x)
|
||||
#define io_chdir(x) _chdir(x)
|
||||
#define io_stat _stat
|
||||
|
||||
#define IO_S_ISDIR(m) ((m) & _S_IFDIR)
|
||||
#else
|
||||
#define io_mkdir mkdir
|
||||
#define io_chdir chdir
|
||||
#define io_stat stat
|
||||
|
||||
#define IO_S_ISDIR(m) ((m) & S_IFDIR)
|
||||
|
||||
#define IO_DIR DIR
|
||||
#define io_dirent dirent
|
||||
#define io_opendir opendir
|
||||
#define io_readdir readdir
|
||||
#define io_closedir closedir
|
||||
#endif
|
||||
|
||||
/* site.c */
|
||||
|
|
@ -19,4 +44,7 @@ int action_help(int argc, char** argv);
|
|||
/* seed.c */
|
||||
int action_seed(int argc, char** argv);
|
||||
|
||||
/* util.c */
|
||||
char* u_strvacat(const char* str, ...);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue