Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
wrightkhlebisol committed Jul 26, 2023
2 parents a74aaac + e0ec559 commit 2c949eb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
37 changes: 19 additions & 18 deletions linkedlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
envstruct *insert_end(envstruct *head, char *key, char *value)
{
envstruct *curr = head;
envstruct *new_node = malloc(sizeof(envstruct));

if (new_node == NULL)
Expand All @@ -26,8 +27,6 @@ envstruct *insert_end(envstruct *head, char *key, char *value)
return (new_node);
}

envstruct *curr = head;

while (curr->next != NULL)
{
curr = curr->next;
Expand All @@ -38,12 +37,12 @@ envstruct *insert_end(envstruct *head, char *key, char *value)
}

/**
* get_value - Get value at key
* @head: list root
* @key: key of list
* get_value - gets value of env var
* @head: head variable
* @key: value variable
*
* Return: Value at given key
*/
* Return: NULL
*/
char *get_value(envstruct *head, char *key)
{
envstruct *curr = head;
Expand Down Expand Up @@ -82,22 +81,22 @@ int print_all(envstruct *head)
}

/**
* remove_value - Remove value corresponding to key
* @head: list root
* @key: key to remove
* remove_value - remove env variable
* @head: head variable
* @key: key variable
*
* Return: Integer for success or failue
*/
* Return: 0 or 1
*/
int remove_value(envstruct **head, char *key)
{
envstruct *curr = *head;
envstruct *prev = NULL;

if (head == NULL || *head == NULL)
{
return (1);
}

envstruct *curr = *head;
envstruct *prev = NULL;

while (curr != NULL)
{
if (strcmp(curr->key, key) == 0)
Expand All @@ -124,9 +123,11 @@ int remove_value(envstruct **head, char *key)
}

/**
* free_list - Free allocated spaces
* @head: list root
*/
* free_list - frees the list_mem
* @head: head variable
*
* Return: void
*/
void free_list(envstruct *head)
{
while (head != NULL)
Expand Down
35 changes: 31 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "main.h"
int main(void);

char *lineptr = NULL;

/**
* main - Entrance to program
*
* Return: Exit code
*/
int main(void)
{
envstruct *head = NULL;

atexit(clean_up);
signal(SIGINT, sig_int_handler);
envstruct *head = NULL;

/** init_env_list(head); */
while (1)
Expand Down Expand Up @@ -120,7 +123,11 @@ int is_builtin_cmd(char *cmd)
/**
* exec_builtin_cmd - execute builtin commands
* @argv: argument vector - points to arguments entered
<<<<<<< HEAD
* @head: head node
=======
* @head: head of lists.
>>>>>>> e0ec559d5998b75685d75ab581a10646aac9bbfd
*
* Return: void
*/
Expand All @@ -147,7 +154,10 @@ void exec_builtin_cmd(char **argv, envstruct *head)
}
if (strstr(argv[0], "cd") == argv[0])
{
/** cd_cmd(argv); */
if (cd_cmd(argv) == -1)
{
perror("");
}
}
}

Expand Down Expand Up @@ -231,11 +241,18 @@ void env_cmd(void)
*/
void init_env_list(envstruct *head)
{
while (*environ != NULL)
int i = 0;

while (environ[i] != NULL)
{
char *key = strtok(*environ, "="), *val = strtok(NULL, "=");
head = insert_end(head, key, val);
<<<<<<< HEAD
*environ++;
=======

i++;
>>>>>>> e0ec559d5998b75685d75ab581a10646aac9bbfd
}

}
Expand Down Expand Up @@ -284,8 +301,18 @@ void unsetenv_cmd(char **argv, envstruct *head)
*
* Return: void
*/
void cd_cmd(char **argv)
int cd_cmd(char **argv)
{
int stat;

stat = chdir(argv[1]);

if (stat == -1)
{
perror("");
return (-1);
}
return (0);

}

Expand Down
5 changes: 3 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ typedef struct env_var
char *value;
struct env_var *next;
} envstruct;

extern char **environ;
char *lineptr;
extern char *lineptr;

void exit_cmd(int);
void env_cmd(void);

void setenv_cmd(char **argv, envstruct *head);
void unsetenv_cmd(char **argv, envstruct *head);
/** void cd_cmd(char **argv); */
int cd_cmd(char **argv);

void exec_builtin_cmd(char **argv, envstruct *head);
void exec_executable_cmd(char *cmd, char **argv, char **env);
Expand Down
Binary file modified shell
Binary file not shown.

0 comments on commit 2c949eb

Please sign in to comment.