-
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 #1 from dimadem/diamdem_backend
Diamdem backend
- Loading branch information
Showing
15 changed files
with
505 additions
and
17 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 |
---|---|---|
@@ -1,2 +1,26 @@ | ||
![Norminette workflow](https://github.com/dimadem/minishell/actions/workflows/norminette.yml/badge.svg) | ||
![Compilation workflow](https://github.com/dimadem/minishell/actions/workflows/ci.yml/badge.svg) | ||
|
||
|
||
|
||
build/: Directory for object files and other intermediate build artifacts. | ||
|
||
docs/: Documentation for the project. | ||
|
||
inc/: Header files for the project, defining interfaces for different modules. | ||
- builtins.h: Declarations for built-in shell commands. | ||
- execute.h: Declarations for command execution functions. | ||
- parser.h: Declarations for command-line parsing functions. | ||
- pipe.h: Declarations for piping functions. | ||
- redirection.h: Declarations for redirection functions. | ||
- shell.h: General declarations for the shell. | ||
|
||
lib/: Directory for third-party libraries, such as libft. | ||
|
||
src/: Source files for the project, organized into subdirectories by functionality. | ||
- builtins/: Implementation of built-in shell commands. | ||
- execute/: Implementation of command execution logic. | ||
- parser/: Implementation of command-line parsing. | ||
- pipe/: Implementation of piping between commands. | ||
- redirection/: Implementation of input/output redirection. | ||
- main.c: Entry point of the shell application. |
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,25 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* builtins.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:34:46 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:34:47 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef BUILTINS_H | ||
# define BUILTINS_H | ||
|
||
/* builtin functions */ | ||
int builtin_cd(char **args); | ||
int builtin_echo(char **argv); | ||
int builtin_env(char **argv); | ||
int builtin_exit(char **argv); | ||
// int export(char **argv); | ||
// int pwd(char **argv); | ||
// int unset(char **argv); | ||
|
||
#endif |
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,18 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* execute.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:34:42 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:34:43 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef EXECUTE_H | ||
# define EXECUTE_H | ||
|
||
int execute(char **args); | ||
|
||
#endif |
Binary file not shown.
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,33 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:31:07 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:31:19 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include "libft.h" | ||
|
||
int builtin_cd(const char **args) | ||
{ | ||
char *target_dir; | ||
char *home_dir; | ||
|
||
home_dir = getenv("HOME"); | ||
target_dir = (char *)args[1]; | ||
if (!target_dir) | ||
target_dir = home_dir; | ||
else if (target_dir[0] == '~') | ||
target_dir = ft_strjoin(home_dir, target_dir + 1); | ||
if (chdir(target_dir) != 0) | ||
{ | ||
perror("cd"); | ||
return (1); | ||
} | ||
return (0); | ||
} |
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,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* echo.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:31:33 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:38:36 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
int builtin_echo(const char **argv) | ||
{ | ||
int newline; | ||
int i; | ||
|
||
newline = 1; | ||
if (ft_strcmp(argv[1], "-n") == 0) | ||
{ | ||
newline = 0; | ||
argv++; | ||
} | ||
i = -1; | ||
while (*argv++) | ||
{ | ||
write(1, argv[i], ft_strlen(argv[i])); | ||
i++; | ||
} | ||
if (newline) | ||
write(1, "\n", 1); | ||
return (0); | ||
} |
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,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* env.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:32:34 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:39:19 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int builtin_env(void) | ||
{ | ||
return (0); | ||
} |
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,16 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* exit.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/03 16:32:42 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:39:06 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int builtin_exit(void) | ||
{ | ||
return (0); | ||
} |
Empty file.
Empty file.
Empty file.
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,64 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* execute.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/31 11:02:00 by dmdemirk #+# #+# */ | ||
/* Updated: 2024/06/03 16:33:53 by dmdemirk ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "builtins.h" | ||
#include "libft.h" | ||
#include <stdio.h> | ||
#include <sys/wait.h> | ||
|
||
int new_process(char **args); | ||
|
||
int execute(char **args) | ||
{ | ||
size_t i; | ||
char *builtin_commands[7]; | ||
int (*builtin_functions[7])(char **); | ||
|
||
builtin_commands[0] = "cd"; | ||
builtin_commands[1] = "echo"; | ||
builtin_commands[2] = "env"; | ||
builtin_commands[3] = "exit"; | ||
builtin_functions[0] = &builtin_cd; | ||
builtin_functions[1] = &builtin_echo; | ||
builtin_functions[2] = &builtin_env; | ||
builtin_functions[3] = &builtin_exit; | ||
if (args[0] == NULL) | ||
return (1); | ||
i = -1; | ||
while (++i < sizeof(builtin_commands) / sizeof(char *)) | ||
{ | ||
if (ft_strcmp(args[0], builtin_commands[i]) == 0) | ||
return ((*builtin_functions[i])(args)); | ||
else | ||
return (new_process(args)); | ||
} | ||
return (1); | ||
} | ||
|
||
int new_process(char **args) | ||
{ | ||
pid_t pid; | ||
int status; | ||
|
||
pid = fork(); | ||
if (pid == 0) | ||
{ | ||
if (execvp(args[0], args) == -1) | ||
perror("minishell"); | ||
exit(EXIT_FAILURE); | ||
} | ||
else if (pid < 0) | ||
perror("minishell"); | ||
else | ||
waitpid(pid, &status, 0); | ||
return (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
Oops, something went wrong.