Index: EcnlProtoTool/trunk/prototool/src/arduino.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/arduino.c	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/arduino.c	(revision 331)
@@ -4,4 +4,5 @@
 #include <stdio.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 #include "../llbruby.h"
 
@@ -544,2 +545,68 @@
 	return 0;
 }
+
+unsigned int Utf8_to_Utf16(const char *src, int *code_size)
+{
+	int i;
+	unsigned int uc = 0;
+	unsigned char len = 0;
+
+	len = 0;
+	if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; }
+	else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; }
+	else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; }
+	else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; }
+	else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; }
+	else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; }
+
+	i = 1;
+	while ((i <= len) && ((src[i] & 0xC0) == 0x80)) {
+		uc = (uc << 6) | (src[i] & 0x3F);
+		i++;
+	}
+
+	//消費文字数設定
+	*code_size = i;
+
+	//現状、2バイト限定
+	return uc;
+}
+
+int bs_char_count(char *str, int pos)
+{
+	int num = 1, local_pos = pos;
+	char *c;
+
+	while (1) {
+		c = str + local_pos;
+
+		if ((*c & 0x80) != 0x80)
+			return num;
+
+		if (((*c & 0xE0) == 0xC0) && (num == 2)) {
+			return num;
+		}
+		else if (((*c & 0xF0) == 0xE0) && (num == 3)) {
+			return num;
+		}
+		else if (((*c & 0xF8) == 0xF0) && (num == 4)) {
+			return num;
+		}
+		else if (((*c & 0xFC) == 0xF8) && (num == 5)) {
+			return num;
+		}
+		else if (((*c & 0xFE) == 0xFC) && (num == 6)) {
+			return num;
+		}
+		else {
+			if (local_pos > 0) {
+				local_pos--;
+				num++;
+			}
+			else
+				return 0;
+		}
+	}
+
+	return 0;
+}
Index: EcnlProtoTool/trunk/prototool/src/arduino.h
===================================================================
--- EcnlProtoTool/trunk/prototool/src/arduino.h	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/arduino.h	(revision 331)
@@ -10,24 +10,5 @@
 #include <string.h>
 #include <time.h>
-#include <analogin_api.h>
-#include <analogout_api.h>
-#include <buffer.h>
-#include <can_api.h>
-#include <dma_api.h>
-#include <ethernet_api.h>
-#include <gpio_api.h>
-#include <gpio_irq_api.h>
-#include <i2c_api.h>
-#include <lp_ticker_api.h>
-#include <pinmap.h>
-#include <port_api.h>
-#include <pwmout_api.h>
-#include <rtc_api.h>
-#include <serial_api.h>
-#include <sleep_api.h>
-#include <spi_api.h>
-#include <ticker_api.h>
-#include <us_ticker_api.h>
-#include <wait_api.h>
+#include <mbed_api.h>
 
 #ifndef bool
Index: EcnlProtoTool/trunk/prototool/src/libbb/libbb.h
===================================================================
--- EcnlProtoTool/trunk/prototool/src/libbb/libbb.h	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/libbb/libbb.h	(revision 331)
@@ -25,5 +25,5 @@
 
 #include <ctype.h>
-#include "_dirent.h"
+#include "dirent.h"
 #include <errno.h>
 #include <fcntl.h>
@@ -61,5 +61,5 @@
 #endif
 #include <sys/wait.h>
-#include "_termios.h"
+#include <termios.h>
 #include <time.h>
 #include <sys/param.h>
Index: EcnlProtoTool/trunk/prototool/src/libbb/vi.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/libbb/vi.c	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/libbb/vi.c	(revision 331)
@@ -210,4 +210,5 @@
 # define Isprint(c) ((unsigned char)(c) >= ' ' && (c) != 0x7f && (unsigned char)(c) != 0x9b)
 #else
+#define MULTI_BYTE_MULTIPLE	3
 bool Isprint(unsigned char c)
 {
@@ -228,4 +229,17 @@
 	mbc_st--;
 	return true;
+}
+bool IsMultiByteChar(unsigned char c, int *bytes)
+{
+	bool ret = false;
+	*bytes = 1;
+	if ((c & 0xE0) == 0xC0) { *bytes = 2; }
+	else if ((c & 0xF0) == 0xE0) { *bytes = 3; }
+	else if ((c & 0xF8) == 0xF0) { *bytes = 4; }
+	else if ((c & 0xFC) == 0xF8) { *bytes = 5; }
+	else if ((c & 0xFE) == 0xFC) { *bytes = 6; }
+	if (*bytes != 1)
+		ret = true;
+	return ret;
 }
 #endif
@@ -583,5 +597,9 @@
 static int format_edit_status(void);	// format file status on status line
 static void redraw(int);	// force a full screen refresh
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 static char* format_line(char* /*, int*/);
+#else
+static char* format_line(char* , int*, int*);
+#endif
 static void refresh(int);	// update the terminal from screen[]
 
@@ -1590,4 +1608,7 @@
 	char *tp;
 	int cnt, ro, co;
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+	int last_code_size = 0;
+#endif
 
 	beg_cur = begin_line(d);	// first char of cur line
@@ -1654,4 +1675,5 @@
 		co += (code_size > 1 ? 2 : code_size);
 		tp += code_size;
+		last_code_size = code_size;
 #endif
 	}
@@ -1674,5 +1696,9 @@
 	}
 	if (co >= columns + offset) {
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 		offset = co - columns + 1;
+#else
+		offset = co - columns + (last_code_size > 1 ? 2 : 1);
+#endif
 	}
 	// if the first char of the line is a tab, and "dot" is sitting on it
@@ -1831,5 +1857,10 @@
 			break;
 		if (*p == '\t') {
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 			co = next_tabstop(co);
+#else
+			co += tabstop;
+			p++;
+#endif
 		}
 #ifndef ENABLE_BASIC_MULTI_CHAR_CODE
