Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct stringlist *scan;
- int fd[2];
- /*
- SCHEME:
- STDIN --> O --> O --> O --> STDOUT
- */
- int eval(tree,inport,outport)
- evptr tree;
- int inport, outport;
- {
- if (tree->tag == PIPETAG) {
- pipe(fd);
- eval(tree->son.left, 0, 1);
- eval(tree->son.right, 1, 0);
- } else if (tree->tag == LEAF) {
- char **commands;
- int i=0;
- commands = (char**) malloc(10 * sizeof(char*));
- if (commands == NULL)
- exit(-1);
- for (scan = tree->leaf.data; scan != NULL; scan = scan->next) {
- commands[i] = scan->fname;
- i++;
- }
- commands[i] = NULL;
- //======================================================
- pid_t pid;
- pid = sfork();
- if (pid == 0) {
- printf("inport: %d outport: %d\n", inport, outport);
- if (inport == 0) {
- dup2(fd[WRITE_END], STDOUT_FILENO);
- } else if (inport != 0) {
- dup2(inport, STDIN_FILENO);
- //dup2(fd[WRITE_END], STDOUT_FILENO);
- }
- execvp(commands[0], commands);
- exit(1);
- }
- else {
- //close(fd[READ_END]);
- //close(fd[WRITE_END]);
- free(commands);
- wait(NULL);
- }
- } else if (tree->tag == NULLTAG) {
- } else if (tree->tag == EXITAG) {
- exit(0);
- } else {
- exit(1);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement