My Own printf()
Posted: Sat Dec 15, 2001 12:00 am
Hello,
I've written a printf() of my own, but it doesn't
work when i compiled it with my kernel, i can't seem
to find the problem...
this is the file, hope somebody can tell me what's
wrong with it, thanks you!
----------- printf.h ----------
#ifndef __printf_h_
#define __printf_h_
#include <stdarg.h>
#include "string.h" /* includes strcat(char*,char* */
#include "io.h" /* includes puts(void *) */
void printf(const char *format,...)
{
va_list args;
char *buffer;
int ir2,i,null_found=0;
char *pcr3,current=0x20,cr1;
va_start(args,format);
while (*format!=0x00)
{
switch(*format)
{
case '\\':
current='\\';
format++;
switch(*format)
{
case 'n':
*buffer=0x0d;
buffer++;
*buffer=0x0a;
break;
case 'r':
*buffer=0x0d;
buffer++;
*buffer=0x0a;
break;
case 'a':
*buffer=0x07;
break;
case 'b':
buffer--;
buffer--;
break;
case 't':
for (i=1;i<=4;i++)
*(buffer++)=' ';
break;
case '\\':
*buffer='\\';
break;
case 'x':
/* not to implement */
*buffer='-';
break;
default:
*buffer=current;
buffer++;
*buffer=*format;
break;
}
break;
case '%':
current='%';
format++;
switch(*format)
{
case 'b':
/* not to implement */
*buffer='*';
break;
case 'c':
cr1=va_arg(args,char);
*buffer=cr1;
break;
case 'd':
ir2=va_arg(args,int);
break;
case 'f':
/* not to implement */
*buffer='#';
break;
case 's':
pcr3=va_arg(args,char *);
strcat(buffer,pcr3);
break;
case 'x':
/* not to implement */
*buffer='|';
break;
default:
*buffer=current;
buffer++;
*buffer=*format;
break;
}
break;
default:
*buffer=*format;
break;
}
format++;
buffer++;
}
/* now just need to dump [buffer] onto the screen */
puts(buffer);
return;
}
#endif
Thanks,
Ben Hsu
I've written a printf() of my own, but it doesn't
work when i compiled it with my kernel, i can't seem
to find the problem...
this is the file, hope somebody can tell me what's
wrong with it, thanks you!
----------- printf.h ----------
#ifndef __printf_h_
#define __printf_h_
#include <stdarg.h>
#include "string.h" /* includes strcat(char*,char* */
#include "io.h" /* includes puts(void *) */
void printf(const char *format,...)
{
va_list args;
char *buffer;
int ir2,i,null_found=0;
char *pcr3,current=0x20,cr1;
va_start(args,format);
while (*format!=0x00)
{
switch(*format)
{
case '\\':
current='\\';
format++;
switch(*format)
{
case 'n':
*buffer=0x0d;
buffer++;
*buffer=0x0a;
break;
case 'r':
*buffer=0x0d;
buffer++;
*buffer=0x0a;
break;
case 'a':
*buffer=0x07;
break;
case 'b':
buffer--;
buffer--;
break;
case 't':
for (i=1;i<=4;i++)
*(buffer++)=' ';
break;
case '\\':
*buffer='\\';
break;
case 'x':
/* not to implement */
*buffer='-';
break;
default:
*buffer=current;
buffer++;
*buffer=*format;
break;
}
break;
case '%':
current='%';
format++;
switch(*format)
{
case 'b':
/* not to implement */
*buffer='*';
break;
case 'c':
cr1=va_arg(args,char);
*buffer=cr1;
break;
case 'd':
ir2=va_arg(args,int);
break;
case 'f':
/* not to implement */
*buffer='#';
break;
case 's':
pcr3=va_arg(args,char *);
strcat(buffer,pcr3);
break;
case 'x':
/* not to implement */
*buffer='|';
break;
default:
*buffer=current;
buffer++;
*buffer=*format;
break;
}
break;
default:
*buffer=*format;
break;
}
format++;
buffer++;
}
/* now just need to dump [buffer] onto the screen */
puts(buffer);
return;
}
#endif
Thanks,
Ben Hsu