This commit is contained in:
parent
61378d315b
commit
110a170af4
5 changed files with 41 additions and 2 deletions
3
objs.mk
3
objs.mk
|
|
@ -20,6 +20,9 @@ src/src_help.o: src/help.c
|
|||
OBJS += src/src_main.o
|
||||
src/src_main.o: src/main.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/main.c
|
||||
OBJS += src/src_process.o
|
||||
src/src_process.o: src/process.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/process.c
|
||||
OBJS += src/src_seed.o
|
||||
src/src_seed.o: src/seed.c
|
||||
$(CC) $(CFLAGS) -c -o $@ src/seed.c
|
||||
|
|
|
|||
18
src/seed.c
18
src/seed.c
|
|
@ -29,10 +29,28 @@ int action_seed(int argc, char** argv){
|
|||
fprintf(f, "</skinconfig>\n");
|
||||
fclose(f);
|
||||
|
||||
if((f = fopen("site/content/index.xml", "w")) == NULL){
|
||||
fprintf(stderr, "Failed to open site/content/index.xml\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(f, "<?xml version=\"1.0\"?>\n");
|
||||
fprintf(f, "<document>\n");
|
||||
fprintf(f, " <header>\n");
|
||||
fprintf(f, " <title>Welcome to template</title>\n");
|
||||
fprintf(f, " </header>\n");
|
||||
fprintf(f, " <body>\n");
|
||||
fprintf(f, " <section id=\"status\">\n");
|
||||
fprintf(f, " <title>Congratulations</title>\n");
|
||||
fprintf(f, " </section>\n");
|
||||
fprintf(f, " </body>\n");
|
||||
fprintf(f, "</document>\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");
|
||||
describe("site/content/index.xml", "Example index file");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
10
src/site.c
10
src/site.c
|
|
@ -5,6 +5,7 @@ static void scan(const char* path){
|
|||
char* out = u_strvacat("build/", path, NULL);
|
||||
IO_DIR* dir;
|
||||
|
||||
io_mkdir(out, 0755);
|
||||
if((dir = io_opendir(in)) != NULL){
|
||||
struct io_dirent* d;
|
||||
|
||||
|
|
@ -14,10 +15,15 @@ static void scan(const char* path){
|
|||
|
||||
if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) continue;
|
||||
|
||||
p = u_strvacat(in, d->d_name, "/", NULL);
|
||||
p = u_strvacat(in, d->d_name, NULL);
|
||||
if(io_stat(p, &s) == 0){
|
||||
if(IO_S_ISDIR(s.st_mode)){
|
||||
scan(p);
|
||||
char* p2 = u_strvacat(d->d_name, "/", NULL);
|
||||
scan(p2);
|
||||
free(p2);
|
||||
}else if(strcmp(d->d_name, "index.xml") == 0){
|
||||
process(out, p);
|
||||
printf("%s\n", p);
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
|
|
|
|||
|
|
@ -46,5 +46,9 @@ int action_seed(int argc, char** argv);
|
|||
|
||||
/* util.c */
|
||||
char* u_strvacat(const char* str, ...);
|
||||
char* u_strdup(const char* str);
|
||||
|
||||
/* process.c */
|
||||
void process(const char* out, const char* full);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,3 +20,11 @@ char* u_strvacat(const char* str, ...){
|
|||
|
||||
return r;
|
||||
}
|
||||
|
||||
char* u_strdup(const char* str){
|
||||
char* s = malloc(strlen(str) + 1);
|
||||
|
||||
strcpy(s, str);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue