/*	
 *	clipprnt.c
 *
 *	CLiP - Common Library for P/ECE
 *	Copyright (C) 2001-2006 Naoyuki Sawa
 *
 *	* Tue May 20 06:00:00 JST 2003 Naoyuki Sawa
 *	- http://minix.technoir.org/src/lib/stdio/doprnt.c傪婎偵夵憿偟傑偟偨丅
 *	* Thu Jul 13 06:12:00 JST 2006 Naoyuki Sawa
 *	- snprintf(),vsnprintf()傪捛壛偟傑偟偨丅
 *	- snprintf(),vsnprintf()懳墳偺偨傔偵丄婛懚偺doprnt()傪夵憿偟傑偟偨丅
 *	  doprnt()偼sprintf(),vsprintf()偑棙梡偟偰偄偨僒僽儖乕僠儞偱丄夵憿屻傕堷偒懕偒棙梡偟傑偡丅
 *	  sprintf(),vsprintf()偵塭嬁偑弌側偄傛偆婥傪偮偗偨偮傕傝偱偡偑丄偟偽傜偔偺娫偼梫拲堄偱偡丅
 */
#include "clip.h"

/****************************************************************************
 *
 ****************************************************************************/

					// 亖堄枴亖		亖椺亖
#define FL_LJUST	(1 <<  0)	// 嵍媗傔		%-5d
#define FL_ZEROFILL	(1 <<  1)	// 0媗傔		%05d
#define FL_SIGN		(1 <<  2)	// +/-昞\帵		%+5d
#define FL_SPACE	(1 <<  3)	// 嬻敀/-昞\帵		% 5d
#define FL_ALT		(1 <<  4)	// 0/0x/0X昞\帵		%#x
#define FL_SHORT	(1 <<  5)	// 僴乕僼儚乕僪堷悢	%hd
#define FL_PRECSPEC	(1 <<  6)	// 惛搙巜掕偁傝		%9.5f
#define FL_SIGNEDCONV	(1 <<  7)	// 晞崋偁傝		%d
#define FL_NOMORE	(1 << 31)	// 乮撪晹巊梡乯

/* width傗precision傪庢摼偟傑偡丅 */
static const char*
gnum(const char* fmt, int* ip, va_list* app)
{
	int i, c;

	if(*fmt == '*') {
		*ip = va_arg(*app, int);
		fmt++;
	} else {
		i = 0;
		for(;;) {
			c = *fmt;
			if(c < '0' || '9' < c) break;
			i = i * 10 + (c - '0');
			fmt++;
		}
		*ip = i;
	}

	return fmt;
}

/* 惍悢抣傪昞\帵偟傑偡丅 */
static char*
i_compute(unsigned val, int base, char* s, int precision)
{
	int c;

	c = val % base;
	val /= base;
	if(val || precision > 1) s = i_compute(val, base, s, precision - 1);
	*s++ = c < 10 ? '0' + c : 'a' + (c - 10);

	return s;
}

/* 惍悢堷悢傪昞\帵偟傑偡丅 */
static char*
o_print(char* s, int flags, int nrdigits, int c, va_list* app)
{
	unsigned val;
	int base;
	char *old_s = s;

	/* 抣傪庢摼丅 */
	val = va_arg(*app, unsigned);
	if(flags & FL_SHORT) {
		if(flags & FL_SIGNEDCONV) {
			val = (         short)val;
		} else {
			val = (unsigned short)val;
		}
	}

	/* 晞崋昞\帵丅 */
	if(flags & FL_SIGNEDCONV) {
		if((int)val < 0) {
			*s++ = '-';
			val = -(int)val;
		} else if(flags & FL_SIGN) {
			*s++ = '+';
		} else if(flags & FL_SPACE) {
			*s++ = ' ';
		}
	}

	/* 婎悢昞\帵丅 */
	if(flags & FL_ALT) {
		switch(c) {
		case 'o': *s++ = '0';             break;
		case 'p':
		case 'x':
		case 'X': *s++ = '0'; *s++ = 'x'; break;
		}
	}

	/* 抣傪昞\帵丅 */
	switch(c) {
	case 'b': base =  2; break;
	case 'o': base =  8; break;
	case 'd':
	case 'i':
	case 'u': base = 10; break;
	case 'p':
	case 'x':
	case 'X': base = 16; break;
	default : base = -1; DIE();
	}
	s = i_compute(val, base, s, nrdigits);
	if(c == 'X') {
		while(old_s != s) {
			*old_s = toupper(*old_s);
			old_s++;
		}
	}

	return s;
}

