mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
parse-cmd: A very basic skeleton of functions to come
This commit is contained in:
parent
f490cc22f5
commit
5f95751b36
3 changed files with 105 additions and 6 deletions
|
|
@ -6,13 +6,14 @@
|
||||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/28 14:55:31 by khais #+# #+# */
|
/* Created: 2025/03/28 14:55:31 by khais #+# #+# */
|
||||||
/* Updated: 2025/03/28 16:42:57 by jguelen ### ########.fr */
|
/* Updated: 2025/04/04 16:05:25 by jguelen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MINISHELL_H
|
#ifndef MINISHELL_H
|
||||||
# define MINISHELL_H
|
# define MINISHELL_H
|
||||||
|
|
||||||
|
# include "libft.h"
|
||||||
# include "env/env.h"
|
# include "env/env.h"
|
||||||
# include "parser/wordlist/wordlist.h"
|
# include "parser/wordlist/wordlist.h"
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
|
|
@ -115,6 +116,7 @@ typedef struct s_simple_cmd
|
||||||
typedef struct s_minishell
|
typedef struct s_minishell
|
||||||
{
|
{
|
||||||
t_env *env;
|
t_env *env;
|
||||||
|
int lines_read;
|
||||||
int last_return_value;
|
int last_return_value;
|
||||||
} t_minishell;
|
} t_minishell;
|
||||||
|
|
||||||
|
|
|
||||||
79
src/parser/cmd_parsing.c
Normal file
79
src/parser/cmd_parsing.c
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cmd_parsing.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||||
|
/* Updated: 2025/04/04 18:21:17 by jguelen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cmd_parsing.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** NOTE: Tjis file will temporarily include way more fucntions than allowed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void parse_error(t_minishell *app, t_worddesc *token)
|
||||||
|
{
|
||||||
|
ft_dprintf(STDERR_FILENO, "minishell: syntax error near unexpected "
|
||||||
|
"token `%s'", token->word);
|
||||||
|
app->last_return_value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
t_connector which_connector_type(t_worddesc *token)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** TODO Recheck error cases to see if allocation error occurred or something
|
||||||
|
** else and if this is necessary.
|
||||||
|
*/
|
||||||
|
t_cmd *minishell_parse(t_minishell *app, char *command_line)
|
||||||
|
{
|
||||||
|
t_cmd_builder builder;
|
||||||
|
t_cmd *root_cmd;
|
||||||
|
|
||||||
|
builder.tokens = minishell_wordsplit(command_line);
|
||||||
|
root_cmd = minishell_cmds_parse(app, &builder);
|
||||||
|
if (!root_cmd || builder.tokens)
|
||||||
|
{
|
||||||
|
parse_error(app, builder.tokens->word);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (root_cmd);
|
||||||
|
}
|
||||||
|
|
@ -3,16 +3,18 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* cmd_parsing.h :+: :+: :+: */
|
/* cmd_parsing.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */
|
/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */
|
||||||
/* Updated: 2025/03/28 18:55:00 by jguelen ### ########.fr */
|
/* Updated: 2025/04/04 18:25:25 by jguelen ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CMD_PARSING_H
|
||||||
|
# define CMD_PARSING_H
|
||||||
|
|
||||||
# include "../minishell.h"
|
# include "../minishell.h"
|
||||||
|
|
||||||
//TODO
|
|
||||||
typedef struct s_cmd_builder
|
typedef struct s_cmd_builder
|
||||||
{
|
{
|
||||||
t_wordlist *tokens;
|
t_wordlist *tokens;
|
||||||
|
|
@ -23,4 +25,20 @@ typedef struct s_cmd_builder
|
||||||
** last_here_doc is meant to store only one entry.
|
** last_here_doc is meant to store only one entry.
|
||||||
*/
|
*/
|
||||||
t_redirectee *last_here_doc;
|
t_redirectee *last_here_doc;
|
||||||
}
|
} t_cmd_builder;
|
||||||
|
|
||||||
|
void parse_error(t_minishell *app, t_worddesc *token);
|
||||||
|
t_cmd *minishell_parse(t_minishell *app, char *command_line);
|
||||||
|
|
||||||
|
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
t_cmd *minishell_simple_lst_parse(t_minishell *app, t_cmd_builder *builder);
|
||||||
|
|
||||||
|
t_connector which_connector_type(t_worddesc *token);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue