printf error fixed
authorLiu Aleaxander <Aleaxander@gmail.com>
Tue, 2 Jun 2009 23:38:19 +0000 (07:38 +0800)
committerLiu Aleaxander <Aleaxander@gmail.com>
Tue, 2 Jun 2009 23:38:19 +0000 (07:38 +0800)
and removed the itao function as the printf function works well now

Makefile
core/cache.c
core/hello.c
core/include/core.h
core/printf.c

index de0d2fd..fb411e7 100644 (file)
--- 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 \
index c2c7a91..dca85a7 100644 (file)
@@ -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);
index ae75ced..a159111 100644 (file)
@@ -3,19 +3,6 @@
 #include <stdio.h>
 #include <string.h>
 
-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 */
 }
index bd04feb..8e7cd03 100644 (file)
@@ -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 *);
index 3872e92..b1b0466 100644 (file)
@@ -1,23 +1,16 @@
 #include <stdio.h>
 #include <unistd.h>
 
-
-
-
-#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);