Commit 6c9945c9 authored by pêle-mêle's avatar pêle-mêle
Browse files

exit arguments

parent 556668eb
......@@ -62,6 +62,7 @@ enum e_retcode
INVALID_CD_PATH,
INVALID_CD_NEW_PATH,
INVALID_PWD_PATH,
INVALID_PATH_DIR,
FD_ERROR,
_EXEC_ERROR_,
AMBIG_REDIR,
......
......@@ -6,7 +6,7 @@
# By: mvidal-a <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/12/23 13:17:34 by mvidal-a #+# #+# #
# Updated: 2021/01/27 11:54:52 by mvidal-a ### ########.fr #
# Updated: 2021/02/02 15:56:28 by mvidal-a ### ########.fr #
# #
# **************************************************************************** #
......@@ -75,6 +75,7 @@ SRCS_CUSTOM += strjoin_free.c
SRCS_CUSTOM += ft_varnamelen.c
SRCS_CUSTOM += blank_str.c
SRCS_CUSTOM += push_int_to_array.c
SRCS_CUSTOM += ft_isnumber.c
VPATH = part_1:part_2:bonus:custom
......
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isnumber.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/02 15:55:50 by mvidal-a #+# #+# */
/* Updated: 2021/02/02 16:14:16 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isnumber(char *str)
{
while (ft_isspace(*str))
str++;
while (!ft_isspace(*str) && *str != '\0')
{
if (!ft_isdigit(*str))
return (FALSE);
str++;
}
return (TRUE);
}
......@@ -6,7 +6,7 @@
/* By: mvidal-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/04 12:29:06 by mvidal-a #+# #+# */
/* Updated: 2021/01/31 19:00:44 by mvidal-a ### ########.fr */
/* Updated: 2021/02/02 15:56:12 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -107,6 +107,7 @@ int ft_isspace(int c);
int blank_str(char *line);
int ft_isset(char c, char *set);
int ft_strcmp(const char *s1, const char *s2);
int ft_isnumber(char *str);
char *strjoin_free(char *s1, char const *s2);
void *ft_lstshift(t_list **lst);
......
============= Resolu ? yessss
"exit 42" doit exit en renvoyant 42
"exit fds" -> exit 2 after 'bad exit return code' error
"exit 42 1431" -> print "exit" before error
......@@ -14,6 +10,8 @@ CTRL-D apres avoir ecrit un debut de cmd
"cat | exit"======>ne devrait pas exit
"> a" boucle inf
masaki:
......
#include "execution.h"
#include "builtins.h"
#include <string.h>
#include <string.h>// dans un header
static int launch_exit(char **args, t_xe *xe)
{
if (args != NULL)
if (args != NULL) // necessaire?
{
if (ft_arraylen(args) > 2)
return (EXIT_ARG_ERR);
if (args[1] != NULL)
xe->stat_loc = ft_atoi(args[1]) % 256;
{
if (ft_isnumber(args[1]) == TRUE)
{
if (args[2] != NULL)
{
xe->stat_loc = 1;
return (EXIT_ARG_ERR);
}
xe->stat_loc = ft_atoi(args[1]) % 256;
}
else // "exit NaN"
{
xe->stat_loc = 2;
return (FT_EXIT);//another error, to print like bash
}
}
else
xe->stat_loc = 0;
}
......@@ -20,7 +34,6 @@ static int search_path(DIR *dirp, char *name)
{
struct dirent *buf;
errno = 0; // to distinguish the NULL ret value: end of stream, or error
buf = readdir(dirp);
while (buf != NULL)
{
......@@ -28,8 +41,6 @@ static int search_path(DIR *dirp, char *name)
return (SUCCESS);
buf = readdir(dirp);
}
if (errno != 0)
;//error
return (FAILURE);
}
......@@ -46,11 +57,11 @@ int search_exec(char **path, char *name)
if (search_path(dirp, name) == SUCCESS)
{
if (closedir(dirp) == ERROR)
;//error
return (INVALID_PATH_DIR);
return (i);
}
if (closedir(dirp) == ERROR)
;//error
return (INVALID_PATH_DIR);
}
i++;
}
......
......@@ -57,6 +57,7 @@ static int err_output(int err_code)
"cd: cannot change directory",
"cd: cannot set variable PWD",
"pwd: cannot get current directory path",
"Error reading a directory in PATH",
"fd"};
ft_putstr_fd("error: ", STDERR_FILENO);
......
Markdown is supported
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