aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/main.c b/main.c
index 1024d17..fcfbbd0 100644
--- a/main.c
+++ b/main.c
@@ -40,6 +40,28 @@ void *create_make() {
return NULL;
}
+void *create_src() {
+ /* Create simple main.c */
+ int fd = creat("main.c", 00644);
+ FILE *file = fdopen(fd, "w");
+ fprintf(file, "#include <stdio.h>\n\nint main() {\n\tprintf(\"Hello world\\n\");\n}");
+ fclose(file);
+
+ return NULL;
+}
+
+void new(char *argv[]) {
+ char *name = argv[2];
+ 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_join(s_thread, NULL);
+ pthread_join(m_thread, NULL);
+ exit(0);
+}
int main(int argc, char *argv[]) {
/* Struct to hold files */
@@ -50,7 +72,7 @@ int main(int argc, char *argv[]) {
/* Parse args to determine which mode to run in
* Not very robust, needs improvement
*/
- enum { RUN, BUILD, BUILD_RELEASE } mode = RUN;
+ enum { RUN, BUILD, BUILD_RELEASE, NEW } mode = RUN;
if (argc > 1) {
switch(argv[1][0]) {
case 'r': break;
@@ -61,6 +83,8 @@ int main(int argc, char *argv[]) {
break;
}
mode = BUILD; break;
+ case 'n':
+ new(argv); break;
default: printf("Unknown argument: '%s'\nDefaulting to 'run'\n", argv[1]);
}
}