/** * @file * * @brief Print Formatted Output * @ingroup libcsupport */ /* * (C) Copyright 1997 - * - NavIST Group - Real-Time Distributed Systems and Industrial Automation * * http://pandora.ist.utl.pt * * Instituto Superior Tecnico * Lisboa * PORTUGAL * * Disclaimer: * * This file is provided "AS IS" without warranty of any kind, either * expressed or implied. * * This code is based on code by: Jose Rufino - IST */ #if HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include static void printNum( long long num, unsigned base, bool sign, unsigned maxwidth, char lead ); /** * 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 ) { for (; *fmt != '\0'; fmt++) { unsigned base = 0; unsigned width = 0; enum { LFLAG_INT, LFLAG_LONG, LFLAG_LONG_LONG } lflag = LFLAG_INT; bool minus = false; bool sign = false; char lead = ' '; char c = *fmt; long long num; if (c != '%') { rtems_putc(c); continue; } ++fmt; c = *fmt; if (c == '0') { lead = '0'; ++fmt; c = *fmt; } if (c == '-') { minus = true; ++fmt; c = *fmt; } while (c >= '0' && c <= '9' ) { width *= 10; width += ((unsigned) c - '0'); ++fmt; c = *fmt; } if (c == 'l') { lflag = LFLAG_LONG; ++fmt; c = *fmt; if (c == 'l') { lflag = LFLAG_LONG_LONG; ++fmt; c = *fmt; } } if ( c == 'c' ) { /* need a cast here since va_arg() only takes fully promoted types */ char chr = (char) va_arg(ap, int); rtems_putc(chr); continue; } if ( c == 's' ) { unsigned i, len; char *s, *str; str = va_arg(ap, char *); if ( str == NULL ) { str = ""; } /* calculate length of string */ for ( len=0, s=str ; *s ; len++, s++ ) ; /* leading spaces */ if ( !minus ) for ( i=len ; i 0) { toPrint[count++] = (char) (unsigned_num - (n * base)); unsigned_num = n; } toPrint[count++] = (char) unsigned_num; for (n=maxwidth ; n > count; n-- ) rtems_putc(lead); for (n = 0; n < count; n++) { rtems_putc("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); } }