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,11 +3,12 @@
|
||||||
|
|
||||||
#define _XOPEN_SOURCE 500
|
#define _XOPEN_SOURCE 500
|
||||||
|
|
||||||
#include "../lists/lists.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
char* get_makefile(struct list *files);
|
#include "../lists/lists.h"
|
||||||
ssize_t get_file_lastmodiftime(char* filename);
|
|
||||||
|
char *get_makefile(struct list *files);
|
||||||
|
ssize_t get_file_lastmodiftime(char *filename);
|
||||||
int run_command(char *command);
|
int run_command(char *command);
|
||||||
int file_exists(char *filename);
|
int file_exists(char *filename);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,25 +4,25 @@
|
||||||
#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
|
||||||
// WARNING buffer must be freed after use
|
// WARNING buffer must be freed after use
|
||||||
struct line
|
struct line
|
||||||
{
|
{
|
||||||
char* buffer; // Line content
|
char *buffer; // Line content
|
||||||
ssize_t length; // Line length
|
ssize_t length; // Line length
|
||||||
size_t number; // Line number in file
|
size_t number; // Line number in file
|
||||||
FILE* file_stream; // Full file stream
|
FILE *file_stream; // Full file stream
|
||||||
};
|
};
|
||||||
|
|
||||||
int ischar(char c);
|
int ischar(char c);
|
||||||
int isblankline(struct line *l);
|
int isblankline(struct line *l);
|
||||||
int skipblanks(char *buf, size_t buf_len);
|
int skipblanks(char *buf, size_t buf_len);
|
||||||
size_t readword(char *buf, size_t buf_len, char **word);
|
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);
|
char *insert_str(char *base, char *str, size_t index);
|
||||||
size_t read_declaration(struct line *line, size_t index, char **word);
|
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);
|
size_t append_str(char *base, char *str, size_t index, char **res);
|
||||||
|
|
|
||||||
1
minimake/src/lists/.gitignore
vendored
1
minimake/src/lists/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
list.c
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef LIST_H
|
#ifndef LISTS_H
|
||||||
#define LIST_H
|
#define LISTS_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct list
|
struct list
|
||||||
{
|
{
|
||||||
void* data;
|
void *data;
|
||||||
struct list *next;
|
struct list *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ struct list
|
||||||
** Insert a node containing `value` at the beginning of the list.
|
** Insert a node containing `value` at the beginning of the list.
|
||||||
** Return `NULL` if an error occured.
|
** 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.
|
** Return the lenght of the list.
|
||||||
|
|
@ -44,7 +44,7 @@ void list_deep_destroy(struct list *l);
|
||||||
** Return `NULL` if an error occured.
|
** Return `NULL` if an error occured.
|
||||||
*/
|
*/
|
||||||
// START PROTO list_append
|
// 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
|
// END PROTO list_append
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -54,7 +54,7 @@ struct list *list_append(struct list *list, void* value);
|
||||||
** Return `NULL` if an error occured.
|
** Return `NULL` if an error occured.
|
||||||
*/
|
*/
|
||||||
// START PROTO list_insert
|
// 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
|
// END PROTO list_insert
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -70,7 +70,7 @@ struct list *list_remove(struct list *list, size_t index);
|
||||||
** Return `-1` if nothing is found.
|
** Return `-1` if nothing is found.
|
||||||
*/
|
*/
|
||||||
// START PROTO list_find
|
// START PROTO list_find
|
||||||
int list_find(struct list *list, void* value);
|
int list_find(struct list *list, void *value);
|
||||||
// END PROTO list_find
|
// 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);
|
// 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
|
||||||
|
|
@ -33,12 +33,12 @@ struct variable
|
||||||
// WARNING its values must be freed after use
|
// WARNING its values must be freed after use
|
||||||
struct rule
|
struct rule
|
||||||
{
|
{
|
||||||
char* name;
|
char *name;
|
||||||
struct list *dependencies;
|
struct list *dependencies;
|
||||||
struct list *recipe;
|
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);
|
void make_parse(char *path);
|
||||||
int make_run(struct list *rules);
|
int make_run(struct list *rules);
|
||||||
void drop(int status, char *format, ...);
|
void drop(int status, char *format, ...);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue