diff --git a/linkedlist.c b/linkedlist.c index b63b765..5c6618a 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -3,78 +3,114 @@ envstruct *insert_end(envstruct *head, char *key, char *value) { envstruct *new_node = malloc(sizeof(envstruct)); - - if (new_node == NULL) { - return NULL; + + if (new_node == NULL) + { + return (NULL); } new_node->key = strdup(key); new_node->value = strdup(value); new_node->next = NULL; - if (head == NULL) { - return new_node; + if (head == NULL) + { + return (new_node); } envstruct *curr = head; - while (curr->next != NULL) { + + while (curr->next != NULL) + { curr = curr->next; } curr->next = new_node; - return head; + return (head); } +/** + * get_value - gets value of env var + * @head: head variable + * @key: value variable + * + * Return: NULL +*/ char *get_value(envstruct *head, char *key) { envstruct *curr = head; - - if (head == NULL || key == NULL) { - return NULL; + + if (head == NULL || key == NULL) + { + return (NULL); } - while (curr != NULL) { - if (strcmp(curr->key, key) == 0) { - return curr->value; + while (curr != NULL) + { + if (strcmp(curr->key, key) == 0) + { + return (curr->value); } curr = curr->next; } - return NULL; + return (NULL); } +/** + * remove_value - remove env variable + * @head: head variable + * @key: key variable + * + * Return: 0 or 1 +*/ int remove_value(envstruct **head, char *key) { - if (head == NULL || *head == NULL) { - return 1; + if (head == NULL || *head == NULL) + { + return (1); } envstruct *curr = *head; envstruct *prev = NULL; - while (curr != NULL) { - if (strcmp(curr->key, key) == 0) { - if (prev == NULL) { + while (curr != NULL) + { + if (strcmp(curr->key, key) == 0) + { + if (prev == NULL) + { *head = curr->next; - } else { + } + else + { prev->next = curr->next; } free(curr->key); free(curr->value); free(curr); - return 0; + return (0); } prev = curr; curr = curr->next; } - return 1; + return (1); } -void free_list(envstruct *head) { - while (head != NULL) { +/** + * free_list - frees the list_mem + * @head: head variable + * + * Return: void +*/ +void free_list(envstruct *head) +{ + while (head != NULL) + { envstruct *temp = head; + head = head->next; free(temp->key); free(temp->value); diff --git a/main.c b/main.c index fe8ceff..6d4384b 100644 --- a/main.c +++ b/main.c @@ -119,6 +119,7 @@ int is_builtin_cmd(char *cmd) /** * exec_builtin_cmd - execute builtin commands * @argv: argument vector - points to arguments entered + * @head: head of lists. * * Return: void */ diff --git a/main.h b/main.h index 3721755..39022a0 100644 --- a/main.h +++ b/main.h @@ -25,6 +25,7 @@ typedef struct env_var char *value; struct env_var *next; } envstruct; + extern char **environ; char *lineptr; diff --git a/shell b/shell deleted file mode 100755 index 9e81928..0000000 Binary files a/shell and /dev/null differ