From c4c8ca8bf13383d2ebc8fb3dae95eb2a170e9c5a Mon Sep 17 00:00:00 2001 From: adjoly Date: Sun, 19 May 2024 14:21:03 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=93=9D=E3=80=8D=20doc:=20Added?= =?UTF-8?q?=20doc=20in=20.h=20for=20parsing=20and=20tokenizer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/parsing.h | 16 +++++++++-- include/prompt.h | 39 ++++++++++++++++++++++++++ include/tokenizer.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 include/prompt.h create mode 100644 include/tokenizer.h diff --git a/include/parsing.h b/include/parsing.h index e5fc7c9..b24a40a 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ -/* Updated: 2024/05/18 20:50:05 by adjoly ### ########.fr */ +/* Updated: 2024/05/19 13:45:01 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,7 @@ # define PARSING_H # include "libft.h" - -# define HEREDOC_FD -2 +# include "tokenizer.h" typedef struct s_cmd { @@ -25,7 +24,18 @@ typedef struct s_cmd int outfile; } t_cmd; +/** + * @brief Take the argv of a command a split the argv and the command it self + * + * @param The full argv of the command + * + * @return (t_cmd *) cmd and argv splited into a struct + */ t_cmd *split_cmd(char *cmd_av); + +/* + * @deprecated + */ t_list *split_pipe(char *readline); #endif diff --git a/include/prompt.h b/include/prompt.h new file mode 100644 index 0000000..3452ad4 --- /dev/null +++ b/include/prompt.h @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* prompt.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/19 13:48:05 by adjoly #+# #+# */ +/* Updated: 2024/05/19 14:20:45 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PROMPT_H +# define PROMPT_H + +/** + * @brief return the short hostname from /etc/hostname + * or return nixos if file doesn't exist or is empty + * + * @return (char *) The short hostname + */ +char *get_hostname(void); + +/** + * @brief return the pwd (from the env), and if in home put a ~ + * replacing the home directory + * + * @return (char *) the pwd + */ +char *get_pwd(void); + +/** + * @brief return the full prompt + * + * @prompt (char *) the prompt + */ +char *get_prompt(void); + +#endif diff --git a/include/tokenizer.h b/include/tokenizer.h new file mode 100644 index 0000000..fcbcf53 --- /dev/null +++ b/include/tokenizer.h @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* tokenizer.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */ +/* Updated: 2024/05/19 14:02:58 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TOKENIZER_H +# define TOKENIZER_H + +# include "libft.h" +# include + +typedef enum s_redirection_sign +{ + HEREDOC, + INFILE, + OUTFILE, + OUT_APPEND, +} t_redirection_sign; + +typedef struct s_redirection +{ + char *file_name; + t_redirection_sign sign; +} t_redirection; + +typedef struct s_token +{ + char *argv; + t_list *redirection; +} t_token; + +/** + * @brief Convert the raw command into a t_token that contains the argv of the command an a linked list of redirection + * + * @param cmd A string that containt the command to tokenize + * + * @return (t_token *) The tokenized version of the command + * + */ +t_token *__to_token(char *cmd); + +/** + * @brief ** + * + * @param + * + * @return () + * + */ + +/** + * @brief Convert the readline output, split all command and put it in linked list of t_token (given by t_token function) + * + * @param readline The readline output + * + * @return (t_list *) Linked list of t_token + * + */ +t_list *tokenizer(char *readline); + +#endif