From e751e537459b681b4a0b56276e58f08296f9dc8f Mon Sep 17 00:00:00 2001 From: Liu Aleaxander Date: Wed, 3 Jun 2009 07:38:19 +0800 Subject: [PATCH] printf error fixed and removed the itao function as the printf function works well now --- Makefile | 2 +- core/cache.c | 29 +++++++++++------------------ core/hello.c | 17 ++--------------- core/include/core.h | 1 - core/printf.c | 13 +++---------- 5 files changed, 17 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index de0d2fd..fb411e7 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ BOBJECTS = $(BTARGET) \ # Note: libinstaller is both a BSUBDIR and an ISUBDIR. It contains # files that depend only on the B phase, but may have to be regenerated # for "make installer". -BSUBDIRS = codepage com32 lzo core memdisk modules mbr memdump gpxe sample \ +BSUBDIRS = codepage com32 lzo core memdisk modules mbr memdump sample \ libinstaller dos win32 ITARGET = IOBJECTS = $(ITARGET) dos/copybs.com \ diff --git a/core/cache.c b/core/cache.c index c2c7a91..dca85a7 100644 --- a/core/cache.c +++ b/core/cache.c @@ -103,12 +103,9 @@ void get_cache_block(com32sys_t * regs) static int total_read; static int missed; - char buf[10]; - + #if 0 - itoa(buf, block); - myputs(buf); - myputs(" this is what we are looking cache for block\n\r"); + printf("we are looking for cache of %d\n", block); #endif if ( !block ) { @@ -139,19 +136,7 @@ void get_cache_block(com32sys_t * regs) missed ++; } - total_read ++; -#if 0 /* testing how efficiency the cache is */ - if ( total_read % 5 == 0 ) { - itoa(buf, total_read); - myputs("total_read "); - myputs(buf); - myputs("\tmissed "); - itoa(buf, missed); - myputs(buf); - myputs("\n\r"); - } -#endif /* remove cs from current position in list */ cs->prev->next = cs->next; @@ -168,9 +153,17 @@ void get_cache_block(com32sys_t * regs) cs->next = head; out: + + total_read ++; + +#if 0 /* testing how efficiency the cache is */ + if ( total_read % 5 == 0 ) + printf("total_read %d\tmissed %d\n", total_read, missed); +#endif + /* in fact, that would never be happened */ if ( (char *)(cs->data) > (char*)0x100000 ) - myputs("the buffer addres higher than 1M limit\n\r"); + printf("the buffer addres higher than 1M limit\n\r"); regs->gs = SEG(cs->data); regs->esi.w[0]= OFFS(cs->data); diff --git a/core/hello.c b/core/hello.c index ae75ced..a159111 100644 --- a/core/hello.c +++ b/core/hello.c @@ -3,19 +3,6 @@ #include #include -void itoa(char *str, int num) -{ - char buf[10]; - int i = 0; - - do { - buf[i++] = num % 10 + 0x30; - }while ( num /= 10 ); - - str[i] = '\0'; - for (; i > 0; i -- ) - *str++ = buf[i-1]; -} void myputchar(int c) { @@ -37,7 +24,7 @@ void myputs(const char *str) void hello(void) { - static char hello_str[] = "Hello, World! (hello.c)\n"; + static char hello_str[] = "Hello, World!"; - myputs(hello_str); + printf("%s from (%s)\n", hello_str, __FILE__); /* testing */ } diff --git a/core/include/core.h b/core/include/core.h index bd04feb..8e7cd03 100644 --- a/core/include/core.h +++ b/core/include/core.h @@ -12,7 +12,6 @@ extern void getlinsec(void); /* hello.c */ extern void myputs(const char*); -extern void itoa(char *, int); void __cdecl core_intcall(uint8_t, const com32sys_t *, com32sys_t *); diff --git a/core/printf.c b/core/printf.c index 3872e92..b1b0466 100644 --- a/core/printf.c +++ b/core/printf.c @@ -1,23 +1,16 @@ #include #include - - - -#define BUF_SIZE 1024 - -char buf[BUF_SIZE]; - - -extern void myputs(const char *); +#include "core.h" int printf(const char *format, ...) { + char buf[1024]; va_list ap; int rv; va_start(ap, format); - rv = sprintf(buf, format, ap); + rv = vsnprintf(buf, sizeof buf, format, ap); va_end(ap); myputs(buf); -- 2.7.4