Skip to content

Commit

Permalink
fix betty
Browse files Browse the repository at this point in the history
  • Loading branch information
GideonBature committed Jul 26, 2023
1 parent 7ebc8e7 commit 766b5d4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
84 changes: 60 additions & 24 deletions linkedlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct env_var
char *value;
struct env_var *next;
} envstruct;

extern char **environ;
char *lineptr;

Expand Down
Binary file removed shell
Binary file not shown.

0 comments on commit 766b5d4

Please sign in to comment.