From 672691d576d71e03ecc5bf8052ac7f0e4f60c352 Mon Sep 17 00:00:00 2001 From: Jakub Adamski Date: Sat, 12 Jan 2019 15:58:36 +0100 Subject: [PATCH] dodanie kolorow historia komend zmiana na strtok i readline --- Microshell/Makefile | 2 +- Microshell/help | 6 ++-- Microshell/microshell | Bin 13304 -> 13368 bytes Microshell/microshell.c | 74 +++++++++++++++++++++------------------- Microshell/opis | 24 +++++++++++++ 5 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 Microshell/opis diff --git a/Microshell/Makefile b/Microshell/Makefile index 15f9ce4..6872834 100644 --- a/Microshell/Makefile +++ b/Microshell/Makefile @@ -1,4 +1,4 @@ microshell: microshell.c - gcc -Wall -ansi -o microshell microshell.c + gcc -Wall -ansi -o microshell microshell.c -lreadline -lncurses clean: rm microshell diff --git a/Microshell/help b/Microshell/help index 19e6780..1391faa 100644 --- a/Microshell/help +++ b/Microshell/help @@ -7,9 +7,9 @@ Index number=s444341 Limits Max length of line=1000 Max number of arguments=100 -Max length of argument=100 ------------- Working commands +up/down arrow - commands history help - manual exit - ends microshell cd - changing directory @@ -20,9 +20,11 @@ spath: 0 - turns off displaying current directory 1 - turns on displaying current directory PATH commands + if you want colors use + for example ls --color WARNING -dont use path shorcuts +dont use enviroment shorcuts example cd ~/ or echo $HOME ------------- diff --git a/Microshell/microshell b/Microshell/microshell index 37159ed3a887e8a02c308e922f0ac2b0eecd58f9..2aed7bf6eb50e393bada0991c901317f4be003c5 100755 GIT binary patch literal 13368 zcmeHOdvH`$nm?URARu%C0-{8@%YX|iZGr>>PMmZgaAO5zFn|okrqhq4hkj)HA%W7_ z%!XL@WZF$x>M*W5VB_RLn9!_V=B8 zzRtau?j5IUtM(rbmHy86`yS^zkNY_1e*AGu+mZVXuAOmrfm0R*ioFHw^S>|ovOW3<5H={gDKC$t&wo&y0y1P0;?n8Sh{z0 zZ^OFP>(;uHarYY8Z}LyNTet6$Es+~F6jDyzBaGz#a%VU_^U)0#>Z^bI-anpr@5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include const int max = 1000; -int cut(char **argv, char *command){ - int i = 0, w = 0, x = 0; - char argument[100]; - while (1){ - if(command[i] == 10){ - argv[w] = NULL; - break; - } - else if (command[i] == 32){ - i+=1; - x=0; - continue; - } - else{ - while(command[i] != 32 && command[i]!=10){ - argument[x]=command[i]; - x+=1; - i+=1; - } - argument[x] = '\0'; - argv[w]=malloc(x+1 * sizeof(char)); - strcpy(argv[w], argument); - w+=1; - } +void cut(char **argv, char *command){ + int w = 0; + char sep[] = " "; + char *ptr = strtok(command, sep); + while (ptr != NULL){ + argv[w]=ptr; + w+=1; + ptr = strtok(NULL, sep); } - return w+1; + argv[w]=NULL; } void cd (char **argv){ @@ -78,21 +64,39 @@ void spathf (char **argv, int *spath){ } int main (){ - int ile, i, spath = 1; + int spath = 1; + using_history(); while (1){ char* argv[100]; - char komenda[max], directory[max]; + char *komenda, *prompt, directory[max]; if (getcwd(directory, sizeof(directory)) == NULL){ perror("getcwd() error"); return -1; } 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 (spath){ + prompt = (char*)malloc(strlen(directory)+strlen(p->pw_name)+22 *sizeof(char)); + prompt[0]='\0'; + strcat(prompt, "\033[1;32m"); + strcat(prompt, "["); + strcat(prompt, directory); + strcat(prompt, "]\033[0m"); + strcat(prompt, p->pw_name); + } + else{ + prompt = (char*)malloc(strlen(p->pw_name)+3 *sizeof(char)); + strcat(prompt, p->pw_name); + } + strcat(prompt, "$ "); + + if (!(komenda = readline(prompt))) + break; + if (komenda[0] == 0) + continue; + + add_history(komenda); + cut(argv, komenda); if (argv[0]==NULL) continue; @@ -124,8 +128,8 @@ int main (){ else wait(NULL); - for(i=0; ipw_name +mozna zrobic (*p).pw_name + +/*fgets(komenda, max, stdin);*/