Usuń 'microshell/microshell.c'
This commit is contained in:
parent
2069912ec5
commit
85af3a36d6
@ -1,78 +0,0 @@
|
||||
//Skrypt wykonany za pomoca poradnika https://www.youtube.com/watch?v=O5YVGg81Gdo https://www.youtube.com/watch?v=5Qim9wufNP0 oraz kursów i instrukcji ogólno dostępnych w internecie
|
||||
//Kopiowanie oraz korzytsanie z kodu do własnych potrzeb zabronione
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <wait.h>
|
||||
#include <time.h>
|
||||
#define space " \n"
|
||||
#define max_c 500
|
||||
#define BRIGHT 1
|
||||
#define GREEN 32
|
||||
#define BLUE 34
|
||||
#define PINK 35
|
||||
#define CYAN 36
|
||||
void help() {
|
||||
printf(" Robert Stachecki \n Obslugiwane polecenia: \n exit \n cd \n pwd \n date \n help \n exit \n date \n");
|
||||
}
|
||||
void clear(){
|
||||
printf("\033[H\033[J");
|
||||
}
|
||||
const char *getUserName()
|
||||
{
|
||||
uid_t uid = geteuid();
|
||||
struct passwd *pw = getpwuid(uid);
|
||||
return pw->pw_name;
|
||||
}
|
||||
void date(){
|
||||
time_t t = time(NULL);
|
||||
struct tm *tm = localtime(&t);
|
||||
char s[64];
|
||||
strftime(s, sizeof(s), "%c", tm);
|
||||
printf("%s\n", s);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
char cwd[512], hostName[128], *pwd[1000];
|
||||
register struct passwd *pw;
|
||||
register uid_t uid;
|
||||
uid = geteuid ();
|
||||
pw = getpwuid (uid);
|
||||
char line[max_c], lend[max_c], * commands[max_c], ** command;
|
||||
while (1) {
|
||||
gethostname(hostName, 128);
|
||||
getcwd(cwd, 512);
|
||||
printf("%c[%dm%s",0x1B, GREEN, pw->pw_name);
|
||||
printf("%c[%dm",0x1B,0);
|
||||
printf("@");
|
||||
printf("%c[%dm%s ",0x1B, PINK, hostName);
|
||||
printf("%c[%dm%s",0x1B, CYAN, cwd);
|
||||
printf("%c[%dm $ ",0x1B, GREEN);
|
||||
printf("%c[%dm",0x1B,0);
|
||||
fflush(stdout);
|
||||
if (fgets(line, max_c, stdin )) {
|
||||
command = commands;
|
||||
*command++ = strtok(line,space);
|
||||
while ((*command++ = strtok(NULL,space)));
|
||||
if (strcmp(commands[0], "help")==0) help();
|
||||
|
||||
else if (strcmp(commands[0], "exit")==0) {
|
||||
printf ("Zakończono działanie\n");
|
||||
exit(0);
|
||||
}
|
||||
else if (strcmp(commands[0], "cd")==0) {
|
||||
if (commands[1]==0) printf("Wymagany argument\n");
|
||||
int ret;
|
||||
ret = chdir(commands[1]);
|
||||
strcpy(lend, "pwd");
|
||||
}
|
||||
else if (strcmp(commands[0], "date") == 0){ date(); }
|
||||
else if (strcmp(commands[0], "clear") == 0){ clear(); }
|
||||
else if (strcmp(commands[0], "pwd")==0) printf ("%s\n", cwd);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user