minishell/src/parser/command_list/command_list.h

78 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:45:01 by khais #+# #+# */
/* Updated: 2025/02/25 12:43:52 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COMMAND_LIST_H
# define COMMAND_LIST_H
# include "../wordlist/wordlist.h"
# include "../pipeline/pipeline.h"
typedef enum e_operator
{
OP_INVALID,
OP_AND,
OP_OR,
} t_operator;
/*
** cf. 3.2.4 Lists of Commands
**
** A list is a sequence of one or more pipelines separated by one of the
** **operators** &&, or ||, and optionally terminated by a newline.
**
** AND and OR lists are sequences of one or more pipelines separated by the
** control operators && and ||, respectively.
**
** AND and OR lists are executed with left associativity.
**
** e.g.
**
** ```shell
** A && B && C
** ```
**
** is the same as
**
** ```shell
** (A && B) && C
** ```
**
** An AND list has the form
**
** ```shell
** A && B
** ```
**
** B is execute if and only if A has an exit status of 0 (succes).
**
** An OR list has the form
**
** ```shell
** A || B
** ```
**
** B is execute if and only if A has a non-zero exit status (failure).
**
** The return status of AND and OR lists is the exit status of the last command
** executed in the list.
*/
typedef struct s_command_list
{
t_pipeline **pipelines;
int num_pipelines;
t_operator operator;
} t_command_list;
t_command_list *command_list_from_wordlist(t_wordlist *words);
void command_list_destroy(t_command_list *cmd);
#endif // COMMAND_LIST_H