#include "common.h"
#include <string.h>
void mputs( char * str )
{
char ch;
while( ( ch = *str++ ) )
mputc( ch );
mputc( '\r' );
mputc( '\n' );
}
void mputstr( char * str )
{
char ch;
while( ( ch = *str++ ) )
mputc( ch );
}
void mgetline( char buf[] )
{
int char_num = 0;
char ch;
while( 1 ) {
ch = mgetc();
switch( ch ){
case '\b':
if( char_num > 0 ) {
mputc( ch );
mputc( ' ' );
mputc( ch );
char_num --;
}
break;
case '\n':
case '\r':
mputc( '\r' );
mputc( '\n' );
buf[char_num] = '\0';
return;
break;
case 27:
break;
default:
mputc( ch );
buf[char_num++] = ch;
break;
}
}
}
void mprintf( char * str, ... )
{
char ch;
char * arg = ( char * )(&str + 1);
unsigned int integer;
char ibuf[12];
char * pstr;
int i, temp;
while( ( ch = *str++ ) ) {
switch( ch ) {
case '%':
switch( *str ) {
case 'd':
integer = *( int * )arg;
bzero( ibuf, sizeof(ibuf) );
i = 11;
if( integer != 0 )
while( integer > 0 ) {
ibuf[ --i ] = ( integer % 10 ) + '0';
integer /= 10;
}
else
ibuf[ --i ] = '0';
mputstr( ibuf+i );
str ++;
arg += 4;
break;
case 's':
pstr = ( char * ) (*( int * )arg);
mprintf( pstr );
arg += 4;
str ++;
break;
case 'c':
integer = *( int * )arg;
mputc( integer );
arg += 4;
str ++;
break;
case 'x':
integer = *( int * )arg;
i = 7;
while( i >=0 ) {
temp = 15 & (integer>>(i<<2));
if( temp >=0 && temp <10 ) {
mputc( temp + '0' );
} else {
switch( temp ) {
case 10:
mputc( 'a' );
break;
case 11:
mputc( 'b' );
break;
case 12:
mputc( 'c' );
break;
case 13:
mputc( 'd' );
break;
case 14:
mputc( 'e' );
break;
case 15:
mputc( 'f' );
break;
}
}
i --;
}
arg += 4;
str ++;
break;
}
break;
case '\n':
mputc( '\r' );
mputc( '\n' );
break;
default:
mputc( ch );
break;
}
}
}