minimake/micromake/src/micromake.c

48 lines
1.1 KiB
C
Raw Normal View History

2025-10-23 19:03:00 +02:00
#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
}
}