@@ -1933,7 +1964,11 @@
 {
 	int li;
+	int internal_co = co;
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+	internal_co *= MULTI_BYTE_MULTIPLE;
+#endif
 
 	free(screen);
-	screensize = ro * co + 8;
+	screensize = ro * internal_co + 8;
 	screen = xmalloc(screensize);
 	// initialize the new screen. assume this will be a empty file.
@@ -1941,5 +1976,5 @@
 	//   non-existent text[] lines start with a tilde (~).
 	for (li = 1; li < ro - 1; li++) {
-		screen[(li * co) + 0] = '~';
+		screen[(li * internal_co) + 0] = '~';
 	}
 	return screen;
@@ -3361,6 +3396,43 @@
 }
 
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+//----- get screen column number of string ---------------------
+int get_view_col_from_bytes(char *st, char bytes, int max_size)
+{
+	char *buf_end = st + max_size;
+	int tmp_bytes = 0, tmp_total_bytes = 0, view_col = 0;
+	while (tmp_total_bytes < bytes) {
+		Utf8_to_Utf16(st, &tmp_bytes);
+		tmp_total_bytes += tmp_bytes;
+		view_col += tmp_bytes > 1 ? 2 : 1;
+		st += tmp_bytes;
+		if (st >= buf_end)
+			break;
+	}
+	return view_col;
+}
+//----- get string bytes of screen column ----------------------
+int get_bytes_from_view_col(char *st, int view_col, int max_size)
+{
+	char *buf_end = st + max_size;
+	int tmp_view_col = 0, bytes = 0, tmp_bytes;
+	while (tmp_view_col < view_col) {
+		Utf8_to_Utf16(st, &tmp_bytes);
+		bytes += tmp_bytes;
+		tmp_view_col += tmp_bytes > 1 ? 2 : 1;
+		st += tmp_bytes;
+		if (st >= buf_end)
+			break;
+	}
+	return bytes;
+}
+#endif
+
 //----- Format a text[] line into a buffer ---------------------
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 static char* format_line(char *src /*, int li*/)
+#else
+static char* format_line(char *src , int *bytes, int *view_co)
+#endif
 {
 	unsigned char c;
@@ -3368,8 +3440,16 @@
 	int ofs = offset;
 	char *dest = scr_out_buf; // [MAX_SCR_COLS + MAX_TABSTOP * 2]
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+	int tmp_bytes, tmp_columns_count, total_bytes = 0, view_columns = 0;
+	memset(scr_out_buf, 0x00, sizeof(scr_out_buf));
+#endif
 
 	c = '~'; // char in col 0 in non-existent lines is '~'
 	co = 0;
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 	while (co < columns + tabstop) {
+#else
+	while (view_columns < columns + ofs/* + tabstop*/) {
+#endif
 		// have we gone past the end?
 		if (src < end) {
@@ -3386,4 +3466,8 @@
 					while ((co % tabstop) != (tabstop - 1)) {
 						dest[co++] = c;
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+						total_bytes++;
+						view_columns++;
+#endif
 					}
 				} else {
@@ -3397,4 +3481,22 @@
 		}
 		dest[co++] = c;
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+		total_bytes++;
+		view_columns++;
+		if (IsMultiByteChar(c, &tmp_bytes)) {
+			if (view_columns + 1 > columns + ofs) {
+				dest[--co] = ' ';
+			}
+			else {
+				view_columns++;
+				int i;
+				for (i = 0; i < tmp_bytes - 1; i++) {
+					dest[co++] = *src++;
+					total_bytes++;
+				}
+			}
+		}
+#endif
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 		// discard scrolled-off-to-the-left portion,
 		// in tabstop-sized pieces
@@ -3404,7 +3506,9 @@
 			ofs -= tabstop;
 		}
+#endif
 		if (src >= end)
 			break;
 	}
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 	// check "short line, gigantic offset" case
 	if (co < ofs)
@@ -3416,4 +3520,26 @@
 	if (co < columns)
 		memset(&dest[co], ' ', columns - co);
+#else
+	// check "short line, gigantic offset" case
+	if (view_columns < ofs)
+		ofs = view_columns;
+	// discard last scrolled off part
+	view_columns -= ofs;
+	tmp_columns_count = 0;
+	while (tmp_columns_count < ofs) {
+		IsMultiByteChar(*dest, &tmp_bytes);
+		dest += tmp_bytes;
+		total_bytes -= tmp_bytes;
+		tmp_columns_count += tmp_bytes > 1 ? 2 : 1;
+	}
+	// fill the rest with spaces
+	if (view_columns < columns) {
+		int ofs_bytes = get_bytes_from_view_col(scr_out_buf, ofs, co);
+		memset(&dest[co - ofs_bytes], ' ', columns - view_columns);
+		total_bytes = total_bytes + (columns - view_columns);
+	}
+	*bytes = total_bytes;
+	*view_co = view_columns;
+#endif
 	return dest;
 }
@@ -3430,4 +3556,7 @@
 	int li, changed;
 	char *tp, *sp;		// pointer into text[] and screen[]
