Пример #1
0
static void interpret_pipe(struct interpreter_context *context, struct ast_node *node)
{
    struct gsh_command *cmd1 = node->n_children;
    struct gsh_command *cmd2 = node->n_children->next;
    
    int in = sys_fcntl(0, 0, 0, 0);
    int out = sys_fcntl(1, 0, 0, 0);
    int err = sys_fcntl(2, 0, 0, 0);
    
    int pipe_des[2];
    sys_pipe(pipe_des);
    
    close(0);
    sys_fcntl(pipe_des[0], 0, 0, 0);
    int pid = interpret_cmd(context, cmd2, P_NOWAIT);
    
    close(0);
    close(1);
    close(2);
    
    sys_fcntl(in, 0, 0, 0);
    sys_fcntl(pipe_des[1], 0, 1, 0);
    sys_fcntl(pipe_des[1], 0, 2, 0);
    
    interpret_cmd(context, cmd1, P_WAIT);
    
    
    close(1);
    close(2);
    
    
    sys_fcntl(out, 0, 1, 0);
    sys_fcntl(err, 0, 2, 0);
    

    close(pipe_des[0]);
    close(pipe_des[1]);
    
    int status;
    sys_waitpid(pid, &status);
    
    close(out);
    close(err);
}
Пример #2
0
static void interpret_node(struct interpreter_context *context, struct ast_node *node)
{
    switch(node->n_type) {
        case NODE_CMD:
            interpret_cmd(context, (struct gsh_command*)node, P_WAIT);
            break;
        case NODE_RDIR:
            interpret_rdir(context, node);
            break;
        case NODE_PIPE:
            interpret_pipe(context, node);
            break;
    }
}
Пример #3
0
static void interpret_rdir(struct interpreter_context *context, struct ast_node *node)
{
    struct gsh_command *file = node->n_children->next;
    int f = sys_open(file->c_args[0], O_WRONLY | O_CREAT);
    int out = sys_fcntl(1, 0, 0, 0);
    int err = sys_fcntl(2, 0, 0, 0);
    close(1);
    close(2);
    sys_fcntl(f, 0, 1, 0);
    sys_fcntl(f, 0, 2, 0);
    interpret_cmd(context, node->n_children, P_WAIT);
    close(f);
    close(1);
    close(2);
    sys_fcntl(out, 0, 1, 0);
    sys_fcntl(err, 0, 2, 0);
    close(out);
    close(err);
}
Пример #4
0
int main()
{
	enableInterrupts();

	while(1) {
		clear_scr();
		dino_print("Welcome to dinoDOS. Please login.\n\0");
		while(!validate()) {
			dino_print("Error: invalid credentials.\n\0");
		}
		//we do not want to logout yet
		logout = FALSE;
		clear_scr();
		//begin the shell promt
		while(!logout) {
			//holds the current input
			char curInput[MAX_INPUT];
			//used to print or not print a new line after a command
			bool addNewLine;
			//print the prompt
			dino_print(prompt);
			//wait for input
			read_input(curInput, MAX_INPUT);

			//only run on non-empty inputs
			if (strlen(curInput) > 0) {
				//return tells if a line break should be printed
				addNewLine = interpret_cmd(curInput);
			} else {
				//we want to add a new line if it was empty
				addNewLine = TRUE;
			}
			//print the new line if we want it		
			if (addNewLine) {
				dino_print("\n\0");
			}
			//let the another process continue
			yield();
			//on to the next command!
		}
	}
}