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 along
17 // with eCos; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 // As a special exception, if other files instantiate templates or use macros
21 // or inline functions from this file, or you compile this file and link it
22 // with other works to produce a work based on this file, this file does not
23 // by itself cause the resulting work to be covered by the GNU General Public
24 // License. However the source code for this file must still be made available
25 // in accordance with section (3) of the GNU General Public License.
27 // This exception does not invalidate any other reasons why a work based on
28 // this file might be covered by the GNU General Public License.
30 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
31 // at http://sources.redhat.com/ecos/ecos-license/
32 // -------------------------------------------
33 //####ECOSGPLCOPYRIGHTEND####
40 #if SYSTEM_MODULE_PRINT
44 #include "athos_api.h"
46 #define is_digit(c) ((c >= '0') && (c <= '9'))
48 #if defined(__GNUC__) && defined(__mips__)
49 #define va_list __builtin_va_list
50 #define va_arg __builtin_va_arg
51 #define va_start __builtin_va_start
52 #define va_end __builtin_va_end
53 #define va_copy __builtin_va_copy
59 cmnos_write_char(char c)
64 } else if (c == '\r') {
71 (*_putc)(char c) = cmnos_write_char;
74 _cvt(unsigned long val, char *buf, long radix, char *digits)
85 *cp++ = digits[val % radix];
99 int cmnos_vprintf(void (*putc)(char c), const char *fmt, va_list ap)
101 char buf[sizeof(long)*8];
102 char c, sign, *cp=buf;
103 int left_prec, right_prec, zero_fill, pad, pad_on_right,
104 i, islong, islonglong;
106 int res = 0, length = 0;
108 while ((c = *fmt++) != '\0') {
111 left_prec = right_prec = pad_on_right = islong = islonglong = 0;
122 while (is_digit(c)) {
123 left_prec = (left_prec * 10) + (c - '0');
129 while (is_digit(c)) {
130 right_prec = (right_prec * 10) + (c - '0');
134 right_prec = left_prec;
142 // long long qualifier
147 // Fetch value [numeric descriptors only]
160 val = va_arg(ap, long);
162 val = (long)va_arg(ap, long);
164 val = (long)va_arg(ap, int);
166 if ((c == 'd') || (c == 'D')) {
172 // Mask to unsigned, sized quantity
174 val &= (1ULL << (sizeof(long) * 8)) - 1;
176 val &= (1ULL << (sizeof(int) * 8)) - 1;
189 left_prec = sizeof(unsigned long)*2;
201 length = _cvt(val, buf, 10, "0123456789");
205 length = _cvt(val, buf, 16, "0123456789abcdef");
208 length = _cvt(val, buf, 16, "0123456789ABCDEF");
215 cp = va_arg(ap, char *);
220 while (cp[length] != '\0') length++;
224 c = va_arg(ap, int /*char*/);
231 if (left_prec == 0) {
233 length = sizeof(long)*8;
235 length = sizeof(long)*8;
237 length = sizeof(int)*8;
239 for (i = 0; i < length-1; i++) {
240 buf[i] = ((val & ((long)1<<i)) ? '1' : '.');
252 pad = left_prec - length;
276 while (length-- > 0) {
296 fw_cmnos_printf(const char *fmt, ...)
303 //if (A_SERIAL_ENABLED()) {
305 ret = cmnos_vprintf(_putc, fmt, ap);
314 #endif /* MOVE_PRINT_TO_RAM */
316 #endif /* SYSTEM_MODULE_PRINT */