fixed norme
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/02/19 22:56:25 by tomoron ### ########.fr #
|
||||
# Updated: 2024/02/21 13:12:47 by marde-vr ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -19,6 +19,7 @@ SRCS_RAW = main.c\
|
||||
exit.c\
|
||||
echo.c\
|
||||
alias.c\
|
||||
unalias.c\
|
||||
pwd.c\
|
||||
parsing.c\
|
||||
debug.c\
|
||||
|
53
srcs/alias.c
53
srcs/alias.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/16 23:16:07 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/02/18 19:05:38 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/21 13:12:07 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -39,56 +39,25 @@ char *get_alias_value(t_cmd *arg)
|
||||
return (res);
|
||||
}
|
||||
|
||||
int unalias(t_cmd *args, t_alias **aliases)
|
||||
void print_aliases(t_alias **aliases)
|
||||
{
|
||||
t_alias *alias;
|
||||
|
||||
if (args->next && !ft_strcmp(args->next->token, "-a"))
|
||||
{
|
||||
free_alias(*aliases);
|
||||
*aliases = 0;
|
||||
return (0);
|
||||
}
|
||||
alias = *aliases;
|
||||
while (alias)
|
||||
{
|
||||
if (alias->next && args->next && !ft_strcmp(alias->next->name, args->next->token))
|
||||
{
|
||||
if (alias->next->next)
|
||||
alias->next = alias->next->next;
|
||||
else
|
||||
alias->next = 0;
|
||||
alias->next = 0;
|
||||
free_alias(alias);
|
||||
return (0);
|
||||
}
|
||||
if (alias->next)
|
||||
alias = alias->next;
|
||||
else
|
||||
alias = 0;
|
||||
}
|
||||
if (args->next && args->next->type == ARG)
|
||||
ft_printf("minishell: unalias: %s: not found\n", args->next->token);
|
||||
else
|
||||
ft_printf("unalias: usage: unalias name\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
int alias(t_cmd *args, t_alias **aliases)
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
t_alias *cur_alias;
|
||||
|
||||
cur_alias = *aliases;
|
||||
if (!args->next || args->next->type != ARG)
|
||||
{
|
||||
while (cur_alias)
|
||||
{
|
||||
ft_printf("alias %s=%s\n", cur_alias->name, cur_alias->value);
|
||||
cur_alias = cur_alias->next;
|
||||
}
|
||||
}
|
||||
|
||||
int alias(t_cmd *args, t_alias **aliases)
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
|
||||
if (!args->next || args->next->type != ARG)
|
||||
print_aliases(aliases);
|
||||
else
|
||||
{
|
||||
name = get_alias_name(args->next);
|
||||
@ -99,7 +68,7 @@ int alias(t_cmd *args, t_alias **aliases)
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_printf("alias %s=%s\n", name, ft_get_alias(*aliases, name));
|
||||
ft_printf("alias %s=%s\n", name, get_alias(*aliases, name));
|
||||
free(name);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/02/16 23:59:37 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/20 21:04:53 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,6 +16,7 @@ int cd(t_cmd *args)
|
||||
{
|
||||
char *new_wd;
|
||||
|
||||
ft_printf_fd(2, "%s\n", args->next->next->token);
|
||||
if (args->next && args->next->next && args->next->next->type == ARG)
|
||||
{
|
||||
ft_printf_fd(2, "minishell: cd: too many arguments\n");
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* debug.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 15:46:51 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:59:08 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 18:32:33 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:50:01 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -143,6 +143,7 @@ void exec_command(t_cmd *parsed_cmd, t_env **env, t_alias **aliases)
|
||||
int args_count;
|
||||
char **cmd_args;
|
||||
int i;
|
||||
pid_t pid;
|
||||
|
||||
if (!parsed_cmd || exec_builtin(parsed_cmd, env, aliases))
|
||||
return ;
|
||||
@ -159,7 +160,6 @@ void exec_command(t_cmd *parsed_cmd, t_env **env, t_alias **aliases)
|
||||
cur_cmd = cur_cmd->next;
|
||||
i++;
|
||||
}
|
||||
pid_t pid;
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
{
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* handle_alias.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/17 02:54:36 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 13:35:11 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/21 13:09:40 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,7 +22,7 @@ t_cmd *handle_alias(t_cmd *cmd, t_env *env, t_alias *alias)
|
||||
if (!cmd)
|
||||
return (0);
|
||||
if (cmd->type == ARG)
|
||||
alias_command = ft_get_alias(alias,cmd->token);
|
||||
alias_command = get_alias(alias, cmd->token);
|
||||
if (!alias_command)
|
||||
return (cmd);
|
||||
res = parse_command(alias_command, env);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 16:31:52 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/21 13:09:00 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,7 +43,7 @@ void free_alias(t_alias *alias)
|
||||
free(alias);
|
||||
}
|
||||
|
||||
char *ft_get_alias(t_alias *alias, char *name)
|
||||
char *get_alias(t_alias *alias, char *name)
|
||||
{
|
||||
while (alias)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/19 22:51:05 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:56:33 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -81,7 +81,8 @@ int main(int argc, char **argv, char **envp)
|
||||
(void)argv;
|
||||
env = get_env(envp);
|
||||
aliases = 0;
|
||||
aliases = alias_add_back(0, ft_strdup("test"), ft_strdup("echo test")); // debug
|
||||
aliases = alias_add_back(0, ft_strdup("test"), ft_strdup("echo test"));
|
||||
// debug
|
||||
handle_minishellrc(&env, &aliases);
|
||||
while (env && command)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 18:32:24 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/21 13:09:11 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -77,7 +77,7 @@ t_cmd *handle_alias(t_cmd *cmd, t_env *env, t_alias *alias);
|
||||
int cd(t_cmd *args);
|
||||
int alias(t_cmd *args, t_alias **aliases);
|
||||
void free_alias(t_alias *alias);
|
||||
char *ft_get_alias(t_alias *alias, char *var_name);
|
||||
char *get_alias(t_alias *alias, char *var_name);
|
||||
t_alias *alias_add_back(t_alias *alias, char *name, char *value);
|
||||
int unalias(t_cmd *args, t_alias **aliases);
|
||||
int ft_export(t_cmd *cmd, t_env **env);
|
||||
|
@ -6,31 +6,17 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/16 17:40:16 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/02/18 18:01:11 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:54:01 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void handle_minishellrc(t_env **env, t_alias **aliases)
|
||||
void exec_rc_file(t_env **env, t_alias **aliases, int fd)
|
||||
{
|
||||
char *home;
|
||||
char *rc_path;
|
||||
int fd;
|
||||
char *line;
|
||||
t_cmd *parsed_cmd;
|
||||
|
||||
home = ft_get_env(*env, "HOME");
|
||||
rc_path = ft_strjoin(home, "/.minishellrc");
|
||||
if (access(rc_path, R_OK) != -1)
|
||||
{
|
||||
fd = open(rc_path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
free(env);
|
||||
perror("open");
|
||||
return ;
|
||||
}
|
||||
line = get_next_line(fd);
|
||||
while (line)
|
||||
{
|
||||
@ -43,6 +29,26 @@ void handle_minishellrc(t_env **env, t_alias **aliases)
|
||||
free(line);
|
||||
line = get_next_line(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_minishellrc(t_env **env, t_alias **aliases)
|
||||
{
|
||||
char *home;
|
||||
char *rc_path;
|
||||
int fd;
|
||||
|
||||
home = ft_get_env(*env, "HOME");
|
||||
rc_path = ft_strjoin(home, "/.minishellrc");
|
||||
if (access(rc_path, R_OK) != -1)
|
||||
{
|
||||
fd = open(rc_path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
free(env);
|
||||
perror("open");
|
||||
return ;
|
||||
}
|
||||
exec_rc_file(env, aliases, fd);
|
||||
close(fd);
|
||||
}
|
||||
free(rc_path);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/18 12:41:34 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:57:40 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "minishell.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/09 18:31:21 by tomoron #+# #+# */
|
||||
/* Updated: 2024/02/16 21:19:30 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/02/21 12:47:39 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "minishell.h"
|
||||
|
56
srcs/unalias.c
Normal file
56
srcs/unalias.c
Normal file
@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* unalias.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/21 13:11:45 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/02/21 13:11:59 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int remove_alias(t_cmd *args, t_alias **aliases)
|
||||
{
|
||||
t_alias *alias;
|
||||
|
||||
alias = *aliases;
|
||||
while (alias)
|
||||
{
|
||||
if (alias->next && args->next
|
||||
&& !ft_strcmp(alias->next->name, args->next->token))
|
||||
{
|
||||
if (alias->next->next)
|
||||
alias->next = alias->next->next;
|
||||
else
|
||||
alias->next = 0;
|
||||
alias->next = 0;
|
||||
free_alias(alias);
|
||||
return (1);
|
||||
}
|
||||
if (alias->next)
|
||||
alias = alias->next;
|
||||
else
|
||||
alias = 0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int unalias(t_cmd *args, t_alias **aliases)
|
||||
{
|
||||
if (args->next && !ft_strcmp(args->next->token, "-a"))
|
||||
{
|
||||
free_alias(*aliases);
|
||||
*aliases = 0;
|
||||
return (0);
|
||||
}
|
||||
if (remove_alias(args, aliases))
|
||||
return (1);
|
||||
if (args->next && args->next->type == ARG)
|
||||
ft_printf("minishell: unalias: %s: not found\n", args->next->token);
|
||||
else
|
||||
ft_printf("unalias: usage: unalias name\n");
|
||||
return (1);
|
||||
}
|
Reference in New Issue
Block a user