From df86b89290402ddf3e22d7b2d3a5381da7a0aefc Mon Sep 17 00:00:00 2001 From: aspiring_aurelian Date: Fri, 8 Dec 2023 17:18:44 -0600 Subject: Merge create_make and create_src --- main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index fcfbbd0..4b68fb4 100644 --- a/main.c +++ b/main.c @@ -30,21 +30,21 @@ void *f1_newer(void *arg) { pthread_exit(&ret); } -void *create_make() { - /* Create simple makefile */ - int fd = creat("makefile", 00644); +void *create_template(void *arg) { + /* Create simple main.c and makefile boilerplate */ + char *path = (char *) arg; + int fd = creat(path, 00644); FILE *file = fdopen(fd, "w"); - fprintf(file, "debug: main.c\n\tgcc -Wall main.c -o ./bin/debug\nrelease: main.c\n\tgcc -O2 -march=native main.c -o ./bin/release"); - fclose(file); - - return NULL; -} + switch(path[2]) { + case 'i': + fprintf(file, "#include \n\nint main() {\n\tprintf(\"Hello world\\n\");\n}"); + break; + case 'k': + fprintf(file, "debug: main.c\n\tgcc -Wall main.c -o ./bin/debug\nrelease: main.c\n\tgcc -O2 -march=native main.c -o ./bin/release"); + break; + default: break; + } -void *create_src() { - /* Create simple main.c */ - int fd = creat("main.c", 00644); - FILE *file = fdopen(fd, "w"); - fprintf(file, "#include \n\nint main() {\n\tprintf(\"Hello world\\n\");\n}"); fclose(file); return NULL; @@ -55,8 +55,8 @@ void new(char *argv[]) { mkdir(name, 0777); chdir(name); pthread_t s_thread, m_thread; - pthread_create(&s_thread, NULL, create_src, NULL); - pthread_create(&m_thread, NULL, create_make, NULL); + pthread_create(&s_thread, NULL, create_template, (void *) "main.c"); + pthread_create(&m_thread, NULL, create_template, (void *) "makefile"); pthread_join(s_thread, NULL); pthread_join(m_thread, NULL); @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) { * check age of source vs. bin */ pthread_t f_thread, check_thread; - pthread_create(&f_thread, NULL, create_make, NULL); + pthread_create(&f_thread, NULL, create_template, (void *) "makefile"); pthread_create(&check_thread, NULL, f1_newer, (void *)&files); mkdir("./bin", 0777); -- cgit v1.2.3