vi in busybox

busybox にも独自の vi が入っている。
制限事項は以下の通り。

/*
* Things To Do:
* EXINIT
* $HOME/.exrc and ./.exrc
* add magic to search /foo.*bar
* add :help command
* :map macros
* how about mode lines: vi: set sw=8 ts=8:
* if mark[] values were line numbers rather than pointers
* it would be easier to change the mark when add/delete lines
* More intelligence in refresh()
* ":r !cmd" and "!cmd" to filter text through an external command
* A true "undo" facility
* An "ex" line oriented mode- maybe using "cmdedit"
*/

map やアンドゥは仕方ないとしても、
r! が使えないのは痛い。

実装の方は、テキスト管理が行単位でなく、ファイルまるごとで1つのバッファになっているのが vi としては珍しい(?)。
しかもギャップバッファも何も使っていない。
1文字を挿入する関数の名前は stupid_insert() だ。

static Byte *stupid_insert(Byte * p, Byte c) // stupidly insert the char c at 'p'

カウントを再帰で処理しているのも面白い。

//----- Execute a Vi Command -----------------------------------
static void do_cmd(Byte c)
{
.....
	case 'j':			// j- goto next line, same col
	case VI_K_DOWN:	// cursor key Down
		if (cmdcnt-- > 1) {
			do_cmd(c);
		}				// repeat cnt
		dot_next();		// go to next B-o-l
		dot = move_to_col(dot, ccol + offset);	// try stay in same col
		break;
.....

ソースは vi.c 1つで3944行。