/* 晜摦彫悢堷悢傪昞\帵偟傑偡丅 */
static char*
f_print(char* s, int flags, int precision, va_list* app)
{
	double val;
	int c;

	/* 抣傪庢摼丅 */
	val = va_arg(*app, double);

	/* 晞崋昞\帵丅 */
	if(val < 0) {
		*s++ = '-';
		val = -val;
	} else if(flags & FL_SIGN) {
		*s++ = '+';
	} else if(flags & FL_SPACE) {
		*s++ = ' ';
	}

	/* 巐幪屲擖梡偺+0.5or0.05or0.005... */
	val += pow(10, -precision) / 2;

	/* 惍悢晹昞\帵丅 */
	c = (int)val;
	val -= c;
	s = i_compute(c, 10, s, 1);

	/* 彫悢晹昞\帵丅 */
	if(precision) {
		*s++ = '.';
		do {
			val *= 10;
			c = (int)val;
			val -= c;
			*s++ = '0' + c;
		} while(--precision);
	}

	return s;
}

static int
//doprnt(char* out, const char* fmt, va_list ap)
//伀2006/07/13 snprintf(),vsnprintf()懳墳
//伀
//伀- snprintf(),vsnprintf()懳墳偵偍偄偰丄doprnt()偺堷悢偵僶僢僼傽僒僀僘(cnt)傪捛壛偡傞偺偱側偔丄僶僢僼傽枛旜偺億僀儞僞(end)傪捛壛偡傞傛偆愝寁偟偨棟桼偼丄
//伀  偙偆偡傞曽偑丄vsprintf()偐傜偺棙梡帪偵丄柍尷僶僢僼傽傪昞\尰偡傞偺偑梕堈偩偭偨偐傜偱偡丅(柍尷僶僢僼傽偺枛旜偺億僀儞僞偼丄((char*)-1)偲昞\偣傑偡丅)
//伀  傑偨丄doprnt()偺幚憰偵偍偄偰傕丄巆傝僶僢僼傽僒僀僘傪娗棟偡傞傛傝傕丄師偺弌椡埵抲(out)偑僶僢僼傽枛旜(end)傪挻偊偰偄側偄偐傪専嵏偡傞曽偑娙扨偱偡丅
//伀
//伀- snprintf()傪埲壓偺傛偆偵屇傃弌偟偨応崌丄
//伀
//伀	char buf[10];
//伀	snprintf(buf, 10, fmt, ...);
//伀
//伀  doprnt()傊偺堷悢out,end偼丄壓恾偺傛偆側埵抲傪巜偟偰偄傑偡丅
//伀
//伀	buf[0][1][2][3][4][5][6][7][8][9]
//伀	    |                          |
//伀	   out                        end
//伀
//伀  end偼(僶僢僼傽偺枛旜)偱偁傝丄(僶僢僼傽偺枛旜+1)偱偼側偄偙偲偵拲堄偟偰偔偩偝偄丅
//伀  廔抂偺nul傪娷傑側偄丄桳岠側暥帤傪奿擺偱偒傞偺偼丄(out乣end-1)偺斖埻偲側傝傑偡丅
//伀
//伀- 廔抂偺nul傪娷傑側偄桳岠側暥帤偑(out乣end-1)偺斖埻偵廂傑偭偨応崌丄捈屻偵nul傪奿擺偟丄nul傪娷傑側偄暥帤悢傪曉偟傑偡丅
//伀  廔抂偺nul傪娷傑側偄桳岠側暥帤偑(end-1)傪挻偊傞応崌丄(end-1)埲崀傪愗傝幪偰偰(end)偵nul傪奿擺偟丄寢壥(-1)傪曉偟傑偡丅
//伀
//伀- 傕偟丄snprintf()傪僶僢僼傽僒僀僘0偱屇傃弌偟偨応崌丄
//伀
//伀	snprintf(buf, 0, fmt, ...);
//伀
//伀  doprnt()傊偺堷悢out,end偼丄end偑out傛傝傕慜傪巜偟偰偄傑偡丅
//伀
//伀	buf[-1][0]
//伀	    |   |
//伀	   end out
//伀
//伀  偙偺応崌丄廔抂偺nul傕奿擺偣偢偵丄寢壥(-1)傪曉偟傑偡丅
//伀
doprnt(char* out, char* end, const char* fmt, va_list ap)
{
/*{{2006/07/13 snprintf(),vsnprintf()懳墳*/
#define OUT(C)				\
	do {				\
		char __c__ = (C);	\
		if(out < end) {		\
			*out = __c__;	\
		}			\
		out++;			\
	} while(0)
/*}}2006/07/13 snprintf(),vsnprintf()懳墳*/

	int c, pad, len, flags, width, precision, zfill;
	char buf[256];	/* 悢抣偺弌椡暆傗惛搙偑偙偺僒僀僘傪挻偊傞偲堎忢摦嶌偟傑偡丅 */
	char *s, *old_s;
	char *old_out = out;

	/* 彂幃暥帤楍傪憱嵏偟偰乧 */
	while((c = *fmt++) != '\0') {
		/* 亀%[flags][width][.precision][h|l]type亁偱側偗傟偽偦偺傑傑昞\帵丅 */
		if(c != '%') {
			//*out++ = c;
			//伀2006/07/13 snprintf(),vsnprintf()懳墳
			OUT(c);
			continue;
		}

		/* [flags]庢摼丅 */
		flags = 0;
		do {
			switch(*fmt) {
			case '-': flags |= FL_LJUST;    break;	/* 嵍媗傔 */
			case '0': flags |= FL_ZEROFILL; break;	/* 0媗傔 */
			case '+': flags |= FL_SIGN;     break;	/* +/-昞\帵 */
			case ' ': flags |= FL_SPACE;    break;	/* 嬻敀/-昞\帵 */
			case '#': flags |= FL_ALT;      break;	/* 0/0x/0X昞\帵 */
			default : flags |= FL_NOMORE;   continue;
			}
			fmt++;
		} while(!(flags & FL_NOMORE));
		if((flags & FL_LJUST) && (flags & FL_ZEROFILL)) DIE();
		if((flags & FL_SIGN ) && (flags & FL_SPACE   )) DIE();

		/* [width]庢摼丅 */
		fmt = gnum(fmt, &width, &ap);
		if(*fmt == '.') {
			fmt++;
			fmt = gnum(fmt, &precision, &ap);
			flags |= FL_PRECSPEC;
		}

		/* [h|l]庢摼丅 */
		switch(*fmt) {
		case 'h': flags |= FL_SHORT; fmt++; break;
		case 'l': /* int偲摨偠偱偡 */fmt++; break;
		case 'L': DIE(); /* long double 偼枹懳墳 */
		}

		s = old_s = buf;
		switch(c = *fmt++) {
		default:
			//*out++ = c;
			//伀2006/07/13 snprintf(),vsnprintf()懳墳
			OUT(c);
			continue;
		case 'n':
			if(flags & FL_SHORT) {
				*va_arg(ap, short*) = (short)(out - old_out);
			} else {
				*va_arg(ap, int  *) = (int  )(out - old_out);
			}
			continue;
		case 'c':
			*s++ = va_arg(ap, int);
			break;
		case 's':
			old_s = va_arg(ap, char*);
			if(old_s == NULL) old_s = "(null)";
			s = old_s;
			while(*s != '\0') {
				if(flags & FL_PRECSPEC) {
					if(!precision) break;
					precision--;
				}
				s++;
			}
			break;
		case 'b':
		case 'o':
		case 'u':
		case 'p':
		case 'x':
		case 'X':
			if(!(flags & FL_PRECSPEC)) precision = 1;
			s = o_print(s, flags, precision, c, &ap);
			break;
		case 'd':
		case 'i':
			flags |= FL_SIGNEDCONV;
			if(!(flags & FL_PRECSPEC)) precision = 1;
			s = o_print(s, flags, precision, c, &ap);
			break;
		case 'f':
		case 'e': /* 1.2e3宍幃偼枹懳墳丅'f'偲摨偠埖偄偲偟傑偡丅 */
		case 'E': /* 1.2e3宍幃偼枹懳墳丅'f'偲摨偠埖偄偲偟傑偡丅 */
		case 'g': /* 1.2e3宍幃偼枹懳墳丅'f'偲摨偠埖偄偲偟傑偡丅 */
		case 'G': /* 1.2e3宍幃偼枹懳墳丅'f'偲摨偠埖偄偲偟傑偡丅 */
			flags |= FL_SIGNEDCONV;
			if(!(flags & FL_PRECSPEC)) precision = 6;
			s = f_print(s, flags, precision, &ap);
			break;
		}

		zfill = (flags & FL_ZEROFILL) ? '0' : ' ';
		len = s - old_s;
		pad = width - len;
		if(pad > 0) {
			if(!(flags & FL_LJUST)) {
				/* 晞崋(+/-/嬻敀)偲婎悢(0/0x/0X)偼0媗傔偵愭峴偟傑偡丅 */
				if(flags & FL_ZEROFILL) {
					if(flags & FL_SIGNEDCONV) {
						switch(*old_s) {
						case '+':
						case '-':
						case ' ':
							//*out++ = *old_s++;
							//伀2006/07/13 snprintf(),vsnprintf()懳墳
							OUT(*old_s++);
							len--;
							break;
						}
					}
					if(flags & FL_ALT) {
						//switch(c) {
						//case 'o':
						//	*out++ = *old_s++;
						//	len--;
						//	break;
						//case 'p':
						//case 'x':
						//case 'X':
						//	*out++ = *old_s++;
						//	*out++ = *old_s++;
						//	len -= 2;
						//	break;
						//}
						//伀2006/07/13 snprintf(),vsnprintf()懳墳
						switch(c) {
						case 'p':
						case 'x':
						case 'X':
							OUT(*old_s++);
							len--;
							/* FALLTHRU */
						case 'o':
							OUT(*old_s++);
							len--;
							break;
						}
					}
				}
				/* 嬻敀傑偨偼0媗傔丅 */
				while(pad > 0) {
					//*out++ = zfill;
					//伀2006/07/13 snprintf(),vsnprintf()懳墳
					OUT(zfill);
					pad--;
				}
			}
		}
		while(len > 0) {
			//*out++ = *old_s++;
			//伀2006/07/13 snprintf(),vsnprintf()懳墳
			OUT(*old_s++);
			len--;
		}
		while(pad > 0) {
			//*out++ = zfill;
			//伀2006/07/13 snprintf(),vsnprintf()懳墳
			OUT(zfill);
			pad--;
		}
	}

	//*out = '\0'; /* 廔抂偺NUL朰傟偢偵! */
	//return out - old_out;
	//伀2006/07/13 snprintf(),vsnprintf()懳墳
	if(out <= end) {
		*out = '\0';
		return out - old_out;
	} else {
		if(end >= old_out) {
			*end = '\0';
		} else {
			/* 僶僢僼傽僒僀僘偑0埲壓偺応崌偼丄nul傕奿擺偟側偄丅 */
		}
		return -1;
	}

/*{{2006/07/13 snprintf(),vsnprintf()懳墳*/
#undef OUT
/*}}2006/07/13 snprintf(),vsnprintf()懳墳*/
}

