# 命令是怎样被执行的❌

命令执行的总入口是 `script_driver()`，不论是命令行输入还是执行脚本最终都是通过它。调用路径分别如下：

* 命令行输入： `update.c:mainloop()` => `update.c:update_input()` => `input.c:process_input()` => `parse.c:parse_input()` => `tokenize.c:script_driver()`

`process_input()` 本质上仍然是事件循环的一部分，一次只捕获一个按键，因此最终是否真的调用 `parse_input()` 取决于用户是否按下了回车键。这部分处理在 `cursor.c` 中进行，按下回车键后会设置标记 `TINTIN_FLAG_PROCESSINPUT`，否则就会跳过后续处理：

```
	if (!HAS_BIT(gtd->flags, TINTIN_FLAG_PROCESSINPUT))
	{
		pop_call();
		return;
	}
```

* 执行脚本：`files.c:do_read()` => `files.c:read_file()` => `tokenize.c:script_driver()`

注意 `read_file()` 中有一个相当长的前置处理，在交给 `script_driver()` 之前，实际上就已经做了一些粗略的词法处理：

* 去掉注释
* 处理花括号
* 忽略 `'\r'`，去掉 `'\n'`，并且根据命令分隔符（也就是 `';'`）拆分命令。
* FIXME: 没找到关于转义字符的处理，不确定是何时处理的。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dzp.gitbook.io/tt1book/tintin++-yuan-dai-ma-jie-xi/ming-ling-shi-zen-yang-bei-zhi-xing-de.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
