보너스를 위한 파싱
별거 없지만 조심해야 할 부분들이 있다.
- argument count의 갯수를 생각한다.
- 명령이 어디서부터 시작하는지 봐야 한다.
c
./pipex here_doc limiter cmd0 cmd1 file
- 원 명령어를 찾는 부분에서 조심할 필요가 있다.
헤더 파일
c
#ifndef INFO_BONUS_H
# define INFO_BONUS_H
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <sys/wait.h>
# include <sys/types.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# include "../libft/libft.h"
# define READ 0
# define WRITE 1
# define MALLOC_FAIL 100
# define WRONG_PATH 101
# define PIPE_ERROR 102
# define FORK_ERROR 103
# define WRONG_SPLIT 104
# define NO_FILE 105
# define EXEC_FAIL 106
# define DUP2_FAIL 108
# define CLOSE_FAIL 109
# define HEREDOC_FILE "/var/tmp/infile_for_header"
typedef struct s_box
{
int cmd_num; // 명령 갯수
char *infile; // 시작 파일
char *outfile; // 끝 파일
char **env; // 환경변수
char **path; // 파일 경로 (malloc)
char ***cmd_org; // 원 명령어들 (malloc)
char **cmd; // 절대경로들 (malloc)
int infile_fd; // 시작 파일 fd
int outfile_fd; // 끝 파일 fd
int pipe[2]; // 파이프
pid_t pid; // 프로세스 pid
int flag; // heredoc 부분
char *limiter; // heredoc 리미터
} t_box;
void free_double(char **box);
void free_tools(t_box *tools);
void exit_cmd(int r, t_box *tools);
char **get_path(char **env);
void set_process(t_box *tools);
void create_pipe(t_box *tools);
void child(t_box *tools, int i);
#endif