100 lines
2.1 KiB
C
100 lines
2.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/wait.h>
|
||
|
#include <string.h>
|
||
|
#include <errno.h>
|
||
|
#include <stdbool.h>
|
||
|
#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;
|
||
|
}
|