0922 - tamagoyakii/minishell GitHub Wiki
연결 리스트로 변경
- 파싱 단계에서 구현 단계로 넘겨주는 구조체
typedef enum e_redir_type
{
INPUT, /* > */
OUTPUT, /* < */
A_OUTPUT, /* >> */
HEREDOC /* << */
} t_redir_type;
typedef struct s_redir
{
int r_type; /* redirect : >, <, >> | heredoc : << */
char *value; /* redirect : filename | heredoc : endstr */
struct s_redir *next;
} t_redir;
/* 구현부로 넘김 */
typedef struct s_argv
{
char **cmd; /* execve()가 이중포인터를 받기 때문에 */
struct s_redir *in;
struct s_redir *out;
struct s_argv *next;
} t_argv;
- 토큰 관련 구조체
typedef enum e_token_type
{
WORD,
REDIR,
PIPE,
NULL
} t_token_type;
typedef struct s_token
{
int t_type;
char *str;
} t_token;
- 환경변수 구조체
typedef struct s_env
{
char *key;
char *value;
struct s_env *prev;
struct s_env *next;
} t_env;
=> 프로그램 실행과 동시에 초기화하여 사용
- 초기화
// wochae
- 환경 변수 초기화 및 저장
- 구조체 초기화
- 사용자 입력 처리(Read Input)
// wochae
- 문자열 입력
- 입력값 유효성 검사
- 환경변수 치환(Replace env)
// wochae
- 환경변수 치환
- 문자열 분할(Split Line)
// donghyuk
- 맨 앞 공백 제거
- quotes, double quotes 제거 + unclosed 여부 확인
- 이중 배열 생성
- 토큰 생성(Create token)
// jihyukim
- 토큰 리스트 생성(type 정의, str 할당)
- 토큰 유효성 검사(redirection, pipeline unclosed 여부 확인)
- 인자 생성(Create Argvs)
// jihyukim
- 토큰을 알맞게 할당
- wochae -> donghyuk :
char *replace_env()
- donghyuk -> jihyukim :
char **split_input()
- 메인 프로세스에서 실행
- 무슨 명령어인지 검사(cmd[0] 확인)
- 실행
- 파이프 개수 확인
- while 돌면서 파이프 개수만큼 파이프 함수 실행
- 포크 실행
- 자식 프로세스 시그널 설정 필요한가? → 필요하다
- 안쓰는 fd 닫아주기
- 자식 프로세스 들어가서 in, out 따라가면서 파일 생성
- 파이프에 따라 fd 설정
- 파일 next가 없는 경우에만 infile fd, outfile fd로 설정
- 파일 next가 있는 경우 fd close
- heredoc은 마지막인지 아닌지 체크해서 마지막이면 저장하고 아니면 말고(임시파일 생성은 마지막일 때만)
- 실행하기
- 프로세스 기다려서 exit status 설정
- 받은 인자 프리해주기
- single_builtin인 경우 infile을 찾을 수 없다면 return시켜주는 부분
- heredoc 부분
- wait, exit status 부분
- free 함수들
- exceve 함수 PATH 찾는 부분
- builtin 함수 전부 다
- 주말 전까지
-
nheo
: 전체적인 흐름 코딩 -
jabae
: pipe 공부,nheo
코드 토대로 플로우 차트 짜기
- 주말 동안
- built-in 함수 나눠서 구현하기