NIQUE TA GROSSE MÈRE LA SALOPE PUTE PUTE -Camille Chauvet 2004/2023
This commit is contained in:
parent
1626424ed7
commit
3d66fbe9a9
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c
|
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c
|
||||||
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c
|
SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c env2.c env3.c execution.c spacer.c env_fill.c builtins/echo.c builtins/pwd.c builtins/export.c builtins/env.c builtins/cd.c builtins/exit.c
|
||||||
|
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
46
builtins/exit.c
Normal file
46
builtins/exit.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* exit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2023/02/24 12:44:05 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../minishell.h"
|
||||||
|
|
||||||
|
static int error(int err, char *reason, char *problem, int fd)
|
||||||
|
{
|
||||||
|
write(fd, "bash: exit: ", 12);
|
||||||
|
if (problem != NULL)
|
||||||
|
{
|
||||||
|
ft_putstr_fd(problem, fd);
|
||||||
|
write(fd, ": ", 2);
|
||||||
|
}
|
||||||
|
ft_putstr_fd(reason, fd);
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
return (err);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_exit(char **args, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (args[0] == NULL)
|
||||||
|
return (0);
|
||||||
|
i = -1;
|
||||||
|
if (ft_atoi_check(args[0]) == 0)
|
||||||
|
return (error(2, "numeric argument required", args[0], fd));
|
||||||
|
if (args[1] != NULL)
|
||||||
|
return (error(-1, "too many arguments", NULL, fd));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
return(ft_exit(argv + 1, 1));
|
||||||
|
}
|
@ -6,13 +6,13 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/23 17:15:13 by erey-bet ### ########.fr */
|
/* Updated: 2023/02/24 12:32:22 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../minishell.h"
|
#include "../minishell.h"
|
||||||
|
|
||||||
int error(char *str, int fd)
|
static int error(char *str, int fd)
|
||||||
{
|
{
|
||||||
write(fd, "bash: export: `", 15);
|
write(fd, "bash: export: `", 15);
|
||||||
write(fd, str, ft_strlen(str));
|
write(fd, str, ft_strlen(str));
|
||||||
|
10
minishell.h
10
minishell.h
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 13:45:30 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/23 16:46:51 by erey-bet ### ########.fr */
|
/* Updated: 2023/02/24 12:31:02 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -74,14 +74,16 @@ int echo(int fd, char **strs);
|
|||||||
/* PWD */
|
/* PWD */
|
||||||
int pwd(int fd);
|
int pwd(int fd);
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(int fd);
|
||||||
/* ENV */
|
/* Env */
|
||||||
int print_env(t_list **env, int fd);
|
int print_env(t_list **env, int fd);
|
||||||
/* EXPORT */
|
/* Export */
|
||||||
int export(t_list **env, char **args, int fd);
|
int export(t_list **env, char **args, int fd);
|
||||||
/* CD */
|
/* CD */
|
||||||
int move_folder(char *path, int fd);
|
int move_folder(char *path, int fd);
|
||||||
/* UNSET */
|
/* Unset */
|
||||||
int unset(t_list **env, char **args, int fd);
|
int unset(t_list **env, char **args, int fd);
|
||||||
|
/* Exit */
|
||||||
|
int ft_exit(char **args, int fd);
|
||||||
|
|
||||||
typedef struct s_cmd
|
typedef struct s_cmd
|
||||||
{
|
{
|
||||||
|
50
utils/ft_atoi_check.c
Normal file
50
utils/ft_atoi_check.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi_check.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/12/08 16:37:19 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
static int ft_isspace(char c)
|
||||||
|
{
|
||||||
|
if (c == ' ' || c == '\f'
|
||||||
|
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_atoi_check(const char *nptr)
|
||||||
|
{
|
||||||
|
long result;
|
||||||
|
int sign;
|
||||||
|
|
||||||
|
while (ft_isspace(*nptr))
|
||||||
|
nptr++;
|
||||||
|
sign = 1;
|
||||||
|
if (*nptr == '+' || *nptr == '-')
|
||||||
|
{
|
||||||
|
if (*nptr == '-')
|
||||||
|
sign = -1;
|
||||||
|
nptr++;
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
while (*nptr >= '0' && *nptr <= '9')
|
||||||
|
{
|
||||||
|
result = result * 10 + *nptr++ - '0';
|
||||||
|
if ((result > 2147483647 && sign == 1)
|
||||||
|
|| (result > 2147483648 && sign == -1))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (*nptr--)
|
||||||
|
return (0);
|
||||||
|
if (*nptr == '-' || *nptr == '+')
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
@ -25,5 +25,6 @@ int ft_str_is_empty(const char *str);
|
|||||||
char **ft_split_quoted(const char *s, char c);
|
char **ft_split_quoted(const char *s, char c);
|
||||||
void ft_strshift(char *str, int shift);
|
void ft_strshift(char *str, int shift);
|
||||||
char *ft_quote_remover(char *str);
|
char *ft_quote_remover(char *str);
|
||||||
|
int ft_atoi_check(const char *nptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user