tnode *bst_insert(tnode *ptr, int key) { if (ptr == NULL) return new_tnode(key) ; if ( ptr->data > key ) ptr->left = bst_insert( ptr->left, key) ; else ptr->right = bst_insert( ptr->right, key) ; ptr->size++ ; // update size return ptr ; }
struct tnode *newnode(cmd_ptr *cmdptr) { int j, n; char *token, *tempstring; struct tnode *t = NULL, *t1 = NULL; for (j = 0;j < cmdptr->number_cmd;j++) { if (t != NULL) { t->next = new_tnode(); t = t->next; } else t = new_tnode(); if (j == 0) t1 = t; t->type = TPIPE; t->argv[0] = malloc(sizeof(char) * strlen(cmdptr->ptr[j]->cmdname)); strcpy(t->argv[0], cmdptr->ptr[j]->cmdname); tempstring = malloc(sizeof(char) * strlen((cmdptr->ptr[j]->arg) + 1)); strcpy(tempstring, cmdptr->ptr[j]->arg); token = strtok(tempstring, " "); for (n = 0;n < cmdptr->ptr[j]->number_arg;n++) { t->argv[n+1] = malloc(sizeof(char) * (strlen(token) + 1)); strcpy(t->argv[n+1], token); token = strtok(NULL, " "); } } if (strlen(cmdptr->head)) { t1->fin = malloc(sizeof(char) * strlen((cmdptr->head) + 1)); strcpy(t1->fin, cmdptr->head); t1->flags |= FFIN; } if (strlen(cmdptr->tail)) { t1->fout = malloc(sizeof(char) * strlen((cmdptr->tail) + 1)); strcpy(t1->fout, cmdptr->tail); } if (cmdptr->indicater == 2) t1->flags |= FAPN; free(cmdptr); return t1; }
static struct tnode *bnode(char *line) { char *token; struct tnode *t; int i = 0; t = new_tnode(); t->type = TBDIN; token = strtok(line, " "); while (token != NULL) { t->argv[i] = malloc(sizeof(char) * (strlen(token) + 1)); strcpy(t->argv[i++], token); token = strtok(NULL, " "); } t->argv[i] = NULL; return t; }