-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from facetint/facetint
Facetint
- Loading branch information
Showing
89 changed files
with
2,443 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* builtin.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/03 13:04:26 by facetint #+# #+# */ | ||
/* Updated: 2024/03/03 13:04:27 by facetint ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include "../includes/minishell.h" | ||
#include "../libft/libft.h" | ||
#include "../memory-allocator/allocator.h" | ||
#include "../includes/env.h" | ||
|
||
|
||
int isbuiltin(char *cmd) | ||
{ | ||
if (ft_strncmp(cmd, "echo", ft_strlen("echo")) == 0) | ||
return (1); | ||
if (ft_strncmp(cmd, "export", ft_strlen("export")) == 0) | ||
return (1); | ||
if (ft_strncmp(cmd, "env", ft_strlen("env")) == 0) | ||
return(1); | ||
if (ft_strncmp(cmd, "exit", ft_strlen("exit")) == 0) | ||
return (1); | ||
if (ft_strncmp(cmd, "pwd", ft_strlen("pwd")) == 0) | ||
return (1); | ||
if (ft_strncmp(cmd, "cd", ft_strlen("cd")) == 0) | ||
return(1); | ||
if (ft_strncmp(cmd, "unset", ft_strlen("unset")) == 0) | ||
return(1); | ||
return (0); | ||
} | ||
|
||
void handle_builtin(t_command *cmd, int fd[2]) | ||
{ | ||
if (ft_strncmp(cmd->name, "echo", ft_strlen("echo")) == 0) | ||
builtin_echo(cmd, fd); | ||
else if (ft_strncmp(cmd->name, "export", ft_strlen("export")) == 0) | ||
builtin_export(cmd, fd); | ||
else if (ft_strncmp(cmd->name, "env", ft_strlen("env")) == 0) | ||
builtin_env(get_global_env()); | ||
else if (ft_strncmp(cmd->name, "exit", ft_strlen("exit")) == 0) | ||
builtin_exit(cmd); | ||
else if (ft_strncmp(cmd->name, "pwd", ft_strlen("pwd")) == 0) | ||
builtin_pwd(cmd); | ||
if (ft_strncmp(cmd->name, "cd", ft_strlen("cd")) == 0) | ||
return; | ||
if (ft_strncmp(cmd->name, "unset", ft_strlen("unset")) == 0) | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: hcoskun <hcoskun@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
<<<<<<< HEAD:builtin/cd.c | ||
/* Created: 2024/03/03 11:48:16 by facetint #+# #+# */ | ||
/* Updated: 2024/03/03 11:48:37 by facetint ### ########.fr */ | ||
======= | ||
/* Created: 2023/06/24 20:38:03 by hcoskun42 #+# #+# */ | ||
/* Updated: 2023/07/08 14:34:36 by hcoskun ### ########.fr */ | ||
>>>>>>> main:libft/ft_putchar_fd.c | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/minishell.h" | ||
#include "../libft/libft.h" | ||
#include <stdio.h> | ||
|
||
<<<<<<< HEAD:builtin/cd.c | ||
======= | ||
void ft_putchar_fd(char c, int fd) | ||
{ | ||
write(fd, &c, 1); | ||
} | ||
>>>>>>> main:libft/ft_putchar_fd.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* echo.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/03 11:48:26 by facetint #+# #+# */ | ||
/* Updated: 2024/03/03 11:48:27 by facetint ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/minishell.h" | ||
#include "../libft/libft.h" | ||
#include <stdio.h> | ||
|
||
int is_n_option(char *str) | ||
{ | ||
int i; | ||
int len; | ||
|
||
if (!str) | ||
return 0; | ||
len = ft_strlen(str); | ||
if (len < 2) | ||
return 0; | ||
if (str[0] != '-') | ||
return 0; | ||
i = 1; | ||
while (str[i] == 'n') | ||
i++; | ||
if (i == len) | ||
return 1; | ||
return 0; | ||
} | ||
|
||
void builtin_echo(t_command *cmd, int fd[2]) | ||
{ | ||
char **args; | ||
int i; | ||
int n_option; | ||
|
||
args = cmd->args; | ||
i = 0; | ||
n_option = 0; | ||
while (is_n_option(args[i])) | ||
i++; | ||
if (i > 0) | ||
n_option = 1; | ||
while (args[i]) | ||
{ | ||
ft_putstr_fd(args[i], fd[1]); | ||
if (args[i + 1] != NULL) | ||
ft_putstr_fd(" ", fd[1]); | ||
i++; | ||
} | ||
if (!n_option) | ||
ft_putstr_fd("\n", fd[1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* env.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/02 20:06:35 by facetint #+# #+# */ | ||
/* Updated: 2024/03/02 20:14:21 by facetint ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/minishell.h" | ||
#include "../libft/libft.h" | ||
#include "../includes/env.h" | ||
#include <stdio.h> | ||
|
||
void builtin_env(t_envList *env) | ||
{ | ||
t_envList *lst; | ||
|
||
lst = env; | ||
while (lst) | ||
{ | ||
printf("%s=%s\n", lst->key, lst->value); | ||
lst = lst->next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* exit.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/03 13:04:14 by facetint #+# #+# */ | ||
/* Updated: 2024/03/03 14:11:41 by facetint ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/minishell.h" | ||
#include <stdio.h> | ||
#include "../memory-allocator/allocator.h" | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include "../libft/libft.h" | ||
#include "stdbool.h" | ||
|
||
static bool is_numeric(char *s) | ||
{ | ||
while ((9 <= *s && *s <= 13) || *s == 32) | ||
s++; | ||
if (*s == 43 || *s == 45) | ||
s++; | ||
while (48 <= *s && *s <= 57) | ||
s++; | ||
while ((9 <= *s && *s <= 13) || *s == 32) | ||
s++; | ||
if (*s != '\0') | ||
return (false); | ||
return (true); | ||
} | ||
void builtin_exit(t_command *cmd) | ||
{ | ||
bool status; | ||
int exit_value; | ||
|
||
exit_value = 0; | ||
if (!(cmd->args[0])) | ||
exit(EXIT_SUCCESS); | ||
status = is_numeric((cmd->args[0])); | ||
if (status == false) | ||
{ | ||
printf("bash: exit: %s: numeric argument required\n", | ||
cmd->args[0]); | ||
exit_value = 255; | ||
} | ||
else if (status == true && !(cmd->args[1])) | ||
exit_value = ft_atoi((cmd->args[0])); | ||
else | ||
{ | ||
printf("bash: exit: too many arguments\n"); | ||
return ; | ||
} | ||
exit(exit_value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* export.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: hcoskun <hcoskun@student.42.fr> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
<<<<<<< HEAD:builtin/export.c | ||
/* Created: 2024/03/02 14:15:14 by facetint #+# #+# */ | ||
/* Updated: 2024/03/03 11:39:15 by facetint ### ########.fr */ | ||
======= | ||
/* Created: 2023/07/08 16:18:16 by hcoskun #+# #+# */ | ||
/* Updated: 2023/07/11 14:47:49 by hcoskun ### ########.fr */ | ||
>>>>>>> main:libft/ft_lstadd_back.c | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "../includes/minishell.h" | ||
#include "../includes/env.h" | ||
#include <unistd.h> | ||
#include "../libft/libft.h" | ||
|
||
void builtin_export(t_command *cmd, int fd[2]) | ||
{ | ||
<<<<<<< HEAD:builtin/export.c | ||
(void)cmd; | ||
t_envList *tmp = get_global_env(); | ||
while (tmp) | ||
{ | ||
write(fd[1], "declare -x ", 12); | ||
write(fd[1], tmp->key, ft_strlen(tmp->key)); | ||
write(fd[1], "=", 1); | ||
write(fd[1], tmp->value, ft_strlen(tmp->value)); | ||
write(fd[1], "\n", 1); | ||
tmp = tmp->next; | ||
} | ||
|
||
} | ||
======= | ||
t_list *last_node; | ||
|
||
if (!lst) | ||
return ; | ||
if (!*lst) | ||
{ | ||
*lst = new; | ||
return ; | ||
} | ||
last_node = ft_lstlast(*lst); | ||
if (!last_node) | ||
return ; | ||
last_node -> next = new; | ||
} | ||
>>>>>>> main:libft/ft_lstadd_back.c |
Oops, something went wrong.