diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7756c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +a.out +*.o diff --git a/micromake/src/micromake.c b/micromake/src/micromake.c new file mode 100644 index 0000000..a2272e5 --- /dev/null +++ b/micromake/src/micromake.c @@ -0,0 +1,47 @@ +#define _POSIX_C_SOURCE 200809L +#define BUFFER_SIZE 1024 +#define STRING_BUFFER_SIZE 32 + +#include +#include +#include +#include + +// Helps to match a string (excludes blanks and special characters) +int is_char(char c) +{ + return c != '\0' && !isblank(c) && c != ':' && c != '=' && c != '#'; +} + +int main(int argc, char **argv) +{ + // Open file + FILE *stream = fopen(argv[1], "r"); + if (stream == 0) + errx(1, "Could not open file"); + + // Allocate buffer + size_t buf_size = BUFFER_SIZE; + char *buf = malloc(sizeof(char) * buf_size); + if (buf == NULL) + errx(1, "Could not allocate more memory"); + + // Read + ssize_t nread; + while ((nread = getline(&buf, &buf_size, stream)) != -1) + { + int i = 0; + // Skip blanks + while (i < nread && isblank(buf[i])) + i++; + + // Read target name + size_t str_buf_size = STRING_BUFFER_SIZE; + char *str_buf = malloc(sizeof(char) * str_buf_size); + while (is_char(buf[i])) + { + } + + // Read deps + } +} diff --git a/microshell/a.out b/microshell/a.out deleted file mode 100755 index a27d743..0000000 Binary files a/microshell/a.out and /dev/null differ diff --git a/microshell/microshell.c b/microshell/microshell.c index 72dbf99..4a7b661 100644 --- a/microshell/microshell.c +++ b/microshell/microshell.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,21 +7,24 @@ int main(int argc, char **argv) { if (argc < 2) - errx(1, "Not enough args"); + err(1, "Not enough args"); int id = fork(); if (id < 0) - errx(1, "Cannot fork"); + err(1, "Cannot fork"); if (id == 0) { int res = 0; wait(&res); + // printf("%d\n", res); return res; } else { int res = execl("/bin/sh", "supershell", "-c", argv[1], NULL); - exit(res); + printf("process exit status: %d\n", res); + // exit(res); + return res; } }