Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. char** shell_parseLine(char* line){
  2. char** buffer;
  3. char* singleArgumentInQuotations;
  4. //count args
  5. int i;
  6. int argStartIndex=0;
  7. int counter=0;
  8. bool isQuotationOpened =false;
  9. buffer=malloc(1000); //jak dodwać kurwa kolejne pointery to ja nie wiem
  10. for (i=0;i<=strlen(line);i++){
  11. if (line[i] == '"'){
  12. if (isQuotationOpened){
  13. //closing the quoatuion
  14. // buffer = malloc(counter* sizeof(char*));
  15. buffer[counter] = malloc((i-argStartIndex-1)* sizeof(char));
  16. strncpy(buffer[counter],line+argStartIndex+1,i-argStartIndex-1);
  17.  
  18. counter++;
  19. }
  20. else{
  21. argStartIndex = i;
  22. }
  23. isQuotationOpened=!isQuotationOpened;
  24. }
  25. if ((line[i]==' ' || line[i]=='\0') && !isQuotationOpened ){
  26. //buffer = malloc(counter * sizeof(char*));
  27. buffer[counter] = malloc((i-argStartIndex-1) * sizeof(char));
  28. strncpy(buffer[counter],line+argStartIndex,(size_t)i-argStartIndex);
  29.  
  30. counter++;
  31. }
  32. }
  33. return buffer;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement