some improvements
This commit is contained in:
parent
519b265164
commit
7739a2a6d6
18
myshell.c
18
myshell.c
@ -84,19 +84,18 @@ for(int i=0;i<=lenght-1; i++){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cd(char command[BUFFERSIZE]){
|
void cd(char command[BUFFERSIZE]){
|
||||||
char *tok;
|
char *temp;
|
||||||
tok = strchr(command,' ');
|
temp = strchr(command,' ');
|
||||||
|
|
||||||
char *tempTok = tok + 1;
|
temp = temp+1;
|
||||||
tok = tempTok;
|
char *locationOfNewLine = strchr(temp, '\n');
|
||||||
char *locationOfNewLine = strchr(tok, '\n');
|
|
||||||
if(locationOfNewLine) {
|
if(locationOfNewLine) {
|
||||||
*locationOfNewLine = '\0';
|
*locationOfNewLine = '\0';
|
||||||
}
|
}
|
||||||
chdir(tok);
|
chdir(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_dir(char *name) {
|
void ls(char *name) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@ -113,7 +112,7 @@ void list_dir(char *name) {
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main() {
|
||||||
|
|
||||||
char command[BUFFERSIZE];
|
char command[BUFFERSIZE];
|
||||||
|
|
||||||
@ -124,8 +123,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (strcmp(command, "help\n") == 0){ help(); }
|
if (strcmp(command, "help\n") == 0){ help(); }
|
||||||
else if (strcmp(command, "ls\n") == 0){
|
else if (strcmp(command, "ls\n") == 0){
|
||||||
chdir(*(++argv));
|
ls(".");
|
||||||
list_dir(".");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else if (strcmp(command, "pwd\n") == 0){
|
else if (strcmp(command, "pwd\n") == 0){
|
||||||
|
Loading…
Reference in New Issue
Block a user