linux busybox中文显示修改教程,linuxbusybox


1.内核修改

进入内核,执行make menuconfig后

依次进入

File systems --->

Native language support --->

NLS UTF-8

选上NLS UTF-8 保存退出编译内核.

2.busybox修改

修改文件printable_string.c中两处,如下:

	while (1) {
		unsigned char c = *s;
		if (c == '\0') {
			/* 99+% of inputs do not need conversion */
			if (stats) {
				stats->byte_count = (s - str);
				stats->unicode_count = (s - str);
				stats->unicode_width = (s - str);
			}
			return str;
		}
		if (c < ' ')
			break;
#if 0 //modify
		if (c >= 0x7f)
			break;
#endif
		s++;
	}
		while (1) {
			unsigned char c = *d;
			if (c == '\0')
				break;
#if 0 //modify
			if (c < ' ' || c >= 0x7f)
#else
			if (c < ' ')
#endif
				*d = '?';
			d++;
		}

红色部分为修改部分.

修改 unicode.c函数unicode_conv_to_printable2中

	if (unicode_status != UNICODE_ON) {
		char *d;
		if (flags & UNI_FLAG_PAD) {
			d = dst = xmalloc(width + 1);
			while ((int)--width >= 0) {
				unsigned char c = *src;
				if (c == '\0') {
					do
						*d++ = ' ';
					while ((int)--width >= 0);
					break;
				}
#if 0 //modify 
				*d++ = (c >= ' ' && c < 0x7f) ? c : '?';
#else
				*d++ = (c >= ' ') ? c : '?';
#endif
				src++;
			}
			*d = '\0';
		} else {
			d = dst = xstrndup(src, width);
			while (*d) {
				unsigned char c = *d;
#if 0 //modify 
				if (c < ' ' || c >= 0x7f)
#else
				if (c < ' ')
#endif
					*d = '?';
				d++;
			}
		}
		if (stats)
			stats->byte_count = stats->unicode_count = (d - dst);
		return dst;
	}

红色部分为修改部分,修改后重新编译busybox.

文件系统执行挂载时加入参数

iocharset=utf8

这样在终端就能正常显示中文。

相关内容