Skip to content

Commit 306c57e

Browse files
committed
simple shell
1 parent ed93f7c commit 306c57e

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

_execute.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @env: environment variable
77
* Return: output executed command else -1
88
*/
9-
int execute_command(char *get_address, char __attribute__((__unused__)) **env)
9+
int execute_command(char *get_address)
1010
{
1111
char *delim = " \n\t\r";
1212
char **tokens = NULL, *command_path = NULL;
@@ -16,13 +16,13 @@ int execute_command(char *get_address, char __attribute__((__unused__)) **env)
1616
if (!tokens || tokens[0] == NULL)
1717
{
1818
perror("Error ");
19-
free(tokens);
19+
_free_memo(tokens);
2020
return (ex);
2121
}
2222
if (_strcmp(tokens[0], "exit") == 0)
2323
{
2424
if (tokens[1] != NULL)
25-
status = atoi(tokens[1]);
25+
status = _atoi(tokens[1]);
2626
_free_memo(tokens);
2727
free(command_path);
2828
exit(status);
@@ -38,7 +38,7 @@ int execute_command(char *get_address, char __attribute__((__unused__)) **env)
3838
if (!command_path)
3939
{
4040
perror("command not found");
41-
/*free(tokens);*/
41+
_free_memo(tokens);
4242
free(command_path);
4343
ex = 127;
4444
return (ex);

_getenv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ char *_getenv(const char *str)
2828
value = _strdup(environ[l] + len + 1);
2929
if (value == NULL)
3030
{
31+
free(value);
3132
perror("Error: ");
3233
return (NULL);
3334
}

_locator.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77
*/
88
char *locate_path(char *com_val)
99
{
10-
char *read_path = NULL, *copy_of_path, *file = NULL, *token_to_path;
10+
char *read_path = NULL,/*copy_of_path,*/ *file = NULL, *token_to_path;
1111
size_t length, dir_length;
1212
struct stat buff;
1313

1414
if (stat(com_val, &buff) == 0)
1515
{
16-
free(read_path);
17-
return (_strdup(com_val));
16+
/*free(read_path);*/
17+
return (com_val);
1818
}
1919
read_path = _getenv("PATH");
2020
if (!read_path)
2121
return (NULL);
22-
copy_of_path = _strdup(read_path);
23-
if (!copy_of_path)
24-
return (NULL);
25-
token_to_path = strtok(copy_of_path, ":");
22+
/*copy_of_path = _strdup( read_path);
23+
free(read_path);*/
24+
token_to_path = strtok(read_path, ":");
2625

2726
while (token_to_path != NULL)
2827
{
@@ -31,7 +30,6 @@ char *locate_path(char *com_val)
3130
file = malloc(dir_length + length + 2);
3231
if (!file)
3332
{
34-
free(copy_of_path);
3533
free(read_path);
3634
return (NULL);
3735
}
@@ -40,14 +38,13 @@ char *locate_path(char *com_val)
4038
_strcat(file, com_val);
4139
if (stat(file, &buff) == 0)
4240
{
43-
free(copy_of_path);
4441
free(read_path);
4542
return (file);
4643
}
4744
free(file);
4845
token_to_path = strtok(NULL, ":");
4946
}
50-
free(copy_of_path);
5147
free(read_path);
48+
/*free(file);*/
5249
return (NULL);
5350
}

header.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
extern char **environ;
1515

1616
/*....... Path finders.......*/
17-
int main(int argc, char __attribute__((__unused__)) *argv[], char **env);
17+
int main(int argc, char __attribute__((__unused__)) *argv[]);
1818
char *locate_path(char *com_val);
19-
int execute_command(char *get_address, char __attribute__((__unused__)) **env);
19+
int execute_command(char *get_address);
2020

2121
/*........Tokenizers......*/
2222
char **tokenize(char *buffer, const char *delim);

hsh

-152 Bytes
Binary file not shown.

my_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Return: 0 when successfull.
1111
*/
1212

13-
int main(int argc, char __attribute__((__unused__)) *argv[], char **env)
13+
int main(int argc, char __attribute__((__unused__)) *argv[])
1414
{
1515
char *get_address = NULL;
1616
size_t length_input = 0;
@@ -29,7 +29,7 @@ int main(int argc, char __attribute__((__unused__)) *argv[], char **env)
2929
}
3030
if (get_address[0] != '\0')
3131
{
32-
string_line = execute_command(get_address, env);
32+
string_line = execute_command(get_address);
3333
if (string_line != 0)
3434
return (string_line);
3535
}

0 commit comments

Comments
 (0)