42_minishell/include/include.h
mcolonna 8d5ccfeb82 check some TODOs
- "is t_call.argv ended by NULL?"
- "does it return the good path if there is several possibilities?"
2024-04-29 15:56:49 +02:00

90 lines
3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* include.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
/* Updated: 2024/04/29 15:56:26 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INCLUDE_H
# define INCLUDE_H
# include <stdbool.h>
# include <stdio.h>
# include <errno.h>
# include <string.h>
# include <sys/types.h>
# include <unistd.h>
# include <fcntl.h>
# include <stdlib.h>
# include <strings.h>
# include <sys/wait.h>
# include "libft.h"
# include "libtf.h"
///// ASK COMMAND /////
// Show the prompt and ask a command to the user.
// Return the command.
const char *ask_command(t_memclass mc);
///// PARSE_COMMAND /////
// 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
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;
// 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(const t_memclass mc, const char *command);
///// EXECUTE COMMAND /////
// Execute the command given. Return the exit status.
int execute_command(t_memclass mc, t_command command,
char *const envp[]);
///// ERROR /////
// Call to show an error.
// If msg == "errno", use perror()
void minishell_error(const char *msg);
// Call perror() and exit the program.
void fatal_error(const char *msg);
///// PATH /////
// Get the PATH values.
// Return a list of strings ended by NULL.
char **get_path(char *const envp[]);
// Search the program in $PATH.
// Returns the path of the program to use, or NULL if there is none.
// If there is several possibilities, it returns the one from the first path
// given in $PATH.
const char *search_path(
const t_memclass mc, const char **path, const char *prog);
///// MAIN /////
extern t_memclass g_mc;
#endif