vi-1.18源码阅读笔记
附上源码链接:https://files-cdn.cnblogs.com/files/shiweifu/vi.zip
vi_main
首先进入主函数
主函数一开始给这些变量赋值:
CMrc= "\033[%d;%dH"; // Terminal Crusor motion ESC sequence
CMup= "\033[A"; // move cursor up one line, same col
CMdown="\n"; // move cursor down one line, same col
Ceol= "\033[0K"; // Clear from cursor to end of line
Ceos= "\033[0J"; // Clear from cursor to end of screen
SOs = "\033[7m"; // Terminal standout mode on
SOn = "\033[0m"; // Terminal standout mode off
bell= "\007"; // Terminal bell sequence
这些值是静态全局变量,具体的用法是用其改变编辑器的输出或者光标的位置,例如fprintf(stdout, CMrc, 10, 10)
就是把光标移动到10、10
的位置
更多可以参见:man console_codes
然后,主函数设置了一个status_buffer
,大小为200,它的主要用途是hold messages
status_buffer = (Byte *) malloc(200); // hold messages to user
即状态信息输出缓存
接下来,使用getopt
解