Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int parser_read(bsh_command_chain_t *chain, char **line) {
- char buf[LINE_BUFFER_MAX];
- char *p = *line;
- int i;
- bzero(&buf, sizeof(buf));
- for(i=0;(p=(*line)+i)[0] != '\0'; i++) {
- switch(p[0]) {
- case CHAR_SPACE:
- if(strlen(buf) > 0) {
- if(chain->command == NULL) { chain_set_command(chain, (char *)&buf); }
- else { chain_set_argument(chain, (char *)&buf); }
- bzero(buf, sizeof(buf));
- }
- break;
- case CHAR_PIPE:
- if(chain->command != NULL) {
- *line = ++p; // adjust line, to the current parser location
- return CHAIN_WANT_PROCESS_PIPE;
- } else if(strlen(buf) > 0) {
- *line = ++p; // adjust line ..
- chain_set_command(chain, (char *)&buf);
- return CHAIN_WANT_PROCESS_PIPE;
- }
- break;
- default:
- strncat(buf, p, 1);
- }
- }
- if(strlen(buf) > 0)
- if(chain->command == NULL) chain_set_command(chain, (char *)&buf);
- else chain_set_argument(chain, (char *)&buf);
- if(strlen(buf) == 0) return CONTEXT_NOCONTEXT;
- return CHAIN_DONE;
- }
Add Comment
Please, Sign In to add comment