Move C labels to start-of-line
[coreboot.git] / src / console / vtxprintf.c
index 0f12672a5001a2e2618d279e28f228e8c922440d..405302311d6d6a6c85ca6692ea3fbdbf7f61f827 100644 (file)
@@ -4,47 +4,15 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  */
 
-#include <stdarg.h>
 #include <string.h>
+#include <div64.h>
+#include <console/vtxprintf.h>
 
 /* haha, don't need ctype.c */
 #define isdigit(c)     ((c) >= '0' && (c) <= '9')
 #define is_digit isdigit
 #define isxdigit(c)    (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
 
-static unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
-{
-       unsigned long result = 0,value;
-
-       if (!base) {
-               base = 10;
-               if (*cp == '0') {
-                       base = 8;
-                       cp++;
-                       if ((*cp == 'x') && isxdigit(cp[1])) {
-                               cp++;
-                               base = 16;
-                       }
-               }
-       }
-       while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
-           ? toupper(*cp) : *cp)-'A'+10) < base) {
-               result = result*base + value;
-               cp++;
-       }
-       if (endp)
-               *endp = (char *)cp;
-       return result;
-}
-
-static long simple_strtol(const char *cp,char **endp,unsigned int base)
-{
-       if(*cp=='-')
-               return -simple_strtoul(cp+1,endp,base);
-       return simple_strtoul(cp,endp,base);
-}
-
-
 static int skip_atoi(const char **s)
 {
        int i=0;
@@ -62,14 +30,8 @@ static int skip_atoi(const char **s)
 #define SPECIAL        32              /* 0x */
 #define LARGE  64              /* use 'ABCDEF' instead of 'abcdef' */
 
-#define do_div(n,base) ({ \
-int __res; \
-__res = ((unsigned long) n) % (unsigned) base; \
-n = ((unsigned long) n) / (unsigned) base; \
-__res; })
-
-static int number(void (*tx_byte)(unsigned char byte), long num, int base, int size, int precision
-       ,int type)
+static int number(void (*tx_byte)(unsigned char byte),
+       unsigned long long num, int base, int size, int precision, int type)
 {
        char c,sign,tmp[66];
        const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
@@ -85,7 +47,7 @@ static int number(void (*tx_byte)(unsigned char byte), long num, int base, int s
        c = (type & ZEROPAD) ? '0' : ' ';
        sign = 0;
        if (type & SIGN) {
-               if (num < 0) {
+               if ((signed long long)num < 0) {
                        sign = '-';
                        num = -num;
                        size--;
@@ -140,7 +102,7 @@ static int number(void (*tx_byte)(unsigned char byte), long num, int base, int s
 int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args)
 {
        int len;
-       unsigned long num;
+       unsigned long long num;
        int i, base;
        const char *s;
 
@@ -150,7 +112,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
        int precision;          /* min. # of digits for integers; max
                                   number of chars for from string */
        int qualifier;          /* 'h', 'l', or 'L' for integer fields */
-       
+
        int count;
 
        for (count=0; *fmt ; ++fmt) {
@@ -158,10 +120,10 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
                        tx_byte(*fmt), count++;
                        continue;
                }
-                       
+
                /* process flags */
                flags = 0;
-               repeat:
+repeat:
                        ++fmt;          /* this also skips first '%' */
                        switch (*fmt) {
                                case '-': flags |= LEFT; goto repeat;
@@ -170,7 +132,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
                                case '#': flags |= SPECIAL; goto repeat;
                                case '0': flags |= ZEROPAD; goto repeat;
                                }
-               
+
                /* get field width */
                field_width = -1;
                if (is_digit(*fmt))
@@ -188,7 +150,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
                /* get the precision */
                precision = -1;
                if (*fmt == '.') {
-                       ++fmt;  
+                       ++fmt;
                        if (is_digit(*fmt))
                                precision = skip_atoi(&fmt);
                        else if (*fmt == '*') {
@@ -205,6 +167,10 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
                if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
                        qualifier = *fmt;
                        ++fmt;
+                       if (*fmt == 'l') {
+                               qualifier = 'L';
+                               ++fmt;
+                       }
                }
 
                /* default base */
@@ -248,7 +214,10 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
 
 
                case 'n':
-                       if (qualifier == 'l') {
+                       if (qualifier == 'L') {
+                               long long *ip = va_arg(args, long long *);
+                               *ip = count;
+                       } else if (qualifier == 'l') {
                                long * ip = va_arg(args, long *);
                                *ip = count;
                        } else {
@@ -286,16 +255,19 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args
                                --fmt;
                        continue;
                }
-               if (qualifier == 'l')
+               if (qualifier == 'L') {
+                       num = va_arg(args, unsigned long long);
+               } else if (qualifier == 'l') {
                        num = va_arg(args, unsigned long);
-               else if (qualifier == 'h') {
+               else if (qualifier == 'h') {
                        num = (unsigned short) va_arg(args, int);
                        if (flags & SIGN)
                                num = (short) num;
-               } else if (flags & SIGN)
+               } else if (flags & SIGN) {
                        num = va_arg(args, int);
-               else
+               } else {
                        num = va_arg(args, unsigned int);
+               }
                count += number(tx_byte, num, base, field_width, precision, flags);
        }
        return count;