[BusyBox] vi: Telnet commands instead of termios [RFC]

Shaun Jackman sjackman at gmail.com
Fri Mar 18 21:25:15 UTC 2005


editors/vi.c uses termios -- tcgetattr and tcsetattr -- to switch the
terminal between raw mode and cooked mode. My embedded system doesn't
have termios, so I modified those two functions to spit out some
Telnet commands. I wrapped this in an #ifdef
CONFIG_FEATURE_USE_TERMIOS, and let Telnet commands be the default.
Perhaps the better plan would be to check for
CONFIG_FEATURE_USE_TERMIOS first, if not that then
CONFIG_FEATURE_USE_TELNET_COMMANDS, and if not that then make
rawmode() and cookmode() be no-ops.

Providing alternatives to termios is a good idea, but doing it through
busybox in a variety of places is not tasteful. Should rawmode() and
cookmode() be pulled out into libbb, where other applets could use
them?

Cheers,
Shaun

//----- Set terminal attributes --------------------------------
static void rawmode(void)
{
#ifdef CONFIG_FEATURE_USE_TERMIOS
	tcgetattr(0, &term_orig);
	term_vi = term_orig;
	term_vi.c_lflag &= (~ICANON & ~ECHO);	// leave ISIG ON- allow intr's
	term_vi.c_iflag &= (~IXON & ~ICRNL);
	term_vi.c_oflag &= (~ONLCR);
	term_vi.c_cc[VMIN] = 1;
	term_vi.c_cc[VTIME] = 0;
	erase_char = term_vi.c_cc[VERASE];
	tcsetattr(0, TCSANOW, &term_vi);
#else
	fputs("\xff\xfb\x01" /* IAC WILL ECHO     */
	      "\xff\xfe\x22" /* IAC DONT LINEMODE */, stdout);
#endif
}

static void cookmode(void)
{
#ifdef CONFIG_FEATURE_USE_TERMIOS
	fflush(stdout);
	tcsetattr(0, TCSANOW, &term_orig);
#else
	fputs("\xff\xfc\x01" /* IAC WONT ECHO   */
              "\xff\xfd\x22" /* IAC DO LINEMODE */
	      "\xff\xfa\x22" /* IAC SB LINEMODE */
	          "\x01\x01" /*     MODE EDIT   */
	      "\xff\xf0"     /* IAC SE          */, stdout);
#endif
}



More information about the busybox mailing list