This commit is contained in:
2024-03-27 17:22:11 +01:00
parent a9fde3bad1
commit ffbbd564f9
15 changed files with 133 additions and 142 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
/* Updated: 2024/03/27 14:59:17 by tomoron ### ########.fr */ /* Updated: 2024/03/27 16:25:53 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ int cmd_is_builtin(t_msh *msh, char *cmd_token)
} }
else if (!ft_strcmp(cmd_token, "exit")) else if (!ft_strcmp(cmd_token, "exit"))
{ {
exit_bt(msh); g_return_code = exit_bt(msh);
return (1); return (1);
} }
else if (!ft_strcmp(cmd_token, "export")) else if (!ft_strcmp(cmd_token, "export"))

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
/* Updated: 2024/03/27 16:20:06 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:01:49 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,10 +71,9 @@ char **get_cmd_args(t_msh *msh)
if (cur_cmd->type == ARG) if (cur_cmd->type == ARG)
{ {
if (!i) if (!i)
cmd_args[i] = remove_path(cur_cmd->value); cmd_args[i++] = remove_path(cur_cmd->value);
else else
cmd_args[i] = cur_cmd->value; cmd_args[i++] = cur_cmd->value;
i++;
} }
else else
cur_cmd = cur_cmd->next; cur_cmd = cur_cmd->next;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */
/* Updated: 2024/03/27 16:21:14 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:20:40 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,7 +47,7 @@ int echo(t_token *args)
if (!args->value[i]) if (!args->value[i])
put_nl = 0; put_nl = 0;
else else
ft_printf("%s ",args->value); ft_printf("%s ", args->value);
args = args->next; args = args->next;
} }
put_args(args); put_args(args);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/03/27 14:49:53 by tomoron ### ########.fr */ /* Updated: 2024/03/27 16:52:02 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,31 +66,17 @@ void exec_command(t_msh *msh, int i, int cmd_count)
remove_command_from_msh(msh); remove_command_from_msh(msh);
} }
void exec_commands(t_msh *msh) void end_execution(t_msh *msh, int cmd_count)
{ {
int cmd_count;
int i; int i;
int status; int status;
i = -1;
if (!msh->cmds)
return ;
cmd_count = get_cmd_count(msh->cmds);
msh->fds = ft_calloc(cmd_count, sizeof(int **));
msh->pids = ft_calloc(cmd_count, sizeof(int *));
if (!msh->pids || !msh->fds)
ft_exit(msh, 1);
while (++i < cmd_count)
exec_command(msh, i, cmd_count);
i = 0; i = 0;
while (i < cmd_count) while (i < cmd_count)
{ waitpid(msh->pids[i++], &status, 0);
waitpid(msh->pids[i], &status, 0);
i++;
}
if (!g_return_code && WIFEXITED(status)) if (!g_return_code && WIFEXITED(status))
g_return_code = WEXITSTATUS(status); g_return_code = WEXITSTATUS(status);
if(WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT) if (WIFSIGNALED(status) && WTERMSIG(status) == SIGQUIT)
printf("Quit (core dumped)\n"); printf("Quit (core dumped)\n");
i = 0; i = 0;
while (i < cmd_count) while (i < cmd_count)
@ -107,3 +93,21 @@ void exec_commands(t_msh *msh)
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
set_echoctl(0); set_echoctl(0);
} }
void exec_commands(t_msh *msh)
{
int cmd_count;
int i;
i = -1;
if (!msh->cmds)
return ;
cmd_count = get_cmd_count(msh->cmds);
msh->fds = ft_calloc(cmd_count, sizeof(int **));
msh->pids = ft_calloc(cmd_count, sizeof(int *));
if (!msh->pids || !msh->fds)
ft_exit(msh, 1);
while (++i < cmd_count)
exec_command(msh, i, cmd_count);
end_execution(msh, cmd_count);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
/* Updated: 2024/03/27 15:35:57 by tomoron ### ########.fr */ /* Updated: 2024/03/27 16:24:45 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,7 +33,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code)
*exit_code = g_return_code; *exit_code = g_return_code;
} }
void exit_bt(t_msh *msh) int exit_bt(t_msh *msh)
{ {
t_token *cur_cmd; t_token *cur_cmd;
int exit_code; int exit_code;
@ -43,10 +43,7 @@ void exit_bt(t_msh *msh)
ft_printf("exit\n"); ft_printf("exit\n");
if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG if (cur_cmd && cur_cmd->next && cur_cmd->next->type == ARG
&& ft_strisnbr(cur_cmd->value)) && ft_strisnbr(cur_cmd->value))
{
ft_putstr_fd("minishell: exit: too many arguments\n", 2); ft_putstr_fd("minishell: exit: too many arguments\n", 2);
g_return_code = 1;
}
else else
{ {
get_exit_bt_return_code(msh, &exit_code); get_exit_bt_return_code(msh, &exit_code);
@ -62,4 +59,5 @@ void exit_bt(t_msh *msh)
free_msh(msh); free_msh(msh);
exit(exit_code); exit(exit_code);
} }
return (1);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
/* Updated: 2024/03/27 14:57:44 by tomoron ### ########.fr */ /* Updated: 2024/03/27 16:55:22 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ void print_env_declare(t_env *env)
{ {
if (strcmp(env->name, "_")) if (strcmp(env->name, "_"))
{ {
if(*(env->value)) if (*(env->value))
printf("declare -x %s=\"%s\"\n", env->name, env->value); printf("declare -x %s=\"%s\"\n", env->name, env->value);
else else
printf("declare -x %s\n", env->name); printf("declare -x %s\n", env->name);
@ -27,22 +27,18 @@ void print_env_declare(t_env *env)
} }
} }
int check_var_name(char *name) int export_invalid_identifier(char *arg, char *name)
{ {
if (ft_isdigit(*name) || !*name) ft_putstr_fd("minishell: export: `", 2);
return (0); ft_putstr_fd(arg, 2);
while (*name) ft_putstr_fd("': not a valid identifier\n", 2);
{ free(name);
if (!ft_isalnum(*name) && *name != '_')
return (0);
name++;
}
return (1); return (1);
} }
int ft_export(t_msh *msh) int ft_export(t_msh *msh)
{ {
t_cmd *cmd; t_token *cmd;
char *arg; char *arg;
char *name; char *name;
char *value; char *value;
@ -60,13 +56,7 @@ int ft_export(t_msh *msh)
len++; len++;
name = ft_substr(arg, 0, len); name = ft_substr(arg, 0, len);
if (!name || !check_var_name(name)) if (!name || !check_var_name(name))
{ return (export_invalid_identifier(arg, name));
ft_putstr_fd("minishell: export: `", 2);
ft_putstr_fd(arg, 2);
ft_putstr_fd("': not a valid identifier\n", 2);
free(name);
return (1);
}
if (arg[len]) if (arg[len])
len++; len++;
value = ft_strdup(arg + len); value = ft_strdup(arg + len);
@ -102,7 +92,7 @@ void delete_from_env(t_msh *msh, char *name)
int ft_unset(t_msh *msh) int ft_unset(t_msh *msh)
{ {
t_cmd *cmd; t_token *cmd;
cmd = msh->cmds; cmd = msh->cmds;
if (cmd) if (cmd)

View File

@ -6,17 +6,22 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
/* Updated: 2024/03/27 15:56:11 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:18:03 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
t_cmd *cmd_add_back(t_token *cmd, char *value, t_token_type type) t_token *cmd_add_back(t_token *cmd, char *value, t_token_type type)
{ {
t_cmd *res; t_token *res;
t_cmd *current; t_token *current;
if (value && !*value)
{
free(value);
return (cmd);
}
res = ft_calloc(1, sizeof(t_token)); res = ft_calloc(1, sizeof(t_token));
if (!res) if (!res)
return (cmd); return (cmd);
@ -31,7 +36,7 @@ t_cmd *cmd_add_back(t_token *cmd, char *value, t_token_type type)
return (cmd); return (cmd);
} }
void free_cmd(t_token *cmd) int free_cmd(t_token *cmd)
{ {
if (cmd) if (cmd)
{ {
@ -48,4 +53,5 @@ void free_cmd(t_token *cmd)
free(cmd); free(cmd);
cmd = 0; cmd = 0;
} }
return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/03/27 15:05:42 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:02:16 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,39 +71,11 @@ t_env *get_env(char **envp)
return (env); return (env);
} }
void print_binary(unsigned int num)
{
int size;
int i;
if (num == 0)
{
printf("0");
return ;
}
//Tom qu'est-ce que t'a fait ?????
// Taille d'un unsigned int en bits
size = sizeof(unsigned int) * 8;
// Parcours de chaque bit de droite à gauche
for (i = size - 1; i >= 0; i--)
{
// Vérifie si le bit est 1 ou 0
if (num & (1u << i))
printf("1");
else
printf("0");
}
}
int init_minishell(t_msh **msh, int argc, char **argv, char **envp) int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
{ {
struct termios t_p; struct termios t_p;
*msh = ft_calloc(1, sizeof(t_msh)); ft_exit(*msh, 1);
if (!*msh)
ft_exit(*msh, 1);
(void)argc; (void)argc;
(void)argv; (void)argv;
(*msh)->env = get_env(envp); (*msh)->env = get_env(envp);
@ -111,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(*msh)->echoctl = t_p.c_lflag & ECHOCTL; (*msh)->echoctl = t_p.c_lflag & ECHOCTL;
signal(SIGINT, signal_handler_interactive); signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
if(set_echoctl(0)) if (set_echoctl(0))
ft_exit(*msh, 1); ft_exit(*msh, 1);
return (0); return (0);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/03/27 15:24:41 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:20:14 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,7 +52,7 @@ typedef struct s_env
typedef struct s_msh typedef struct s_msh
{ {
struct s_env *env; struct s_env *env;
struct s_cmd *cmds; struct s_token *cmds;
int **fds; int **fds;
int *pids; int *pids;
enum e_token_type in_type; enum e_token_type in_type;
@ -66,10 +66,10 @@ typedef struct s_msh
extern int g_return_code; extern int g_return_code;
t_token *cmd_add_back(t_token *res, char *token, t_token_type type); t_token *cmd_add_back(t_token *res, char *token, t_token_type type);
void free_cmd(t_token *cmd); int free_cmd(t_token *cmd);
void exec_commands(t_msh *msh); void exec_commands(t_msh *msh);
int echo(t_token *args); int echo(t_token *args);
void exit_bt(t_msh *msh); int exit_bt(t_msh *msh);
t_env *env_add_back(t_env *env, char *name, char *value); t_env *env_add_back(t_env *env, char *name, char *value);
void free_env(t_env *env); void free_env(t_env *env);
int print_env(t_env *env); int print_env(t_env *env);
@ -118,5 +118,7 @@ char *get_tmp_file_name(t_msh *msh);
int contains_newline(char *str); int contains_newline(char *str);
void parse_var(t_msh *msh, char *line); void parse_var(t_msh *msh, char *line);
int set_echoctl(int value); int set_echoctl(int value);
int add_return_code_to_str(char *res);
int parsing_syntax_error(t_token *res);
#endif #endif

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
/* Updated: 2024/03/24 08:50:11 by marde-vr ### ########.fr */ /* Updated: 2024/03/27 17:20:20 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
@ -47,10 +47,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
if (**cmd == '\'' && !*in_dquote) if (**cmd == '\'' && !*in_dquote)
*in_quote = !*in_quote; *in_quote = !*in_quote;
if (**cmd == '$' && !*in_quote) if (**cmd == '$' && !*in_quote)
{
(*cmd)++;
i += add_var_to_str(res + i, cmd, env); i += add_var_to_str(res + i, cmd, env);
}
else if (**cmd == '~' && !*in_quote && !*in_dquote) else if (**cmd == '~' && !*in_quote && !*in_dquote)
i += add_home_to_str(res + i); i += add_home_to_str(res + i);
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
@ -86,12 +83,12 @@ t_token_type get_token_type(char **command)
return (res); return (res);
} }
t_cmd *parse_command(char *command, t_env *env) t_token *parse_command(char *command, t_env *env)
{ {
int in_quote; int in_quote;
int in_dquote; int in_dquote;
t_cmd *res; t_token *res;
char *token; char *value;
t_token_type type; t_token_type type;
in_quote = 0; in_quote = 0;
@ -101,26 +98,16 @@ t_cmd *parse_command(char *command, t_env *env)
{ {
type = get_token_type(&command); type = get_token_type(&command);
if (type == ARG) if (type == ARG)
token = get_token(&command, &in_quote, &in_dquote, env); value = get_token(&command, &in_quote, &in_dquote, env);
else else
token = 0; value = 0;
if (type == ARG && token == 0) if (type == ARG && value == 0)
{ return (free_cmd(res));
free_cmd(res); res = cmd_add_back(res, value, type);
return (0);
}
if (token && !*token)
free(token);
else
res = cmd_add_back(res, token, type);
while (ft_isspace(*command)) while (ft_isspace(*command))
command++; command++;
} }
if (command && (in_quote || in_dquote)) if (command && (in_quote || in_dquote))
{ return (parsing_syntax_error(res));
free_cmd(res);
ft_putstr_fd("minishell: syntax error\n", 2);
return (0);
}
return (res); return (res);
} }

View File

@ -6,10 +6,8 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */ /* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
/* Updated: 2024/03/27 15:01:00 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:20:51 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
/* Updated: 2024/03/05 17:29:06 by marde-vr ### ########.fr */ /* Updated: 2024/03/27 17:09:50 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -72,20 +72,11 @@ int get_token_len(char *command, t_env *env)
return (res); return (res);
} }
int add_return_code_to_str(char *res) int invalid_variable_char(char *res, char c)
{ {
char *var; res[0] = '$';
int i; res[1] = c;
return (2);
i = 0;
var = ft_itoa(g_return_code);
while (var && var[i])
{
res[i] = var[i];
i++;
}
free(var);
return (i);
} }
int add_var_to_str(char *res, char **command, t_env *env) int add_var_to_str(char *res, char **command, t_env *env)
@ -95,6 +86,7 @@ int add_var_to_str(char *res, char **command, t_env *env)
int i; int i;
i = 0; i = 0;
(*command)++;
if (**command == '\'' || **command == '"') if (**command == '\'' || **command == '"')
{ {
*res = '$'; *res = '$';
@ -102,21 +94,14 @@ int add_var_to_str(char *res, char **command, t_env *env)
return (1); return (1);
} }
if (!ft_isalnum(**command) && **command != '_' && **command != '?') if (!ft_isalnum(**command) && **command != '_' && **command != '?')
{ return (invalid_variable_char(res, **command));
res[0] = '$';
res[1] = **command;
return (2);
}
if (**command == '?') if (**command == '?')
return (add_return_code_to_str(res)); return (add_return_code_to_str(res));
var_name = get_var_name(*command); var_name = get_var_name(*command);
var = ft_get_env(env, var_name); var = ft_get_env(env, var_name);
free(var_name); free(var_name);
while (var && var[i]) while (var && var[i])
{ res[i] = var[i++];
res[i] = var[i];
i++;
}
*command += get_var_name_len(*command) - 1; *command += get_var_name_len(*command) - 1;
return (i); return (i);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/03/27 16:22:39 by tomoron ### ########.fr */ /* Updated: 2024/03/27 17:21:09 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -76,6 +76,7 @@ ags");
} }
return (0); return (0);
} }
void signal_handler_command(int signum) void signal_handler_command(int signum)
{ {
(void)signum; (void)signum;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/03/27 15:00:24 by tomoron ### ########.fr */ /* Updated: 2024/03/27 16:55:04 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,6 +31,35 @@ void ft_exit(t_msh *msh, int exit_code)
exit(exit_code); exit(exit_code);
} }
int check_var_name(char *name)
{
if (ft_isdigit(*name) || !*name)
return (0);
while (*name)
{
if (!ft_isalnum(*name) && *name != '_')
return (0);
name++;
}
return (1);
}
int add_return_code_to_str(char *res)
{
char *var;
int i;
i = 0;
var = ft_itoa(g_return_code);
while (var && var[i])
{
res[i] = var[i];
i++;
}
free(var);
return (i);
}
int file_access(t_msh *msh, int *found) int file_access(t_msh *msh, int *found)
{ {
int fd; int fd;

20
srcs/utils2.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */
/* Updated: 2024/03/27 17:19:35 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int parsing_syntax_error(t_token *res)
{
free_cmd(res);
ft_putstr_fd("minishell: syntax error\n", 2);
return (0);
}