기본파트 목표
다음과 같이 명령어를 쳤을 때..
bash
./pipex file1 cmd1 cmd2 file2
다음과 같은 결과가 나오면 된다.
shell
< file1 cmd1 | cmd2 > outfile
보너스파트 목표
heredoc 구현
heredoc 이란?
- 문자열을 쉘스크립트나 프로그래밍 언어 중에 그대로 포함시키기 위한 방법
<<뒤에 식별자를 선언하고 원하는 문자열을 쓴 후에 식별자로 끝내면 된다.
헤더파일
c
#ifndef PIPEX_INFO_H
# define PIPEX_INFO_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 WRONG_PATH 100
# define PIPE_ERROR 101
# define FORK_ERROR 102
# define WRONG_SPLIT 103
# define NO_FILE 104
# define EXEC_ERROR_1 105
# define EXEC_ERROR_2 106
# define DUP2_FAIL 107
# define CLOSE_FAIL 108
typedef struct s_box
{
int cmd_num; // 명령 갯수
char **env; // 환경변수
char **path; // 파일 경로 (2차원 배열) [malloc]
char *infile; // 시작파일
char *outfile; // 끝파일
char **cmd_org1; // 명령1 : 원 명령어 [malloc]
char **cmd_org2; // 명령2 : 원 명령어 [malloc]
char *cmd1; // 명령1 : 절대경로 [malloc]
char *cmd2; // 명령2 : 절대경로 [malloc]
int infile_fd; // 시작파일 fd
int outfile_fd; // 끝파일 fd
int pipe[2]; // 프로세스별 파이프 (fd[0], fd[1])
pid_t pid1; // 프로세스 명령어1
pid_t pid2; // 프로세스 명령어2
} t_box;
void free_double(char **box);
int put_error(void);
void put_exit(t_box *tools);
void exit_error(int reason, t_box *tools);
void free_tools(t_box *tools);
void set_process(t_box *tools);
#endif