From 7bd0dbc385ae19569fe3a5a1eebde201400138cd Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 15 May 2009 15:02:43 +0000 Subject: 2009-05-15 Joel Sherrill * libcsupport/Makefile.am, libcsupport/src/printk.c: Restructure to make analysis and coverage easier. Now 100% covered. * libcsupport/src/vprintk.c: New file. --- cpukit/libcsupport/src/printk.c | 137 ----------------------------- cpukit/libcsupport/src/vprintk.c | 182 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 137 deletions(-) create mode 100644 cpukit/libcsupport/src/vprintk.c (limited to 'cpukit/libcsupport/src') diff --git a/cpukit/libcsupport/src/printk.c b/cpukit/libcsupport/src/printk.c index 9754574c38..41864164ce 100644 --- a/cpukit/libcsupport/src/printk.c +++ b/cpukit/libcsupport/src/printk.c @@ -24,143 +24,6 @@ #include #include -/* - * printNum - print number in a given base. - * Arguments - * num - number to print - * base - base used to print the number. - */ -static void printNum( - long unsigned int num, - int base, - int sign, - int maxwidth, - int lead -) -{ - long unsigned int n; - int count; - char toPrint[20]; - - if ( (sign == 1) && ((long)num < 0) ) { - BSP_output_char('-'); - num = -num; - if (maxwidth) maxwidth--; - } - - count = 0; - while ((n = num / base) > 0) { - toPrint[count++] = (num - (n*base)); - num = n; - } - toPrint[count++] = num; - - for (n=maxwidth ; n > count; n-- ) - BSP_output_char(lead); - - for (n = 0; n < count; n++) { - BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); - } -} - -/* - * vprintk - * - * A simplified version of printf intended for use when the - * console is not yet initialized or in ISR's. - * - * Arguments: - * as in printf: fmt - format string, ... - unnamed arguments. - */ -void vprintk( - const char *fmt, - va_list ap -) -{ - char c, *str; - int lflag, base, sign, width, lead, minus; - - for (; *fmt != '\0'; fmt++) { - lflag = 0; - base = 0; - sign = 0; - width = 0; - minus = 0; - lead = ' '; - if (*fmt == '%') { - fmt++; - if (*fmt == '0' ) { - lead = '0'; - fmt++; - } - if (*fmt == '-' ) { - minus = 1; - fmt++; - } - while (*fmt >= '0' && *fmt <= '9' ) { - width *= 10; - width += (*fmt - '0'); - fmt++; - } - - if ((c = *fmt) == 'l') { - lflag = 1; - c = *++fmt; - } - switch (c) { - case 'o': case 'O': base = 8; sign = 0; break; - case 'i': case 'I': - case 'd': case 'D': base = 10; sign = 1; break; - case 'u': case 'U': base = 10; sign = 0; break; - case 'x': case 'X': base = 16; sign = 0; break; - case 'p': base = 16; sign = 0; lflag = 1; break; - case 's': - { int i, len; - char *s; - - str = va_arg(ap, char *); - - /* calculate length of string */ - for ( len=0, s=str ; *s ; len++, s++ ) - ; - - /* leading spaces */ - if ( !minus ) - for ( i=len ; i +#include +#include + +static void printNum( + long unsigned int num, + int base, + int sign, + int maxwidth, + int lead +); + +/* + * vprintk + * + * A simplified version of printf intended for use when the + * console is not yet initialized or in ISR's. + * + * Arguments: + * as in printf: fmt - format string, ... - unnamed arguments. + */ +void vprintk( + const char *fmt, + va_list ap +) +{ + char c, *str; + int lflag, base, sign, width, lead, minus; + + for (; *fmt != '\0'; fmt++) { + lflag = 0; + base = 0; + sign = 0; + width = 0; + minus = 0; + lead = ' '; + if (*fmt != '%') { + BSP_output_char(*fmt); + continue; + } + fmt++; + if (*fmt == '0' ) { + lead = '0'; + fmt++; + } + if (*fmt == '-' ) { + minus = 1; + fmt++; + } + while (*fmt >= '0' && *fmt <= '9' ) { + width *= 10; + width += (*fmt - '0'); + fmt++; + } + + if ((c = *fmt) == 'l') { + lflag = 1; + c = *++fmt; + } + if ( c == 'c' ) { + BSP_output_char(va_arg(ap, int)); + continue; + } + if ( c == 's' ) { + int i, len; + char *s; + + str = va_arg(ap, char *); + + /* calculate length of string */ + for ( len=0, s=str ; *s ; len++, s++ ) + ; + + /* leading spaces */ + if ( !minus ) + for ( i=len ; i 0) { + toPrint[count++] = (num - (n*base)); + num = n; + } + toPrint[count++] = num; + + for (n=maxwidth ; n > count; n-- ) + BSP_output_char(lead); + + for (n = 0; n < count; n++) { + BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); + } +} -- cgit v1.2.3