JUSTOCASOUUUU
This commit is contained in:
parent
a8ca407247
commit
939a923a27
9 changed files with 70 additions and 29 deletions
|
|
@ -21,10 +21,10 @@ $(TARGET): $(OBJS)
|
||||||
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||||
@echo $(OBJS)
|
@echo $(OBJS)
|
||||||
|
|
||||||
debug: CFLAGS += $(DBG_CFLAGS)
|
# debug: CFLAGS += $(DBG_CFLAGS)
|
||||||
debug: LDFLAGS += $(DBG_LDFLAGS)
|
# debug: LDFLAGS += $(DBG_LDFLAGS)
|
||||||
debug: $(OBJS)
|
# debug: $(OBJS)
|
||||||
$(CC) -o $(TARGET) $^ $(LDFLAGS) $(LDLIBS)
|
# $(CC) -o $(TARGET) $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
dash ./tests/run.sh
|
dash ./tests/run.sh
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
#define _XOPEN_SOURCE 500
|
#define _XOPEN_SOURCE 500
|
||||||
|
|
||||||
#include "../lists/lists.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "../lists/lists.h"
|
||||||
|
|
||||||
char *get_makefile(struct list *files);
|
char *get_makefile(struct list *files);
|
||||||
ssize_t get_file_lastmodiftime(char *filename);
|
ssize_t get_file_lastmodiftime(char *filename);
|
||||||
int run_command(char *command);
|
int run_command(char *command);
|
||||||
|
|
|
||||||
|
|
@ -219,3 +219,45 @@ size_t read_declaration(struct line *line, size_t index, char **word)
|
||||||
*word = res;
|
*word = res;
|
||||||
return i - index;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
#define STRING_BUFFER_SIZE 32
|
#define STRING_BUFFER_SIZE 32
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
// Holds line information
|
// Holds line information
|
||||||
// Exists only because of EPITA's annoying 4 parameters limit
|
// Exists only because of EPITA's annoying 4 parameters limit
|
||||||
|
|
|
||||||
1
minimake/src/lists/.gitignore
vendored
1
minimake/src/lists/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
list.c
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef LIST_H
|
#ifndef LISTS_H
|
||||||
#define LIST_H
|
#define LISTS_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
@ -107,4 +107,4 @@ int list_find(struct list *list, void* value);
|
||||||
// struct list *list_split(struct list *list, size_t index);
|
// struct list *list_split(struct list *list, size_t index);
|
||||||
// END PROTO list_split
|
// END PROTO list_split
|
||||||
|
|
||||||
#endif /* ! LIST_H */
|
#endif /* ! LISTS_H */
|
||||||
|
|
|
||||||
|
|
@ -466,12 +466,11 @@ static int run_rule(struct rule *rule)
|
||||||
struct list *commands = rule->recipe;
|
struct list *commands = rule->recipe;
|
||||||
struct list *dependencies = rule->dependencies;
|
struct list *dependencies = rule->dependencies;
|
||||||
|
|
||||||
// Expand dependencies variables
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Build dependencies
|
// Build dependencies
|
||||||
while (dependencies != NULL)
|
while (dependencies != NULL)
|
||||||
{
|
{
|
||||||
|
// Expand variables
|
||||||
|
|
||||||
// Check file existence
|
// Check file existence
|
||||||
if (!file_exists(dependencies->data))
|
if (!file_exists(dependencies->data))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "lists/lists.h"
|
|
||||||
#include "lines/lines.h"
|
#include "lines/lines.h"
|
||||||
|
#include "lists/lists.h"
|
||||||
|
|
||||||
// Holds variable information
|
// Holds variable information
|
||||||
// WARNING its values must be freed after use
|
// WARNING its values must be freed after use
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue