Commit 2caf9fb9 authored by pêle-mêle's avatar pêle-mêle
Browse files

reorganize headers, norm, etc

parent 18ea4e58
......@@ -24,6 +24,7 @@ SRC += ft_cd.c
SRC += ft_export.c
SRC += ft_unset.c
SRC += ft_env.c
SRC += ft_exit.c
SRC += options.c
SRC += var_utils.c
......@@ -34,7 +35,6 @@ vpath %.c $(SRC_DIR)
INC_DIR = inc/
HDR += minishell.h
HDR += signals.h
HDR += parsing.h
HDR += execution.h
......
#ifndef BUILTINS_H
# define BUILTINS_H
# include "execution.h"
# define ECHO_OPTIONS "n"
# define ECHO_N_OPTION 0b00000001
# define ENTIRE_STR -1
/*
** builtins
*/
int ft_echo(char **args, t_xe *xe);
int ft_pwd(char **args, t_xe *xe);
int ft_cd(char **args, t_xe *xe);
int ft_export(char **args, t_xe *xe);
int ft_unset(char **args, t_xe *xe);
int ft_env(char **args, t_xe *xe);
int ft_exit(enum e_retcode ret, t_xe *xe);
/*
** utils
*/
t_byte shift_options(char ***args, char *op_chars);
int check_var_name(char *var, ssize_t name_len);
#endif
#ifndef EXECUTION_H
# define EXECUTION_H
# include "minishell.h"
# include "signals.h"
#include <sys/types.h> // waitpid, opendir
#include <sys/wait.h> // waitpid
#include <fcntl.h> // open
#include <dirent.h> // readdir, opendir
# define ECHO_OPTIONS "n"
# define ECHO_N_OPTION 0b00000001
# include "minishell.h"
# define ENTIRE_STR -1
# define NOT_FOUND -1
enum e_cmd_code
......@@ -31,29 +31,4 @@ typedef int (*t_exec)(char **args, t_xe *xe);
int execute_cmd(char **args, char **redir_paths, enum e_redir_op *redir_types, t_xe *xe);
/*
** builtins
*/
int ft_echo(char **args, t_xe *xe);
int ft_pwd(char **args, t_xe *xe);
int ft_cd(char **args, t_xe *xe);
int ft_export(char **args, t_xe *xe);
int ft_unset(char **args, t_xe *xe);
int ft_env(char **args, t_xe *xe);
/*
** utils
*/
int exec_error(int err_code, t_xe *xe);
/*
** utils
*/
t_byte shift_options(char ***args, char *op_chars);
int env_replace_var(char *var_name, char *value, t_xe *xe);
int check_var_name(char *var, ssize_t name_len);
#endif
......@@ -12,6 +12,7 @@
# include <unistd.h>
# include <stdlib.h>
# include <errno.h>
# include <signal.h>
# include "libft.h"
......@@ -107,11 +108,12 @@ typedef struct s_xe
** **********************************
*/
/*
** free utils
*/
void signal_handler(void);
int handle_execution(t_xe *xe, int fd_in, int proc);
int env_replace_var(char *var_name, char *value, t_xe *xe);
/*
** free utils
*/
......@@ -125,8 +127,8 @@ void free_commands(t_list **commands);
** ft_exit.c
*/
int clean_and_exit(int ret, t_xe *xe);
void putstr_stderr(const char *str);
int ft_error(int ret, t_xe *xe);
int ft_exit(enum e_retcode retcode, t_xe *xe);
#endif
#ifndef SIGNALS_H
# define SIGNALS_H
#include <signal.h>
#include "minishell.h"
void signal_handler(void);
#endif
......@@ -6,7 +6,7 @@
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/26 12:18:10 by mvidal-a #+# #+# */
/* Updated: 2021/01/26 12:18:20 by mvidal-a ### ########.fr */
/* Updated: 2021/02/01 11:34:22 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -20,4 +20,3 @@ int blank_str(char *line)
return (TRUE);
return (FALSE);
}
......@@ -6,7 +6,7 @@
/* By: abenoit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/08 10:56:12 by abenoit #+# #+# */
/* Updated: 2021/01/08 11:04:58 by abenoit ### ########.fr */
/* Updated: 2021/02/01 11:34:42 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -39,5 +39,5 @@ char **merge_str_array(char **ar1, char **ar2)
new_array[i + j] = NULL;
free(ar1);
free(ar2);
return(new_array);
return (new_array);
}
......@@ -6,7 +6,7 @@
/* By: mvidal-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/07 18:06:07 by mvidal-a #+# #+# */
/* Updated: 2021/01/28 17:14:12 by mvidal-a ### ########.fr */
/* Updated: 2021/02/01 11:35:13 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
......@@ -24,7 +24,7 @@ ssize_t ft_putstr_fd(const char *s, int fd)
{
size_t len;
ssize_t ret;
len = ft_strlen(s);
ret = write(fd, s, len);
if (ret == (ssize_t)len)
......
"exit 42" doit exit en renvoyant 42
et tester sur bash "exit 42 1431" ou "exit fds"
arthur:
commande "."
......@@ -18,6 +23,8 @@ create file when redirecting output without doing anything ("> a")
error when redir_in file does not exist ("< unknown_file")
error when redir_out file does not have write permission
commande "."
compare with bash: "cat | exit"
......@@ -49,9 +56,6 @@ mkdir ok; cd ok; rmdir ../ok; pwd
cd: leaks in getcwd
"exit 42" doit exit en renvoyant 42
tester sur bash "exit 42 1431" ou "exit fds"
strerror au lieu de perror qui est pas autorise
......
#include "execution.h"
#include "builtins.h"
#include <stdio.h> // perror
......@@ -11,14 +11,19 @@ int ft_cd(char **args, t_xe *xe)
if (args[1] == NULL)
{
ret = get_var_pos(xe->env, "HOME", 4);
if (ret == -1)
if (ret == NOT_FOUND)
return (HOME_NOT_SET);
path = get_var_value(xe->env, "HOME", 4);
}
else if (args[2] != NULL)
{
printf("trop d'arguments\n"); // temp
return (FAILURE); // temp
}
else
path = ft_strdup(args[1]);
if (path == NULL)
return (SUCCESS); // err
return (MALLOC_ERR); // err
oldpwd = getcwd(NULL, 0); // error
if (chdir(path) == ERROR)
{
......
#include "execution.h"
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/01 11:26:53 by mvidal-a #+# #+# */
/* Updated: 2021/02/01 13:09:37 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtins.h"
int ft_echo(char **args, t_xe *xe)
{
......
#include "execution.h"
#include "builtins.h"
int ft_env(char **args, t_xe *xe)
{
......
#include "builtins.h"
int ft_exit(enum e_retcode ret, t_xe *xe)
{
ft_error(ret, xe);
return (clean_and_exit(ret, xe));
}
#include "execution.h"
#include "builtins.h"
char **sort_variables(char **env, char **exported)
{
......
#include "execution.h"
#include "builtins.h"
int ft_pwd(char **args, t_xe *xe)
{
......
#include "execution.h"
#include "builtins.h"
static int unset_one_var(char *var, t_xe *xe)
{
......
#include "execution.h"
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* options.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvidal-a <mvidal-a@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/01 11:27:03 by mvidal-a #+# #+# */
/* Updated: 2021/02/01 13:09:56 by mvidal-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtins.h"
t_byte check_arg_for_options(char *arg, char *op_chars)
{
......@@ -41,4 +53,3 @@ t_byte shift_options(char ***args, char *op_chars)
}
return (options);
}
#include "minishell.h"
#include "signals.h"
#include "parsing.h"
#include "execution.h"
#include <sys/types.h> // waitpid
#include <sys/wait.h> // waitpid
void child_setup(const int *fd, int fd_in)
{
signal(SIGINT, SIG_DFL); // error if SIG_ERR? (check errno)
......
#include "execution.h"
#include "builtins.h"
#include <sys/types.h> // waitpid, opendir
#include <sys/wait.h> // waitpid
#include <stdio.h> // perror
#include <dirent.h> // readdir, opendir
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
static int launch_exit(char **args, t_xe *xe)
{
......@@ -66,7 +60,7 @@ static int exec_cmd(char *cmd, char **args, t_xe *xe)
{
xe->child = 1;
if (execve(cmd, args, xe->env) == ERROR)
perror("External function error:");
perror("External function error:"); // -> strerror
return (CHILD_EXIT);
}
else
......
......@@ -83,9 +83,3 @@ int ft_error(int ret, t_xe *xe)
ft_putstr_fd("ERROR CODE ERROR (printed for debug)", STDERR_FILENO);// temp
return (SUCCESS);
}
int ft_exit(enum e_retcode ret, t_xe *xe)
{
ft_error(ret, xe);
return (clean_and_exit(ret, xe));
}
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