From 766b5d4d6ae55d0f08d9a0d10dc1e477ebd4e224 Mon Sep 17 00:00:00 2001 From: Gideon Bature Date: Wed, 26 Jul 2023 01:41:07 +0100 Subject: [PATCH] fix betty --- linkedlist.c | 84 ++++++++++++++++++++++++++++++++++++--------------- main.c | 1 + main.h | 1 + shell | Bin 17552 -> 0 bytes 4 files changed, 62 insertions(+), 24 deletions(-) delete mode 100755 shell 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 9e81928790f98b7e458921e7baab08fb97d77f93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17552 zcmeHPe{@t;e!mkKjR+ z=clUX-SjDK$CTw(djT>=3CK^2_UZmHwcAl{25(mSgF1gqx!-Gb|Jjb*kzIMUvMXQU zr2P~S3RBJ}<%Is`X@727Lq;e}-FD5|&P|snGr^SFptAZ@I{M#fuU^~L1f(0`rn?j@ zm~wmf!jAItpDjGht8{x_<4~^q%~YpX%xa0Rn>%M#OSHNr-j>-^y=mUu>bY}*sYGzL z41wYb;E(3ivb!4u#;uz$9?r7uif4Z$8?WW0-!SXry7zwibn{nMGz9*x{P@0c-}rD6 z=}_EcLpoH*pPphCe?4lXL;0u?&x&pl!j&k*4fvz-de-0d7w>&%!?DTDvdn}nuNZrN=xJLENM5M7XmP(0uDw0lb7EQ546LjDiU()vdKjli0wYV$0$88<6L%>bjmi75;)Lk4;qo~|3-UIcV<%C+ z4WGnLKnHDjz=reuCEqvLaGt+}PqE>Z+Rx>{=$hv;!G@PH2pX{Ae2*jXbQ?~6=2BzB zsSPgkY&hqRWFZ?)*D4pohL2(pwBCkaX~XZg;iGN%S{sguVU=bZewBp^(Qd;lZ1^S{ zKGueBx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