42_minishell/include/parse_command.h
2024-06-27 14:53:45 +02:00

49 lines
2.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
/* Updated: 2024/06/27 13:47:56 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_COMMAND_H
# define PARSE_COMMAND_H
# include "include.h"
// Represents a call to a program (the program name and its arguments)
typedef struct s_call
{
const char *program; // path of the program to call.
int argc; // number of arguments given
char *const *argv; // arguments given (ended by NULL)
// (argc and argv must include the program name)
} t_call;
// Represents a command given by the user.
typedef struct s_command
{
int error; // 0 if parse_command() succeded, error status if not
bool empty; // true if there isn't anything to do
const t_call *calls; // all calls to programs (ended by .program == NULL)
int input_fd; // fd to use with '<' redirection (0 by default)
int output_fd; // fd to use with '>' redirection (1 by default)
} t_command;
// An element of a list of pipes
typedef struct s_pipes
{
int pipe[2]; // Simple pipe, we write on pipe[1] and we read on pipe[0]
} t_pipes;
// Return the t_command representing the command given by the user.
// If error, return a t_command wth the value .error = true.
t_command parse_command(t_env *env, const char *command);
const char *variables_get(t_list *variables, const char *name);
#endif