This commit is contained in:
Guillem George 2025-10-23 19:03:00 +02:00
parent 62ece126f9
commit eac570d6f5
4 changed files with 56 additions and 3 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
a.out
*.o

47
micromake/src/micromake.c Normal file
View file

@ -0,0 +1,47 @@
#define _POSIX_C_SOURCE 200809L
#define BUFFER_SIZE 1024
#define STRING_BUFFER_SIZE 32
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
// 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
}
}

Binary file not shown.

View file

@ -1,4 +1,5 @@
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
@ -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;
}
}