Commit e9aa85a3 authored by abenoit's avatar abenoit
Browse files

builtins error returns added

parent 838a6616
......@@ -62,6 +62,7 @@ typedef char *(*t_parse)(t_state_machine *, char *);
/*
** check_syntax.c
*/
int parsing_error(int err_code, int *stat_loc);
int check_syntax(char *line);
/*
......
UID PID PENDING BLOCKED IGNORED CAUGHT STAT TTY TIME COMMAND
1001 2372 0000000000000000 0000000000000002 0000000000384000 0000000188013003 Ss pts/0 0:00 zsh
1001 3722 0000000000000000 0000000000000002 0000000000384000 0000000188013003 Ss pts/1 0:00 zsh
1001 3770 0000000000000000 0000000000000000 0000000000000000 0000000000010002 S+ pts/1 0:16 sh ./test.sh
1001 31878 0000000000000000 0000000000000000 0000000000000000 0000000180005007 D+ pts/0 0:00 git add .
1001 31914 0000000000000000 0000000000000000 0000000000000000 00000001f3d1fef9 R+ pts/1 0:00 ps -s
......@@ -26,6 +26,7 @@ int ft_cd(char **args, t_xe *xe)
perror("cd");
free(path);
free(oldpwd);
xe->stat_loc = 1;
return (SUCCESS); //notify failure anyway ?
}
env_replace_var("OLDPWD", oldpwd, xe);
......@@ -33,5 +34,6 @@ int ft_cd(char **args, t_xe *xe)
path = getcwd(NULL, 0);
env_replace_var("PWD", path, xe);
free(path);
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -19,5 +19,6 @@ int ft_echo(char **args, t_xe *xe)
}
if (!(options & ECHO_N_OPTION))
ft_putchar_fd('\n', STDOUT_FILENO);
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -3,6 +3,7 @@
int ft_env(char **args, t_xe *xe)
{
(void)args;
ft_printarray_fd(xe->env, STDOUT_FILENO); // change fd for pipes
ft_printarray_fd(xe->env, STDOUT_FILENO);
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -218,5 +218,6 @@ int ft_export(char **args, t_xe *xe)
if (ft_export_checks(args + 1, xe) != SUCCESS)
return (MALLOC_ERR);
}
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -8,9 +8,14 @@ int ft_pwd(char **args, t_xe *xe)
(void)xe;
buf = getcwd(NULL, 0);
if (buf == NULL)
return (FAILURE); // other code!
{
putstr_stderr("pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type\n"); // leaks si le write marche pas
xe->stat_loc = 1;
return (SUCCESS); // other code!
}
ft_putstr_fd(buf, STDOUT_FILENO);
ft_putchar_fd('\n', STDOUT_FILENO);
free(buf);
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -38,8 +38,13 @@ int ft_unset(char **args, t_xe *xe)
return (MALLOC_ERR);
}
else
{
putstr_stderr("unset: Variable identifier (name) invalid\n"); // leaks si le write marche pas
xe->stat_loc = 1;
return (SUCCESS);
}
args++;
}
xe->stat_loc = 0;
return (SUCCESS);
}
......@@ -53,7 +53,7 @@ static int main_loop(t_xe *xe)
if (ret == SUCCESS)
{
if ((ret = check_syntax(line)) != SUCCESS)
return (SUCCESS); // necessitates SUCCESS to avoid exiting but needs further error management
return (parsing_error(ret, &(xe->stat_loc))); // necessitates SUCCESS to avoid exiting but needs further error management
ret = handle_execution(xe, STDIN_FILENO, 0);
//printf("ret = %d\n", ret);
free(line);
......
#include "parsing.h"
int parsing_error(int err_code)
int parsing_error(int err_code, int *stat_loc)
{
const char *err_msg[NB_PARSING_ERRORS] = {
"=== no error (here for padding) ===",
......@@ -15,7 +15,8 @@ int parsing_error(int err_code)
ft_putstr_fd("minishell: syntax error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code], STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
return (err_code);
*stat_loc = 2;
return (SUCCESS);
}
void check_others(t_byte *flags, char c)
......@@ -103,17 +104,17 @@ int check_bsl_and_quotes(t_byte *flags, char c)
int final_checks(int flags)
{
if (flags & S_BACKSL)
return (parsing_error(ESCAPE_NL));
return (ESCAPE_NL);
if (flags & S_APPEND)
return (parsing_error(REDIR_PATH_MISSING));
return (REDIR_PATH_MISSING);
if (flags & S_R_REDIR)
return (parsing_error(REDIR_PATH_MISSING));
return (REDIR_PATH_MISSING);
if (flags & S_L_REDIR)
return (parsing_error(REDIR_PATH_MISSING));
return (REDIR_PATH_MISSING);
if (flags & S_QUOTE)
return (parsing_error(SQUOTE_MISSING));
return (SQUOTE_MISSING);
if (flags & S_DQUOTE)
return (parsing_error(DQUOTE_MISSING));
return (DQUOTE_MISSING);
return (SUCCESS);
}
......@@ -136,7 +137,7 @@ int check_syntax(char *line)
{
ret = check_bsl_and_quotes(&flags, line[i]);
if (ret != SUCCESS)
return (parsing_error(ret));
return (ret);
i++;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment