From 43137eaa24c2b0222982a6c0f19c76d49a541555 Mon Sep 17 00:00:00 2001 From: s444505 Date: Wed, 30 Jan 2019 08:45:45 +0100 Subject: [PATCH] microshell --- microshell/#microshell.c# | 183 ++++++++++++++++++++++++++++++ microshell/makefile | 5 + microshell/microshell | Bin 0 -> 17856 bytes microshell/microshell.c | 200 +++++++++++++++++++++++++++++++++ microshell/microshell_backup.c | 99 ++++++++++++++++ 5 files changed, 487 insertions(+) create mode 100644 microshell/#microshell.c# create mode 100644 microshell/makefile create mode 100644 microshell/microshell create mode 100644 microshell/microshell.c create mode 100644 microshell/microshell_backup.c diff --git a/microshell/#microshell.c# b/microshell/#microshell.c# new file mode 100644 index 0000000..23a3cc8 --- /dev/null +++ b/microshell/#microshell.c# @@ -0,0 +1,183 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define BUFFER_SIZE 4096 + +void mv(char **args,int size){ + if(size>3){ + printf("Too many arguments\n"); + return; + } + int des=symlink(args[1],args[2]); + if(des==-1){ + printf("%s\n",strerror(errno)); + } + unlink(args[1]); +} + +void ls(char **args,int size){ + struct dirent *des; + DIR *dr; + if(size==1) dr=opendir("."); + if(size==2) dr=opendir(args[1]); + if(size>2){ + printf("Too many arguments\n"); + return; + } + if(dr==NULL){ + printf("%s\n",strerror(errno)); + return; + } + while((des=readdir(dr))!=NULL){ + char *nazwa=des->d_name; + if(nazwa[0]!='.') printf("%s\n",nazwa); + } + closedir(dr); +} + +void mk_dir(char **args,int size){ + int i=0,w; + if(size==1) printf("Missing operand\n"); + else{ + for(i=1;i2) printf("Too many arguments\n"); + else{ + int d=chdir(args[1]); + if(d==-1){ + printf("%s\n",strerror(errno)); + } + } +} + +void rm(char **args,int size){ + if(size==1) printf("Too few arguments\n"); + else{ + int i,des; + for(i=1;iMR5XDAOPIVPhc7U9VBo{()#YaBuaNr1R+2+Dk8O|ZP#JLg_;dU*DD8Uei5AXe6 zPruddXeV5y?oTynU%y|!_xkngo}QVWZhzIYvA(#d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RcXJG^fvZEfY1V;IOkNxAV2he( zS^_Y_oT+L~IHm^YQG*Y24}79a%Z>gNZrXu^3Cubz|IK-Noxv>w&-!Mfy)=}V^16$O znzEcHdNuxN$$|Cx{gkPOGHc@dIAcqZvFh`CEYoXPP*J=72H@Bd6yy5&eU~Zgt7W0w z`VpJG1sPf*VEsXrVTzYHnP@$U;>7DSyl!&`FcQh>tBQCXir1SUA`{uLrhCEAS`O>; zdp6TrCCvV_9Me{m)7lX8{65aKM(NxASFoVxEs81Y^LsnfVI|1*+uQ%3(qE_Kc>Rm% zHf5Of=@H4U{|#Ui6JD?5^+KlV@edMaB44d31;(n+>jg~r+XAj$7w{}+rf=Hxd0l}i z`>Vur{xkl#O`reW2d1ys)-SkTw)b6|KCe?S<#j@qx3~X?N}v0WpO=~bry9Sk&wexi zoK2tCJ(yDeT9dtgdcLL*bN#$N!nB49lo5OVuL7r6Ty~S+r}^Jgu*);g^q0`3M`PB{ zy}wrjL}EFU8|N8+3k5XxSfAHr_}{A-Q{#unC+l%P(z*nRus*LBpK}95DpmR>H?jWH zD6s11-m_{<4X($o&-@rNeka^{-(-QErZv+PYXuu2u#s w)c~gZ482Qn{CNJPV)k7ss-Mj_m>IWiz;V4SORv?1^zU11N}OjwMeX|k3*j+Mf&c&j literal 0 HcmV?d00001 diff --git a/microshell/microshell.c b/microshell/microshell.c new file mode 100644 index 0000000..aa94d3b --- /dev/null +++ b/microshell/microshell.c @@ -0,0 +1,200 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define BUFFER_SIZE 2048 + +void mv(char **args,int size){ + if(size>3){ + printf("Too many arguments\n"); + return; + } + int des=link(args[1],args[2]); + if(des==-1){ + printf("%s\n",strerror(errno)); + }else{ + unlink(args[1]); + } +} + +void ls(char **args,int size){ + struct dirent *des; + DIR *dr; + if(size==1) dr=opendir("."); + if(size==2) dr=opendir(args[1]); + if(size>2){ + printf("Too many arguments\n"); + return; + } + if(dr==NULL){ + printf("%s\n",strerror(errno)); + return; + } + while((des=readdir(dr))!=NULL){ + char *nazwa=des->d_name; + if(nazwa[0]!='.') printf("%s\n",nazwa); + } + closedir(dr); +} + +void mk_dir(char **args,int size){ + int i=0,w; + if(size==1) printf("Missing operand\n"); + else{ + for(i=1;i2) printf("Too many arguments\n"); + else{ + int d=chdir(args[1]); + if(d==-1){ + printf("%s\n",strerror(errno)); + } + } +} + +void rm(char **args,int size){ + if(size==1) printf("Too few arguments\n"); + else{ + int i,des; + for(i=1;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define BUFFER_SIZE 4096 + +void mk_dir(){ + +} + +void touch(){ + char file[1024]; + scanf("%s",file); + int des=open(file, O_CREAT | O_EXCL, S_IWRITE|S_IREAD); + if(des==(-1)){ + printf("%s\n",strerror(errno)); + } +} + +void help(){ + printf(" ls | wyswietla pliki w biezacym katalogu\n"); + printf(" | z arg -a lacznie z plikami ukrytymi\n"); + printf(" pwd | wyswietla katalog w ktorym obecnie znajduje sie uzytkownik\n"); + printf(" |\n"); + printf(" cp *plik1* *plik2* | kopiuje plik1 pod nazwa i lokalizacja plik2\n"); + printf(" |\n"); + printf(" mv *plik1* *plik2* | przenosi plik1 pod nazwa i do lokalizacji plik2\n"); +} + +void cd(){ + char pathname[50]; + scanf("%s",pathname); + chdir(pathname); +} + +void read_order(char order[20]){ + if(strcmp(order,"pwd")==0){ + char cwd[1024]; + printf("%s\n",getcwd(cwd,1024)); + } + else if(strcmp(order,"exit")==0){ + exit(0); + } + else if(strcmp(order,"help")==0){ + help(); + } + else if(strcmp(order,"touch")==0){ + touch(); + } + else if(strcmp(order,"cd")==0){ + cd(); + } + else{ + printf("Unknown command\n"); + } +} + +void extract_args(char line[BUFFER_SIZE],int *status){ + int i=0,j=0; + char order[16]; + for(i=0;i<16;i++){ + if(line[i]!=' '&&line[i]!='\n'){ + order[i]=line[i]; + } + else if(line[i]=='\n'){ + i=0; + break; + }else{ + i++; + break; + } + } + + read_order(order); + +} + +int main(){ + while(true) + { + char cwd[1024]; + char line[BUFFER_SIZE]; + int status=0; + int i; + getcwd(cwd,1024); + printf("%s:-$ ",cwd); + fgets(line,BUFFER_SIZE,stdin); + if(strcmp(line,"\n")==0) continue; + extract_args(line,&status); + // extract_args(); + } + return 0; +}