JUSTOCASOUUUU

This commit is contained in:
Gu://em_ 2025-10-31 22:31:08 +01:00
parent a8ca407247
commit 1efc35a59e
9 changed files with 70 additions and 29 deletions

View file

@ -21,10 +21,10 @@ $(TARGET): $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
@echo $(OBJS)
debug: CFLAGS += $(DBG_CFLAGS)
debug: LDFLAGS += $(DBG_LDFLAGS)
debug: $(OBJS)
$(CC) -o $(TARGET) $^ $(LDFLAGS) $(LDLIBS)
# debug: CFLAGS += $(DBG_CFLAGS)
# debug: LDFLAGS += $(DBG_LDFLAGS)
# debug: $(OBJS)
# $(CC) -o $(TARGET) $^ $(LDFLAGS) $(LDLIBS)
check:
dash ./tests/run.sh

View file

@ -3,11 +3,12 @@
#define _XOPEN_SOURCE 500
#include "../lists/lists.h"
#include <sys/types.h>
char* get_makefile(struct list *files);
ssize_t get_file_lastmodiftime(char* filename);
#include "../lists/lists.h"
char *get_makefile(struct list *files);
ssize_t get_file_lastmodiftime(char *filename);
int run_command(char *command);
int file_exists(char *filename);

View file

@ -24,7 +24,7 @@ struct hash_map
size_t hash(const char *str);
struct hash_map *hashmap_init(size_t size);
bool hashmap_insert(struct hash_map *hash_map, char *key, void *value,
bool *updated);
bool *updated);
void hashmap_free(struct hash_map *hash_map);
void hashmap_dump(struct hash_map *hash_map);
void *hashmap_get(const struct hash_map *hash_map, char *key);

View file

@ -219,3 +219,45 @@ size_t read_declaration(struct line *line, size_t index, char **word)
*word = res;
return i - index;
}
// Takes a string, expands its variables and returns the resulting buffer
// WARNING allocates the result on the heap, free result after use
char *expand_str(char *str)
{
size_t str_i = 0;
size_t buf_i = 0;
size_t buf_size = BUFFER_SIZE;
char *buf = malloc(BUFFER_SIZE * sizeof(char));
while (str[str_i] != '\0')
{
// Reallocate more space if necessary
resize_buf(&buf, buf_size, buf_i);
// Expand variable
if (buf[buf_i] == '$')
{
// Temporary variables
char *expanded_var;
char *tmp_res_buf;
struct line false_line = {
.buffer = buf, .file_stream = NULL, .length = 0, .number = 0
};
str_i += expand_variable(&false_line, str_i + 1, &expanded_var);
buf_size = append_str(buf, expanded_var, buf_i, &tmp_res_buf);
// Replace buf with buf + expanded_variable
buf_i = strlen(tmp_res_buf);
free(buf);
// free(expanded_var);
buf = tmp_res_buf;
continue;
}
buf[buf_i] = str[str_i];
buf_i++;
str_i++;
}
buf[buf_i] = '\0';
return buf;
}

View file

@ -4,25 +4,25 @@
#define STRING_BUFFER_SIZE 32
#include <stddef.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/types.h>
// Holds line information
// Exists only because of EPITA's annoying 4 parameters limit
// WARNING buffer must be freed after use
struct line
{
char* buffer; // Line content
ssize_t length; // Line length
size_t number; // Line number in file
FILE* file_stream; // Full file stream
char *buffer; // Line content
ssize_t length; // Line length
size_t number; // Line number in file
FILE *file_stream; // Full file stream
};
int ischar(char c);
int isblankline(struct line *l);
int skipblanks(char *buf, size_t buf_len);
size_t readword(char *buf, size_t buf_len, char **word);
size_t resize_buf(char** buf, size_t buf_size, size_t index);
size_t resize_buf(char **buf, size_t buf_size, size_t index);
char *insert_str(char *base, char *str, size_t index);
size_t read_declaration(struct line *line, size_t index, char **word);
size_t append_str(char *base, char *str, size_t index, char **res);

View file

@ -1 +0,0 @@
list.c

View file

@ -1,11 +1,11 @@
#ifndef LIST_H
#define LIST_H
#ifndef LISTS_H
#define LISTS_H
#include <stddef.h>
struct list
{
void* data;
void *data;
struct list *next;
};
@ -13,7 +13,7 @@ struct list
** Insert a node containing `value` at the beginning of the list.
** Return `NULL` if an error occured.
*/
struct list *list_prepend(struct list *list, void* value);
struct list *list_prepend(struct list *list, void *value);
/*
** Return the lenght of the list.
@ -44,7 +44,7 @@ void list_deep_destroy(struct list *l);
** Return `NULL` if an error occured.
*/
// START PROTO list_append
struct list *list_append(struct list *list, void* value);
struct list *list_append(struct list *list, void *value);
// END PROTO list_append
/*
@ -54,7 +54,7 @@ struct list *list_append(struct list *list, void* value);
** Return `NULL` if an error occured.
*/
// START PROTO list_insert
struct list *list_insert(struct list *list, void* value, size_t index);
struct list *list_insert(struct list *list, void *value, size_t index);
// END PROTO list_insert
/*
@ -70,7 +70,7 @@ struct list *list_remove(struct list *list, size_t index);
** Return `-1` if nothing is found.
*/
// START PROTO list_find
int list_find(struct list *list, void* value);
int list_find(struct list *list, void *value);
// END PROTO list_find
/*
@ -107,4 +107,4 @@ int list_find(struct list *list, void* value);
// struct list *list_split(struct list *list, size_t index);
// END PROTO list_split
#endif /* ! LIST_H */
#endif /* ! LISTS_H */

View file

@ -466,12 +466,11 @@ static int run_rule(struct rule *rule)
struct list *commands = rule->recipe;
struct list *dependencies = rule->dependencies;
// Expand dependencies variables
// TODO
// Build dependencies
while (dependencies != NULL)
{
// Expand variables
// Check file existence
if (!file_exists(dependencies->data))
{

View file

@ -18,8 +18,8 @@
#include <stdio.h>
#include <sys/types.h>
#include "lists/lists.h"
#include "lines/lines.h"
#include "lists/lists.h"
// Holds variable information
// WARNING its values must be freed after use
@ -33,12 +33,12 @@ struct variable
// WARNING its values must be freed after use
struct rule
{
char* name;
char *name;
struct list *dependencies;
struct list *recipe;
};
int make(char *path, struct list* rules, char *argv0, int flags);
int make(char *path, struct list *rules, char *argv0, int flags);
void make_parse(char *path);
int make_run(struct list *rules);
void drop(int status, char *format, ...);