file_size = ngx_file_size(&cf->conf_file->file.info);
获取 配置文件的大小
此时
file_size=364
for ( ;; ) {if (b->pos >= b->last) {
此时
b->pos =0x5cd4701487e4
b->last =0x5cd47014893c
b->start=0x5cd4701487d0条件不成立
ch = *b->pos++;
从缓冲区的当前处理位置获取 一个字符,然后指针后移为下一个字符的处理做准备
此时
ch=(换行符)
配置文件 nginx.confworker_processes 1;events {worker_connections 1024; }http {server {listen 80;server_name localhost;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}} }
这次处理到第一行的末尾 分号之后的换行符
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}
此时 条件成立
此时
line=1 变为 line=2 进入第二行
sharp_comment=0 条件不成立
if (sharp_comment) {continue;}
此时
sharp_comment=0
if (quoted) {quoted = 0;continue;}
此时
quoted=0
if (need_space) {
此时
need_space=0
if (last_space) {
此时
last_space=1
start = b->pos - 1;start_line = cf->conf_file->line;
更新 单词开始位置的记录
此时
start_line=2
if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {continue;}
上一个字符是分隔符,这次还是分隔符,跳过这个字符的后续处理
进入下一次循环,处理下一个字符
for ( ;; ) {if (b->pos >= b->last) {
此时
b->pos =0x64b74246e7e5
b->last =0x64b74246e93c
b->start=0x64b74246e7d0条件不成立
ch = *b->pos++;
此时
ch=(换行符)
第二行是一个空行,只有一个换行符
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}
此时
line=2 变为 line=3 进入第三行
sharp_comment=0 条件不成立
if (sharp_comment) {continue;}
此时
sharp_comment=0
if (quoted) {quoted = 0;continue;}
此时
quoted=0
if (need_space) {
此时
need_space=0
if (last_space) {
此时
last_space=1
start = b->pos - 1;start_line = cf->conf_file->line;
此时
start_line=3
if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {continue;}
此时 条件成立,进入下一次循环
for ( ;; ) {if (b->pos >= b->last) {
此时
b->pos =0x64b74246e7e6
b->last =0x64b74246e93c
b->start=0x64b74246e7d0条件不成立
ch = *b->pos++;
此时
ch=e
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}
此时
条件不成立
if (sharp_comment) {continue;}
此时
sharp_comment=0
if (quoted) {quoted = 0;continue;}
此时
quoted=0
if (need_space) {
此时
need_space=0
if (last_space) {
此时
last_space=1
start = b->pos - 1;start_line = cf->conf_file->line;
此时
start_line=3
if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {continue;}
此时
条件不成立
switch (ch) {
进入这个分支
default:last_space = 0;
进入下一次循环
for ( ;; ) {if (b->pos >= b->last) {
此时
b->pos =0x64b74246e7e7
b->last =0x64b74246e93c
b->start=0x64b74246e7d0条件不成立
ch = *b->pos++;
此时
ch=v
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}
此时
条件不成立
if (sharp_comment) {continue;}
此时
sharp_comment=0
if (quoted) {quoted = 0;continue;}
此时
quoted=0
if (need_space) {
此时
need_space=0
if (last_space) {
此时
last_space=0
} else {if (ch == '{' && variable) {continue;}variable = 0;if (ch == '\\') {quoted = 1;continue;}if (ch == '$') {variable = 1;continue;}
此时 条件不成立
if (d_quoted) {if (ch == '"') {d_quoted = 0;need_space = 1;found = 1;}} else if (s_quoted) {if (ch == '\'') {s_quoted = 0;need_space = 1;found = 1;}} else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF|| ch == ';' || ch == '{'){last_space = 1;found = 1;}
此时
d_quoted=0
s_quoted=0条件不成立
if (found) {
此时
found=0
重复以上逻辑
接下来
ch=e
ch=n
ch=t
ch=s
ch= (空格)
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}if (sharp_comment) {continue;}if (quoted) {quoted = 0;continue;}if (need_space) {
此时
sharp_comment=0
quoted=0
need_space=0
以上条件不成立
if (last_space) {
last_space=0
} else {if (ch == '{' && variable) {continue;}variable = 0;if (ch == '\\') {quoted = 1;continue;}if (ch == '$') {variable = 1;continue;}if (d_quoted) {if (ch == '"') {d_quoted = 0;need_space = 1;found = 1;}} else if (s_quoted) {if (ch == '\'') {s_quoted = 0;need_space = 1;found = 1;}
此时
d_quoted=0
s_quoted=0条件不成立
} else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF|| ch == ';' || ch == '{'){last_space = 1;found = 1;}
此时
ch= 空格
last_space = 1 标记此次字符是分隔符
found = 1; 表示找到了一个单词
if (found) {
此时
found=1
word = ngx_array_push(cf->args);if (word == NULL) {return NGX_ERROR;}
获取新元素
word->data = ngx_pnalloc(cf->pool, b->pos - 1 - start + 1);if (word->data == NULL) {return NGX_ERROR;}
为单词分配内存
for (dst = word->data, src = start, len = 0;src < b->pos - 1;len++){if (*src == '\\') {switch (src[1]) {case '"':case '\'':case '\\':src++;break;case 't':*dst++ = '\t';src += 2;continue;case 'r':*dst++ = '\r';src += 2;continue;case 'n':*dst++ = '\n';src += 2;continue;}}*dst++ = *src++;}*dst = '\0';word->len = len;
复制单词到 word
此时
word->data=events
word->len=6
if (ch == ';') {return NGX_OK;}if (ch == '{') {return NGX_CONF_BLOCK_START;}found = 0;
此时 条件不成立
found 重置为0
进入下一次循环
ch={
if (ch == LF) {cf->conf_file->line++;if (sharp_comment) {sharp_comment = 0;}}if (sharp_comment) {continue;}if (quoted) {quoted = 0;continue;}if (need_space) {
此时
sharp_comment=0
quoted=0
need_space=0
以上条件不成立
if (last_space) {
此时
last_space=1
start = b->pos - 1;start_line = cf->conf_file->line;if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {continue;}
此时
条件不成立
switch (ch) {
进入以下分支
case '{':if (cf->args->nelts == 0) {ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,"unexpected \"%c\"", ch);return NGX_ERROR;}if (ch == '{') {return NGX_CONF_BLOCK_START;}return NGX_OK;
此时
cf->args->nelts=1
返回 NGX_CONF_BLOCK_START
表示此次以 { 为结束