diff --git a/Microshell/help b/Microshell/help index 2319af2..ff12bcb 100644 --- a/Microshell/help +++ b/Microshell/help @@ -8,4 +8,9 @@ Author= Jakub Adamski Working commands help - manual exit - ends microshell +cd - changing directory +(nie dziala dla np ~/) +jak zrobie echo $HOME tez nie dziala +dodac informacje o limitach dlugosci albo zrobic +to dynamicznie diff --git a/Microshell/microshell b/Microshell/microshell index 3e47d1e..9fc8062 100755 Binary files a/Microshell/microshell and b/Microshell/microshell differ diff --git a/Microshell/microshell.c b/Microshell/microshell.c index 9bb3987..52246c9 100644 --- a/Microshell/microshell.c +++ b/Microshell/microshell.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include const int max = 1000; @@ -35,20 +38,72 @@ int cut(char **argv, char *command){ return w+1; } +void cd (char **argv){ + if(argv[1] == NULL){ + printf("Add arguments\n"); + return; + } + else if(argv[2] != NULL){ + printf("Too many arguments\n"); + return; + } + else{ + if (chdir(argv[1]) != 0) + perror("chdir error"); + return; + } +} + +void spathf (char **argv, int *spath){ + int l; + if (argv[1] == NULL){ + printf("Add arguments\n"); + return; + } + else if (argv[2] != NULL){ + printf("Too many arguments\n"); + return; + } + else if (!strcmp(argv[1], "help")){ + printf("Arguments:\n0 turns off path showing\n1 turns on path showing\n"); + return; + } + l = argv[1][0] - '0'; + if (argv[1][1] != 0 || l < 0 || l > 1){ + printf("Wrong number\n"); + return; + } + else + *spath = l; +} + int main (){ - int ile, i; + int ile, i, spath = 1; while (1){ char* argv[100]; char komenda[max], directory[max]; if (getcwd(directory, sizeof(directory)) == NULL){ perror("getcwd() error"); - return 1; + return -1; } - printf("[%s]$ ", directory); + struct passwd *p = getpwuid(getuid()); + /*dodac obsluge bledow do get?*/ + if (spath) + printf("[%s]", directory); + printf("%s$ ", p->pw_name); /* mozna zrobic (*p).pw_name */ fgets(komenda, max, stdin); ile = cut(argv, komenda); + if (argv[0]==NULL) continue; + else if (!strcmp(argv[0], "spath")){ + spathf(argv, &spath); + continue; + } + else if (!strcmp(argv[0], "cd")){ + cd(argv); + continue; + } else if (!strcmp(argv[0], "help")){ if (fork() == 0){ execlp("cat", "cat", "help", NULL);