funkcja cut
This commit is contained in:
parent
3073884260
commit
86cd2fe0c0
@ -5,54 +5,22 @@
|
||||
|
||||
const int max = 1000;
|
||||
|
||||
int cut(char **argv, char *command){
|
||||
int i=0;
|
||||
return i;
|
||||
}
|
||||
|
||||
int main (){
|
||||
void cut(char **argv, char *command){
|
||||
int i = 0, w = 0, x = 0;
|
||||
char argument[100];
|
||||
while (1){
|
||||
char komenda[max], directory[max];
|
||||
if (getcwd(directory, sizeof(directory)) == NULL){
|
||||
perror("getcwd() error");
|
||||
return 1;
|
||||
}
|
||||
printf("[%s]$ ", directory);
|
||||
fgets(komenda, max, stdin);
|
||||
if (!strcmp(komenda, "exit\n"))
|
||||
break;
|
||||
|
||||
else{
|
||||
int i = 0, z, w = 0, x = 0;
|
||||
char polecenie[100], argument[100];
|
||||
char* argv[100];
|
||||
while (1){
|
||||
if(komenda[i] == 10){
|
||||
if(command[i] == 10){
|
||||
argv[w] = NULL;
|
||||
execvp(polecenie, argv);
|
||||
break;
|
||||
}
|
||||
else if (komenda[i] == 32){
|
||||
else if (command[i] == 32){
|
||||
i+=1;
|
||||
x=0;
|
||||
continue;
|
||||
}
|
||||
else if(w==0){
|
||||
w=1;
|
||||
while(komenda[i] != 32 && komenda[i]!=10){
|
||||
polecenie[x]=komenda[i];
|
||||
i+=1;
|
||||
x+=1;
|
||||
}
|
||||
polecenie[x] = '\0';
|
||||
printf("%s\n", polecenie);
|
||||
argv[w-1]=malloc(x+1 * sizeof(char));
|
||||
strcpy(argv[w-1], polecenie);
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
while(komenda[i] != 32 && komenda[i]!=10){
|
||||
argument[x]=komenda[i];
|
||||
while(command[i] != 32 && command[i]!=10){
|
||||
argument[x]=command[i];
|
||||
x+=1;
|
||||
i+=1;
|
||||
}
|
||||
@ -63,6 +31,23 @@ int main (){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (){
|
||||
char* argv[100];
|
||||
while (1){
|
||||
char komenda[max], directory[max];
|
||||
if (getcwd(directory, sizeof(directory)) == NULL){
|
||||
perror("getcwd() error");
|
||||
return 1;
|
||||
}
|
||||
printf("[%s]$ ", directory);
|
||||
fgets(komenda, max, stdin);
|
||||
|
||||
if (!strcmp(komenda, "exit\n"))
|
||||
break;
|
||||
else
|
||||
cut(argv, komenda);
|
||||
execvp(argv[0], argv);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user