From 52a5a9d9bd8d767bd76c02f20668e1c7d92e33f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20L=2E=20=C5=A0ijanec?= Date: Wed, 29 Apr 2020 22:38:41 +0200 Subject: setting up folder structure --- src/.jsbundle.c.swp | Bin 0 -> 1024 bytes src/fopenmkdir.c | 33 +++++++++++++++++++++++++++++++++ src/jsbundle.c | 41 ++++++++++++++++++++++++++++++++++++----- src/tape.c | 6 ++++++ 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/.jsbundle.c.swp create mode 100644 src/fopenmkdir.c create mode 100644 src/tape.c (limited to 'src') diff --git a/src/.jsbundle.c.swp b/src/.jsbundle.c.swp new file mode 100644 index 0000000..c512f34 Binary files /dev/null and b/src/.jsbundle.c.swp differ 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 +#include +#include +#include + +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 #include #include +#include +#include -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 +#include +#include +#include +#include +#include -- cgit v1.2.3