Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char** shell_parseLine(char* line){
- char** buffer;
- char* singleArgumentInQuotations;
- //count args
- int i;
- int argStartIndex=0;
- int counter=0;
- bool isQuotationOpened =false;
- buffer=malloc(1000); //jak dodwać kurwa kolejne pointery to ja nie wiem
- for (i=0;i<=strlen(line);i++){
- if (line[i] == '"'){
- if (isQuotationOpened){
- //closing the quoatuion
- // buffer = malloc(counter* sizeof(char*));
- buffer[counter] = malloc((i-argStartIndex-1)* sizeof(char));
- strncpy(buffer[counter],line+argStartIndex+1,i-argStartIndex-1);
- counter++;
- }
- else{
- argStartIndex = i;
- }
- isQuotationOpened=!isQuotationOpened;
- }
- if ((line[i]==' ' || line[i]=='\0') && !isQuotationOpened ){
- //buffer = malloc(counter * sizeof(char*));
- buffer[counter] = malloc((i-argStartIndex-1) * sizeof(char));
- strncpy(buffer[counter],line+argStartIndex,(size_t)i-argStartIndex);
- counter++;
- }
- }
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement