diff options
Diffstat (limited to '')
-rw-r--r-- | src/.jsbundle.c.swp | bin | 0 -> 1024 bytes | |||
-rw-r--r-- | src/fopenmkdir.c | 33 | ||||
-rw-r--r-- | src/jsbundle.c | 41 | ||||
-rw-r--r-- | src/tape.c | 6 |
4 files changed, 75 insertions, 5 deletions
diff --git a/src/.jsbundle.c.swp b/src/.jsbundle.c.swp Binary files differnew file mode 100644 index 0000000..c512f34 --- /dev/null +++ b/src/.jsbundle.c.swp diff --git a/src/fopenmkdir.c b/src/fopenmkdir.c new file mode 100644 index 0000000..e4c4d68 --- /dev/null +++ b/src/fopenmkdir.c @@ -0,0 +1,33 @@ +#include <mkdirp.c> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +FILE * fopen_mkdir(char* filename, char* mode) { + FILE * file_to_return; + file_to_return = fopen(filename, mode); + if(file_to_return == NULL) { + char folder_of_file[256]; + strcpy(folder_of_file, filename); + char * p; + p = strrchr(folder_of_file, '/'); + if (!p) { + printf("[fopenmkdir.c] filename contains no slash.\n"); + return NULL; + } else { + printf("folder is %s\n", folder_of_file); + printf("filename is %s\n", filename); + *p = '\0'; + } + if(mkdir_p(folder_of_file) != 0) { + return NULL; + } + file_to_return = fopen(filename, mode); + if(file_to_return == NULL) { + return NULL; + } + return file_to_return; + } else { + return file_to_return; + } +} diff --git a/src/jsbundle.c b/src/jsbundle.c index ad98250..c585ff5 100644 --- a/src/jsbundle.c +++ b/src/jsbundle.c @@ -2,22 +2,53 @@ #include <stdio.h> #include <dirent.h> #include <string.h> +#include <mkdirp.c> +#include <fopenmkdir.c> -int main(int argc, char* argv[]) { - char bundle_filename[64] = "../dist/js/bundle.js"; +int bundle_js(char* bundle_filename, char* js_source_folder_name, char* file_extension) { + // char bundle_filename[64] = "../dist/js/bundle.js"; + // char js_source_folder_name[64] = "../assets/js/"; + // char file_extension[64] = ".js"; + char source_filename[64]; + FILE * bundle_file; + FILE * source_file; + bundle_file = fopen_mkdir(bundle_filename, "w"); + if(bundle_file == NULL) { + char bundle_folderpath[256]; + strcpy(bundle_folderpath, bundle_filename); + char *p = strchr(bundle_folderpath, '/'); + if (!p) { + } else { + *p = '\0'; + } + mkdir_p(bundle_filename); + } + char copy_buffer; DIR *dir; struct dirent *ent; - if ((dir = opendir ("../layout/js/")) != NULL) { + // printf ("[jsbundle.c] bundle_filename: %s\n", bundle_filename); + if ((dir = opendir (js_source_folder_name)) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { if(strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) { char *dot = strrchr(ent->d_name, '.'); - if(dot && !strcmp(dot, ".js")) { - printf ("%s\n", ent->d_name); + if(dot && !strcmp(dot, file_extension)) { + strcpy(source_filename, js_source_folder_name); + strcat(source_filename, ent->d_name); + source_file = fopen(source_filename, "r"); + // printf("[jsbundle.c] source_filename: %s\n", source_filename); + fprintf(bundle_file, "\n// %s\n", source_filename); + copy_buffer = fgetc(source_file); + while (copy_buffer != EOF) { + fputc(copy_buffer, bundle_file); + copy_buffer = fgetc(source_file); + } + fclose(source_file); } } } closedir (dir); + fclose(bundle_file); } else { /* could not open directory */ return 1; diff --git a/src/tape.c b/src/tape.c new file mode 100644 index 0000000..8f09ba6 --- /dev/null +++ b/src/tape.c @@ -0,0 +1,6 @@ +#include <stdio.h> +#include <stdlib.h> +#include <dirent.h> +#include <string.h> +#include <mkdirp.c> +#include <fopenmkdir.c> |