Ejemplo n.º 1
0
Archivo: putk.c Proyecto: gedare/rtems
/**
 * Kernel putk (e.g. puts) function requiring minimal infrastrure.
 */
int putk(const char *s)
{
  const char *p;
  int len_out = 0;

  for (p=s ; *p ; p++, len_out++ )
    rtems_putc(*p);
  rtems_putc('\n');
  return len_out + 1;
}
Ejemplo n.º 2
0
static void vprintk_putchar( int c, void *arg )
{
  rtems_putc((char) c);
}
Ejemplo n.º 3
0
/*
 *  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
)
{
    for (; *fmt != '\0'; fmt++) {
        unsigned base = 0;
        unsigned width = 0;
        bool lflag = false;
        bool minus = false;
        bool sign = false;
        char lead = ' ';
        char c;

        if (*fmt != '%') {
            rtems_putc(*fmt);
            continue;
        }
        fmt++;
        if (*fmt == '0' ) {
            lead = '0';
            fmt++;
        }
        if (*fmt == '-' ) {
            minus = true;
            fmt++;
        }
        while (*fmt >= '0' && *fmt <= '9' ) {
            width *= 10;
            width += ((unsigned) *fmt - '0');
            fmt++;
        }

        if ((c = *fmt) == 'l') {
            lflag = true;
            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<width ; i++ )
                    rtems_putc(' ');

            /* no width option */
            if (width == 0) {
                width = len;
            }

            /* output the string */
            for ( i=0 ; i<width && *str ; str++ )
                rtems_putc(*str);

            /* trailing spaces */
            if ( minus )
                for ( i=len ; i<width ; i++ )
                    rtems_putc(' ');

            continue;
        }