/****************************************************************************
 *
 ****************************************************************************/

/* 乽#include <piece.h>乿偺慜偵乽#define NOPCESPRINTF乿傪朰傟偢偵両 */

/* P/ECE僇乕僱儖傑偨偼EPSON儔僀僽儔儕撪偺娭悢傪抲偒姺偊傑偡丅 */
int
vsprintf(char* out, const char* fmt, va_list ap)
{
	//return doprnt(out, fmt, ap);
	//伀2006/07/13 snprintf(),vsnprintf()懳墳
	return doprnt(out, (char*)-1/*柍尷僶僢僼傽偺枛旜*/, fmt, ap);
}

/* P/ECE僇乕僱儖傑偨偼EPSON儔僀僽儔儕撪偺娭悢傪抲偒姺偊傑偡丅 */
int
sprintf(char* out, const char* fmt, ...)
{
	int n;
	va_list ap;
	va_start(ap, fmt);
	n = vsprintf(out, fmt, ap);
	va_end(ap);
	return n;
}

/*{{2006/07/13 snprintf(),vsnprintf()懳墳*/

/* * Thu Jul 13 06:12:00 JST 2006 Naoyuki Sawa
 * - vsnprintf()傪捛壛偟傑偟偨丅
 *   P/ECE奐敪娐嫬偺儔僀僽儔儕偵偼丄vsnprintf()偑娷傑傟偰偄傑偣傫丅
 * - vsnprintf()偼丄C99偵偰惓幃偵捛壛偝傟偨娭悢偱偡丅
 *   C99偵弨嫆偟偰偄側偄僐儞僷僀儔偱偼丄vsnprintf()傪僒億乕僩偟偰偄側偐偭偨傝丄嫇摦偑堘偭偰偄傞応崌偑偁傝傑偡丅
 *   偨偲偊偽VC++6.0偺_vsnprintf()偼丄弌椡暥帤悢偑(n-1)傪挻偊傞応崌偺嫇摦偑堘偭偰偄傑偡丅
 *   弌椡暥帤悢偑(n-1)傪挻偊傞応崌丄C99偺巇條偱偼丄(n-1)暥帤傑偱暥帤傪弌椡偟丄(n)暥帤栚偵nul傪奿擺偟傑偡丅
 *   偦傟偵懳偟偰VC++6.0偺巇條偱偼丄(n)暥帤傑偱暥帤傪弌椡偟丄nul傪奿擺偟傑偣傫丅(strncpy()偵帡偨嫇摦偱偡丅)
 *   C99偺巇條偺曽偑丄弌椡暥帤楍偑妋幚偵nul廔抂偝傟傞偺偱丄巊偄堈偄偲巚偄傑偡丅
 *   崱夞偺幚憰偼丄C99偺巇條偵廬偄傑偟偨丅
 * - C99偲VC++6.0偺嫇摦偺堘偄傪帵偡僒儞僾儖僐乕僪傪丄埲壓偵帵偟傑偡丅
 *   埲壓偺僒儞僾儖僐乕僪偼snprintf()偺椺偱偡偑丄vsnprintf()傕摨條偱偡丅
 *
 *	main() {
 *	    char buf[] = "0123456789";
 *	    snprintf(buf, 5, "ABCDEFG");     // C99偺嫇摦乧
 *	    printf("<%s>\n", buf);           //   寢壥乽ABCD乿
 *	    _snprintf(buf, 5, "ABCDEFG");    // VC++6.0偺嫇摦乧
 *	    printf("<%s>\n", buf);           //   寢壥乽ABCDE56789乿
 *	}
 *
 * - 嶲峫帒椏乽僾儘僌儔儈儞僌尵岅 C 偺怴婡擻\ (http://seclan.dll.jp/c99d/c99d08.htm#dt19991115)乿傛傝
 *	劇劅劅劅劍劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
 *	劆柤慜	劆int vsnprintf(char * restrict s, size_t n, const char * restrict format, va_list arg);		劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆僿僢僟劆stdio.h												劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆堷悢	劆s      : 弌椡愭僶僢僼傽										劆
 *	劆	劆n      : 弌椡愭僶僢僼傽偺暥帤悢									劆
 *	劆	劆format : 彂幃												劆
 *	劆	劆arg    : va_start 偱弶婜壔偟偨抣									劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆栠傝抣劆弌椡偟偨暥帤悢丅廔抂偺僰儖暥帤偼娷傑側偄丅僄儔乕帪偼晧偺抣丅						劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆夝愢	劆vsprintf 偺 弌椡暥帤悢懳墳斉丅format 偵廬偄暥帤傪彂幃壔偟偰 s 偵嵟戝 n - 1 暥帤弌椡偡傞丅		劆
 *	劆	劆n - 1 暥帤埲忋弌椡偝傟偨応崌偼攋婞偝傟傞丅s 偺廔抂偵偼僰儖暥帤偑晅壛偝傟傞丅				劆
 *	劆	劆嶲峫 : wchar_t 傪庴偗晅偗傞娭悢 vswprintf 偑偁傝丄偙傟偼僶僢僼傽暥帤悢傪巜掕偱偒傞巇條偵側偭偰偄傞丅	劆
 *	劋劅劅劅劏劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
 */
