[minishell] Design init_job
jobを実行するには、入力文字列を適切に加工してリストを生成する必要があります.
Bash Reference Manual, 3.1.1 Shell Operation, 2-4
入力文字列を空白の区切り文字単位で中断し、token typeを判断し、token nodeを生成してリストに追加します.
Argument: (char *) input string
return: (t_token *)token list
(char*)strok(char*str,char*sep)を実現し、入力文字列をスペース区切り記号単位で切り取る. tokenは、wordオペレータタイプ(マクロまたは列挙型)を含むリストを作成します.
単一接続リスト、二重接続リスト、キュー内のデータ構造を使用します.
参照を適切に挿入する方法.
tokenリストを巡回し、プロセス構造体にグループ化します.
Argument: (t_token *)token_list
return: (t_job *)job_list
file typeはmacroかenumか書きます
作業構造体設計.
ファイルリストとプロセスリストでtokenリストノードを再使用する方法
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
Roughly written init_job flowchart
Bash Reference Manual, 3.1.1 Shell Operation, 2-4
init_job
t_job init_job(char *input, envp)
{
return (parser(lexer(input, envp)))
}
Lexer
機能
入力文字列を空白の区切り文字単位で中断し、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
悩みの中
単一接続リスト、二重接続リスト、キュー内のデータ構造を使用します.
参照を適切に挿入する方法.
Parser
機能
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か書きます
作業構造体設計.
ファイルリストとプロセスリストでtokenリストノードを再使用する方法
Reference
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
Reference
この問題について([minishell] Design init_job), 我々は、より多くの情報をここで見つけました https://velog.io/@ganadabang/minishell-Design-init-jobテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol