some improvements

This commit is contained in:
unknown 2019-02-23 15:42:05 +01:00
parent 519b265164
commit 7739a2a6d6

View File

@ -84,19 +84,18 @@ for(int i=0;i<=lenght-1; i++){
}
void cd(char command[BUFFERSIZE]){
char *tok;
tok = strchr(command,' ');
char *temp;
temp = strchr(command,' ');
char *tempTok = tok + 1;
tok = tempTok;
char *locationOfNewLine = strchr(tok, '\n');
temp = temp+1;
char *locationOfNewLine = strchr(temp, '\n');
if(locationOfNewLine) {
*locationOfNewLine = '\0';
}
chdir(tok);
chdir(temp);
}
void list_dir(char *name) {
void ls(char *name) {
DIR *dir;
struct dirent *dp;
struct stat statbuf;
@ -113,7 +112,7 @@ void list_dir(char *name) {
closedir(dir);
}
int main(int argc, char **argv) {
int main() {
char command[BUFFERSIZE];
@ -124,8 +123,7 @@ int main(int argc, char **argv) {
if (strcmp(command, "help\n") == 0){ help(); }
else if (strcmp(command, "ls\n") == 0){
chdir(*(++argv));
list_dir(".");
ls(".");
printf("\n");
}
else if (strcmp(command, "pwd\n") == 0){