From 50fc326366ca001989bed80813c2a9bd95e9419b Mon Sep 17 00:00:00 2001 From: wrightkhlebisol Date: Wed, 26 Jul 2023 08:46:20 +0100 Subject: [PATCH] tokenize env prop --- main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 39df1b7..4661045 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ int main(void) signal(SIGINT, sig_int_handler); envstruct *head = NULL; + /** init_env_list(head); */ while (1) { char *cmd; @@ -54,7 +55,7 @@ int main(void) exit(0); } } - free_list(head); + /** free_list(head); */ return (0); } @@ -232,17 +233,11 @@ void init_env_list(envstruct *head) { while (*environ != NULL) { - char *key = strtok(*environ, "="), *val = NULL; - - while (environ != NULL) - { - val = strtok(NULL, " "); - printf("%s, %s\n", key, val); /**printing each token */ - } + char *key = strtok(*environ, "="), *val = strtok(NULL, "="); head = insert_end(head, key, val); - *environ++; } + } /** @@ -255,7 +250,10 @@ void setenv_cmd(char **argv, envstruct *head) if (argv != NULL) { if ((*(argv + 1) != NULL) && (*(argv + 2) != NULL)) - insert_end(head, *(argv + 1), *(argv + 2)); + { + head = insert_end(head, *(argv + 1), *(argv + 2)); + print_all(head); + } else perror("setenv_cmd insert Error"); } @@ -271,7 +269,10 @@ void unsetenv_cmd(char **argv, envstruct *head) if (argv != NULL) { if ((*(argv + 1) != NULL)) + { remove_value(&head, *(argv + 1)); + print_all(head); + } else perror("setenv_cmd remove Error"); }