Compare commits
60 Commits
13e455cbf4
...
master
Author | SHA1 | Date | |
---|---|---|---|
bd5e1671fc | |||
62e887cfbd | |||
3e7dcd1ba9 | |||
9ab9c06593 | |||
2f6daa4ce5 | |||
b502364a67 | |||
0b56e95868 | |||
882a39fc94 | |||
59d9ed3514 | |||
058c96849b | |||
37bd3efc98 | |||
425fbd15cd | |||
d3fa573054 | |||
227d16ca53 | |||
91ef62d8f9 | |||
d06eb570fc | |||
1ef3fa115e | |||
10db23e4ef | |||
a6a0293095 | |||
a48da783dd | |||
be1f7ebf8c | |||
e65a9f32c0 | |||
8a2eb85dc6 | |||
5d482fc65a | |||
e0fb7f1fd0 | |||
404fcaa15f | |||
fe535a21f0 | |||
8a245f0dd8 | |||
f93fed5cdd | |||
d99aa39070 | |||
f0afd69bf6 | |||
5cbb6f078d | |||
b3e9a23f32 | |||
b1805834ec | |||
0d231a062d | |||
10413e500b | |||
760b8b644e | |||
fdfe1c8b95 | |||
0bf045d4ab | |||
7e0bbd1203 | |||
b96b617e09 | |||
f6617e07c7 | |||
a7e75bb163 | |||
d9ae113b94 | |||
88d955fddc | |||
68c945ae05 | |||
8af6b42642 | |||
46fe9caded | |||
1e00fee53c | |||
4dc8793eec | |||
f66ab7790e | |||
41bbe2bc0b | |||
3374d21cad | |||
94f55af0be | |||
6f3b1ab918 | |||
6a81705b98 | |||
27b8874f75 | |||
cdfa81328b | |||
bb00de527a | |||
7e77c4fe48 |
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
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 ./utils/ft_get_executable.c ./utils/fd.c
|
UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_charset_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c utils/ft_atoi_check.c ./utils/ft_get_executable.c ./utils/fd.c
|
||||||
|
|
||||||
BUILTINS_SRC = builtins/pwd.c \
|
BUILTINS_SRC = builtins/pwd.c \
|
||||||
builtins/export.c \
|
builtins/export.c \
|
||||||
|
40
README.md
40
README.md
@ -1,40 +0,0 @@
|
|||||||
# Minishell
|
|
||||||
|
|
||||||
Minishell is a 42 School project that involves creating a minimalistic shell in C language. The shell should be able to handle basic commands, manage environment variables and implement several built-in functions.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Prompt management (display, editing, history)
|
|
||||||
- Command execution (with or without arguments)
|
|
||||||
- Basic shell operations (pipes, redirections)
|
|
||||||
- Environment variables management (listing, setting, unsetting)
|
|
||||||
- Built-in functions management (echo, cd, env, exit, export, pwd, unset)
|
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
1. Clone this repository: `git clone https://github.com/<your_username>/minishell.git`
|
|
||||||
2. `cd` into the cloned directory: `cd minishell`
|
|
||||||
3. Run the `make` command to compile the program: `make`
|
|
||||||
4. Start the shell by running the executable: `./minishell`
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Once the shell is started, you can enter commands as you would with any other shell. The following are some examples of commands that can be executed:
|
|
||||||
|
|
||||||
- Display the working directory: `pwd`
|
|
||||||
- Change directory: `cd <directory_name>`
|
|
||||||
- Print the value of an environment variable: `echo $<variable_name>`
|
|
||||||
- Set an environment variable: `export <variable_name>=<value>`
|
|
||||||
- Unset an environment variable: `unset <variable_name>`
|
|
||||||
- Display a list of environment variables: `env`
|
|
||||||
- Exit the shell: `exit`
|
|
||||||
|
|
||||||
## Resources
|
|
||||||
|
|
||||||
- 
|
|
||||||
- The C library documentation for the standard library functions used in the program
|
|
||||||
- bash man
|
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
This project was created by [Camille CHAUVET](mailto:camille@chauvet.pro) and [Xamora](mailto:ogame.xamora@42l.fr). If you have any questions or suggestions, feel free to contact us.
|
|
@ -1,17 +1,17 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* minishell.h :+: :+: :+: */
|
/* bozoshell.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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/03/28 16:03:54 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/14 16:16:31 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MINISHELL_H
|
#ifndef BOZOSHELL_H
|
||||||
# define MINISHELL_H
|
# define BOZOSHELL_H
|
||||||
# include "./env/env.h"
|
# include "./env/env.h"
|
||||||
# include "./cmd/cmd.h"
|
# include "./cmd/cmd.h"
|
||||||
# include "./parse/parse.h"
|
# include "./parse/parse.h"
|
||||||
@ -24,6 +24,7 @@
|
|||||||
# include "./utils/utils.h"
|
# include "./utils/utils.h"
|
||||||
# include "./data/data.h"
|
# include "./data/data.h"
|
||||||
# include "./signal/signal.h"
|
# include "./signal/signal.h"
|
||||||
|
# include <stdio.h>
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/27 13:41:31 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 12:57:36 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
int echo(int fd, char **strs);
|
int echo(int fd, char **strs);
|
||||||
int pwd(int fd);
|
int pwd(int fd);
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(void);
|
||||||
int print_env(t_list **env, int fd);
|
int print_env(t_list **env, int fd);
|
||||||
int ft_export(t_list **env, char **args, int fd);
|
int ft_export(t_list **env, char **args, int fd);
|
||||||
int move_folder(char **args, int fd);
|
int move_folder(char **args, t_list **env, int fd);
|
||||||
int unset(t_list **env, char **args, int fd);
|
int unset(t_list **env, char **args, int fd);
|
||||||
int ft_exit(char **args);
|
int ft_exit(char **args, int err);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/27 13:41:44 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 12:57:25 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,6 +17,6 @@
|
|||||||
# include "../env/env.h"
|
# include "../env/env.h"
|
||||||
# include "../utils/utils.h"
|
# include "../utils/utils.h"
|
||||||
|
|
||||||
char *get_pwd(int fd);
|
char *get_pwd(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,33 +6,39 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/21 13:16:24 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:22:22 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./builtins_private.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
int make_move(char *path, int fd)
|
int make_move(char *path, t_list **env)
|
||||||
{
|
{
|
||||||
char *join;
|
char *join;
|
||||||
|
char *old;
|
||||||
|
|
||||||
join = ft_strjoin("/", path);
|
join = ft_strjoin("/", path);
|
||||||
join = ft_strfjoin(get_pwd(fd), join);
|
join = ft_strfjoin(get_pwd(), join);
|
||||||
|
old = get_pwd();
|
||||||
if (chdir(join) == 0)
|
if (chdir(join) == 0)
|
||||||
{
|
{
|
||||||
|
set_value_by_key("OLDPWD", old, env);
|
||||||
|
set_value_by_key("PWD", get_pwd(), env);
|
||||||
free(join);
|
free(join);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
free(old);
|
||||||
free(join);
|
free(join);
|
||||||
write(2, "No such file or directory\n", 26);
|
write(2, "cd: No such file or directory\n", 30);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int move_folder(char **args, int fd)
|
int move_folder(char **args, t_list **env)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
|
char *old;
|
||||||
|
|
||||||
if (args[1] != NULL || args[0] == NULL)
|
if (args[0] == NULL || args[1] != NULL)
|
||||||
{
|
{
|
||||||
write(2, "cd: Wrong number's argument\n", 28);
|
write(2, "cd: Wrong number's argument\n", 28);
|
||||||
return (1);
|
return (1);
|
||||||
@ -40,11 +46,17 @@ int move_folder(char **args, int fd)
|
|||||||
path = args[0];
|
path = args[0];
|
||||||
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
||||||
{
|
{
|
||||||
|
old = get_pwd();
|
||||||
if (chdir(path) == 0)
|
if (chdir(path) == 0)
|
||||||
|
{
|
||||||
|
set_value_by_key("OLDPWD", old, env);
|
||||||
|
set_value_by_key("PWD", get_pwd(), env);
|
||||||
return (0);
|
return (0);
|
||||||
write(2, "No such file or directory\n", 26);
|
}
|
||||||
|
free(old);
|
||||||
|
write(2, "cd: No such file or directory\n", 30);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (make_move(path, fd));
|
return (make_move(path, env));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/28 15:53:52 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/11 14:57:00 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ int check_argument(char *str, int *check_backslash_n)
|
|||||||
while (str[++i])
|
while (str[++i])
|
||||||
if (str[i] != '-' && str[i] != 'n')
|
if (str[i] != '-' && str[i] != 'n')
|
||||||
return (1);
|
return (1);
|
||||||
if (ft_strnstr(str, "n", ft_strlen(str)))
|
if (ft_strnstr(str, "n", ft_strlen(str)) && str[0] == '-')
|
||||||
*check_backslash_n = 1;
|
*check_backslash_n = 1;
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
@ -38,14 +38,16 @@ int echo(int fd, char **strs)
|
|||||||
int check_backslash_n;
|
int check_backslash_n;
|
||||||
int check_start_write;
|
int check_start_write;
|
||||||
int i;
|
int i;
|
||||||
|
int y;
|
||||||
|
|
||||||
check_backslash_n = 0;
|
check_backslash_n = 0;
|
||||||
check_start_write = 0;
|
check_start_write = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (strs[++i])
|
while (strs[++i])
|
||||||
{
|
{
|
||||||
while (is_space(*strs[i]))
|
y = -1;
|
||||||
strs[i]++;
|
while (is_space(strs[i][++y]))
|
||||||
|
;
|
||||||
if (check_start_write == 1
|
if (check_start_write == 1
|
||||||
|| check_argument(strs[i], &check_backslash_n))
|
|| check_argument(strs[i], &check_backslash_n))
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/09 15:04:47 by erey-bet ### ########.fr */
|
/* Updated: 2023/03/30 15:15:04 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ int print_env(t_list **env, int fd)
|
|||||||
current = *env;
|
current = *env;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
{
|
{
|
||||||
if (((t_env *)(current->content))->original)
|
if (((t_env *)(current->content))->value)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
||||||
ft_putstr_fd("=", fd);
|
ft_putstr_fd("=", fd);
|
||||||
@ -30,12 +30,3 @@ int print_env(t_list **env, int fd)
|
|||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*int main(int argc, char *argv[], char **env)
|
|
||||||
{
|
|
||||||
t_list **be;
|
|
||||||
|
|
||||||
be = init_env(env);
|
|
||||||
print_env(be, 1);
|
|
||||||
return (0);
|
|
||||||
}*/
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/10 14:52:22 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/05 12:30:46 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
static int error(int err, char *reason, char *problem)
|
static int error(int err, char *reason, char *problem)
|
||||||
{
|
{
|
||||||
ft_putstr_fd("minishell: exit ", 2);
|
ft_putstr_fd("bozoshell: bozo_exit ", 2);
|
||||||
if (problem != NULL)
|
if (problem != NULL)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(problem, 2);
|
ft_putstr_fd(problem, 2);
|
||||||
@ -24,22 +24,20 @@ static int error(int err, char *reason, char *problem)
|
|||||||
return (err);
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_exit(char **args)
|
int ft_exit(char **args, int err)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
|
|
||||||
if (args[0] == NULL)
|
if (args[0] == NULL)
|
||||||
{
|
{
|
||||||
write(1, "exit\n", 6);
|
write(1, "bozo_exit\n", 10);
|
||||||
return (0);
|
return (err);
|
||||||
}
|
}
|
||||||
err = ft_atoi_check(args[0]);
|
err = ft_atoi_check(args[0]);
|
||||||
if (err == 1)
|
if (err == 1)
|
||||||
return (error(err, "numeric argument required", args[0]));
|
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
|
||||||
if (args[1] != NULL)
|
if (args[1] != NULL)
|
||||||
return (error(1, "too many arguments", NULL));
|
return (error(-1, "bozo_exit: too many arguments\n", NULL));
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
return (error(err, "numeric argument required", args[0]));
|
return (error(err, "bozo_exit: numeric argument required\n", args[0]));
|
||||||
write(1, "exit\n", 6);
|
write(1, "exit\n", 6);
|
||||||
return ((ft_atoi(args[0]) % 256 + 256) % 256);
|
return ((ft_atoi(args[0]) % 256 + 256) % 256);
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,21 @@
|
|||||||
/* 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/03/30 13:04:53 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/14 19:12:10 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./builtins_private.h"
|
#include "./builtins_private.h"
|
||||||
|
|
||||||
static int error(char *str)
|
static int error(char *str, char *to_free1, char *to_free2)
|
||||||
{
|
{
|
||||||
write(2, "bash: export: `", 15);
|
write(2, "bozoshell: export: `", 20);
|
||||||
write(2, str, ft_strlen(str));
|
write(2, str, ft_strlen(str));
|
||||||
write(2, "': not a valid identifier\n", 26);
|
write(2, "': not a valid identifier\n", 26);
|
||||||
|
if (to_free1 != NULL)
|
||||||
|
free(to_free1);
|
||||||
|
if (to_free2 != NULL)
|
||||||
|
free(to_free2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +30,8 @@ void print_export(t_list **env, int fd)
|
|||||||
|
|
||||||
current = *env;
|
current = *env;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
|
{
|
||||||
|
if (ft_strcmp(((t_env *)(current->content))->key, "_"))
|
||||||
{
|
{
|
||||||
write(fd, "declare -x ", 11);
|
write(fd, "declare -x ", 11);
|
||||||
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
||||||
@ -38,6 +44,7 @@ void print_export(t_list **env, int fd)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
write(fd, "\n", 2);
|
write(fd, "\n", 2);
|
||||||
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +78,7 @@ int add_export(t_list **env, char *args)
|
|||||||
if (ft_strchr(args, '=') != NULL)
|
if (ft_strchr(args, '=') != NULL)
|
||||||
{
|
{
|
||||||
if (set_key_value_export(env, args, &key, &value))
|
if (set_key_value_export(env, args, &key, &value))
|
||||||
return (error(args));
|
return (error(args, key, NULL));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -80,10 +87,10 @@ int add_export(t_list **env, char *args)
|
|||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
value = ft_strdup(value);
|
value = ft_strdup(value);
|
||||||
if (possible_key(key) == 2)
|
if (possible_key(key) == 2)
|
||||||
return (error(key));
|
return (error(key, key, value));
|
||||||
}
|
}
|
||||||
if (!possible_key(key))
|
if (!possible_key(key))
|
||||||
return (error(args));
|
return (error(args, key, value));
|
||||||
create_value_by_key(key, value, env);
|
create_value_by_key(key, value, env);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/09 20:00:19 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,13 +20,13 @@ int pwd(int fd)
|
|||||||
ft_putendl_fd(path, fd);
|
ft_putendl_fd(path, fd);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error getcwd", fd);
|
ft_putendl_fd("Error getcwd", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_pwd(int fd)
|
char *get_pwd(void)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ char *get_pwd(int fd)
|
|||||||
return (str);
|
return (str);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putendl_fd("Error getcwd", fd);
|
ft_putendl_fd("Error getcwd", 2);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
|
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/07 12:46:28 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
int error(char *str, int fd)
|
int error(char *str, int fd)
|
||||||
{
|
{
|
||||||
write(fd, "bash: unset: `", 14);
|
write(fd, "bozoshell: unset: `", 19);
|
||||||
write(fd, str, ft_strlen(str));
|
write(fd, str, ft_strlen(str));
|
||||||
write(fd, "': not a valid identifier", 25);
|
write(fd, "': not a valid identifier\n", 26);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
cmd/cmd.c
42
cmd/cmd.c
@ -6,11 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/17 11:57:07 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cmd.h"
|
||||||
#include "cmd_private.h"
|
#include "cmd_private.h"
|
||||||
|
#include "../signal/signal.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
void ft_cmddel(void *ptr)
|
void ft_cmddel(void *ptr)
|
||||||
{
|
{
|
||||||
@ -31,3 +34,40 @@ void ft_cmddel(void *ptr)
|
|||||||
close(content->fd_out[1]);
|
close(content->fd_out[1]);
|
||||||
free(content);
|
free(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_cmdcloser(void *ptr)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
|
||||||
|
cmd = ptr;
|
||||||
|
ft_closer(cmd->fd_in);
|
||||||
|
ft_closer(cmd->fd_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_cmdwaiter(void *ptr)
|
||||||
|
{
|
||||||
|
t_cmd *cmd;
|
||||||
|
int exit_status;
|
||||||
|
|
||||||
|
cmd = ptr;
|
||||||
|
if (cmd->executable != NULL && cmd->own_cmd == 0
|
||||||
|
&& cmd->pid != -1 && cmd->fd_in[0] != -2 && cmd->fd_out[0] != -2)
|
||||||
|
{
|
||||||
|
waitpid(cmd->pid, &exit_status, 0);
|
||||||
|
if (WIFSIGNALED(exit_status))
|
||||||
|
{
|
||||||
|
if (exit_status == 131)
|
||||||
|
{
|
||||||
|
ft_printf("Quit (core dumped)");
|
||||||
|
*ft_get_exit_code() = 131;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*ft_get_exit_code() = 130;
|
||||||
|
ft_printf("\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*ft_get_exit_code() = WEXITSTATUS(exit_status);
|
||||||
|
}
|
||||||
|
signal(SIGINT, ft_ctrlc);
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:47:01 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 15:47:02 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/07 15:03:53 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -26,5 +26,7 @@ typedef struct s_cmd
|
|||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
void ft_cmddel(void *content);
|
void ft_cmddel(void *content);
|
||||||
|
void ft_cmdwaiter(void *content);
|
||||||
|
void ft_cmdcloser(void *ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:50:23 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 15:50:24 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/31 16:33:24 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,4 +17,5 @@
|
|||||||
# include "./cmd.h"
|
# include "./cmd.h"
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
|
# include "../utils/utils.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:42:09 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/27 13:42:58 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 14:48:30 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./data_private.h"
|
#include "./data_private.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
t_data *ft_get_data(void)
|
int *ft_get_exit_code(void)
|
||||||
{
|
{
|
||||||
static t_data data;
|
static int exit_code;
|
||||||
|
|
||||||
return (&data);
|
return (&exit_code);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:43:39 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/27 13:43:40 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 14:45:23 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,10 +18,9 @@ typedef struct s_data
|
|||||||
{
|
{
|
||||||
t_list **env;
|
t_list **env;
|
||||||
t_list **cmds;
|
t_list **cmds;
|
||||||
int exit_code;
|
int *exit_code;
|
||||||
int child_pid;
|
|
||||||
} t_data;
|
} t_data;
|
||||||
|
|
||||||
t_data *ft_get_data(void);
|
int *ft_get_exit_code(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
1
env/env.h
vendored
1
env/env.h
vendored
@ -20,7 +20,6 @@ typedef struct s_env
|
|||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
bool original;
|
|
||||||
} t_env;
|
} t_env;
|
||||||
|
|
||||||
char *ft_env_filler(t_data *data, const char *str);
|
char *ft_env_filler(t_data *data, const char *str);
|
||||||
|
16
env/env1.c
vendored
16
env/env1.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
|
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/30 13:07:15 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:57:38 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,7 +34,11 @@ void add_sort(t_list **head, t_env *var)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (current->next == NULL)
|
if (current->next == NULL)
|
||||||
|
{
|
||||||
current->next = ft_calloc(1, sizeof(t_list));
|
current->next = ft_calloc(1, sizeof(t_list));
|
||||||
|
if (!current->next)
|
||||||
|
return ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_value_by_key(char *key, t_list **head)
|
char *get_value_by_key(char *key, t_list **head)
|
||||||
@ -61,9 +65,7 @@ int set_value_by_key(char *key, char *value, t_list **head)
|
|||||||
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
||||||
{
|
{
|
||||||
free(((t_env *)current->content)->value);
|
free(((t_env *)current->content)->value);
|
||||||
free(((t_env *)current->content)->key);
|
|
||||||
((t_env *)current->content)->value = value;
|
((t_env *)current->content)->value = value;
|
||||||
((t_env *)current->content)->key = key;
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
@ -76,13 +78,15 @@ int create_value_by_key(char *key, char *value, t_list **head)
|
|||||||
t_env *content;
|
t_env *content;
|
||||||
|
|
||||||
if (set_value_by_key(key, value, head) == 0)
|
if (set_value_by_key(key, value, head) == 0)
|
||||||
|
{
|
||||||
|
free(key);
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
content = ft_calloc(1, sizeof(t_env));
|
content = ft_calloc(1, sizeof(t_env));
|
||||||
if (content == NULL)
|
if (content == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
content->key = key;
|
content->key = key;
|
||||||
content->value = value;
|
content->value = value;
|
||||||
content->original = 0;
|
|
||||||
add_sort(head, content);
|
add_sort(head, content);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -98,7 +102,10 @@ t_list **init_env(char **env)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
*head = ft_calloc(1, sizeof(t_list));
|
*head = ft_calloc(1, sizeof(t_list));
|
||||||
if (*head == NULL)
|
if (*head == NULL)
|
||||||
|
{
|
||||||
|
free(head);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
i = -1;
|
i = -1;
|
||||||
while (env[++i])
|
while (env[++i])
|
||||||
{
|
{
|
||||||
@ -107,7 +114,6 @@ t_list **init_env(char **env)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
var->key = get_key(env[i]);
|
var->key = get_key(env[i]);
|
||||||
var->value = get_value(env[i]);
|
var->value = get_value(env[i]);
|
||||||
var->original = 1;
|
|
||||||
add_sort(head, var);
|
add_sort(head, var);
|
||||||
}
|
}
|
||||||
return (head);
|
return (head);
|
||||||
|
2
env/env2.c
vendored
2
env/env2.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/09 19:59:10 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/18 13:26:31 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
5
env/env3.c
vendored
5
env/env3.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/03/30 12:51:54 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/07 13:21:54 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -70,6 +70,7 @@ int delete_by_key(char *key, t_list **head)
|
|||||||
t_list *current;
|
t_list *current;
|
||||||
|
|
||||||
current = *head;
|
current = *head;
|
||||||
|
last = NULL;
|
||||||
while (current->next != NULL)
|
while (current->next != NULL)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
||||||
@ -77,7 +78,7 @@ int delete_by_key(char *key, t_list **head)
|
|||||||
free(((t_env *)current->content)->key);
|
free(((t_env *)current->content)->key);
|
||||||
free(((t_env *)current->content)->value);
|
free(((t_env *)current->content)->value);
|
||||||
free(current->content);
|
free(current->content);
|
||||||
if (last->next != NULL)
|
if (last && last->next)
|
||||||
last->next = current->next;
|
last->next = current->next;
|
||||||
else
|
else
|
||||||
*head = current->next;
|
*head = current->next;
|
||||||
|
8
env/env_fill.c
vendored
8
env/env_fill.c
vendored
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 16:29:08 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 19:06:44 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:09:46 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ static char *ft_getkey(const char *str)
|
|||||||
key = ft_strndup(str + 1, i - 1);
|
key = ft_strndup(str + 1, i - 1);
|
||||||
}
|
}
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (key);
|
return (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ static char *ft_getvalue(t_data *data, char *key)
|
|||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
if (ft_strcmp(key, "?") == 0)
|
if (ft_strcmp(key, "?") == 0)
|
||||||
value = ft_itoa(data->exit_code);
|
value = ft_itoa(*data->exit_code);
|
||||||
else if (ft_strcmp(key, "$") == 0)
|
else if (ft_strcmp(key, "$") == 0)
|
||||||
value = ft_strdup("PID");
|
value = ft_strdup("PID");
|
||||||
else if (key[0] == '\0')
|
else if (key[0] == '\0')
|
||||||
@ -54,7 +54,7 @@ static char *ft_getvalue(t_data *data, char *key)
|
|||||||
value = ft_strdup(value);
|
value = ft_strdup(value);
|
||||||
}
|
}
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (value);
|
return (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:53:35 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 13:00:08 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -23,48 +23,47 @@ static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
|||||||
else if (ft_strcmp(cmd->executable, "export") == 0)
|
else if (ft_strcmp(cmd->executable, "export") == 0)
|
||||||
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
|
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
|
||||||
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
||||||
return_code = (move_folder(cmd->args + 1, cmd->fd_out[0]));
|
return_code = (move_folder(cmd->args + 1, data->env, cmd->fd_out[0]));
|
||||||
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||||
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
||||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
||||||
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
return_code = (echo(cmd->fd_out[0], cmd->args + 1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return_code = ft_exit(cmd->args + 1);
|
return_code = ft_exit(cmd->args + 1, *data->exit_code);
|
||||||
if (return_code >= 0)
|
if (return_code >= 0)
|
||||||
{
|
{
|
||||||
data->exit_code = return_code;
|
*data->exit_code = return_code;
|
||||||
return (-1);
|
return (-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data->exit_code = return_code;
|
*data->exit_code = return_code;
|
||||||
return (return_code);
|
return (return_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ft_executor(t_cmd *cmd, char **env, int fd)
|
static bool ft_executor(t_data *data, t_cmd *cmd, char **env)
|
||||||
{
|
{
|
||||||
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
|
if (cmd->fd_in[0] == -1 || cmd->fd_out[0] == -1 || cmd->executable == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
cmd->pid = fork();
|
cmd->pid = fork();
|
||||||
ft_get_data()->child_pid = cmd->pid;
|
|
||||||
if (cmd->pid == -1)
|
if (cmd->pid == -1)
|
||||||
return (1);
|
return (1);
|
||||||
if (cmd->pid == 0)
|
if (cmd->pid == 0)
|
||||||
{
|
{
|
||||||
|
signal(SIGQUIT, SIG_DFL);
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
dup2(cmd->fd_in[0], 0);
|
dup2(cmd->fd_in[0], 0);
|
||||||
dup2(cmd->fd_out[0], 1);
|
dup2(cmd->fd_out[0], 1);
|
||||||
if (fd != -1)
|
ft_lstiter(*data->cmds, ft_cmdcloser);
|
||||||
close(fd);
|
|
||||||
ft_closer(cmd->fd_in);
|
|
||||||
ft_closer(cmd->fd_out);
|
|
||||||
execve(cmd->executable, cmd->args, env);
|
execve(cmd->executable, cmd->args, env);
|
||||||
ft_eprintf("minishell: permission denied: %s\n", cmd->executable);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
signal(SIGINT, SIG_IGN);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
static int ft_cmd_executor(t_data *data, t_cmd *cmd)
|
||||||
{
|
{
|
||||||
int exit_code;
|
int exit_code;
|
||||||
char **env;
|
char **env;
|
||||||
@ -74,7 +73,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
|||||||
exit_code = ft_execute_own_cmd(data, cmd);
|
exit_code = ft_execute_own_cmd(data, cmd);
|
||||||
ft_closer(cmd->fd_in);
|
ft_closer(cmd->fd_in);
|
||||||
ft_closer(cmd->fd_out);
|
ft_closer(cmd->fd_out);
|
||||||
if (exit_code == -1)
|
if (exit_code == -2)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -82,7 +81,7 @@ static int ft_cmd_executor(t_data *data, t_cmd *cmd, int fd)
|
|||||||
env = env_to_strs(data->env);
|
env = env_to_strs(data->env);
|
||||||
if (env == NULL)
|
if (env == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
exit_code = ft_executor(cmd, env, fd);
|
exit_code = ft_executor(data, cmd, env);
|
||||||
ft_closer(cmd->fd_in);
|
ft_closer(cmd->fd_in);
|
||||||
ft_closer(cmd->fd_out);
|
ft_closer(cmd->fd_out);
|
||||||
ft_freer_tab_ultimate(1, env);
|
ft_freer_tab_ultimate(1, env);
|
||||||
@ -112,7 +111,7 @@ int ft_cmds_executor(t_data *data)
|
|||||||
}
|
}
|
||||||
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
|
if (content->fd_in[0] == -2 || content->fd_out[0] == -2)
|
||||||
ft_mega_closer(content->fd_in, content->fd_out);
|
ft_mega_closer(content->fd_in, content->fd_out);
|
||||||
else if (ft_cmd_executor(data, content, fds[0]))
|
else if (ft_cmd_executor(data, content))
|
||||||
return (1);
|
return (1);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:45:53 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:55:22 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:15:56 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef EXECUTION_PRIVATE_H
|
#ifndef EXECUTION_PRIVATE_H
|
||||||
# define EXECUTION_PRIVATE_H
|
# define EXECUTION_PRIVATE_H
|
||||||
|
# include <signal.h>
|
||||||
|
# include "../signal/signal.h"
|
||||||
# include "../data/data.h"
|
# include "../data/data.h"
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
# include "../cmd/cmd.h"
|
# include "../cmd/cmd.h"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 13:35:50 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 16:53:15 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/31 15:22:21 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ static int ft_replace(char **str, size_t i)
|
|||||||
free(*str);
|
free(*str);
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
*str = temp;
|
*str = temp;
|
||||||
@ -40,7 +40,7 @@ static char *ft_spacer_after(const char *str)
|
|||||||
{
|
{
|
||||||
while (ft_is_in_quote(out, i - 1))
|
while (ft_is_in_quote(out, i - 1))
|
||||||
i++;
|
i++;
|
||||||
if (out[i] == '\0')
|
if (out[i - 1] == '\0' || out[i] == '\0')
|
||||||
break ;
|
break ;
|
||||||
if (ft_is_in("><|", out[i - 1]))
|
if (ft_is_in("><|", out[i - 1]))
|
||||||
{
|
{
|
||||||
@ -66,7 +66,7 @@ static char *ft_spacer_before(const char *str)
|
|||||||
i = -1;
|
i = -1;
|
||||||
while (out[++i] != '\0')
|
while (out[++i] != '\0')
|
||||||
{
|
{
|
||||||
while (ft_is_in_quote(out, i))
|
while (ft_is_in_quote(out, i + 1))
|
||||||
i++;
|
i++;
|
||||||
if (out[i] == '\0')
|
if (out[i] == '\0')
|
||||||
break ;
|
break ;
|
||||||
|
Binary file not shown.
69
main.c
69
main.c
@ -6,14 +6,18 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/30 12:41:52 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/18 12:59:43 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "data/data.h"
|
#include "data/data.h"
|
||||||
#include "env/env.h"
|
#include "env/env.h"
|
||||||
|
#include "libftx/libft/libft.h"
|
||||||
|
#include "libftx/libft/list.h"
|
||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "bozoshell.h"
|
||||||
|
#include "signal/signal.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
static char *ft_get_user_input(void)
|
static char *ft_get_user_input(void)
|
||||||
{
|
{
|
||||||
@ -21,14 +25,14 @@ static char *ft_get_user_input(void)
|
|||||||
char *prompt;
|
char *prompt;
|
||||||
char *pwd;
|
char *pwd;
|
||||||
|
|
||||||
pwd = get_pwd(2);
|
pwd = get_pwd();
|
||||||
if (pwd == NULL)
|
if (pwd == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
prompt = ft_strmerger(2, pwd, "$ ");
|
prompt = ft_strmerger(2, pwd, "$ ");
|
||||||
free(pwd);
|
free(pwd);
|
||||||
if (prompt == NULL)
|
if (prompt == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
line = readline(prompt);
|
line = readline(prompt);
|
||||||
@ -40,35 +44,6 @@ static char *ft_get_user_input(void)
|
|||||||
return (line);
|
return (line);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_cmds_waiter(t_data *data)
|
|
||||||
{
|
|
||||||
t_list *current;
|
|
||||||
t_cmd *content;
|
|
||||||
int exit_status;
|
|
||||||
|
|
||||||
current = *data->cmds;
|
|
||||||
while (current != NULL)
|
|
||||||
{
|
|
||||||
content = current->content;
|
|
||||||
if (content->executable != NULL && content->own_cmd == 0
|
|
||||||
&& content->pid != -1 && content->fd_in[0] != -2 && content->fd_out[0] != -2)
|
|
||||||
{
|
|
||||||
waitpid(content->pid, &exit_status, 0);
|
|
||||||
if (WIFSIGNALED(exit_status))
|
|
||||||
{
|
|
||||||
if (WTERMSIG(exit_status) == SIGKILL)
|
|
||||||
data->exit_code = 131;
|
|
||||||
else
|
|
||||||
data->exit_code = 130;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
data->exit_code = WEXITSTATUS(exit_status);
|
|
||||||
}
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
data->child_pid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ft_minishell(t_data *data, char *line)
|
static int ft_minishell(t_data *data, char *line)
|
||||||
{
|
{
|
||||||
char *line_clean;
|
char *line_clean;
|
||||||
@ -86,26 +61,25 @@ static int ft_minishell(t_data *data, char *line)
|
|||||||
free(line_clean);
|
free(line_clean);
|
||||||
if (ft_cmds_executor(data) == 1)
|
if (ft_cmds_executor(data) == 1)
|
||||||
return (1);
|
return (1);
|
||||||
ft_cmds_waiter(data);
|
ft_lstiter(*data->cmds, ft_cmdwaiter);
|
||||||
ft_lstclear(data->cmds, ft_cmddel);
|
ft_lstclear(data->cmds, ft_cmddel);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_init_data(t_data *data, char **env)
|
int ft_init_data(t_data *data, char **env)
|
||||||
{
|
{
|
||||||
data->exit_code = 0;
|
data->exit_code = ft_get_exit_code();
|
||||||
data->child_pid = 0;
|
|
||||||
data->cmds = malloc(sizeof(t_cmd *));
|
data->cmds = malloc(sizeof(t_cmd *));
|
||||||
if (data->cmds == NULL)
|
if (data->cmds == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
*data->cmds = NULL;
|
*data->cmds = NULL;
|
||||||
data->env = init_env(env);
|
data->env = init_env(env);
|
||||||
if (data->env == NULL)
|
if (data->env == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
free(data->cmds);
|
free(data->cmds);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@ -114,29 +88,28 @@ int ft_init_data(t_data *data, char **env)
|
|||||||
|
|
||||||
int main(int ac, char **av, char **env)
|
int main(int ac, char **av, char **env)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data data;
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
(void) ac;
|
(void) ac;
|
||||||
(void) av;
|
(void) av;
|
||||||
signal(SIGINT, ft_ctrlc);
|
signal(SIGINT, ft_ctrlc);
|
||||||
signal(SIGQUIT, ft_quit);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
data = ft_get_data();
|
if (ft_init_data(&data, env))
|
||||||
if (ft_init_data(data, env))
|
|
||||||
return (1);
|
return (1);
|
||||||
line = ft_get_user_input();
|
line = ft_get_user_input();
|
||||||
while (line != NULL)
|
while (line != NULL)
|
||||||
{
|
{
|
||||||
if (ft_minishell(data, line) == 1)
|
if (ft_minishell(&data, line) == 1)
|
||||||
break ;
|
break ;
|
||||||
free(line);
|
free(line);
|
||||||
line = ft_get_user_input();
|
line = ft_get_user_input();
|
||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
ft_lstclear(data->cmds, ft_cmddel);
|
ft_lstclear(data.cmds, ft_cmddel);
|
||||||
free(data->cmds);
|
free(data.cmds);
|
||||||
ft_lstclear(data->env, env_del);
|
ft_lstclear(data.env, env_del);
|
||||||
free(data->env);
|
free(data.env);
|
||||||
return (data->exit_code);
|
return (*data.exit_code);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:44:38 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 19:31:35 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/11 16:17:19 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ static int ft_args_parse(char *cmd_str, t_cmd *cmd)
|
|||||||
char **tab;
|
char **tab;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
tab = ft_split_quoted(cmd_str, ' ');
|
tab = ft_split_charset_quoted(cmd_str, "\t ");
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
return (1);
|
return (1);
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -80,10 +80,14 @@ int ft_cmd_parser(t_data *data, char *cmd_str)
|
|||||||
cmd = ft_calloc(sizeof(t_cmd), 1);
|
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (ft_redirection(data, cmd, cmd_str))
|
||||||
|
{
|
||||||
|
ft_cmddel(cmd);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_redirection(data, cmd, cmd_str);
|
|
||||||
if (ft_args_parse(cmd_str, cmd))
|
if (ft_args_parse(cmd_str, cmd))
|
||||||
{
|
{
|
||||||
ft_cmddel(cmd);
|
ft_cmddel(cmd);
|
||||||
@ -98,10 +102,10 @@ int ft_cmds_parser(t_data *data, const char *line)
|
|||||||
char **tab;
|
char **tab;
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
|
|
||||||
tab = ft_split_quoted(line, '|');
|
tab = ft_split_charset_quoted(line, "|");
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
i = -1;
|
i = -1;
|
||||||
|
@ -6,20 +6,35 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
/* Created: 2023/03/29 17:32:06 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 19:21:59 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/17 11:15:38 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./redirection_private.h"
|
#include "./redirection_private.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "../signal/signal.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ft_strcmp(redirection_identifier, "<<") == 0)
|
if (ft_strcmp(redirection_identifier, "<<") == 0)
|
||||||
{
|
{
|
||||||
cmd->fd_in[0] = ft_heredoc(data, redirection);
|
|
||||||
if (cmd->fd_in[0] == -2)
|
if (cmd->fd_in[0] == -2)
|
||||||
|
return (0);
|
||||||
|
signal(SIGINT, ft_ctrlc_heredoc);
|
||||||
|
fd = ft_heredoc(data, redirection);
|
||||||
|
signal(SIGINT, ft_ctrlc);
|
||||||
|
if (fd == -2)
|
||||||
return (1);
|
return (1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
|
cmd->fd_in[0] = fd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@ -27,14 +42,25 @@ static bool ft_check_heredoc(t_data *data, t_cmd *cmd,
|
|||||||
static bool ft_check_infile(t_data *data, t_cmd *cmd,
|
static bool ft_check_infile(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ft_strcmp(redirection_identifier, "<") == 0)
|
if (ft_strcmp(redirection_identifier, "<") == 0)
|
||||||
{
|
{
|
||||||
|
if (cmd->fd_in[0] == -2)
|
||||||
|
return (0);
|
||||||
if (ft_file_is_readable(data, redirection))
|
if (ft_file_is_readable(data, redirection))
|
||||||
cmd->fd_in[0] = open(redirection, O_RDONLY);
|
{
|
||||||
|
fd = open(redirection, O_RDONLY);
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
|
cmd->fd_in[0] = fd;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (cmd->fd_in[0] > 2)
|
||||||
|
close(cmd->fd_in[0]);
|
||||||
cmd->fd_in[0] = -2;
|
cmd->fd_in[0] = -2;
|
||||||
return (1);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -43,15 +69,26 @@ static bool ft_check_infile(t_data *data, t_cmd *cmd,
|
|||||||
static bool ft_check_outfile(t_data *data, t_cmd *cmd,
|
static bool ft_check_outfile(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ft_strcmp(redirection_identifier, ">") == 0)
|
if (ft_strcmp(redirection_identifier, ">") == 0)
|
||||||
{
|
{
|
||||||
|
if (cmd->fd_out[0] == -2)
|
||||||
|
return (0);
|
||||||
if (ft_file_is_writable(data, redirection))
|
if (ft_file_is_writable(data, redirection))
|
||||||
cmd->fd_out[0] = open(redirection,
|
{
|
||||||
|
fd = open(redirection,
|
||||||
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = fd;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
cmd->fd_out[0] = -2;
|
cmd->fd_out[0] = -2;
|
||||||
return (1);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -60,15 +97,25 @@ static bool ft_check_outfile(t_data *data, t_cmd *cmd,
|
|||||||
static bool ft_check_outfile_append(t_data *data, t_cmd *cmd,
|
static bool ft_check_outfile_append(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
if (ft_strcmp(redirection_identifier, ">>") == 0)
|
if (ft_strcmp(redirection_identifier, ">>") == 0)
|
||||||
{
|
{
|
||||||
if (ft_file_is_writable(data, redirection))
|
if (cmd->fd_out[0] == -2)
|
||||||
cmd->fd_out[0] = open(redirection,
|
return (0);
|
||||||
|
if (ft_file_is_appendable(data, redirection))
|
||||||
|
{
|
||||||
|
fd = open(redirection,
|
||||||
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
|
cmd->fd_out[0] = fd;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (cmd->fd_out[0] > 2)
|
||||||
|
close(cmd->fd_out[0]);
|
||||||
cmd->fd_out[0] = -2;
|
cmd->fd_out[0] = -2;
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -77,9 +124,28 @@ static bool ft_check_outfile_append(t_data *data, t_cmd *cmd,
|
|||||||
bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
bool ft_check_redirection(t_data *data, t_cmd *cmd,
|
||||||
char *redirection_identifier, char *redirection)
|
char *redirection_identifier, char *redirection)
|
||||||
{
|
{
|
||||||
return (ft_check_heredoc(data, cmd, redirection_identifier, redirection)
|
char *str;
|
||||||
|| ft_check_infile(data, cmd, redirection_identifier, redirection)
|
bool out;
|
||||||
|| ft_check_outfile(data, cmd, redirection_identifier, redirection)
|
|
||||||
|| ft_check_outfile_append(data, cmd, redirection_identifier,
|
if (ft_is_in("<>", redirection_identifier[0])
|
||||||
redirection));
|
&& ft_is_in("<>", redirection[0]))
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: %s: invalid redirection file\n", redirection);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
str = ft_strdup(redirection);
|
||||||
|
if (str == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
ft_quote_remover(str);
|
||||||
|
out = 0;
|
||||||
|
if (ft_check_heredoc(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_infile(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_outfile(data, cmd, redirection_identifier, str)
|
||||||
|
|| ft_check_outfile_append(data, cmd, redirection_identifier, str))
|
||||||
|
out = 1;
|
||||||
|
free(str);
|
||||||
|
return (out);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/15 17:36:11 by cchauvet #+# #+# */
|
/* Created: 2023/02/15 17:36:11 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/02/15 17:41:13 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:12:41 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,15 +20,15 @@ int ft_file_is_readable(t_data *data, const char *path)
|
|||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: No such file or directory\n", path);
|
ft_eprintf("bozoshell: %s: No such file or directory\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
readable = read(fd, "", 0);
|
readable = read(fd, "", 0);
|
||||||
if (readable == -1)
|
if (readable == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -43,18 +43,19 @@ int ft_file_is_writable(t_data *data, const char *path)
|
|||||||
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
writeable = write(fd, "", 0);
|
writeable = write(fd, "", 0);
|
||||||
if (writeable == -1)
|
if (writeable == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
return (fd);
|
close(fd);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_file_is_appendable(t_data *data, const char *path)
|
int ft_file_is_appendable(t_data *data, const char *path)
|
||||||
@ -65,16 +66,17 @@ int ft_file_is_appendable(t_data *data, const char *path)
|
|||||||
fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
writeable = write(fd, "", 0);
|
writeable = write(fd, "", 0);
|
||||||
if (writeable == -1)
|
if (writeable == -1)
|
||||||
{
|
{
|
||||||
data->exit_code = 1;
|
*data->exit_code = 1;
|
||||||
ft_eprintf("minishell: %s: Permission denied\n", path);
|
ft_eprintf("bozoshell: %s: Permission denied\n", path);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
return (fd);
|
close(fd);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,23 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
/* Created: 2023/02/17 15:36:26 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 16:37:05 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/17 12:14:11 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./redirection_private.h"
|
#include "./redirection_private.h"
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int *ft_get_heredoc(void)
|
static bool ft_fd_is_closed(int fd)
|
||||||
{
|
{
|
||||||
static int heredoc = -1;
|
int fd2;
|
||||||
|
|
||||||
return (&heredoc);
|
fd2 = dup(fd);
|
||||||
|
if (fd2 == -1)
|
||||||
|
return (1);
|
||||||
|
close(fd2);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_format_and_write(t_data *data, const char *str, int fd)
|
static int ft_format_and_write(t_data *data, const char *str, int fd)
|
||||||
@ -31,26 +37,29 @@ static int ft_format_and_write(t_data *data, const char *str, int fd)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ft_heredoc2(t_data *data, char *stop, char *line, int fds[2])
|
int ft_heredoc2(t_data *data, char *line, char *stop, int fds[2])
|
||||||
{
|
{
|
||||||
line[ft_strlen(line) - 1] = '\0';
|
if (line == NULL)
|
||||||
if (ft_strcmp(line, stop) == 0)
|
|
||||||
{
|
{
|
||||||
free(line);
|
if (ft_fd_is_closed(0))
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
if (ft_format_and_write(data, line, fds[1]))
|
|
||||||
{
|
{
|
||||||
ft_closer(fds);
|
close(fds[0]);
|
||||||
free(line);
|
fds[0] = -2;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
free(line);
|
else
|
||||||
ft_printf("> ");
|
|
||||||
line = get_next_line(*ft_get_heredoc());
|
|
||||||
if (line == NULL && *ft_get_heredoc() == -1)
|
|
||||||
{
|
{
|
||||||
ft_closer(fds);
|
ft_eprintf("\nbozoshell: warning: here-document at line 1%s",
|
||||||
|
"delimited by end-of-file (wanted `adfsd')\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ft_strcmp(line, stop) == 0)
|
||||||
|
return (1);
|
||||||
|
if (ft_format_and_write(data, line, fds[1]))
|
||||||
|
{
|
||||||
|
close(fds[0]);
|
||||||
|
fds[0] = -2;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -58,24 +67,27 @@ static int ft_heredoc2(t_data *data, char *stop, char *line, int fds[2])
|
|||||||
|
|
||||||
int ft_heredoc(t_data *data, char *stop)
|
int ft_heredoc(t_data *data, char *stop)
|
||||||
{
|
{
|
||||||
char *line;
|
|
||||||
int fds[2];
|
int fds[2];
|
||||||
int return_code;
|
int stdin_bak;
|
||||||
|
char *line;
|
||||||
|
|
||||||
if (pipe(fds) == -1)
|
stdin_bak = dup(0);
|
||||||
return (-1);
|
if (stdin_bak == -1)
|
||||||
*ft_get_heredoc() = dup(0);
|
return (1);
|
||||||
ft_printf("> ");
|
if (pipe(fds))
|
||||||
line = get_next_line(*ft_get_heredoc());
|
|
||||||
while (line != NULL)
|
|
||||||
{
|
{
|
||||||
return_code = ft_heredoc2(data, stop, line, fds);
|
close(stdin_bak);
|
||||||
if (return_code == 2)
|
return (1);
|
||||||
break ;
|
|
||||||
else if (return_code)
|
|
||||||
return (-2);
|
|
||||||
}
|
}
|
||||||
|
line = readline("> ");
|
||||||
|
while (ft_heredoc2(data, line, stop, fds) == 0)
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
|
line = readline("> ");
|
||||||
|
}
|
||||||
|
free(line);
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
*ft_get_heredoc() = -1;
|
dup2(stdin_bak, 0);
|
||||||
|
close(stdin_bak);
|
||||||
return (fds[0]);
|
return (fds[0]);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:44:22 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 19:19:51 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/13 13:26:06 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -78,11 +78,15 @@ int ft_set_redirection(t_data *data, t_cmd *cmd, char **tab)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (tab[i + 1] != NULL)
|
while (tab[i + 1] != NULL)
|
||||||
{
|
{
|
||||||
ft_quote_remover(tab[i + 1]);
|
|
||||||
if (ft_check_redirection(data, cmd, tab[i], tab[i + 1]))
|
if (ft_check_redirection(data, cmd, tab[i], tab[i + 1]))
|
||||||
return (1);
|
return (1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (ft_is_in("<>", tab[i][0]))
|
||||||
|
{
|
||||||
|
ft_eprintf("bozoshell: %s: must be followed by a file\n", tab[i]);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,10 +98,10 @@ int ft_redirection(t_data *data, t_cmd *cmd, char *cmd_str)
|
|||||||
cmd->fd_in[1] = -1;
|
cmd->fd_in[1] = -1;
|
||||||
cmd->fd_out[0] = -1;
|
cmd->fd_out[0] = -1;
|
||||||
cmd->fd_out[1] = -1;
|
cmd->fd_out[1] = -1;
|
||||||
tab = ft_split_quoted(cmd_str, ' ');
|
tab = ft_split_charset_quoted(cmd_str, " \t");
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
ft_remove_redirection(cmd_str);
|
ft_remove_redirection(cmd_str);
|
||||||
|
@ -6,60 +6,31 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:59:01 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 16:09:37 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/17 11:23:21 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "signal_private.h"
|
#include "signal_private.h"
|
||||||
|
|
||||||
static void ft_new_line(void)
|
void ft_ctrlc_heredoc(int num)
|
||||||
|
{
|
||||||
|
close(0);
|
||||||
|
ft_putchar_fd('\n', 1);
|
||||||
|
(void) num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_ctrlc(int num)
|
||||||
{
|
{
|
||||||
rl_replace_line("", 0);
|
rl_replace_line("", 0);
|
||||||
rl_on_new_line();
|
rl_on_new_line();
|
||||||
ft_putchar_fd('\n', 1);
|
ft_putchar_fd('\n', 1);
|
||||||
rl_redisplay();
|
rl_redisplay();
|
||||||
}
|
*ft_get_exit_code() = 130;
|
||||||
|
(void) num;
|
||||||
void ft_ctrlc(int num)
|
|
||||||
{
|
|
||||||
t_data *data;
|
|
||||||
|
|
||||||
if (num == SIGQUIT)
|
|
||||||
return ;
|
|
||||||
data = ft_get_data();
|
|
||||||
data->exit_code = 130;
|
|
||||||
if (*ft_get_heredoc() != -1)
|
|
||||||
{
|
|
||||||
close(*ft_get_heredoc());
|
|
||||||
*ft_get_heredoc() = -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (data->child_pid > 1)
|
|
||||||
{
|
|
||||||
data->child_pid = 0;
|
|
||||||
ft_putchar_fd('\n', 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_new_line();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_quit(int num)
|
void ft_quit(int num)
|
||||||
{
|
{
|
||||||
t_data *data;
|
|
||||||
|
|
||||||
(void) num;
|
(void) num;
|
||||||
data = ft_get_data();
|
|
||||||
data->exit_code = 131;
|
|
||||||
if (data->child_pid > 1)
|
|
||||||
{
|
|
||||||
ft_printf("Quit (core dumped)\n");
|
ft_printf("Quit (core dumped)\n");
|
||||||
data->child_pid = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rl_replace_line("", 0);
|
|
||||||
rl_redisplay();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 16:02:31 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 16:03:11 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/17 11:14:28 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,5 +15,6 @@
|
|||||||
|
|
||||||
void ft_quit(int num);
|
void ft_quit(int num);
|
||||||
void ft_ctrlc(int num);
|
void ft_ctrlc(int num);
|
||||||
|
void ft_ctrlc_heredoc(int num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,13 +6,14 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/28 15:59:42 by cchauvet #+# #+# */
|
/* Created: 2023/03/28 15:59:42 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/28 16:04:46 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:05:00 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef SIGNAL_PRIVATE_H
|
#ifndef SIGNAL_PRIVATE_H
|
||||||
# define SIGNAL_PRIVATE_H
|
# define SIGNAL_PRIVATE_H
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
# include <stdio.h>
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "../libftx/libftx.h"
|
# include "../libftx/libftx.h"
|
||||||
|
BIN
subject.pdf
BIN
subject.pdf
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
|
/* Created: 2023/02/21 13:00:05 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/30 12:45:18 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/07 11:07:52 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ static int ft_quote_verif(const char *str)
|
|||||||
{
|
{
|
||||||
if (ft_is_in_quote(str, ft_strlen(str)))
|
if (ft_is_in_quote(str, ft_strlen(str)))
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: Quote is not closed\n");
|
ft_eprintf("bozoshell: Quote is not closed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -47,7 +47,7 @@ static int ft_pipe_is_alone(const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (check == 0)
|
if (check == 0)
|
||||||
ft_eprintf("minishell: Pipe must be followed and %s",
|
ft_eprintf("bozoshell: Pipe must be followed and %s",
|
||||||
"preced by a command or redirection\n");
|
"preced by a command or redirection\n");
|
||||||
return (check == 0);
|
return (check == 0);
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ static int ft_special_char_dub(const char *str)
|
|||||||
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|
if ((y > 2 && (str[i] == '>' || str[i] == '<'))
|
||||||
|| (y > 1 && str[i] == '|'))
|
|| (y > 1 && str[i] == '|'))
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: too many %s in a row\n", str);
|
ft_eprintf("bozoshell: too many %s in a row\n", str);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
i = i + y;
|
i = i + y;
|
||||||
@ -86,7 +86,7 @@ static int ft_empty_verif(const char *str)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] == ' ')
|
while (str[i] == ' ' || str[i] == '\t')
|
||||||
i++;
|
i++;
|
||||||
return (str[i] == '\0');
|
return (str[i] == '\0');
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ int ft_syntax_verif(t_data *data, const char *str)
|
|||||||
|| ft_pipe_is_alone(str)
|
|| ft_pipe_is_alone(str)
|
||||||
|| ft_special_char_dub(str))
|
|| ft_special_char_dub(str))
|
||||||
{
|
{
|
||||||
data->exit_code = 2;
|
*data->exit_code = 2;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
1
tester
1
tester
Submodule tester deleted from 1c6111b2fd
@ -6,7 +6,7 @@
|
|||||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||||
/* Updated: 2023/02/28 13:52:13 by erey-bet ### ########.fr */
|
/* Updated: 2023/04/04 13:40:43 by erey-bet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ static int ft_isspace(char c)
|
|||||||
|
|
||||||
int ft_atoi_check(const char *nptr)
|
int ft_atoi_check(const char *nptr)
|
||||||
{
|
{
|
||||||
long result;
|
int64_t result;
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
while (ft_isspace(*nptr))
|
while (ft_isspace(*nptr))
|
||||||
@ -37,9 +37,9 @@ int ft_atoi_check(const char *nptr)
|
|||||||
result = 0;
|
result = 0;
|
||||||
while (*nptr >= '0' && *nptr <= '9')
|
while (*nptr >= '0' && *nptr <= '9')
|
||||||
{
|
{
|
||||||
result = result * 10 + *nptr++ - '0';
|
result = result * 10 + (*nptr++ - '0') * sign;
|
||||||
if ((result > 2147483647 && sign == 1)
|
if ((result < 0 && sign == 1)
|
||||||
|| (result > 2147483647 && sign == 1))
|
|| (result > 0 && sign == -1))
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
if (*nptr--)
|
if (*nptr--)
|
||||||
|
@ -20,7 +20,7 @@ int ft_change_exit_code(t_data *data, int new_value)
|
|||||||
exit_code_str = ft_itoa(new_value);
|
exit_code_str = ft_itoa(new_value);
|
||||||
if (exit_code_str == NULL)
|
if (exit_code_str == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
/* Created: 2023/03/27 13:39:48 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/30 13:04:53 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/05 15:09:29 by alouis-j ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,20 +19,20 @@ char *ft_get_executable_with_path(t_data *data, const char *name)
|
|||||||
|
|
||||||
if (access(name, F_OK) != 0)
|
if (access(name, F_OK) != 0)
|
||||||
{
|
{
|
||||||
data->exit_code = 127;
|
*data->exit_code = 127;
|
||||||
ft_eprintf("minishell: %s: No such file or directery\n", name);
|
ft_eprintf("bozoshell: %s: No such file or directery\n", name);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (access(name, X_OK) != 0)
|
if (access(name, X_OK) != 0)
|
||||||
{
|
{
|
||||||
data->exit_code = 126;
|
*data->exit_code = 126;
|
||||||
ft_eprintf("minishell: %s: permission denied\n", name);
|
ft_eprintf("bozoshell: %s: permission denied\n", name);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
path = ft_strdup(name);
|
path = ft_strdup(name);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
return (path);
|
return (path);
|
||||||
@ -46,14 +46,14 @@ static char **ft_get_paths(t_data *data, const char *name)
|
|||||||
paths = get_value_by_key("PATH", data->env);
|
paths = get_value_by_key("PATH", data->env);
|
||||||
if (paths == NULL)
|
if (paths == NULL)
|
||||||
{
|
{
|
||||||
data->exit_code = 127;
|
*data->exit_code = 127;
|
||||||
ft_eprintf("minishell: %s: command not found\n", name);
|
ft_eprintf("bozoshell: %s: command not found\n", name);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
tab = ft_split(paths, ':');
|
tab = ft_split(paths, ':');
|
||||||
if (tab == NULL)
|
if (tab == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
return (tab);
|
return (tab);
|
||||||
@ -66,7 +66,7 @@ static char *ft_file_is_executable(const char *path, const char *name)
|
|||||||
out = ft_strmerger(3, path, "/", name);
|
out = ft_strmerger(3, path, "/", name);
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("bozoshell: malloc failed\n");
|
||||||
free(out);
|
free(out);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -97,8 +97,8 @@ static char *ft_get_executable_without_path(t_data *data, const char *name)
|
|||||||
ft_freer_tab_ultimate(1, paths);
|
ft_freer_tab_ultimate(1, paths);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
{
|
{
|
||||||
data->exit_code = 127;
|
*data->exit_code = 127;
|
||||||
ft_eprintf("minishell: %s: command not found\n", name);
|
ft_eprintf("bozoshell: %s: command not found\n", name);
|
||||||
}
|
}
|
||||||
return (path);
|
return (path);
|
||||||
}
|
}
|
||||||
|
@ -3,39 +3,38 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ft_is_in_quote.c :+: :+: :+: */
|
/* ft_is_in_quote.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/21 12:59:34 by cchauvet #+# #+# */
|
/* Created: 2023/03/30 15:39:25 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/27 15:32:44 by cchauvet ### ########.fr */
|
/* Updated: 2023/03/30 15:52:10 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
int ft_is_in_quote(const char *str, size_t n)
|
int ft_is_in_quote(const char *str, size_t n)
|
||||||
{
|
{
|
||||||
ssize_t i;
|
size_t i;
|
||||||
|
ssize_t start;
|
||||||
|
|
||||||
i = -1;
|
start = -1;
|
||||||
while (str[++i] != '\0' && i < (ssize_t) n)
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
{
|
{
|
||||||
if (str[i] == '\'')
|
if (i == n)
|
||||||
|
break ;
|
||||||
|
if (str[i] == '\"' || str[i] == '\'')
|
||||||
{
|
{
|
||||||
i++;
|
if (start == -1)
|
||||||
while (str[i] != '\'' && str[i] != '\0')
|
start = i;
|
||||||
{
|
else if (str[i] == str[start])
|
||||||
if (i == (ssize_t) n)
|
start = -1;
|
||||||
return (1);
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
if (start == -1)
|
||||||
if (str[i] == '"')
|
|
||||||
{
|
|
||||||
while (str[++i] != '"' && str[i] != '\0')
|
|
||||||
if (i == (ssize_t) n)
|
|
||||||
return (2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
|
if (str[start] == '\'')
|
||||||
|
return (1);
|
||||||
|
return (2);
|
||||||
}
|
}
|
||||||
|
90
utils/ft_split_charset_quoted.c
Normal file
90
utils/ft_split_charset_quoted.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split_charset_quoted.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/04/11 14:50:26 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2023/04/14 15:53:49 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
int new_strs(char ***strs, const char *to_split, int *i, int *j)
|
||||||
|
{
|
||||||
|
if (ft_strlen((*strs)[(*i)]) <= 0)
|
||||||
|
return (0);
|
||||||
|
(*i)++;
|
||||||
|
(*j) = 0;
|
||||||
|
(*strs)[(*i)] = ft_calloc(sizeof(char),
|
||||||
|
(ft_strlen(to_split) + 1));
|
||||||
|
if (!(*strs)[(*i)])
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_strs(const char *to_split, const char *charset, char ***strs, int *i)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int check;
|
||||||
|
|
||||||
|
x = -1;
|
||||||
|
j = 0;
|
||||||
|
while (to_split[++x])
|
||||||
|
{
|
||||||
|
y = -1;
|
||||||
|
check = 1;
|
||||||
|
while (charset[++y])
|
||||||
|
{
|
||||||
|
if (to_split[x] == charset[y] && !ft_is_in_quote(to_split, x))
|
||||||
|
{
|
||||||
|
check = 0;
|
||||||
|
if (new_strs(strs, to_split, i, &j))
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (check)
|
||||||
|
(*strs)[(*i)][j++] = to_split[x];
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_set_null(char ***strs, int i)
|
||||||
|
{
|
||||||
|
if (ft_strlen((*strs)[i]) == 0)
|
||||||
|
{
|
||||||
|
free((*strs)[i]);
|
||||||
|
(*strs)[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split_charset_quoted(const char *to_split, const char *charset)
|
||||||
|
{
|
||||||
|
char **strs;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
strs = ft_calloc(sizeof(char *), (ft_strlen(to_split) + 1));
|
||||||
|
if (!strs)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
strs[0] = ft_calloc(sizeof(char), (ft_strlen(to_split) + 1));
|
||||||
|
if (!strs[0])
|
||||||
|
{
|
||||||
|
free(strs);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (get_strs(to_split, charset, &strs, &i))
|
||||||
|
{
|
||||||
|
i = -1;
|
||||||
|
while (strs[++i])
|
||||||
|
free(strs[i]);
|
||||||
|
free(strs);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
free_set_null(&strs, i);
|
||||||
|
return (strs);
|
||||||
|
}
|
@ -1,75 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split_quoted.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/10/05 19:04:34 by cchauvet #+# #+# */
|
|
||||||
/* Updated: 2023/02/15 14:25:56 by cchauvet ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
size_t ft_seglen_quoted(const char *str, char c)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
len = 0;
|
|
||||||
i = 0;
|
|
||||||
while (str[i] != 0)
|
|
||||||
{
|
|
||||||
while ((str[i] == c || ft_is_in_quote(str, i)) && str[i] != 0)
|
|
||||||
i++;
|
|
||||||
if (str[i] != 0)
|
|
||||||
len++;
|
|
||||||
while ((str[i] != c || ft_is_in_quote(str, i)) && str[i] != 0)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)
|
|
||||||
{
|
|
||||||
size_t tab_index;
|
|
||||||
size_t let_i;
|
|
||||||
size_t start;
|
|
||||||
|
|
||||||
tab_index = 0;
|
|
||||||
let_i = 0;
|
|
||||||
start = 0;
|
|
||||||
if (tab == NULL || s == NULL)
|
|
||||||
return (NULL);
|
|
||||||
while (tab_index < len)
|
|
||||||
{
|
|
||||||
while ((s[let_i] == c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
|
|
||||||
let_i++;
|
|
||||||
start = let_i;
|
|
||||||
while ((s[let_i] != c || ft_is_in_quote(s, let_i)) && s[let_i] != 0)
|
|
||||||
let_i++;
|
|
||||||
tab[tab_index] = ft_substr(s, start, let_i - start);
|
|
||||||
if (tab[tab_index] == NULL)
|
|
||||||
return (ft_cancel((void *)tab, tab_index));
|
|
||||||
tab_index++;
|
|
||||||
}
|
|
||||||
return (tab);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split_quoted(const char *s, char c)
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
char **tab;
|
|
||||||
|
|
||||||
if (s == NULL)
|
|
||||||
return (NULL);
|
|
||||||
len = ft_seglen_quoted(s, c);
|
|
||||||
tab = malloc((len + 1) * sizeof(char *));
|
|
||||||
if (tab == NULL)
|
|
||||||
return (NULL);
|
|
||||||
tab[len] = NULL;
|
|
||||||
if (ft_segsplitter(tab, len, s, c) == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return (tab);
|
|
||||||
}
|
|
68
utils/tags
68
utils/tags
@ -1,68 +0,0 @@
|
|||||||
!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/
|
|
||||||
!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/
|
|
||||||
!_TAG_FIELD_DESCRIPTION epoch /the last modified time of the input file (only for F\/file kind tag)/
|
|
||||||
!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/
|
|
||||||
!_TAG_FIELD_DESCRIPTION input /input file/
|
|
||||||
!_TAG_FIELD_DESCRIPTION name /tag name/
|
|
||||||
!_TAG_FIELD_DESCRIPTION pattern /pattern/
|
|
||||||
!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/
|
|
||||||
!_TAG_FIELD_DESCRIPTION!C++ name /aliased names/
|
|
||||||
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
|
||||||
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C d,macro /macro definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C e,enumerator /enumerators (values inside an enumeration)/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C f,function /function definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C g,enum /enumeration names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C h,header /included header files/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C m,member /struct, and union members/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C s,struct /structure names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C t,typedef /typedefs/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C u,union /union names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C v,variable /variable definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ c,class /classes/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ d,macro /macro definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ e,enumerator /enumerators (values inside an enumeration)/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ f,function /function definitions/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ g,enum /enumeration names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ h,header /included header files/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ m,member /class, struct, and union members/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ n,namespace /namespaces/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ s,struct /structure names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ t,typedef /typedefs/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ u,union /union names/
|
|
||||||
!_TAG_KIND_DESCRIPTION!C++ v,variable /variable definitions/
|
|
||||||
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
|
|
||||||
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
|
|
||||||
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
|
|
||||||
!_TAG_OUTPUT_VERSION 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!C 0.0 /current.age/
|
|
||||||
!_TAG_PARSER_VERSION!C++ 0.0 /current.age/
|
|
||||||
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
|
|
||||||
!_TAG_PROC_CWD /nfs/homes/cchauvet/42/minishell/utils/ //
|
|
||||||
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
|
|
||||||
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
|
|
||||||
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
|
|
||||||
!_TAG_PROGRAM_VERSION 6.0.0 //
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!header local /local header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!header system /system header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!header local /local header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!header system /system header/
|
|
||||||
!_TAG_ROLE_DESCRIPTION!C++!macro undef /undefined/
|
|
||||||
UTILS_H utils.h /^# define UTILS_H$/;" d
|
|
||||||
ft_atoi_check ft_atoi_check.c /^int ft_atoi_check(const char *nptr)$/;" f typeref:typename:int
|
|
||||||
ft_change_exit_code ft_change_exit_code.c /^int ft_change_exit_code(t_data *data, int new_value)$/;" f typeref:typename:int
|
|
||||||
ft_is_in_quote ft_is_in_quote.c /^int ft_is_in_quote(const char *str, size_t n)$/;" f typeref:typename:int
|
|
||||||
ft_isspace ft_atoi_check.c /^static int ft_isspace(char c)$/;" f typeref:typename:int file:
|
|
||||||
ft_printn ft_printn.c /^void ft_printn(const char *str, size_t n)$/;" f typeref:typename:void
|
|
||||||
ft_quote_remover ft_quote_remover.c /^char *ft_quote_remover(char *str)$/;" f typeref:typename:char *
|
|
||||||
ft_seglen_quoted ft_split_quoted.c /^size_t ft_seglen_quoted(const char *str, char c)$/;" f typeref:typename:size_t
|
|
||||||
ft_segsplitter ft_split_quoted.c /^static char **ft_segsplitter(char **tab, size_t len, const char *s, char c)$/;" f typeref:typename:char ** file:
|
|
||||||
ft_split_quoted ft_split_quoted.c /^char **ft_split_quoted(const char *s, char c)$/;" f typeref:typename:char **
|
|
||||||
ft_str_is_empty ft_str_is_empty.c /^int ft_str_is_empty(const char *str)$/;" f typeref:typename:int
|
|
||||||
ft_strnchr ft_strnchr.c /^ssize_t ft_strnchr(const char *str, char c)$/;" f typeref:typename:ssize_t
|
|
||||||
ft_strncpy ft_strncpy.c /^size_t ft_strncpy(char *dst, const char *src, size_t n)$/;" f typeref:typename:size_t
|
|
||||||
ft_strreplace ft_strreplace.c /^char *ft_strreplace(const char *str, const char *fill,$/;" f typeref:typename:char *
|
|
||||||
ft_strshift ft_strshift.c /^void ft_strshift(char *str, int shift)$/;" f typeref:typename:void
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
/* Created: 2023/02/14 14:46:40 by cchauvet #+# #+# */
|
||||||
/* Updated: 2023/03/29 18:52:32 by cchauvet ### ########.fr */
|
/* Updated: 2023/04/11 16:55:16 by cchauvet ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ char *ft_strreplace(const char *str, const char *fill,
|
|||||||
ssize_t ft_strnchr(const char *str, char c);
|
ssize_t ft_strnchr(const char *str, char c);
|
||||||
char *ft_getstr(const char *str, size_t n);
|
char *ft_getstr(const char *str, size_t n);
|
||||||
int ft_str_is_empty(const char *str);
|
int ft_str_is_empty(const char *str);
|
||||||
char **ft_split_quoted(const char *s, char c);
|
char **ft_split_charset_quoted(const char *s, const char *charset);
|
||||||
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);
|
int ft_atoi_check(const char *nptr);
|
||||||
|
Reference in New Issue
Block a user