diff options
author | Chris Johns <chrisj@rtems.org> | 2016-05-20 18:39:50 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2016-05-25 15:47:34 +1000 |
commit | 24d0ee57a4d95f99be6e7e60bd162a30daf0638d (patch) | |
tree | 94239c8cc6b21813ca44b6ca89da73f9038914cc /cpukit/libcsupport | |
parent | psxtests/psxmsgq01: Fix typo (diff) | |
download | rtems-24d0ee57a4d95f99be6e7e60bd162a30daf0638d.tar.bz2 |
cpukit, testsuite: Add rtems_printf and rtems_printer support.
This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.
Printk and related functions are made to return a valid number of
characters formatted and output.
The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.
The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.
Diffstat (limited to '')
-rw-r--r-- | cpukit/libcsupport/Makefile.am | 2 | ||||
-rw-r--r-- | cpukit/libcsupport/src/print_fprintf.c | 29 | ||||
-rw-r--r-- | cpukit/libcsupport/src/print_printf.c | 52 | ||||
-rw-r--r-- | cpukit/libcsupport/src/printf_plugin.c | 18 | ||||
-rw-r--r-- | cpukit/libcsupport/src/printk.c | 9 | ||||
-rw-r--r-- | cpukit/libcsupport/src/printk_plugin.c | 22 | ||||
-rw-r--r-- | cpukit/libcsupport/src/putk.c | 8 | ||||
-rw-r--r-- | cpukit/libcsupport/src/vprintk.c | 28 |
8 files changed, 132 insertions, 36 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am index b3ad3db4e1..f047cfc40f 100644 --- a/cpukit/libcsupport/Makefile.am +++ b/cpukit/libcsupport/Makefile.am @@ -112,6 +112,8 @@ BSD_LIBC_C_FILES = src/strlcpy.c src/strlcat.c src/issetugid.c libcsupport_a_SOURCES = src/gxx_wrappers.c src/getchark.c src/printk.c \ src/printk_plugin.c src/putk.c src/vprintk.c \ src/rtems_putc.c \ + src/print_fprintf.c \ + src/print_printf.c \ src/printf_plugin.c \ src/sup_fs_location.c \ src/sup_fs_eval_path.c \ diff --git a/cpukit/libcsupport/src/print_fprintf.c b/cpukit/libcsupport/src/print_fprintf.c new file mode 100644 index 0000000000..5e46d1c959 --- /dev/null +++ b/cpukit/libcsupport/src/print_fprintf.c @@ -0,0 +1,29 @@ +/** + * @file + * + * @brief RTEMS Print Support + * @ingroup libcsupport + */ + +/* + * Copyright (c) 2016 Chris Johns <chrisj@rtems.org> + * All rights reserved. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems/print.h> + +#include <stdio.h> + +void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file) +{ + printer->context = file; + printer->printer = (rtems_print_plugin_t) fprintf; +} diff --git a/cpukit/libcsupport/src/print_printf.c b/cpukit/libcsupport/src/print_printf.c new file mode 100644 index 0000000000..c8695234c0 --- /dev/null +++ b/cpukit/libcsupport/src/print_printf.c @@ -0,0 +1,52 @@ +/** + * @file + * + * @brief RTEMS Print Support + * @ingroup libcsupport + */ + +/* + * Copyright (c) 2016 Chris Johns <chrisj@rtems.org> + * All rights reserved. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include <rtems/print.h> + +#include <stdio.h> + +int rtems_vprintf( + const rtems_printer *printer, + const char *format, + va_list ap +) +{ + int len = 0; + if ( rtems_print_printer_valid( printer ) ) { + len = printer->printer( printer->context, format, ap ); + } + return len; +} + +int rtems_printf( + const rtems_printer *printer, + const char *format, + ... +) +{ + int len = 0; + if ( rtems_print_printer_valid( printer ) ) { + va_list ap; + va_start( ap, format ); + len = printer->printer( printer->context, format, ap ); + va_end( ap ); + } + return len; +} diff --git a/cpukit/libcsupport/src/printf_plugin.c b/cpukit/libcsupport/src/printf_plugin.c index ab4f4a44a2..097e4126b5 100644 --- a/cpukit/libcsupport/src/printf_plugin.c +++ b/cpukit/libcsupport/src/printf_plugin.c @@ -23,18 +23,18 @@ #include "config.h" #endif -#include <rtems/bspIo.h> +#include <rtems/print.h> #include <stdio.h> -int rtems_printf_plugin(void *context, const char *format, ...) +void rtems_print_printer_printf(rtems_printer *printer) { - int rv; - va_list ap; - - va_start(ap, format); - rv = vprintf(format, ap); - va_end(ap); + printer->context = NULL; + printer->printer = rtems_printf_plugin; +} - return rv; +int rtems_printf_plugin(void *context, const char *format, va_list ap) +{ + (void) context; + return vprintf(format, ap); } diff --git a/cpukit/libcsupport/src/printk.c b/cpukit/libcsupport/src/printk.c index badbd0d591..88cd22aab0 100644 --- a/cpukit/libcsupport/src/printk.c +++ b/cpukit/libcsupport/src/printk.c @@ -32,11 +32,12 @@ /** * Kernel printf function requiring minimal infrastructure. */ -void printk(const char *fmt, ...) +int printk(const char *fmt, ...) { - va_list ap; /* points to each unnamed argument in turn */ - + va_list ap; /* points to each unnamed argument in turn */ + int len; va_start(ap, fmt); /* make ap point to 1st unnamed arg */ - vprintk(fmt, ap); + len = vprintk(fmt, ap); va_end(ap); /* clean up when done */ + return len; } diff --git a/cpukit/libcsupport/src/printk_plugin.c b/cpukit/libcsupport/src/printk_plugin.c index b600378d0a..3ecacb8a28 100644 --- a/cpukit/libcsupport/src/printk_plugin.c +++ b/cpukit/libcsupport/src/printk_plugin.c @@ -19,23 +19,23 @@ #endif #include <stdarg.h> -#include <rtems/bspIo.h> +#include <rtems/print.h> + +void rtems_print_printer_printk( + rtems_printer *printer +) +{ + printer->context = NULL; + printer->printer = printk_plugin; +} int printk_plugin( void *ignored, const char *format, - ... + va_list ap ) { - va_list arg_pointer; - (void) ignored; - - va_start (arg_pointer, format); - - vprintk( format, arg_pointer ); - - va_end(arg_pointer); /* clean up when done */ - + vprintk( format, ap ); return 0; } diff --git a/cpukit/libcsupport/src/putk.c b/cpukit/libcsupport/src/putk.c index 2532a64500..76fa8b0040 100644 --- a/cpukit/libcsupport/src/putk.c +++ b/cpukit/libcsupport/src/putk.c @@ -1,7 +1,7 @@ /** * @file * - * @brief Write Character to Stream + * @brief Write Character to Stream * @ingroup libcsupport */ @@ -23,11 +23,13 @@ /** * Kernel putk (e.g. puts) function requiring minimal infrastrure. */ -void putk(const char *s) +int putk(const char *s) { const char *p; + int len_out = 0; - for (p=s ; *p ; p++ ) + for (p=s ; *p ; p++, len_out++ ) BSP_output_char(*p); BSP_output_char('\n'); + return len_out + 1; } diff --git a/cpukit/libcsupport/src/vprintk.c b/cpukit/libcsupport/src/vprintk.c index 51e4947e43..a254934a0d 100644 --- a/cpukit/libcsupport/src/vprintk.c +++ b/cpukit/libcsupport/src/vprintk.c @@ -30,7 +30,7 @@ #include <stdbool.h> #include <rtems/bspIo.h> -static void printNum( +static int printNum( long long num, unsigned base, bool sign, @@ -45,11 +45,12 @@ static void printNum( * Arguments: * as in printf: fmt - format string, ... - unnamed arguments. */ -void vprintk( +int vprintk( const char *fmt, va_list ap ) { + int len_out = 0; for (; *fmt != '\0'; fmt++) { unsigned base = 0; unsigned width = 0; @@ -66,6 +67,7 @@ void vprintk( if (c != '%') { rtems_putc(c); + ++len_out; continue; } @@ -101,6 +103,7 @@ void vprintk( /* need a cast here since va_arg() only takes fully promoted types */ char chr = (char) va_arg(ap, int); rtems_putc(chr); + ++len_out; continue; } @@ -120,7 +123,7 @@ void vprintk( /* leading spaces */ if ( !minus ) - for ( i=len ; i<width ; i++ ) + for ( i=len ; i<width ; i++, len_out++ ) rtems_putc(' '); /* no width option */ @@ -129,12 +132,12 @@ void vprintk( } /* output the string */ - for ( i=0 ; i<width && *str ; str++ ) + for ( i=0 ; i<width && *str ; str++, len_out++ ) rtems_putc(*str); /* trailing spaces */ if ( minus ) - for ( i=len ; i<width ; i++ ) + for ( i=len ; i<width ; i++, len_out++ ) rtems_putc(' '); continue; @@ -154,6 +157,7 @@ void vprintk( base = 16; sign = false; lflag = LFLAG_LONG; } else { rtems_putc(c); + ++len_out; continue; } @@ -172,8 +176,10 @@ void vprintk( break; } - printNum(num, base, sign, width, lead); + len_out += printNum(num, base, sign, width, lead); } + + return len_out; } /** @@ -181,7 +187,7 @@ void vprintk( * @param[in] num is the number to print * @param[in] base is the base used to print the number */ -static void printNum( +static int printNum( long long num, unsigned base, bool sign, @@ -194,9 +200,11 @@ static void printNum( unsigned count; #define UINT64_MAX_IN_OCTAL_FORMAT "1777777777777777777777" char toPrint[sizeof(UINT64_MAX_IN_OCTAL_FORMAT)]; + int len_out = 0; if ( sign && (num < 0) ) { rtems_putc('-'); + ++len_out; unsigned_num = (unsigned long long) -num; if (maxwidth) maxwidth--; } else { @@ -210,10 +218,12 @@ static void printNum( } toPrint[count++] = (char) unsigned_num; - for (n=maxwidth ; n > count; n-- ) + for (n=maxwidth ; n > count; n--, len_out++ ) rtems_putc(lead); - for (n = 0; n < count; n++) { + for (n = 0; n < count; n++, len_out++) { rtems_putc("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); } + + return len_out; } |