示例#1
0
void print( int h, char * text, va_list args )
{
	int i=0;
	BYTE * string;

	// sanity check
	if( h < 0 )
		return;

	while( text[i] )
	{
		if( text[i] == '%' )
		{
			i++;

			switch( text[i] )
			{
				case 's':
					string = va_arg( args, BYTE * );
					write( h, string, strlen( (char *)string ) );
					break;
				case 'c':
					// To-Do: fix this! "warning: cast to pointer from integer of different size"
					write( h, (BYTE*)(va_arg( args, BYTE )), 1 );
					break;
				case 'd':
					printf_putint( h, va_arg( args, int ) );
					break;
				case 'i':
					printf_putint( h, va_arg( args, int ) );
					break;
				case 'u':
					printf_putuint( h, va_arg( args, unsigned int ) );
					break;
				case 'x':
					printf_puthex( h, va_arg( args, DWORD ) );
					break;
				default:
					write( h, (BYTE*)&text[i], 1 );
			}

		}
		else
		{
示例#2
0
void printf( const char *s, ... )
{
	va_list args;

	uint32_t u;
	int32_t i;
	char *str;

	va_start(args,s);

	while(*s) {
		if(*s!='%') {
			printf_putchar(*s);
		} else {
			s++;
			switch(*s) {
				case 'd':
					i = va_arg(args,int32_t);
					printf_putint(i);
					break;
				case 'x':
					u = va_arg(args,uint32_t);
					printf_puthex(u);
					break;
				case 's':
					str = va_arg(args,char*);
					printf_putstring(str);
					break;
				case 0:
					return;
					break;
				default:
					printf_putchar(*s);
					break;
			}
		}
		s++;
	}
	va_end(args);
}