job을 실행시키기 위해서는 입력 문자열을 적절하게 가공해서 리스트를 생성해야 한다.
Bash Reference Manual, 3.1.1 Shell Operation, 2-4
t_job init_job(char *input, envp)
{
return (parser(lexer(input, envp)))
}
입력 문자열을 blank 구분자 단위로 끊어 token type을 판단, token node를 생성해 리스트에 추가한다.
Argument: (char *) input string
return: (t_token *)token list
typedef struct s_token
{
char *token
int type
struct s_token *next
} t_token
단일 연결리스트, 이중 연결리스트, 큐 중 어떤 자료구조를 사용할 지.
quoting을 어떻게 적절하게 끼워넣을지.
token리스트를 순회하며 프로세스 구조체에 파싱한다.
Argument: (t_token *)token_list
return: (t_job *)job_list
iterates token-list {
if token == redirection operator
redirection type과 함께 노드를 생성하고 file 리스트에 추가. redirection type은
'<' '>' '<<' '>>' 인지에 따라 결정된다.
에러처리
operator의 next token이 word가 아니면 syntax error
else if token == control operator '|'
순회할 때 인풋이 파싱될 프로세스 구조체를 새로 생성한다.
else // if token == word
words의 수에 맞게 문자열 배열을 생성해 순서대로 넣어준다.
argv[0]은 command 나머지는 command의 argument
}
typedef struct s_file
{
char *name
int type
struct s_file *next
} t_file
typedef struct s_process
{
char **args
pid_t pid
char completed;
int status;
t_file *file;
struct s_process *next;
} t_process
file type을 macro를 쓸지, enum을 쓸지.
job 구조체 설계.
token리스트 노드를 file리스트 및 process리스트에서 어떻게 재사용할지.
https://ruslanspivak.com/lsbasi-part13/
https://www.gnu.org/software/bash/manual/html_node/Shell-Operation.html
https://www.gnu.org/software/libc/manual/html_node/Data-Structures.html#Data-Structures