int
vsnprintf(char* out, int cnt, const char* fmt, va_list ap)
{
	return doprnt(out, out + cnt - 1/*僶僢僼傽偺枛旜*/, fmt, ap);
}

/* * Thu Jul 13 06:12:00 JST 2006 Naoyuki Sawa
 * - snprintf()傪捛壛偟傑偟偨丅
 *   P/ECE奐敪娐嫬偺儔僀僽儔儕偵偼丄snprintf()偑娷傑傟偰偄傑偣傫丅
 * - VC++6.0偺_snprintf()偲偺嫇摦偺堘偄偵偮偄偰偼丄vsnprintf()偲摨條偱偡丅
 *   vsnprintf()偺僐儊儞僩傪嶲徠偟偰偔偩偝偄丅
 *
 * - 嶲峫帒椏乽僾儘僌儔儈儞僌尵岅 C 偺怴婡擻\ (http://seclan.dll.jp/c99d/c99d08.htm#dt19991115)乿傛傝
 *	劇劅劅劅劍劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劉
 *	劆柤慜	劆int snprintf(char * restrict s, size_t n, const char * restrict format, ...);				劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆僿僢僟劆stdio.h												劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆堷悢	劆s      : 弌椡愭僶僢僼傽										劆
 *	劆	劆n      : 弌椡愭僶僢僼傽偺暥帤悢									劆
 *	劆	劆format : 彂幃												劆
 *	劆	劆...    : 彂幃偱巜掕偟偨抣										劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆栠傝抣劆弌椡偟偨暥帤悢丅廔抂偺僰儖暥帤偼娷傑側偄丅僄儔乕帪偼晧偺抣丅						劆
 *	劌劅劅劅劑劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劎
 *	劆夝愢	劆sprintf 偺弌椡暥帤悢巜掕斉丅format 偵廬偄暥帤傪彂幃壔偟偰 s 偵嵟戝 n - 1 暥帤弌椡偡傞丅		劆
 *	劆	劆n - 1 暥帤埲忋弌椡偝傟偨応崌偼攋婞偝傟傞丅s 偺廔抂偵偼僰儖暥帤偑晅壛偝傟傞丅				劆
 *	劆	劆嶲峫 : wchar_t 傪庴偗晅偗傞娭悢 swprintf 偑偁傝丄偙傟偼僶僢僼傽暥帤悢傪巜掕偱偒傞巇條偵側偭偰偄傞丅	劆
 *	劋劅劅劅劏劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劅劊
 */
int
snprintf(char* out, int cnt, const char* fmt, ...)
{
	int n;
	va_list ap;
	va_start(ap, fmt);
	n = vsnprintf(out, cnt, fmt, ap);
	va_end(ap);
	return n;
}
/*}}2006/07/13 snprintf(),vsnprintf()懳墳*/

