-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from maqamylee0/peter_shell
incomplete implementation of cd
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* _getenv - gets an environment variable | ||
* @name: name of the variable | ||
* @env: environment variables | ||
* | ||
* Return: pointer to variable or NULL (not found) | ||
*/ | ||
char *_getenv(const char *name, char **env) | ||
{ | ||
char *value = NULL; | ||
char *temp; | ||
int i, j; | ||
|
||
i = 0; | ||
while (env[i] != NULL) | ||
{ | ||
j = 0; | ||
temp = env[i]; | ||
while (name[j] != '\0' && name[j] == temp[j]) | ||
j++; | ||
if (name[j] == '\0' && temp[j] == '=') | ||
{ | ||
value = temp + j + 1; | ||
break; | ||
} | ||
i++; | ||
} | ||
return (value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "main.h" | ||
|
||
/** | ||
* get_cd_path - gets path for cd | ||
* @argv: array of arguments | ||
* @env: environment variable | ||
* | ||
* Return: path to change directory to | ||
*/ | ||
char *get_cd_path(char **argv, char **env) | ||
{ | ||
char *path = NULL; | ||
|
||
if (argv[1] == NULL) | ||
{ | ||
path = _getenv("HOME", env); | ||
} | ||
else if (_strcmp(argv[1], "-") == 0) | ||
{ | ||
path = _getenv("OLDPWD", env); | ||
} | ||
else | ||
{ | ||
path = argv[1]; | ||
} | ||
return (path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.