Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. commands[0][0] = command
  2. commands[0][1] = arg1
  3. commands[0][2] = arg2
  4.  
  5. commands[1][0] = command
  6.  
  7. commands[2][0] = command
  8. commands[2][1] = arg1
  9.  
  10. int _pipe(char* input){
  11.  
  12. char** commands[MAX_STRING];
  13.  
  14. char temp_command[MAX_STRING];
  15.  
  16. char* args[MAX_ARGS];
  17. int args_size = 0;
  18.  
  19. int total_commands = 0;
  20. int start = 0;
  21.  
  22. for(int i = 0; i < strlen(input); i++){
  23.  
  24. if(input[i] == '|' || (start != 0 && i == strlen(input) - 1)){
  25.  
  26. memcpy(temp_command, &input[start], (size_t) i);
  27. temp_command[i] = 0;
  28.  
  29. commands[total_commands++] = tokenize(temp_command, &args_size);
  30. //I suspect this line is the culprit, but I don't know any alternative
  31. //Also, tokenize just returns a string array. I'm passing args_size because I needed to pass it by reference in another function.
  32.  
  33. start = i+1;
  34. }
  35. }
  36.  
  37. for(int i = 0; i < total_commands; i++)
  38. printf("ncommand start: [%s]", commands[i][0]);
  39.  
  40. return 0;
  41.  
  42. }
  43.  
  44. > command1 | command2
  45.  
  46. command start: [command2]
  47. command start: [command2]
  48.  
  49. > command1 | command2
  50.  
  51. command start: [command1]
  52. command start: [command2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement