From 29a8e10e63f7e4ed1b08c4984c6c01431d3ccb06 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 19:08:18 +0200 Subject: first ideas of my understanding --- src/builtins_part_one.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/builtins_part_one.c diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c new file mode 100644 index 0000000..d7ab540 --- /dev/null +++ b/src/builtins_part_one.c @@ -0,0 +1,173 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtins_part_one.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: chuhlig +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ +/* Updated: 2024/08/09 19:07:31 by chuhlig ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int echo(char **av) +{ + int i; + int f; + + i = 1; + if (av[1][0] == '\0') + { + write(1, "\n", 1); + return (1); + } + if (ft_strcmp(av[1], "-n")) + { + i++; + f = 1; + } + while (av[i]) + { + write(1, &av[1], ft_strlen(av[i])); + i++; + } + if (f) + write(1, "\n", 1); + return (0); +} +// Und args wären bei +// echo Hello World +// dann +// echo, Hello und World + + +// Die Builtins haben bitte int als return type. 0 = Success, 1 = Error usw. +// Als Parameter kann ich dir die das hier geben: +// char **args +// Aufpassen: args[0] ist der Name des Commands. +// t_env *env +// Hier hast du alle Variablen drin. +// Schau dir dafür am besten env.h an. + + + +// 2-G-4:~ chuhlig$ echo -n hello +// hello2-G-4:~ chuhlig$ echo test -n hello +// test -n hello + + + +// minishell % echo -n "Das ist" +// echo -n " ein Beispiel" +// echo " für echo -n." + +// 2-G-4:~ chuhlig$ echo 'hello world' +// hello world +// 2-G-4:~ chuhlig$ echo hello'world' +// helloworld +// 2-G-4:~ chuhlig$ echo hello""world +// helloworld +// 2-G-4:~ chuhlig$ echo '' + +// 2-G-4:~ chuhlig$ echo "$PWD" +// /Users/chuhlig +// 2-G-4:~ chuhlig$ echo '$PWD' +// $PWD +// 2-G-4:~ chuhlig$ echo "aspas ->'" +// aspas ->' +// 2-G-4:~ chuhlig$ echo "aspas -> ' " +// aspas -> ' +// 2-G-4:~ chuhlig$ echo 'aspas ->"' +// aspas ->" +// 2-G-4:~ chuhlig$ echo 'aspas -> " ' +// aspas -> " +// 2-G-4:~ chuhlig$ echo "> >> < * ? [ ] | ; [ ] || && ( ) & # $ \ <<" +// > >> < * ? [ ] | ; [ ] || && ( ) & # $ \ << +// 2-G-4:~ chuhlig$ echo '> >> < * ? [ ] | ; [ ] || && ( ) & # $ \ <<' +// > >> < * ? [ ] | ; [ ] || && ( ) & # $ \ << +// 2-G-4:~ chuhlig$ echo "exit_code ->$? user ->$USER home -> $HOME" +// exit_code ->0 user ->chuhlig home -> /Users/chuhlig +// 2-G-4:~ chuhlig$ echo 'exit_code ->$? user ->$USER home -> $HOME' +// exit_code ->$? user ->$USER home -> $HOME +// 2-G-4:~ chuhlig$ echo "$" +// $ +// 2-G-4:~ chuhlig$ echo '$' +// $ +// 2-G-4:~ chuhlig$ echo $ +// $ + +// 2-G-4:~ chuhlig$ echo "test" -n hello +// test -n hello +// 2-G-4:~ chuhlig$ echo -n "test" -n hello +// test -n hello2-G-4:~ chuhlig$ echo -n "test" echo -n hello +// test echo -n hello2-G-4:~ chuhlig$ + + + +// 2-G-4:~ chuhlig$ echo -n "test1 test2" test3 +// test1 test2 test32-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n " test1 test2 " 'test3 ' +// test1 test2 test3 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n test1test2 +// test1test22-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo test1 -n +// test1 -n +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo "test1 -n" +// test1 -n +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -n test1 +// test12-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -n -n -n -n test1 +// test12-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo - +// - +// 2-G-4:~ chuhlig$ echo -- +// -- +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo " -nn " +// -nn +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo "-n test1 -n test2" +// -n test1 -n test2 +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo "test1 -n test2" +// test1 -n test2 +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo ~42 +// ~42 +// 2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -n -nasd +// -nasd2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -n -n-nnnnn +// -n-nnnnn2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -nnnnnnn -n -nnn -nnnnn -n-n +// -n-n2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -nnnnnnn -n -nnn -nnnnn -n feel my pain +// feel my pain2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo -n -n -n-n +// -n-n2-G-4:~ chuhlig$ +// 2-G-4:~ chuhlig$ echo "'totally logical'" +// 'totally logical' +// 2-G-4:~ chuhlig$ echo 'totally logical' +// totally logical +// 2-G-4:~ chuhlig$ echo ''totally logical'' +// totally logical +// 2-G-4:~ chuhlig$ echo ""'totally logical'"" +// totally logical + +// 2-G-4:~ chuhlig$ eCho + +// 2-G-4:~ chuhlig$ eChO + +// 2-G-4:~ chuhlig$ eCHO + +// 2-G-4:~ chuhlig$ ECHO +int pwd_builtin(void) +{ + char cwd[1028]; + + getcwd(cwd, sizeof(cwd)); + printf("%s\n", cwd); + return (0); +} \ No newline at end of file -- cgit v1.2.3 From d9fcd5d84006f312dc417124c697341f2d94de6b Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Sun, 18 Aug 2024 04:30:20 +0200 Subject: 2nd push with unset export exit and cd --- src/builtins_part_one.c | 267 ++++++++++++++++++++++++------------------------ 1 file changed, 135 insertions(+), 132 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index d7ab540..fc0fdab 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,16 +6,19 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/08/09 19:07:31 by chuhlig ### ########.fr */ +/* Updated: 2024/08/18 04:28:56 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ +#include "env.h" + int echo(char **av) { int i; int f; i = 1; + f = 1; if (av[1][0] == '\0') { write(1, "\n", 1); @@ -24,7 +27,7 @@ int echo(char **av) if (ft_strcmp(av[1], "-n")) { i++; - f = 1; + f = 0; } while (av[i]) { @@ -35,139 +38,139 @@ int echo(char **av) write(1, "\n", 1); return (0); } -// Und args wären bei -// echo Hello World -// dann -// echo, Hello und World - - -// Die Builtins haben bitte int als return type. 0 = Success, 1 = Error usw. -// Als Parameter kann ich dir die das hier geben: -// char **args -// Aufpassen: args[0] ist der Name des Commands. -// t_env *env -// Hier hast du alle Variablen drin. -// Schau dir dafür am besten env.h an. - - - -// 2-G-4:~ chuhlig$ echo -n hello -// hello2-G-4:~ chuhlig$ echo test -n hello -// test -n hello - - - -// minishell % echo -n "Das ist" -// echo -n " ein Beispiel" -// echo " für echo -n." - -// 2-G-4:~ chuhlig$ echo 'hello world' -// hello world -// 2-G-4:~ chuhlig$ echo hello'world' -// helloworld -// 2-G-4:~ chuhlig$ echo hello""world -// helloworld -// 2-G-4:~ chuhlig$ echo '' - -// 2-G-4:~ chuhlig$ echo "$PWD" -// /Users/chuhlig -// 2-G-4:~ chuhlig$ echo '$PWD' -// $PWD -// 2-G-4:~ chuhlig$ echo "aspas ->'" -// aspas ->' -// 2-G-4:~ chuhlig$ echo "aspas -> ' " -// aspas -> ' -// 2-G-4:~ chuhlig$ echo 'aspas ->"' -// aspas ->" -// 2-G-4:~ chuhlig$ echo 'aspas -> " ' -// aspas -> " -// 2-G-4:~ chuhlig$ echo "> >> < * ? [ ] | ; [ ] || && ( ) & # $ \ <<" -// > >> < * ? [ ] | ; [ ] || && ( ) & # $ \ << -// 2-G-4:~ chuhlig$ echo '> >> < * ? [ ] | ; [ ] || && ( ) & # $ \ <<' -// > >> < * ? [ ] | ; [ ] || && ( ) & # $ \ << -// 2-G-4:~ chuhlig$ echo "exit_code ->$? user ->$USER home -> $HOME" -// exit_code ->0 user ->chuhlig home -> /Users/chuhlig -// 2-G-4:~ chuhlig$ echo 'exit_code ->$? user ->$USER home -> $HOME' -// exit_code ->$? user ->$USER home -> $HOME -// 2-G-4:~ chuhlig$ echo "$" -// $ -// 2-G-4:~ chuhlig$ echo '$' -// $ -// 2-G-4:~ chuhlig$ echo $ -// $ - -// 2-G-4:~ chuhlig$ echo "test" -n hello -// test -n hello -// 2-G-4:~ chuhlig$ echo -n "test" -n hello -// test -n hello2-G-4:~ chuhlig$ echo -n "test" echo -n hello -// test echo -n hello2-G-4:~ chuhlig$ - - - -// 2-G-4:~ chuhlig$ echo -n "test1 test2" test3 -// test1 test2 test32-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n " test1 test2 " 'test3 ' -// test1 test2 test3 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n test1test2 -// test1test22-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo test1 -n -// test1 -n -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo "test1 -n" -// test1 -n -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -n test1 -// test12-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -n -n -n -n test1 -// test12-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo - -// - -// 2-G-4:~ chuhlig$ echo -- -// -- -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo " -nn " -// -nn -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo "-n test1 -n test2" -// -n test1 -n test2 -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo "test1 -n test2" -// test1 -n test2 -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo ~42 -// ~42 -// 2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -n -nasd -// -nasd2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -n -n-nnnnn -// -n-nnnnn2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -nnnnnnn -n -nnn -nnnnn -n-n -// -n-n2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -nnnnnnn -n -nnn -nnnnn -n feel my pain -// feel my pain2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo -n -n -n-n -// -n-n2-G-4:~ chuhlig$ -// 2-G-4:~ chuhlig$ echo "'totally logical'" -// 'totally logical' -// 2-G-4:~ chuhlig$ echo 'totally logical' -// totally logical -// 2-G-4:~ chuhlig$ echo ''totally logical'' -// totally logical -// 2-G-4:~ chuhlig$ echo ""'totally logical'"" -// totally logical - -// 2-G-4:~ chuhlig$ eCho - -// 2-G-4:~ chuhlig$ eChO - -// 2-G-4:~ chuhlig$ eCHO - -// 2-G-4:~ chuhlig$ ECHO -int pwd_builtin(void) + +int pwd(void) { char cwd[1028]; getcwd(cwd, sizeof(cwd)); printf("%s\n", cwd); return (0); -} \ No newline at end of file +} + +int env(char **env) +{ + int i; + + i = 0; + while (env[i] != NULL) + { + printf("%s\n", env[i]); + i++; + } + return (0); +} + +int cd(char **av) +{ + + if(av[1] == NULL) + { + while (env[i] != NULL) // home command + { + if (ft_strncmp(env[i], "HOME=", 5) == 0) + break ; + i++; + } + // before chdir we need to update old pwd + // getcwd(cwd, sizeof(cwd)); + // str = ft_strjoin("PWD= or old pwd=", cwd); + // env[i] = str; + if(chdir(env[i] + 5) == -1) + return; + } + else + //update old pwd + // + while (env[i] != NULL) // home command + { + if (ft_strncmp(env[i], "old PWD=", 5) == 0) + break ; + i++; + } + str = ft_strjoin("old pwd=", cwd); + env[i] = str; + // + chdir(av[1] == -1); + return ; + // udpate pwd + while (env[i] != NULL) // home command + { + if (ft_strncmp(env[i], "PWD=", 5) == 0) + break ; + i++; + } + str = ft_strjoin("PWD=", cwd); + env[i] = str; +} + +// exit + + +int exit(char *av) +{ + freenode free toke free sequence stop repl free env + clear history +} +//joar + +//export + +int export(char **av, t_env **env) +{ + char *tmp; + if(tmp = ft_strchr(av[1])) + { + tmp = '\0'; + t_env *current; + current = *env; + while(current) + { + if (strcmp(current->name, av[1]) == 0) + { + free(current->value); + current->value = ft_strdup(tmp + 1); + break; + } + current = current->next; + } + if (!current) + { + current = malloc(sizeof(t_env)); + current->name = ft_strdup(av[1]); + current->value = ft_strdup(tmp + 1); + current->next = *env; + *env = current; + } + return (0); + } + else + syntax return 1; +} + +//unset + +int unset(char **av, t_env **env) +{ + t_env *current; + t_env *prev; + + current = env; + prev = NULL; + while (current) + { + if(ft_strcmp(current->name, av[1] == 0)) + break ; + prev = current; + current = current->next; + } + if(current) + { + if(prev) + prev->next = current->next; + else + *env = current->next + free(t_env); + } + return (0); +} -- cgit v1.2.3 From 8fb55b598b6a2f7565fe4a5f82186dc04ee6e7eb Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Thu, 29 Aug 2024 15:55:46 +0200 Subject: temporary here get envlst --- src/builtins_part_one.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index fc0fdab..6ca0caa 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/08/18 04:28:56 by chuhlig ### ########.fr */ +/* Updated: 2024/08/29 14:24:13 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -116,10 +116,11 @@ int exit(char *av) //export +// add a part to append it to list and maybe also check bc export pwd or home stuf int export(char **av, t_env **env) { char *tmp; - if(tmp = ft_strchr(av[1])) + if(tmp = ft_strchr(av[1], '=')) { tmp = '\0'; t_env *current; @@ -149,14 +150,17 @@ int export(char **av, t_env **env) } //unset - +//for unset as well check and for name part int unset(char **av, t_env **env) { t_env *current; t_env *prev; - + char *tmp; + current = env; prev = NULL; + tmp = ft_strchr(av[1], '='); + tmp = '\0'; while (current) { if(ft_strcmp(current->name, av[1] == 0)) @@ -174,3 +178,27 @@ int unset(char **av, t_env **env) } return (0); } + +void getenvlst(t_env **env, char **en) +{ + char *tmp; + int i; + int t; + t_env *current; + + t = 0; + i = 0; + while (en[i] != NULL) + { + tmp = ft_strchr(en[i], '='); + tmp = '\0'; + current = *env; + current = malloc(sizeof(t_env)); + current->name = ft_strdup(en[i]); + current->value = ft_strdup(tmp + 1); + current->next = *env; + *env = current; + i++; + } + return (0); +} \ No newline at end of file -- cgit v1.2.3 From 85ddabacb816a04fa86875d0aab6ec6337e132ed Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Thu, 29 Aug 2024 15:56:23 +0200 Subject: just date --- src/main.c | 2 +- src/tokenizer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 8523b9e..596b611 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */ -/* Updated: 2024/07/18 16:44:14 by chuhlig ### ########.fr */ +/* Updated: 2024/08/26 19:55:57 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/tokenizer.c b/src/tokenizer.c index 34685ac..dfdffe1 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */ +/* Updated: 2024/08/29 15:01:48 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit v1.2.3 From 5373e9e53accb20438d92a78224221734786d051 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Thu, 29 Aug 2024 15:57:14 +0200 Subject: added other token append to remove the error that its not at the start --- src/new_token.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/new_token.c b/src/new_token.c index 92ff421..6431c7d 100644 --- a/src/new_token.c +++ b/src/new_token.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* new_token.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 14:29:44 by dkaiser #+# #+# */ -/* Updated: 2024/06/28 14:59:34 by dkaiser ### ########.fr */ +/* Updated: 2024/08/29 15:30:52 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,3 +50,28 @@ t_token *new_redir_token(int type, t_token *previous, t_token *next) token->content.redir_type = type; return (token); } + +// void ft_append_token(int type, t_token **list)// but we need somewhere token/node head initialize with nul +// { +// t_token *node; +// t_token *last_node; + +// if (!list) +// return ; +// node = malloc(sizeof(t_token)); +// if (!node) +// return ; +// node->next = NULL; +// node->type = type; +// if (!*list) +// { +// *list = node; +// node->previous = NULL; +// } +// else +// { +// last_node = ft_lstlast(*list); +// last_node->next = node; +// node->previous = last_node; +// } +// } \ No newline at end of file -- cgit v1.2.3 From 801598045e52071af1effa3a28ddffb17671b08e Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Wed, 4 Sep 2024 17:53:41 +0200 Subject: update for builtins and now 2 envlist --- src/builtins_part_one.c | 79 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 21 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index 6ca0caa..10d8979 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,13 +6,13 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/08/29 14:24:13 by chuhlig ### ########.fr */ +/* Updated: 2024/09/04 17:52:49 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "env.h" -int echo(char **av) +int echo(char **av)//more or less done { int i; int f; @@ -39,29 +39,44 @@ int echo(char **av) return (0); } -int pwd(void) + +int pwd(t_env **env, char *av) //done { - char cwd[1028]; + t_env *current; + t_env *prev; + char *tmp; - getcwd(cwd, sizeof(cwd)); - printf("%s\n", cwd); + current = env; + prev = NULL; + while (current) + { + if(ft_strcmp(current->name, av == 0)) + break ; + prev = current; + current = current->next; + } + ft_printf("%s\n", current->value); return (0); } -int env(char **env) +int env(t_env **env)// here i need str env oder ich print es alles zusammen xD { - int i; + t_env *current; + t_env *prev; + char *tmp; - i = 0; - while (env[i] != NULL) + current = env; + prev = NULL; + while (current) { - printf("%s\n", env[i]); - i++; + ft_printf("%s\n", current->name); + prev = current; + current = current->next; } return (0); } -int cd(char **av) +int cd(t_env **env,char **av) // here also need to do the same again for envstrarr. dont like it { if(av[1] == NULL) @@ -116,8 +131,7 @@ int exit(char *av) //export -// add a part to append it to list and maybe also check bc export pwd or home stuf -int export(char **av, t_env **env) +int export(char **av, t_env **env) // here also need to do the same again for envstrarr. dont like it { char *tmp; if(tmp = ft_strchr(av[1], '=')) @@ -151,7 +165,7 @@ int export(char **av, t_env **env) //unset //for unset as well check and for name part -int unset(char **av, t_env **env) +int unset(char **av, t_env **env) // here also need to do the same again for envstrarr. dont like it { t_env *current; t_env *prev; @@ -174,19 +188,17 @@ int unset(char **av, t_env **env) prev->next = current->next; else *env = current->next - free(t_env); + free(t_env);//need function for this } return (0); } -void getenvlst(t_env **env, char **en) +void getenvlst(t_env **env, char **en)// seperated name and value { char *tmp; int i; - int t; t_env *current; - t = 0; i = 0; while (en[i] != NULL) { @@ -201,4 +213,29 @@ void getenvlst(t_env **env, char **en) i++; } return (0); -} \ No newline at end of file +} + +void getenvlststr(t_env **env, char **en)//without serparation +{ + int i; + size_t t; + t_env *current; + + t = 0; + i = 0; + while (en[i] != NULL) + { + current = *env; + current = malloc(sizeof(t_env)); + while(en[t] != '=') + t++; + current->name = ft_substr(en[i], 0, t); + current->value = ft_strdup(en[i]); + current->next = *env; + *env = current; + i++; + } + return (0); +} + +//should name the list different \ No newline at end of file -- cgit v1.2.3 From fd179cf97e176b00cd01763d82e89d9af6ed355c Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 13 Sep 2024 21:21:09 +0200 Subject: update builtins for env structure --- src/builtins_part_one.c | 141 ++++++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 59 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index 10d8979..e99bb90 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,13 +6,13 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/09/04 17:52:49 by chuhlig ### ########.fr */ +/* Updated: 2024/09/13 21:20:17 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "env.h" -int echo(char **av)//more or less done +int echo(char **av) { int i; int f; @@ -40,7 +40,7 @@ int echo(char **av)//more or less done } -int pwd(t_env **env, char *av) //done +int pwd(t_env **env, char *av) { t_env *current; t_env *prev; @@ -59,75 +59,98 @@ int pwd(t_env **env, char *av) //done return (0); } -int env(t_env **env)// here i need str env oder ich print es alles zusammen xD +int env(t_env **env) { t_env *current; t_env *prev; - char *tmp; current = env; prev = NULL; while (current) { - ft_printf("%s\n", current->name); + ft_printf("%s", current->name); + ft_printf("=%s\n", current->value); prev = current; current = current->next; } return (0); } -int cd(t_env **env,char **av) // here also need to do the same again for envstrarr. dont like it +void update_oldpwd(t_env **env) { + t_env *current; + t_env *prev; + char cwd[1028]; + char *tmp; - if(av[1] == NULL) - { - while (env[i] != NULL) // home command + while (current) // home command { - if (ft_strncmp(env[i], "HOME=", 5) == 0) + if (ft_strncmp(current->name, "OLDPWD", 6) == 0) break ; - i++; + prev = current; + current = current->next; } - // before chdir we need to update old pwd - // getcwd(cwd, sizeof(cwd)); - // str = ft_strjoin("PWD= or old pwd=", cwd); - // env[i] = str; - if(chdir(env[i] + 5) == -1) - return; + getcwd(cwd, sizeof(cwd)); + tmp = ft_strdup(cwd); + free(current->value); + current->value = tmp; +} + +void update_pwd(t_env **env) +{ + t_env *current; + t_env *prev; + char cwd[1028]; + char *tmp; + + while (current) + { + if (ft_strncmp(current->name, "PWD", 3) == 0) + break ; + prev = current; + current = current->next; } - else - //update old pwd - // - while (env[i] != NULL) // home command + getcwd(cwd, sizeof(cwd)); + tmp = ft_strdup(cwd); + free(current->value); + current->value = tmp; +} + +int cd(t_env **env,char **av) +{ + t_env *current; + t_env *prev; + t_env *pwd; + + current = env; + if(av[1] == NULL) + { + while (current) // home command { - if (ft_strncmp(env[i], "old PWD=", 5) == 0) - break ; - i++; + if (ft_strncmp(current->name, "HOME", 4) == 0) + break ; + prev = current; + current = current->next; } - str = ft_strjoin("old pwd=", cwd); - env[i] = str; - // - chdir(av[1] == -1); + if(chdir(current->value) == -1) return ; - // udpate pwd - while (env[i] != NULL) // home command + } + else { - if (ft_strncmp(env[i], "PWD=", 5) == 0) - break ; - i++; + update_oldpwd(&env); + if(chdir(av[1]) == -1) + return ; + update_pwd(&env); } - str = ft_strjoin("PWD=", cwd); - env[i] = str; } // exit - int exit(char *av) { freenode free toke free sequence stop repl free env clear history } -//joar //export @@ -215,27 +238,27 @@ void getenvlst(t_env **env, char **en)// seperated name and value return (0); } -void getenvlststr(t_env **env, char **en)//without serparation -{ - int i; - size_t t; - t_env *current; +// void getenvlststr(t_env **env, char **en)//without serparation +// { +// int i; +// size_t t; +// t_env *current; - t = 0; - i = 0; - while (en[i] != NULL) - { - current = *env; - current = malloc(sizeof(t_env)); - while(en[t] != '=') - t++; - current->name = ft_substr(en[i], 0, t); - current->value = ft_strdup(en[i]); - current->next = *env; - *env = current; - i++; - } - return (0); -} +// t = 0; +// i = 0; +// while (en[i] != NULL) +// { +// current = *env; +// current = malloc(sizeof(t_env)); +// while(en[t] != '=') +// t++; +// current->name = ft_substr(en[i], 0, t); +// current->value = ft_strdup(en[i]); +// current->next = *env; +// *env = current; +// i++; +// } +// return (0); +// } //should name the list different \ No newline at end of file -- cgit v1.2.3 From a4927cc09474bcd1cf7280392485146abce0a12c Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 13 Sep 2024 21:46:52 +0200 Subject: update for unset export and cd --- src/builtins_part_one.c | 61 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index e99bb90..42561e9 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/09/13 21:20:17 by chuhlig ### ########.fr */ +/* Updated: 2024/09/13 21:46:08 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -125,6 +125,7 @@ int cd(t_env **env,char **av) current = env; if(av[1] == NULL) { + update_oldpwd(&env); while (current) // home command { if (ft_strncmp(current->name, "HOME", 4) == 0) @@ -157,33 +158,39 @@ int exit(char *av) int export(char **av, t_env **env) // here also need to do the same again for envstrarr. dont like it { char *tmp; - if(tmp = ft_strchr(av[1], '=')) + t_env *current; + int i; + + i = i; + while(av[i]) { - tmp = '\0'; - t_env *current; - current = *env; - while(current) + if(tmp = ft_strchr(av[i], '=')) { - if (strcmp(current->name, av[1]) == 0) + tmp = '\0'; + current = *env; + while(current) { - free(current->value); - current->value = ft_strdup(tmp + 1); - break; - } - current = current->next; + if (strcmp(current->name, av[i]) == 0) + { + free(current->value); + current->value = ft_strdup(tmp + 1); + break; + } + current = current->next; + } + if (!current) + { + current = malloc(sizeof(t_env)); + current->name = ft_strdup(av[i]); + current->value = ft_strdup(tmp + 1); + current->next = *env; + *env = current; + } + return (0); } - if (!current) - { - current = malloc(sizeof(t_env)); - current->name = ft_strdup(av[1]); - current->value = ft_strdup(tmp + 1); - current->next = *env; - *env = current; - } - return (0); + i++; } - else - syntax return 1; + return 1; } //unset @@ -192,12 +199,9 @@ int unset(char **av, t_env **env) // here also need to do the same again for env { t_env *current; t_env *prev; - char *tmp; current = env; prev = NULL; - tmp = ft_strchr(av[1], '='); - tmp = '\0'; while (current) { if(ft_strcmp(current->name, av[1] == 0)) @@ -210,8 +214,9 @@ int unset(char **av, t_env **env) // here also need to do the same again for env if(prev) prev->next = current->next; else - *env = current->next - free(t_env);//need function for this + *env = current->next; + free(current->value); + free(current); } return (0); } -- cgit v1.2.3 From 9b1ddf7b3491f26d8b3ba9daeca7174aede9c781 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Tue, 17 Sep 2024 16:34:57 +0200 Subject: added remove for env list --- src/builtins_part_one.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index 42561e9..5a35236 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/09/13 21:46:08 by chuhlig ### ########.fr */ +/* Updated: 2024/09/17 16:23:15 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -155,7 +155,7 @@ int exit(char *av) //export -int export(char **av, t_env **env) // here also need to do the same again for envstrarr. dont like it +int export(char **av, t_env **env) { char *tmp; t_env *current; @@ -195,7 +195,7 @@ int export(char **av, t_env **env) // here also need to do the same again for en //unset //for unset as well check and for name part -int unset(char **av, t_env **env) // here also need to do the same again for envstrarr. dont like it +int unset(char **av, t_env **env) { t_env *current; t_env *prev; @@ -243,6 +243,24 @@ void getenvlst(t_env **env, char **en)// seperated name and value return (0); } + +void free_envlst(t_env **env) +{ + t_env *cur; + t_env *new; + + cur = *env; + while (cur) + { + new = cur->next; + free(cur->name); + free(cur->value); + free(cur); + cur = new; + } + +} + // void getenvlststr(t_env **env, char **en)//without serparation // { // int i; -- cgit v1.2.3 From 2b6dfc7368384655da2a843896539f443695b972 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Thu, 17 Oct 2024 14:30:23 +0200 Subject: removed env stuf to move it into env branch --- src/builtins_part_one.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index 5a35236..d817336 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/09/17 16:23:15 by chuhlig ### ########.fr */ +/* Updated: 2024/10/17 14:29:40 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -221,45 +221,6 @@ int unset(char **av, t_env **env) return (0); } -void getenvlst(t_env **env, char **en)// seperated name and value -{ - char *tmp; - int i; - t_env *current; - - i = 0; - while (en[i] != NULL) - { - tmp = ft_strchr(en[i], '='); - tmp = '\0'; - current = *env; - current = malloc(sizeof(t_env)); - current->name = ft_strdup(en[i]); - current->value = ft_strdup(tmp + 1); - current->next = *env; - *env = current; - i++; - } - return (0); -} - - -void free_envlst(t_env **env) -{ - t_env *cur; - t_env *new; - - cur = *env; - while (cur) - { - new = cur->next; - free(cur->name); - free(cur->value); - free(cur); - cur = new; - } - -} // void getenvlststr(t_env **env, char **en)//without serparation // { -- cgit v1.2.3 From 00ad7429f223c85e99da6ffa8f7dade0c73c97b5 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 25 Oct 2024 20:53:44 +0200 Subject: update for builtins and extra functions --- src/builtins_part_one.c | 180 +++++++++++------------------------------------- src/builtins_part_two.c | 82 ++++++++++++++++++++++ 2 files changed, 124 insertions(+), 138 deletions(-) create mode 100644 src/builtins_part_two.c diff --git a/src/builtins_part_one.c b/src/builtins_part_one.c index d817336..6b92d9c 100644 --- a/src/builtins_part_one.c +++ b/src/builtins_part_one.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/09 17:01:16 by chuhlig #+# #+# */ -/* Updated: 2024/10/17 14:29:40 by chuhlig ### ########.fr */ +/* Updated: 2024/10/25 20:52:36 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,6 @@ int echo(char **av) return (0); } - int pwd(t_env **env, char *av) { t_env *current; @@ -50,7 +49,7 @@ int pwd(t_env **env, char *av) prev = NULL; while (current) { - if(ft_strcmp(current->name, av == 0)) + if (ft_strcmp(current->name, av == 0)) break ; prev = current; current = current->next; @@ -76,85 +75,12 @@ int env(t_env **env) return (0); } -void update_oldpwd(t_env **env) -{ - t_env *current; - t_env *prev; - char cwd[1028]; - char *tmp; - - while (current) // home command - { - if (ft_strncmp(current->name, "OLDPWD", 6) == 0) - break ; - prev = current; - current = current->next; - } - getcwd(cwd, sizeof(cwd)); - tmp = ft_strdup(cwd); - free(current->value); - current->value = tmp; -} - -void update_pwd(t_env **env) -{ - t_env *current; - t_env *prev; - char cwd[1028]; - char *tmp; - - while (current) - { - if (ft_strncmp(current->name, "PWD", 3) == 0) - break ; - prev = current; - current = current->next; - } - getcwd(cwd, sizeof(cwd)); - tmp = ft_strdup(cwd); - free(current->value); - current->value = tmp; -} - -int cd(t_env **env,char **av) -{ - t_env *current; - t_env *prev; - t_env *pwd; - - current = env; - if(av[1] == NULL) - { - update_oldpwd(&env); - while (current) // home command - { - if (ft_strncmp(current->name, "HOME", 4) == 0) - break ; - prev = current; - current = current->next; - } - if(chdir(current->value) == -1) - return ; - } - else - { - update_oldpwd(&env); - if(chdir(av[1]) == -1) - return ; - update_pwd(&env); - } -} - -// exit - int exit(char *av) { - freenode free toke free sequence stop repl free env - clear history + freenode free toke free sequence stop repl free env; + clear history; } -//export - int export(char **av, t_env **env) { char *tmp; @@ -162,87 +88,65 @@ int export(char **av, t_env **env) int i; i = i; - while(av[i]) + while (av[i]) { - if(tmp = ft_strchr(av[i], '=')) + if (t_strchr(av[i], '=')) { + tmp = ft_strchr(av[i], '='); tmp = '\0'; current = *env; - while(current) + while (current) { - if (strcmp(current->name, av[i]) == 0) + if (ft_strcmp(current->name, tmp[i]) == 0) { - free(current->value); - current->value = ft_strdup(tmp + 1); - break; - } - current = current->next; + free(current->value); + current->value = ft_strdup(tmp + 1); + break ; + } + current = current->next; } if (!current) { - current = malloc(sizeof(t_env)); - current->name = ft_strdup(av[i]); - current->value = ft_strdup(tmp + 1); - current->next = *env; - *env = current; - } - return (0); + current = malloc(sizeof(t_env)); + current->name = ft_strdup(av[i]); + current->value = ft_strdup(tmp + 1); + current->next = *env; + *env = current; + } } i++; } - return 1; + return (1); } -//unset -//for unset as well check and for name part int unset(char **av, t_env **env) { t_env *current; t_env *prev; + int i; + i = 0; current = env; prev = NULL; - while (current) - { - if(ft_strcmp(current->name, av[1] == 0)) - break ; - prev = current; - current = current->next; - } - if(current) + while (av[i]) { - if(prev) - prev->next = current->next; - else - *env = current->next; - free(current->value); - free(current); + while (current) + { + if (ft_strcmp(current->name, av[i] == 0)) + break ; + prev = current; + current = current->next; + } + if (current) + { + if (prev) + prev->next = current->next; + else + *env = current->next; + free(current->value); + free(current); + } + i++; } return (0); -} - - -// void getenvlststr(t_env **env, char **en)//without serparation -// { -// int i; -// size_t t; -// t_env *current; - -// t = 0; -// i = 0; -// while (en[i] != NULL) -// { -// current = *env; -// current = malloc(sizeof(t_env)); -// while(en[t] != '=') -// t++; -// current->name = ft_substr(en[i], 0, t); -// current->value = ft_strdup(en[i]); -// current->next = *env; -// *env = current; -// i++; -// } -// return (0); -// } - -//should name the list different \ No newline at end of file +} \ No newline at end of file diff --git a/src/builtins_part_two.c b/src/builtins_part_two.c new file mode 100644 index 0000000..94ef258 --- /dev/null +++ b/src/builtins_part_two.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtins_part_two.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: chuhlig +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/25 20:52:16 by chuhlig #+# #+# */ +/* Updated: 2024/10/25 20:52:46 by chuhlig ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "env.h" + +void update_oldpwd(t_env **env) +{ + t_env *current; + t_env *prev; + char cwd[1028]; + char *tmp; + + while (current) + { + if (ft_strncmp(current->name, "OLDPWD", 6) == 0) + break ; + prev = current; + current = current->next; + } + getcwd(cwd, sizeof(cwd)); + tmp = ft_strdup(cwd); + free(current->value); + current->value = tmp; +} + +void update_pwd(t_env **env) +{ + t_env *current; + t_env *prev; + char cwd[1028]; + char *tmp; + + while (current) + { + if (ft_strncmp(current->name, "PWD", 3) == 0) + break ; + prev = current; + current = current->next; + } + getcwd(cwd, sizeof(cwd)); + tmp = ft_strdup(cwd); + free(current->value); + current->value = tmp; +} + +int cd(t_env **env, char **av) +{ + t_env *current; + t_env *prev; + t_env *pwd; + + current = env; + if (av[1] == NULL) + { + update_oldpwd(&env); + while (current) + { + if (ft_strncmp(current->name, "HOME", 4) == 0) + break ; + prev = current; + current = current->next; + } + if (chdir(current->value) == -1) + return ; + } + else + { + update_oldpwd(&env); + if (chdir(av[1]) == -1) + return ; + update_pwd(&env); + } +} \ No newline at end of file -- cgit v1.2.3