Closed habvi closed 1 year ago
execute_command_internal()
echo a >outfile
tokenize/is_token_kind_redirection_from_node()
transfer_redirect_node_from_command()
move_redirect_from_command()
redirect操作(左から順番にfile open, fd付け替えを実行)がやりにくかったので、redirectの構造を大きく見直しましたー!
before
ast->redirects->list (t_deque *) にredirect関係のtokenを順番に格納 [token1(redirect)]-[token2(file)]-[token3(redirect)]-... typedef struct s_redirect { t_deque *list; int in_fd; int out_fd; char *heredoc_filename; } t_redirect;
ast->redirects->list = [<] - [in1] - [>] - [out1] - [<<] - [eof1] - [<<] - [eof2] ...
after
ast->redirect_list (t_deque *)にredirect関係の構造体を順番に格納 [redirect1(kind1, file1)]-[redirect2(kind2, file2)]-... in/out fd を ast->proc_fd[2]に格納 typedef struct s_redirect { t_token_kind kind; t_deque *tokens; char *heredoc_filename; } t_redirect;
redirect_symbol + file
ast->redirect_list = [ redirect1( kind="<", tokens=[in1] ) ] - [ redirect2( kind=">",tokens=[out1] )] - ...
execute_command_internal()
でredirectをin/out_fdに繋げる必要がありそう -> add f3e84dfecho a >outfile
などの後にstdoutがoutfileに繋がりっぱなしだったので、予めstdin/out のcopy_in/outをとっておき、close(stdin/out) -> dup2(copy_in/out, stdin/out) で戻すことで動いた(とりあえず感...) この辺りtokenize/is_token_kind_redirection_from_node()
を heredoc だけにしたことで、他の redirects がtransfer_redirect_node_from_command()
されずに command に居続けてるのを修正 -> 1fa130dmove_redirect_from_command()
の位置が悪いかもredirect操作(左から順番にfile open, fd付け替えを実行)がやりにくかったので、redirectの構造を大きく見直しましたー!
before
ast->redirects->list = [<] - [in1] - [>] - [out1] - [<<] - [eof1] - [<<] - [eof2] ...
after
redirect_symbol + file
をセットとし、kind, tokenに分けて構造体に格納したものを、ast->redirect_listに連結したast->redirect_list = [ redirect1( kind="<", tokens=[in1] ) ] - [ redirect2( kind=">",tokens=[out1] )] - ...