aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
blob: 033547304d31c80194db6269ad43dbbb38014415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ast.h                                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/06/27 11:48:27 by dkaiser           #+#    #+#             */
/*   Updated: 2025/01/16 18:26:30 by dkaiser          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "debug_tools.h"
#include "stdlib.h"

enum						e_node_type
{
	PIPE_NODE,
	CMD_NODE,
	STRING_NODE
};

typedef struct s_pipe
{
	struct s_node			*left;
	struct s_node			*right;
}							t_pipe;

enum						e_redirection_type
{
	INPUT_FILE = 1,
	INPUT_LIMITER = 2,
	OUTPUT_OVERRIDE = 4,
	OUTPUT_APPEND = 8
};

typedef struct s_redirection
{
	int						type;
	char					*specifier;
}							t_redirection;

typedef struct s_cmd
{
	char					**args;
	struct s_redirection	redirs[2];
	t_list					*create_files;
}							t_cmd;

union						u_node_content
{
	struct s_pipe			pipe;
	struct s_cmd			cmd;
	char					*string;
};

typedef struct s_node
{
	int						type;
	union u_node_content	content;
}							t_node;

t_node						*new_node(int type);
t_node						*new_pipe_node(t_node *left, t_node *right);
t_node						*new_cmd_node(char **args, t_redirection redirs[2],
								t_list *create_files);
t_node						*new_string_node(char *string);

void						free_node(t_node *node);