Guest User

Untitled

a guest
Jul 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. int parser_read(bsh_command_chain_t *chain, char **line) {
  2. char buf[LINE_BUFFER_MAX];
  3. char *p = *line;
  4. int i;
  5.  
  6. bzero(&buf, sizeof(buf));
  7.  
  8. for(i=0;(p=(*line)+i)[0] != '\0'; i++) {
  9. switch(p[0]) {
  10. case CHAR_SPACE:
  11. if(strlen(buf) > 0) {
  12. if(chain->command == NULL) { chain_set_command(chain, (char *)&buf); }
  13. else { chain_set_argument(chain, (char *)&buf); }
  14. bzero(buf, sizeof(buf));
  15. }
  16. break;
  17. case CHAR_PIPE:
  18. if(chain->command != NULL) {
  19. *line = ++p; // adjust line, to the current parser location
  20. return CHAIN_WANT_PROCESS_PIPE;
  21. } else if(strlen(buf) > 0) {
  22. *line = ++p; // adjust line ..
  23. chain_set_command(chain, (char *)&buf);
  24. return CHAIN_WANT_PROCESS_PIPE;
  25. }
  26. break;
  27. default:
  28. strncat(buf, p, 1);
  29. }
  30. }
  31.  
  32. if(strlen(buf) > 0)
  33. if(chain->command == NULL) chain_set_command(chain, (char *)&buf);
  34. else chain_set_argument(chain, (char *)&buf);
  35.  
  36. if(strlen(buf) == 0) return CONTEXT_NOCONTEXT;
  37. return CHAIN_DONE;
  38. }
Add Comment
Please, Sign In to add comment