+#ifdef ENABLE_BASIC_MULTI_CHAR_CODE
+	int bytes, view_co;
+#endif
 
 	if (ENABLE_FEATURE_VI_WIN_RESIZE IF_FEATURE_VI_ASK_TERMINAL(&& !G.get_rowcol_error) ) {
@@ -3444,5 +3573,9 @@
 		char *out_buf;
 		// format current text line
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 		out_buf = format_line(tp /*, li*/);
+#else
+		out_buf = format_line(tp , &bytes, &view_co);
+#endif
 
 		// skip to the end of the current text[] line
@@ -3456,7 +3589,13 @@
 		changed = FALSE;	// assume no change
 		cs = 0;
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 		ce = columns - 1;
 		int cursor_column = 0;
 		sp = &screen[li * columns];	// start of screen line
+#else
+		ce = bytes - 1;
+		int cursor_column = 0;
+		sp = &screen[li * columns * MULTI_BYTE_MULTIPLE];	// start of screen line
+#endif
 		if (full_screen) {
 			// force re-draw of every single column from 0 - columns-1
@@ -3494,5 +3633,5 @@
 #else
 		while (ce >= cs) {
-			int code_size = bs_char_count(sp, ce);
+			int code_size = bs_char_count(out_buf, ce);
 			if (memcmp(&out_buf[ce], &sp[ce], code_size)) {
 				changed = TRUE;	// mark for redraw
@@ -3501,4 +3640,6 @@
 			ce -= code_size;
 		}
+		if (view_co < columns - 1)
+			ce = bytes;
 #endif
 		// now, cs is index of first diff, and ce is index of last diff
@@ -3511,7 +3652,18 @@
 
 		// make a sanity check of columns indexes
+#ifndef ENABLE_BASIC_MULTI_CHAR_CODE
 		if (cs < 0) { cs = 0; cursor_column = 0; }
 		if (ce > columns - 1) ce = columns - 1;
 		if (cs > ce) { cs = 0; ce = columns - 1; cursor_column = 0; }
+#else
+		if (cs < 0) { cs = 0; cursor_column = 0; }
+		if (get_view_col_from_bytes(out_buf, ce, (columns * MULTI_BYTE_MULTIPLE)) > columns - 1)
+			ce = get_bytes_from_view_col(out_buf, columns, (columns * MULTI_BYTE_MULTIPLE)) - 1;
+		if (cs > ce) {
+			cs = 0;
+			ce = get_bytes_from_view_col(out_buf, columns, (columns * MULTI_BYTE_MULTIPLE)) - 1;
+			cursor_column = 0;
+		}
+#endif
 		// is there a change between virtual screen and out_buf
 		if (changed) {
Index: EcnlProtoTool/trunk/prototool/src/main.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/main.c	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/main.c	(revision 331)
@@ -49,9 +49,8 @@
 #include <netdb.h>
 #include <unistd.h>
-#include <setjmp.h>
 #include <signal.h>
 #include <time.h>
 #include <sys/time.h>
-#include <sys/unistd.h>
+#include <unistd.h>
 #include <errno.h>
 
@@ -65,5 +64,5 @@
 #include <mruby/dump.h>
 #include <mruby/string.h>
-#include <usrcmd.h>
+#include <ntshell/usrcmd.h>
 
 #define ETHER_MAX_LEN 1518
@@ -89,4 +88,5 @@
 extern int mruby_main(int argc, char **argv);
 extern int mirb_main(int argc, char **argv);
+extern int curl_main(int argc, char **argv);
 extern int tcc_main(int argc, char **argv);
 extern int vi_main(int argc, char **argv);
@@ -101,18 +101,10 @@
 	{"mruby","mruby command", mruby_main},
 	{"mirb", "Embeddable Interactive Ruby Shell", mirb_main},
+	{"curl", "Command lines or scripts to transfer data", curl_main},
 	{"tcc", "Tiny C compiler", tcc_main},
 	{"vi", "Text editor", vi_main},
-	{"cd", "change directory", usrcmd_cd },
-	{"ls", "list files", usrcmd_ls },
-	{"cp", "copy file", usrcmd_cp },
-	{"rm", "remove file", usrcmd_rm },
-	{"mv", "move file", usrcmd_mv },
-	{"mkdir", "Make directory", usrcmd_mkdir},
-	{"hexdump", "Hex dump", usrcmd_hexdump},
 	{"onitest", "Onigumo Test", onitest_main},
 	{"tcp_echo", "TCP echo server/client", tcp_echo_main},
 	{"help", "This is a description text string for help command.", usrcmd_help},
-	{"info", "This is a description text string for info command.", usrcmd_info},
-	{"exit", "Exit Natural Tyny Shell", usrcmd_exit},
 };
 cmd_table_info_t cmd_table_info = { &cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) };
@@ -521,43 +513,14 @@
 }
 
-// Provide implementation of _sbrk (low-level dynamic memory allocation
-// routine) for GCC_ARM which compares new heap pointer with MSP instead of
-// SP.  This make it compatible with RTX RTOS thread stacks.
-
-// Linker defined symbol used by _sbrk to indicate where heap should start.
-int _end;
-uint32_t  _stack;
-
-// Turn off the errno macro and use actual global variable instead.
-#undef errno
-int errno;
-
-static unsigned char* heap = (unsigned char*)&_end;
-
-// Dynamic memory allocation related syscall.
-caddr_t _sbrk(int incr) {
-	unsigned char*        prev_heap = heap;
-	unsigned char*        new_heap = heap + incr;
-
-	if (new_heap >= (unsigned char*)&_stack) {     /* _stack is end of heap section */
-		errno = ENOMEM;
-		return (caddr_t)-1;
-	}
-
-	heap = new_heap;
-	return (caddr_t) prev_heap;
-}
-
-char *optarg;
+void _start_c(long *p);
 int _data, _mdata, _edata;
 int _bss, _ebss;
 
-int _PowerON_Reset(int argc, char **argv)
+void _PowerON_Reset(long *args)
 {
 	memcpy(&_data, &_mdata, (size_t)&_edata - (size_t)&_data);
 	memset(&_bss, 0, (size_t)&_ebss - (size_t)&_bss);
 
-	optarg = *argv;
-	return main(argc, argv);
+	_start_c(args);
 }
 
Index: EcnlProtoTool/trunk/prototool/src/onitest.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/onitest.c	(revision 321)
+++ EcnlProtoTool/trunk/prototool/src/onitest.c	(revision 331)
@@ -9,7 +9,7 @@
 
 #ifdef POSIX_TEST
-#include "onigposix.h"
+#include "onigmoposix.h"
 #else
-#include "oniguruma.h"
+#include "onigmo.h"
 #endif
 
@@ -197,5 +197,5 @@
 	x2("\\x1f", "\x1f", 0, 1);
 	x2("a(?#....\\\\JJJJ)b", "ab", 0, 2);
-	x2("(?x)  G (o O(?-x)oO) g ", "GoOoOgLe", 0, 7);
+	x2("(?x)  G (o O(?-x)oO) g L", "GoOoOgLe", 0, 7);
 	x2(".", "a", 0, 1);
 	n(".", "");
Index: EcnlProtoTool/trunk/prototool/src/shellif.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/shellif.c	(revision 321)
+++ 	(revision )
@@ -1,748 +1,0 @@
-/*
- *  TOPPERS ECHONET Lite Communication Middleware
- * 
- *  Copyright (C) 2017 Cores Co., Ltd. Japan
- * 
- *  ãLì ÒÍCÈºÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
- *  Ai{\tgEFAðüÏµ½àÌðÜÞDÈº¯¶jðgpE¡»Eü
- *  ÏEÄzziÈºCpÆÄÔj·é±Æð³Åø·éD
- *  (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
- *       \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
- *      XR[hÉÜÜêÄ¢é±ÆD
- *  (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJ­Ég
- *      pÅ«é`ÅÄzz·éêÉÍCÄzzÉº¤hL
-gip
- *      Ò}j
-AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
- *      Ì³ÛØKèðfÚ·é±ÆD
- *  (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJ­Ég
- *      pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
- *      ÆD
- *    (a) ÄzzÉº¤hL
-gipÒ}j
-AÈÇjÉCãLÌ
- *        ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
- *    (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
- *        ñ·é±ÆD
- *  (4) {\tgEFAÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶é¢©Èé¹
- *      Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
- *      Ü½C{\tgEFAÌ[UÜ½ÍGh[U©çÌ¢©Èé
- *      RÉîÃ­¿©çàCãLì Ò¨æÑTOPPERSvWFNgð
- *      ÆÓ·é±ÆD
- * 
- *  {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
- *  æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
- *  ÉÎ·éK«àÜßÄC¢©ÈéÛØàsíÈ¢DÜ½C{\tgEF
- *  AÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶½¢©Èé¹QÉÖµÄàC»
- *  ÌÓCðíÈ¢D
- * 
- *  @(#) $Id$
- */
-#include <setjmp.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/select.h>
-#include <poll.h>
-#include <stdarg.h>
-#include "shellif.h"
-#include "analogin_api.h"
-#include "gpio_api.h"
-#include "i2c_api.h"
-#include "pwmout_api.h"
-#include "rtc_api.h"
-#include "serial_api.h"
-#include "us_ticker_api.h"
-#include "wait_api.h"
-#include "arduino.h"
-#include "usrcmd.h"
-#include <sys/mman.h>
-#include <signal.h>
-
-typedef struct __dirstream DIR;
-
-typedef void (*analogin_init_t)(analogin_t *obj, PinName pin);
-typedef uint16_t (*analogin_read_u16_t)(analogin_t *obj);
-typedef void (*gpio_init_t)(gpio_t *obj, PinName pin);
-typedef void (*gpio_dir_t)(gpio_t *obj, PinDirection direction);
-typedef int (*i2c_start_t)(i2c_t *obj);
-typedef int (*i2c_stop_t)(i2c_t *obj);
-typedef void (*i2c_init_t)(i2c_t *obj, PinName sda, PinName scl);
-typedef int (*i2c_read_t)(i2c_t *obj, int address, char *data, int length, int stop);
-typedef int (*i2c_write_t)(i2c_t *obj, int address, const char *data, int length, int stop);
-typedef int (*i2c_byte_read_t)(i2c_t *obj, int last);
-typedef int (*i2c_byte_write_t)(i2c_t *obj, int data);
-typedef void (*pwmout_free_t)(pwmout_t* obj);
-typedef void (*pwmout_init_t)(pwmout_t* obj, PinName pin);
-typedef void (*pwmout_pulsewidth_us_t)(pwmout_t* obj, int us);
-typedef void (*rtc_init_t)(void);
-typedef void (*rtc_free_t)(void);
-typedef int (*rtc_isenabled_t)(void);
-typedef time_t (*rtc_read_t)(void);
-typedef void (*rtc_write_t)(time_t t);
-typedef void (*serial_baud_t)(serial_t *obj, int baudrate);
-typedef void (*serial_init_t)(serial_t *obj, PinName tx, PinName rx);
-typedef int (*serial_readable_t)(serial_t *obj);
-typedef int (*serial_getc_t)(serial_t *obj);
-typedef void (*serial_putc_t)(serial_t *obj, int c);
-typedef uint32_t (*us_ticker_read_t)(void);
-typedef void (*wait_ms_t)(int ms);
-typedef bool (*SD_begin_t)();
-typedef int (*usrcmd_cd_t)(int argc, char **argv);
-typedef int (*usrcmd_ls_t)(int argc, char **argv);
-typedef int (*usrcmd_cp_t)(int argc, char **argv);
-typedef int (*usrcmd_rm_t)(int argc, char **argv);
-typedef int (*usrcmd_mv_t)(int argc, char **argv);
-typedef int (*usrcmd_mkdir_t)(int argc, char **argv);
-typedef int (*usrcmd_hexdump_t)(int argc, char **argv);
-typedef int (*usrcmd_info_t)(int argc, char **argv);
-typedef int (*usrcmd_exit_t)(int argc, char **argv);
-typedef void(*shell_abort_t)();
-typedef void(*shell_exit_t)(int exitcd);
-typedef int (*shell_kill_t)(int pid, int sig);
-typedef int (*shell_gettimeofday_t)(struct timeval * tp, void * tzvp);
-typedef void (*vsyslog_t)(int priority, const char *format, va_list ap);
-typedef int (*shell_open_t)(const char * path, int flags);
-typedef int (*shell_close_t)(int fd);
-typedef int (*shell_read_t)(int fd, char *data, int len);
-typedef int (*shell_write_t)(int fd, char *data, int len);
-typedef int (*shell_lseek_t)(int fd, int ptr, int dir);
-typedef int (*shell_fstat_t)(int fd, struct stat * st);
-typedef int (*shell_stat_t)(const char *fname, struct stat *st);
-typedef int (*shell_link_t)(void);
-typedef int (*shell_unlink_t)(const char *path);
-typedef int (*shell_isatty_t)(int fd);
-typedef int (*fsync_t)(int fd);
-typedef int (*ftruncate_t)(int fd, off_t length);
-typedef int (*ioctl_t)(int fd, int request, va_list ap);
-typedef int (*tcgetattr_t)(int fd, struct termios *termios_p);
-typedef int (*tcsetattr_t)(int fd, int optional_actions, const struct termios *termios_p);
-typedef int (*shell_rename_t)(const char *oldpath, const char *newpath);
-typedef int (*rmdir_t)(const char *path);
-typedef int (*mkdir_t)(const char *path, mode_t mode);
-typedef int (*chmod_t)(const char *path, mode_t mode);
-typedef char *(*getcwd_t)(char *buf, size_t size);
-typedef int (*chdir_t)(const char *path);
-typedef int (*chroot_t)(const char *path);
-typedef int (*closedir_t)(DIR *dir);
-typedef DIR *(*opendir_t)(const char *path);
-typedef struct dirent *(*readdir_t)(DIR *dir);
-typedef void (*rewinddir_t)(DIR *dir);
-typedef void (*seekdir_t)(DIR *dir, long pos);
-typedef long (*telldir_t)(DIR *dir);
-typedef int (*shell_getpid_t)();
-typedef int (*socket_t)(int family, int type, int protocol);
-typedef int (*bind_t)(int fd, const struct sockaddr *addr, socklen_t len);
-typedef int (*listen_t)(int fd, int backlog);
-typedef int (*connect_t)(int fd, const struct sockaddr *addr, socklen_t len);
-typedef int (*accept_t)(int fd, struct sockaddr *addr, socklen_t *len);
-typedef ssize_t (*send_t)(int fd, const void *buf, size_t len, int flags);
-typedef ssize_t (*sendto_t)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen);
-typedef ssize_t (*recv_t)(int fd, void *buf, size_t len, int flags);
-typedef ssize_t (*recvfrom_t)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen);
-typedef int (*shutdown_t)(int fd, int how);
-typedef int (*getsockopt_t)(int fd, int level, int optname, void *optval, socklen_t *optlen);
-typedef int (*setsockopt_t)(int fd, int level, int optname, const void *optval, socklen_t optlen);
-typedef int (*select_t)(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);
-typedef int (*poll_t)(struct pollfd *fds, nfds_t nfds, int timeout);
-typedef int (*gethostname_t)(char *name, size_t len);
-typedef int (*getnameinfo_t)(const struct sockaddr *sa, socklen_t sl, char *node, socklen_t nodelen, char *serv, socklen_t servlen, int flags);
-typedef int (*getpeername_t)(int fd, struct sockaddr *addr, socklen_t *len);
-typedef int (*getsockname_t)(int fd, struct sockaddr *addr, socklen_t *len);
-typedef int (*socketpair_t)(int family, int type, int protocol, int fd[2]);
-
-void analogin_init(analogin_t *obj, PinName pin)
-{
-	__imp_analogin_init(obj, pin);
-}
-
-uint16_t analogin_read_u16(analogin_t *obj)
-{
-	return __imp_analogin_read_u16(obj);
-}
-
-void gpio_init(gpio_t *obj, PinName pin)
-{
-	__imp_gpio_init(obj, pin);
-}
-
-void gpio_dir(gpio_t *obj, PinDirection direction)
-{
-	__imp_gpio_dir(obj, direction);
-}
-
-int i2c_start(i2c_t *obj)
-{
-	return __imp_i2c_start(obj);
-}
-
-int i2c_stop(i2c_t *obj)
-{
-	return __imp_i2c_stop(obj);
-}
-
-void i2c_init(i2c_t *obj, PinName sda, PinName scl)
-{
-	__imp_i2c_init(obj, sda, scl);
-}
-
-int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
-{
-	return __imp_i2c_read(obj, address, data, length, stop);
-}
-
-int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
-{
-	return __imp_i2c_write(obj, address, data, length, stop);
-}
-
-int i2c_byte_read(i2c_t *obj, int last)
-{
-	return __imp_i2c_byte_read(obj, last);
-}
-
-int i2c_byte_write(i2c_t *obj, int data)
-{
-	return __imp_i2c_byte_write(obj, data);
-}
-
-void pwmout_free(pwmout_t* obj)
-{
-	__imp_pwmout_free(obj);
-}
-
-void pwmout_init(pwmout_t* obj, PinName pin)
-{
-	__imp_pwmout_init(obj, pin);
-}
-
-void pwmout_pulsewidth_us(pwmout_t* obj, int us)
-{
-	__imp_pwmout_pulsewidth_us(obj, us);
-}
-
-void rtc_init(void)
-{
-	__imp_rtc_init();
-}
-
-void rtc_free(void)
-{
-	__imp_rtc_free();
-}
-
-int rtc_isenabled(void)
-{
-	return __imp_rtc_isenabled();
-}
-
-time_t rtc_read(void)
-{
-	return __imp_rtc_read();
-}
-
-void rtc_write(time_t t)
-{
-	__imp_rtc_write(t);
-}
-
-void serial_baud(serial_t *obj, int baudrate)
-{
-	__imp_serial_baud(obj, baudrate);
-}
-
-void serial_init(serial_t *obj, PinName tx, PinName rx)
-{
-	__imp_serial_init(obj, tx, rx);
-}
-
-int serial_readable(serial_t *obj)
-{
-	return __imp_serial_readable(obj);
-}
-
-int serial_getc(serial_t *obj)
-{
-	return __imp_serial_getc(obj);
-}
-
-void serial_putc(serial_t *obj, int c)
-{
-	__imp_serial_putc(obj, c);
-}
-
-uint32_t us_ticker_read(void)
-{
-	return __imp_us_ticker_read();
-}
-
-void wait_ms(int ms)
-{
-	__imp_wait_ms(ms);
-}
-
-bool SD_begin()
-{
-	return __imp_SD_begin();
-}
-
-int usrcmd_cd(int argc, char **argv)
-{
-	return __imp_usrcmd_cd(argc, argv);
-}
-
-int usrcmd_ls(int argc, char **argv)
-{
-	return __imp_usrcmd_ls(argc, argv);
-}
-
-int usrcmd_cp(int argc, char **argv)
-{
-	return __imp_usrcmd_cp(argc, argv);
-}
-
-int usrcmd_rm(int argc, char **argv)
-{
-	return __imp_usrcmd_rm(argc, argv);
-}
-
-int usrcmd_mv(int argc, char **argv)
-{
-	return __imp_usrcmd_mv(argc, argv);
-}
-
-int usrcmd_mkdir(int argc, char **argv)
-{
-	return __imp_usrcmd_mkdir(argc, argv);
-}
-
-int usrcmd_hexdump(int argc, char **argv)
-{
-	return __imp_usrcmd_hexdump(argc, argv);
-}
-
-int usrcmd_info(int argc, char **argv)
-{
-	return __imp_usrcmd_info(argc, argv);
-}
-
-int usrcmd_exit(int argc, char **argv)
-{
-	return __imp_usrcmd_exit(argc, argv);
-}
-
-void abort()
-{
-	__imp_shell_abort();
-}
-
-void _exit(int exitcd)
-{
-	__imp_shell_exit(exitcd);
-}
-
-int _kill(int pid, int sig)
-{
-	return __imp_shell_kill(pid, sig);
-}
-
-int _gettimeofday(struct timeval * tp, void * tzvp)
-{
-	return __imp_shell_gettimeofday(tp, tzvp);
-}
-
-void vsyslog(int priority, const char *format, va_list ap)
-{
-	__imp_vsyslog(priority, format, ap);
-}
-
-void syslog(int priority, const char *format, ...)
-{
-	va_list ap;
-	va_start(ap, format);
-	vsyslog(priority, format, ap);
-	va_end(ap);
-}
-
-int _open(const char * path, int flags)
-{
-	return __imp_shell_open(path, flags);
-}
-
-int _close(int fd)
-{
-	return __imp_shell_close(fd);
-}
-
-int _read(int fd, char *data, int len)
-{
-	return __imp_shell_read(fd, data, len);
-}
-
-int _write(int fd, char *data, int len)
-{
-	return __imp_shell_write(fd, data, len);
-}
-
-int _lseek(int fd, int ptr, int dir)
-{
-	return __imp_shell_lseek(fd, ptr, dir);
-}
-
-int _fstat(int fd, struct stat * st)
-{
-	return __imp_shell_fstat(fd, st);
-}
-
-int _stat(const char *fname, struct stat *st)
-{
-	return __imp_shell_stat(fname, st);
-}
-
-int _link(void)
-{
-	return __imp_shell_link();
-}
-
-int _unlink(const char *path)
-{
-	return __imp_shell_unlink(path);
-}
-
-int _isatty(int fd)
-{
-	return __imp_shell_isatty(fd);
-}
-
-int fsync(int fd)
-{
-	return __imp_fsync(fd);
-}
-
-int ftruncate(int fd, off_t length)
-{
-	return __imp_ftruncate(fd, length);
-}
-
-int ioctl(int fd, int request, ...)
-{
-	int result;
-	va_list ap;
-	va_start(ap, request);
-	result = __imp_ioctl(fd, request, ap);
-	va_end(ap);
-	return result;
-}
-
-int tcgetattr(int fd, struct termios *termios_p)
-{
-	return __imp_tcgetattr(fd, termios_p);
-}
-
-int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
-{
-	return __imp_tcsetattr(fd, optional_actions, termios_p);
-}
-
-int _rename(const char *oldpath, const char *newpath)
-{
-	return __imp_shell_rename(oldpath, newpath);
-}
-
-int rmdir(const char *path)
-{
-	return __imp_rmdir(path);
-}
-
-int mkdir(const char *path, mode_t mode)
-{
-	return __imp_mkdir(path, mode);
-}
-
-int chmod(const char *path, mode_t mode)
-{
-	return __imp_chmod(path, mode);
-}
-
-char *getcwd(char *buf, size_t size)
-{
-	return __imp_getcwd(buf, size);
-}
-
-int chdir(const char *path)
-{
-	return __imp_chdir(path);
-}
-
-int chroot(const char *path)
-{
-	return __imp_chroot(path);
-}
-
-int closedir(DIR *dir)
-{
-	return __imp_closedir(dir);
-}
-
-DIR *opendir(const char *path)
-{
-	return __imp_opendir(path);
-}
-
-struct dirent *readdir(DIR *dir)
-{
-	return __imp_readdir(dir);
-}
-
-void rewinddir(DIR *dir)
-{
-	__imp_rewinddir(dir);
-}
-
-void seekdir(DIR *dir, long pos)
-{
-	__imp_seekdir(dir, pos);
-}
-
-long telldir(DIR *dir)
-{
-	return __imp_telldir(dir);
-}
-
-int _getpid()
-{
-	return __imp_shell_getpid();
-}
-
-int socket(int family, int type, int protocol)
-{
-	return __imp_socket(family, type, protocol);
-}
-
-int bind(int fd, const struct sockaddr *addr, socklen_t len)
-{
-	return __imp_bind(fd, addr, len);
-}
-
-int listen(int fd, int backlog)
-{
-	return __imp_listen(fd, backlog);
-}
-
-int connect(int fd, const struct sockaddr *addr, socklen_t len)
-{
-	return __imp_connect(fd, addr, len);
-}
-
-int accept(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	return __imp_accept(fd, addr, len);
-}
-
-ssize_t send(int fd, const void *buf, size_t len, int flags)
-{
-	return __imp_send(fd, buf, len, flags);
-}
-
-ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
-{
-	return __imp_sendto(fd, buf, len, flags, addr, alen);
-}
-
-ssize_t recv(int fd, void *buf, size_t len, int flags)
-{
-	return __imp_recv(fd, buf, len, flags);
-}
-
-ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
-{
-	return __imp_recvfrom(fd, buf, len, flags, addr, alen);
-}
-
-int shutdown(int fd, int how)
-{
-	return __imp_shutdown(fd, how);
-}
-
-int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
-{
-	return __imp_getsockopt(fd, level, optname, optval, optlen);
-}
-
-int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
-{
-	return __imp_setsockopt(fd, level, optname, optval, optlen);
-}
-
-int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
-{
-	return __imp_select(n, rfds, wfds, efds, tv);
-}
-
-int poll(struct pollfd *fds, nfds_t nfds, int timeout)
-{
-	return __imp_poll(fds, nfds, timeout);
-}
-
-unsigned if_nametoindex(const char *name)
-{
-	return 1;
-}
-
-int gethostname(char *name, size_t len)
-{
-	return __imp_gethostname(name, len);
-}
-
-int getnameinfo(const struct sockaddr *sa, socklen_t sl,
-	char *node, socklen_t nodelen,
-	char *serv, socklen_t servlen,
-	int flags)
-{
-	return __imp_getnameinfo(sa, sl, node, nodelen, serv, servlen, flags);
-}
-
-int getpeername(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	return __imp_getpeername(fd, addr, len);
-}
-
-int getsockname(int fd, struct sockaddr *addr, socklen_t *len)
-{
-	return __imp_getsockname(fd, addr, len);
-}
-
-int socketpair(int family, int type, int protocol, int fd[2])
-{
-	return __imp_socketpair(family, type, protocol, fd);
-}
-
-char *basename(char *s)
-{
-	size_t i, j;
-	if (!s || !*s) return ".";
-	i = strlen(s) - 1;
-	for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
-	for (; i&&s[i] == '/'; i--) s[i] = 0;
-	for (; i&&s[i - 1] != '/'; i--);
-	return s + i;
-}
-
-char *dirname(char *_s)
-{
-	char *s = _s;
-	size_t i, j;
-	if (!s || !*s) return ".";
-	i = strlen(s) - 1;
-	for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
-	for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s;
-	for (; s[i] != '/'; i--) if (!i) return (s == _s) ? "." : _s;
-	for (; s[i] == '/'; i--) if (!i) if (s == _s) return "/"; else break;
-	s[i + 1] = 0;
-	return _s;
-}
-
-char *realpath(const char *filename, char *resolved)
-{
-	char *path = getcwd(resolved, 256);
-
-	if (path != NULL)
-		strcat(path, filename);
-
-	return path;
-}
-
-uint32_t htonl(uint32_t n)
-{
-	return (n >> 24) | ((n >> 8) & 0xFF00) | ((n << 8) & 0xFF0000) | (n << 24);
-}
-
-uint32_t ntohl(uint32_t n)
-{
-	return (n >> 24) | ((n >> 8) & 0xFF00) | ((n << 8) & 0xFF0000) | (n << 24);
-}
-
-uint16_t htons(uint16_t n)
-{
-	return ((n >> 8) & 0xFF) | ((n << 8) & 0xFF00);
-}
-
-uint16_t ntohs(uint16_t n)
-{
-	return ((n >> 8) & 0xFF) | ((n << 8) & 0xFF00);
-}
-
-int mprotect(void *addr, size_t len, int prot)
-{
-	return 0;
-}
-
-int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
-{
-	return 0;
-}
-
-unsigned int Utf8_to_Utf16(const char *src, int *code_size)
-{
-	int i;
-	unsigned int uc = 0;
-	unsigned char len = 0;
-
-	len = 0;
-	if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; }
-	else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; }
-	else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; }
-	else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; }
-	else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; }
-	else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; }
-
-	i = 1;
-	while ((i <= len) && ((src[i] & 0xC0) == 0x80)) {
-		uc = (uc << 6) | (src[i] & 0x3F);
-		i++;
-	}
-
-	//Áï¶Ýè
-	*code_size = i;
-
-	//»óA2oCgÀè
-	return uc;
-}
-
-int bs_char_count(char *str, int pos)
-{
-	int num = 1, local_pos = pos;
-	char *c;
-
-	while (1) {
-		c = str + local_pos;
-
-		if ((*c & 0x80) != 0x80)
-			return num;
-
-		if (((*c & 0xE0) == 0xC0) && (num == 2)) {
-			return num;
-		}
-		else if (((*c & 0xF0) == 0xE0) && (num == 3)) {
-			return num;
-		}
-		else if (((*c & 0xF8) == 0xF0) && (num == 4)) {
-			return num;
-		}
-		else if (((*c & 0xFC) == 0xF8) && (num == 5)) {
-			return num;
-		}
-		else if (((*c & 0xFE) == 0xFC) && (num == 6)) {
-			return num;
-		}
-		else {
-			if (local_pos > 0) {
-				local_pos--;
-				num++;
-			}
-			else
-				return 0;
-		}
-	}
-
-	return 0;
-}
Index: EcnlProtoTool/trunk/prototool/src/xprintf.c
===================================================================
--- EcnlProtoTool/trunk/prototool/src/xprintf.c	(revision 321)
+++ 	(revision )
@@ -1,385 +1,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) 1999 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.haxx.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- *
- * Purpose:
- *  A merge of Bjorn Reese's format() function and Daniel's dsprintf()
- *  1.0. A full blooded printf() clone with full support for <num>$
- *  everywhere (parameters, widths and precisions) including variabled
- *  sized parameters (like doubles, long longs, long doubles and even
- *  void * in 64-bit architectures).
- *
- * Current restrictions:
- * - Max 128 parameters
- * - No 'long double' support.
- *
- * If you ever want truly portable and good *printf() clones, the project that
- * took on from here is named 'Trio' and you find more details on the trio web
- * page at https://daniel.haxx.se/trio/
- */
-
-/*------------------------------------------------------------------------/
-/  Universal string handler for user console interface
-/-------------------------------------------------------------------------/
-/
-/  Copyright (C) 2011, ChaN, all right reserved.
-/
-/ * This software is a free software and there is NO WARRANTY.
-/ * No restriction on use. You can use, modify and redistribute it for
-/   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
-/ * Redistributions of source code must retain the above copyright notice.
-/
-/-------------------------------------------------------------------------*/
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-struct nsprintf {
-  char *buffer;
-  size_t length;
-  size_t max;
-};
-
-struct asprintf {
-  char *buffer; /* allocated buffer */
-  size_t len;   /* length of string */
-  size_t alloc; /* length of alloc */
-  int fail;     /* (!= 0) if an alloc has failed and thus
-                   the output is not the complete data */
-};
-
-#define OUTCHAR(x) \
-  do{ \
-    if(stream((unsigned char)(x), (FILE *)data) != -1) \
-      done++; \
-    else \
-     return done; /* return immediately on failure */ \
-  } while(0)
-
-
-static int dprintf_formatf(
-	void *data,
-	int(*stream)(int, FILE *),
-	const char *fmt,
-	va_list arp)
-{
-	unsigned int r, i, j, w, f;
-	unsigned long v;
-	char s[16], c, d, *p;
-
-	/* Number of characters written.  */
-	int done = 0;
-
-	for (;;) {
-		c = *fmt++;					/* Get a char */
-		if (!c) break;				/* End of format? */
-		if (c != '%') {				/* Pass through it if not a % sequense */
-			OUTCHAR(c); continue;
-		}
-		f = 0;
-		c = *fmt++;					/* Get first char of the sequense */
-		if (c == '0') {				/* Flag: '0' padded */
-			f = 1; c = *fmt++;
-		}
-		else {
-			if (c == '-') {			/* Flag: left justified */
-				f = 2; c = *fmt++;
-			}
-		}
-		for (w = 0; c >= '0' && c <= '9'; c = *fmt++)	/* Minimum width */
-			w = w * 10 + c - '0';
-		if (c == 'l' || c == 'L') {	/* Prefix: Size is long int */
-			f |= 4; c = *fmt++;
-		}
-		else if (c == 'h') {	/* Prefix: Size is short int */
-			f |= 16; c = *fmt++;
-		}
-		if (!c) break;				/* End of format? */
-		d = c;
-		if (d >= 'a') d -= 0x20;
-		switch (d) {				/* Type is... */
-		case 'S':					/* String */
-			p = va_arg(arp, char*);
-			for (j = 0; p[j]; j++);
-			while (!(f & 2) && j++ < w) OUTCHAR(' ');
-			for (; *p; p++)
-				OUTCHAR(*p);
-			while (j++ < w) OUTCHAR(' ');
-			continue;
-		case 'C':					/* Character */
-			OUTCHAR((char)va_arg(arp, int)); continue;
-		case 'B':					/* Binary */
-			r = 2; break;
-		case 'O':					/* Octal */
-			r = 8; break;
-		case 'D':					/* Signed decimal */
-		case 'U':					/* Unsigned decimal */
-			r = 10; break;
-		case 'X':					/* Hexdecimal */
-			r = 16; break;
-		default:					/* Unknown type (passthrough) */
-			OUTCHAR(c); continue;
-		}
-
-		/* Get an argument and put it in numeral */
-		v = (f & 4) ? va_arg(arp, long)
-			: ((f & 16) ? ((d == 'D') ? (long)va_arg(arp, short) : (long)va_arg(arp, unsigned short))
-				: ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int)));
-		if (d == 'D' && (v & 0x80000000)) {
-			v = 0 - v;
-			f |= 8;
-		}
-		i = 0;
-		do {
-			d = (char)(v % r); v /= r;
-			if (d > 9) d += (c == 'x') ? 0x27 : 0x07;
-			s[i++] = d + '0';
-		} while (v && i < sizeof(s));
-		if (f & 8) s[i++] = '-';
-		j = i; d = (f & 1) ? '0' : ' ';
-		while (!(f & 2) && j++ < w) OUTCHAR(d);
-		do OUTCHAR(s[--i]); while (i);
-		while (j++ < w) OUTCHAR(' ');
-	}
-	return done;
-}
-/* fputc() look-alike */
-static int addbyter(int output, FILE *data)
-{
-  struct nsprintf *infop=(struct nsprintf *)data;
-  unsigned char outc = (unsigned char)output;
-
-  if(infop->length < infop->max) {
-    /* only do this if we haven't reached max length yet */
-    infop->buffer[0] = outc; /* store */
-    infop->buffer++; /* increase pointer */
-    infop->length++; /* we are now one byte larger */
-    return outc;     /* fputc() returns like this on success */
-  }
-  return -1;
-}
-
-int vsnprintf(char *buffer, size_t maxlength, const char *format,
-                    va_list ap_save)
-{
-  int retcode;
-  struct nsprintf info;
-
-  info.buffer = buffer;
-  info.length = 0;
-  info.max = maxlength;
-
-  retcode = dprintf_formatf(&info, addbyter, format, ap_save);
-  if(info.max) {
-    /* we terminate this with a zero byte */
-    if(info.max == info.length)
-      /* we're at maximum, scrap the last letter */
-      info.buffer[-1] = 0;
-    else
-      info.buffer[0] = 0;
-  }
-  return retcode;
-}
-
-int snprintf(char *buffer, size_t maxlength, const char *format, ...)
-{
-  int retcode;
-  va_list ap_save; /* argument pointer */
-  va_start(ap_save, format);
-  retcode = vsnprintf(buffer, maxlength, format, ap_save);
-  va_end(ap_save);
-  return retcode;
-}
-
-/* fputc() look-alike */
-static int alloc_addbyter(int output, FILE *data)
-{
-  struct asprintf *infop=(struct asprintf *)data;
-  unsigned char outc = (unsigned char)output;
-
-  if(!infop->buffer) {
-    infop->buffer = malloc(32);
-    if(!infop->buffer) {
-      infop->fail = 1;
-      return -1; /* fail */
-    }
-    infop->alloc = 32;
-    infop->len =0;
-  }
-  else if(infop->len+1 >= infop->alloc) {
-    char *newptr;
-
-    newptr = realloc(infop->buffer, infop->alloc*2);
-
-    if(!newptr) {
-      infop->fail = 1;
-      return -1; /* fail */
-    }
-    infop->buffer = newptr;
-    infop->alloc *= 2;
-  }
-
-  infop->buffer[ infop->len ] = outc;
-
-  infop->len++;
-
-  return outc; /* fputc() returns like this on success */
-}
-
-char *aprintf(const char *format, ...)
-{
-  va_list ap_save; /* argument pointer */
-  int retcode;
-  struct asprintf info;
-
-  info.buffer = NULL;
-  info.len = 0;
-  info.alloc = 0;
-  info.fail = 0;
-
-  va_start(ap_save, format);
-  retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
-  va_end(ap_save);
-  if((-1 == retcode) || info.fail) {
-    if(info.alloc)
-      free(info.buffer);
-    return NULL;
-  }
-  if(info.alloc) {
-    info.buffer[info.len] = 0; /* we terminate this with a zero byte */
-    return info.buffer;
-  }
-  else
-    return strdup("");
-}
-
-char *vaprintf(const char *format, va_list ap_save)
-{
-  int retcode;
-  struct asprintf info;
-
-  info.buffer = NULL;
-  info.len = 0;
-  info.alloc = 0;
-  info.fail = 0;
-
-  retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
-  if((-1 == retcode) || info.fail) {
-    if(info.alloc)
-      free(info.buffer);
-    return NULL;
-  }
-
-  if(info.alloc) {
-    info.buffer[info.len] = 0; /* we terminate this with a zero byte */
-    return info.buffer;
-  }
-  else
-    return strdup("");
-}
-
-int vasprintf(char **dst, const char *format, va_list ap_save)
-{
-	int retcode;
-	struct asprintf info;
-
-	info.buffer = NULL;
-	info.len = 0;
-	info.alloc = 0;
-	info.fail = 0;
-
-	retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
-	if ((-1 == retcode) || info.fail) {
-		if (info.alloc)
-			free(info.buffer);
-		return -1;
-	}
-
-	if (info.alloc) {
-		info.buffer[info.len] = 0; /* we terminate this with a zero byte */
-		*dst = info.buffer;
-		return info.len;
-	}
-	else {
-		*dst = strdup("");
-		return 0;
-	}
-}
-
-static int storebuffer(int output, FILE *data)
-{
-  char **buffer = (char **)data;
-  unsigned char outc = (unsigned char)output;
-  **buffer = outc;
-  (*buffer)++;
-  return outc; /* act like fputc() ! */
-}
-
-int sprintf(char *buffer, const char *format, ...)
-{
-  va_list ap_save; /* argument pointer */
-  int retcode;
-  va_start(ap_save, format);
-  retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
-  va_end(ap_save);
-  *buffer=0; /* we terminate this with a zero byte */
-  return retcode;
-}
-
-int printf(const char *format, ...)
-{
-  int retcode;
-  va_list ap_save; /* argument pointer */
-  va_start(ap_save, format);
-
-  retcode = dprintf_formatf(stdout, fputc, format, ap_save);
-  va_end(ap_save);
-  return retcode;
-}
-
-int fprintf(FILE *whereto, const char *format, ...)
-{
-  int retcode;
-  va_list ap_save; /* argument pointer */
-  va_start(ap_save, format);
-  retcode = dprintf_formatf(whereto, fputc, format, ap_save);
-  va_end(ap_save);
-  return retcode;
-}
-
-int vsprintf(char *buffer, const char *format, va_list ap_save)
-{
-  int retcode;
-  retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
-  *buffer=0; /* we terminate this with a zero byte */
-  return retcode;
-}
-
-int vprintf(const char *format, va_list ap_save)
-{
-  return dprintf_formatf(stdout, fputc, format, ap_save);
-}
-
-int vfprintf(FILE *whereto, const char *format, va_list ap_save)
-{
-  return dprintf_formatf(whereto, fputc, format, ap_save);
-}
