fix: now compiles and works for simple commands + clang format

This commit is contained in:
matteo 2026-01-17 19:11:55 +01:00 committed by william.valenduc
parent e9b6d39760
commit c299882586
23 changed files with 168 additions and 150 deletions

View file

@ -1,13 +1,13 @@
#ifndef AST_H
#define AST_H
#include "utils/ast/ast_and_or.h"
#include "utils/ast/ast_base.h"
#include "utils/ast/ast_command.h"
#include "utils/ast/ast_if.h"
#include "utils/ast/ast_and_or.h"
#include "utils/ast/ast_redir.h"
#include "utils/ast/ast_list.h"
#include "utils/ast/ast_end.h"
#include "utils/ast/ast_if.h"
#include "utils/ast/ast_list.h"
#include "utils/ast/ast_redir.h"
#include "utils/ast/ast_void.h"
#endif /* ! AST_H */

View file

@ -1,4 +1,5 @@
#include "utils/ast/ast_and_or.h"
#include <stdlib.h>
bool ast_is_and_or(struct ast *node)
@ -13,7 +14,8 @@ struct ast_and_or *ast_get_and_or(struct ast *node)
return NULL;
}
struct ast *ast_create_and_or(struct ast *left, struct ast *right, enum ast_and_or_type type)
struct ast *ast_create_and_or(struct ast *left, struct ast *right,
enum ast_and_or_type type)
{
struct ast_and_or *and_or = malloc(sizeof(struct ast_and_or));
if (!and_or)

View file

@ -2,14 +2,17 @@
#define AST_AND_OR_H
#include <stdbool.h>
#include "utils/ast/ast_base.h"
enum ast_and_or_type {
enum ast_and_or_type
{
AST_AND_OR_TYPE_AND,
AST_AND_OR_TYPE_OR
};
struct ast_and_or {
struct ast_and_or
{
struct ast *left;
struct ast *right;
enum ast_and_or_type type;
@ -17,7 +20,8 @@ struct ast_and_or {
bool ast_is_and_or(struct ast *node);
struct ast_and_or *ast_get_and_or(struct ast *node);
struct ast *ast_create_and_or(struct ast *left, struct ast *right, enum ast_and_or_type type);
struct ast *ast_create_and_or(struct ast *left, struct ast *right,
enum ast_and_or_type type);
void ast_free_and_or(struct ast_and_or *and_or);
#endif /* ! AST_AND_OR_H */

View file

@ -1,8 +1,8 @@
#include "utils/ast/ast_command.h"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "utils/lists/lists.h"

View file

@ -3,8 +3,8 @@
#include <stdbool.h>
#include "utils/lists/lists.h"
#include "utils/ast/ast_base.h"
#include "utils/lists/lists.h"
struct ast_command
{

View file

@ -1,8 +1,8 @@
#include "utils/ast/ast_end.h"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
bool ast_is_end(struct ast *node)
{

View file

@ -3,8 +3,8 @@
#include <stdbool.h>
#include "utils/lists/lists.h"
#include "utils/ast/ast_base.h"
#include "utils/lists/lists.h"
/**
* Checks if the given AST node is of type AST_END.

View file

@ -1,8 +1,8 @@
#include "utils/ast/ast_if.h"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
struct ast *ast_create_if(struct ast *condition, struct ast *then_clause,
struct ast *else_clause)

View file

@ -1,7 +1,7 @@
#include "utils/ast/ast.h"
#include <assert.h>
#include "utils/ast/ast.h"
struct ast *ast_create_list(struct list *list)
{
struct ast_list *ast_list = malloc(sizeof(struct ast_list));
@ -16,7 +16,7 @@ struct ast *ast_create_list(struct list *list)
struct ast_list *ast_get_list(struct ast *node)
{
assert(node != NULL);
return (struct ast_list*)node->data;
return (struct ast_list *)node->data;
}
bool ast_is_list(struct ast *node)

View file

@ -1,4 +1,5 @@
#include "utils/ast/ast_redir.h"
#include <stdlib.h>
bool ast_is_redir(struct ast *node)
@ -13,13 +14,16 @@ struct ast_redir *ast_get_redir(struct ast *node)
return NULL;
}
struct ast *ast_create_redir(struct ast *child, char *filename, int io_number, enum ast_redir_type type)
struct ast *ast_create_redir(struct ast *child, char *filename, int io_number,
enum ast_redir_type type)
{
struct ast_redir *redir = malloc(sizeof(struct ast_redir));
if (!redir)
return NULL;
redir->child = child;
redir->filename = filename; // Takes ownership? Usually yes in simple ASTs, or dup. Let's assume pointer copy for now, but user must manage memory.
redir->filename =
filename; // Takes ownership? Usually yes in simple ASTs, or dup. Let's
// assume pointer copy for now, but user must manage memory.
redir->io_number = io_number;
redir->type = type;

View file

@ -2,28 +2,33 @@
#define AST_REDIR_H
#include <stdbool.h>
#include "utils/ast/ast_base.h"
enum ast_redir_type {
AST_REDIR_TYPE_LESS, // <
AST_REDIR_TYPE_GREAT, // >
AST_REDIR_TYPE_DLESS, // <<
AST_REDIR_TYPE_DGREAT, // >>
AST_REDIR_TYPE_LESSAND, // <&
AST_REDIR_TYPE_GREATAND, // >&
AST_REDIR_TYPE_CLOBBER // >|
enum ast_redir_type
{
AST_REDIR_TYPE_LESS, // <
AST_REDIR_TYPE_GREAT, // >
AST_REDIR_TYPE_DLESS, // <<
AST_REDIR_TYPE_DGREAT, // >>
AST_REDIR_TYPE_LESSAND, // <&
AST_REDIR_TYPE_GREATAND, // >&
AST_REDIR_TYPE_CLOBBER // >|
};
struct ast_redir {
struct ast_redir
{
struct ast *child;
char *filename;
int io_number; // The FD being redirected (default -1 if not specified, implies 0 or 1 based on type)
int io_number; // The FD being redirected (default -1 if not specified,
// implies 0 or 1 based on type)
enum ast_redir_type type;
};
bool ast_is_redir(struct ast *node);
struct ast_redir *ast_get_redir(struct ast *node);
struct ast *ast_create_redir(struct ast *child, char *filename, int io_number, enum ast_redir_type type);
struct ast *ast_create_redir(struct ast *child, char *filename, int io_number,
enum ast_redir_type type);
void ast_free_redir(struct ast_redir *redir);
#endif /* ! AST_REDIR_H */

View file

@ -1,8 +1,8 @@
#include "utils/ast/ast_void.h"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
bool ast_is_void(struct ast *node)
{

View file

@ -3,8 +3,8 @@
#include <stdbool.h>
#include "utils/lists/lists.h"
#include "utils/ast/ast_base.h"
#include "utils/lists/lists.h"
/**
* Checks if the given AST node is of type AST_VOID.