1 //####ECOSGPLCOPYRIGHTBEGIN####
2 // -------------------------------------------
3 // This file is part of eCos, the Embedded Configurable Operating System.
4 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
5 // Copyright (C) 2002 Gary Thomas
7 // eCos is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 2 or (at your option) any later version.
11 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 // As a special exception, if other files instantiate templates or use macros
20 // or inline functions from this file, or you compile this file and link it
21 // with other works to produce a work based on this file, this file does not
22 // by itself cause the resulting work to be covered by the GNU General Public
23 // License. However the source code for this file must still be made available
24 // in accordance with section (3) of the GNU General Public License.
26 // This exception does not invalidate any other reasons why a work based on
27 // this file might be covered by the GNU General Public License.
29 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
30 // at http://sources.redhat.com/ecos/ecos-license/
31 // -------------------------------------------
32 //####ECOSGPLCOPYRIGHTEND####
39 #if SYSTEM_MODULE_PRINT
43 #include "athos_api.h"
45 #define is_digit(c) ((c >= '0') && (c <= '9'))
47 #if defined(__GNUC__) && defined(__mips__)
48 #define va_list __builtin_va_list
49 #define va_arg __builtin_va_arg
50 #define va_start __builtin_va_start
51 #define va_end __builtin_va_end
52 #define va_copy __builtin_va_copy
58 cmnos_write_char(char c)
63 } else if (c == '\r') {
70 (*_putc)(char c) = cmnos_write_char;
73 _cvt(unsigned long val, char *buf, long radix, char *digits)
84 *cp++ = digits[val % radix];
98 int cmnos_vprintf(void (*putc)(char c), const char *fmt, va_list ap)
100 char buf[sizeof(long)*8];
101 char c, sign, *cp=buf;
102 int left_prec, right_prec, zero_fill, pad, pad_on_right,
103 i, islong, islonglong;
105 int res = 0, length = 0;
107 while ((c = *fmt++) != '\0') {
110 left_prec = right_prec = pad_on_right = islong = islonglong = 0;
121 while (is_digit(c)) {
122 left_prec = (left_prec * 10) + (c - '0');
128 while (is_digit(c)) {
129 right_prec = (right_prec * 10) + (c - '0');
133 right_prec = left_prec;
141 // long long qualifier
146 // Fetch value [numeric descriptors only]
159 val = va_arg(ap, long);
161 val = (long)va_arg(ap, long);
163 val = (long)va_arg(ap, int);
165 if ((c == 'd') || (c == 'D')) {
171 // Mask to unsigned, sized quantity
173 val &= (1ULL << (sizeof(long) * 8)) - 1;
175 val &= (1ULL << (sizeof(int) * 8)) - 1;
188 left_prec = sizeof(unsigned long)*2;
200 length = _cvt(val, buf, 10, "0123456789");
204 length = _cvt(val, buf, 16, "0123456789abcdef");
207 length = _cvt(val, buf, 16, "0123456789ABCDEF");
214 cp = va_arg(ap, char *);
219 while (cp[length] != '\0') length++;
223 c = va_arg(ap, int /*char*/);
230 if (left_prec == 0) {
232 length = sizeof(long)*8;
234 length = sizeof(long)*8;
236 length = sizeof(int)*8;
238 for (i = 0; i < length-1; i++) {
239 buf[i] = ((val & ((long)1<<i)) ? '1' : '.');
251 pad = left_prec - length;
275 while (length-- > 0) {
295 fw_cmnos_printf(const char *fmt, ...)
302 //if (A_SERIAL_ENABLED()) {
304 ret = cmnos_vprintf(_putc, fmt, ap);
313 #endif /* MOVE_PRINT_TO_RAM */
315 #endif /* SYSTEM_MODULE_PRINT */