Created file for builtins and fixed a bug about expansion not working correctly
This commit is contained in:
parent
1ecfba4340
commit
3f08544384
15 changed files with 243 additions and 429 deletions
22
exec/src/builtins/cd.c
Normal file
22
exec/src/builtins/cd.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/10 19:48:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_cd____(t_state *state, t_spawn_info info)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
45
exec/src/builtins/echo.c
Normal file
45
exec/src/builtins/echo.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* echo.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/10 19:47:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_echo__(t_state *state, t_spawn_info info)
|
||||
{
|
||||
t_usize i;
|
||||
bool print_line;
|
||||
t_string s;
|
||||
|
||||
print_line = true;
|
||||
i = 1;
|
||||
s = string_new(1024);
|
||||
if (i < info.arguments.len && str_compare(info.arguments.buffer[i], "-n"))
|
||||
{
|
||||
print_line = false;
|
||||
i++;
|
||||
}
|
||||
while (i < info.arguments.len - 1)
|
||||
{
|
||||
string_push(&s, info.arguments.buffer[i++]);
|
||||
string_push_char(&s, ' ');
|
||||
}
|
||||
if (i < info.arguments.len)
|
||||
string_push(&s, info.arguments.buffer[i]);
|
||||
if (print_line)
|
||||
string_push_char(&s, '\n');
|
||||
// TODO: change the null to the actual redirection thingy, this needs to be done in the handle_builtin function beforehand
|
||||
me_printf_fd(NULL, "%s", s.buf);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
19
exec/src/builtins/env.c
Normal file
19
exec/src/builtins/env.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 14:22:50 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/10 19:44:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/types.h"
|
||||
#include "exec/builtins.h"
|
||||
|
||||
t_error builtin_env___(t_state *state, t_spawn_info info)
|
||||
{
|
||||
return (NO_ERROR);
|
||||
}
|
||||
23
exec/src/builtins/exit.c
Normal file
23
exec/src/builtins/exit.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/10 19:49:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_exit__(t_state *state, t_spawn_info info)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
27
exec/src/builtins/export.c
Normal file
27
exec/src/builtins/export.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* export.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 14:13:41 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/10 19:43:58 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_export(t_state *state, t_spawn_info info)
|
||||
{
|
||||
if (info.arguments.len == 1)
|
||||
{
|
||||
// print env
|
||||
}
|
||||
else
|
||||
{
|
||||
// assign variable
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
28
exec/src/builtins/pwd.c
Normal file
28
exec/src/builtins/pwd.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pwd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/07 13:58:37 by rparodi #+# #+# */
|
||||
/* Updated: 2024/08/10 19:44:12 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_pwd___(t_state *state, t_spawn_info info)
|
||||
{
|
||||
t_string s;
|
||||
|
||||
s = string_new(1024);
|
||||
while (getcwd(s.buf, s.capacity - 1) == NULL)
|
||||
string_reserve(&s, s.capacity * 2);
|
||||
printf("%s\n", s.buf);
|
||||
string_free(s);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
22
exec/src/builtins/unset.c
Normal file
22
exec/src/builtins/unset.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* unset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/10 18:43:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/10 19:49:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/builtins.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
|
||||
t_error builtin_unset_(t_state *state, t_spawn_info info)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue