#include #include #include #include #include #include #include #include #define BASE_DIR "/tmp/chp" #define INTERMEDIATE_DIR "/tmp/chp/intermediate" #define COMPILE_DIR "/tmp/chp/compiled" #define BUFFER_SIZE 25565 char *replace_tag(char *str, int pos) { // TODO char *new = malloc(strlen(str) + 256); memset(new, strlen(str) + 256, sizeof(char)); strncat(new, str, pos); } void handle_file(char *filename) { int filename_length = strlen(filename); if (strncmp(filename + filename_length - 4, ".chp", 4) != 0) return; char *intermediate_filename = strdup(filename); intermediate_filename[filename_length - 2] = '\0'; FILE *input = fopen(filename, "r"); FILE *output = fopen(intermediate_filename, "w"); char buffer[BUFFER_SIZE], newbuffer[BUFFER_SIZE]; while (fgets(buffer, BUFFER_SIZE, input) != NULL) { char *str = buffer, *pos; // TODO /*while ((pos = strstr(str, "d_name, ".", 1) || !strncmp(entry->d_name, "..", 2)) continue; int pathlength = strlen(dirname) + strlen(entry->d_name) + 2; char *pathname = malloc(pathlength); snprintf(pathname, pathlength, "%s/%s", dirname, entry->d_name); switch (entry->d_type) { case DT_REG: handle_file(pathname); break; case DT_DIR: read_directory(pathname); break; } free(pathname); } } int main(void) { puts("Compiling.."); mkdir(BASE_DIR, 0777); mkdir(INTERMEDIATE_DIR, 0777); mkdir(COMPILE_DIR, 0777); char current_dir[PATH_MAX]; getcwd(current_dir, sizeof(current_dir)); read_directory(current_dir); puts("Ready"); return EXIT_SUCCESS; }