1、cli_loop()是整个shell程序的循环,里面包含了用户输入的检测、字符检查、字符拼接、命令解码、历史输入的维护
2、整个shell的运行一直在维护一个结构体
struct pipe {
int num_progs; /* total number of programs in job */
struct child_prog *progs; /* array of commands in pipe */
struct pipe *next; /* to track background commands */
pipe_style followup; /* PIPE_BG, PIPE_SEQ, PIPE_OR, PIPE_AND */
reserved_style r_mode; /* supports if, for, while, until */
};
struct child_prog {
char **argv; /* program name and arguments */
/* was quoted when parsed; copy of struct o_string.nonnull field */
int *argv_nonnull;
int argc; /* number of program arguments */
struct pipe *group; /* if non-NULL, first in group or subshell */
int sp; /* number of SPECIAL_VAR_SYMBOL */
int type;
};
struct p_context {
struct child_prog *child;
struct pipe *list_head;
struct pipe *pipe;
reserved_style w;
int old_flag; /* for figuring out valid reserved words */
struct p_context *stack;
int type; /* define type of parser : ";$" common or special symbol */
/* How about quoting status? */
};
pipe是一个链表,list_head 是该链表的表头