char * fcvt(double val, int nfrac, int *pdecpt, int *psign) // double val, int nfrac, int *pdecpt, int *psign; { return _cvt(FCVT, val, nfrac, pdecpt, psign); }
/*! Assignment operator from timespec. \param that timespec object to assign from \return *this */ Tickval& operator=(const timespec& that) { _value = _cvt(that); return *this; }
char * ecvt(double val, int ndig, int *pdecpt,int *psign) // double val, int ndig, int *pdecpt,int *psign; { return _cvt(ECVT, val, ndig, pdecpt, psign); }
/*! Ctor. \param from construct from timespec object */ explicit Tickval(const timespec& from) : _value(_cvt(from)) {}
/*! Ctor. \param settonow if true, construct with current time */ Tickval(bool settonow=false) : _value(settonow ? _cvt(get_timespec()) : noticks) {}
int _vprintf(void (*putc)(char c, void **param), void **param, const char *fmt, va_list ap) { char buf[sizeof(long long)*8]; char c, sign, *cp=buf; int i; long long val = 0; int res = 0, length, width; int prepad, postpad, leading_zeros; int addr; while ((c = *fmt++) != '\0') { if (c == '%') { c = *fmt++; leading_zeros = (c == '0')?1:0; width = 0; prepad = 0; postpad = 0; while((c >= '0')&&(c <= '9')) { width = (width * 10) + (int)(c-'0'); c = *fmt++; } // Process output switch (c) { case 'd': val = va_arg(ap, int); // up to dword length = _cvt(val, buf, 10, "0123456789", leading_zeros, width); if(length < width) prepad = width - length; cp = buf; break; case 's': cp = va_arg(ap, char *); length = 0; while (cp[length] != '\0') length++; if(length < width) postpad = width - length; if((width) && (length > width)) length = width; // truncate break; case 'c': c = va_arg(ap, int /*char*/); (*putc)(c, param); res++; continue; case 'p': // pointer addr = va_arg(ap, int); length = 7; _hex(addr, buf, length); cp = buf; break; case 'x': // any hex length addr = va_arg(ap, int); // up to dword _hex(addr, buf, width); length = width; cp = buf; break; case 'b': // byte addr = va_arg(ap, int); // byte length = 2; _hex(addr, buf, length); cp = buf; break; default: (*putc)('%', param); (*putc)(c, param); res += 2; continue; } while (prepad-- > 0) { (*putc)(' ', param); res++; } while (length-- > 0) { c = *cp++; (*putc)(c, param); res++; } while (postpad-- > 0) { (*putc)(' ', param); res++; } } else {
int lcd_vprintf(void (*putc)(cyg_int8), const char *fmt0, va_list ap) { char c, sign, *cp; int left_prec, right_prec, zero_fill, length, pad, pad_on_right; char buf[32]; long val; while ((c = *fmt0++)) { cp = buf; length = 0; if (c == '%') { c = *fmt0++; left_prec = right_prec = pad_on_right = 0; if (c == '-') { c = *fmt0++; pad_on_right++; } if (c == '0') { zero_fill = TRUE; c = *fmt0++; } else { zero_fill = FALSE; } while (is_digit(c)) { left_prec = (left_prec * 10) + (c - '0'); c = *fmt0++; } if (c == '.') { c = *fmt0++; zero_fill++; while (is_digit(c)) { right_prec = (right_prec * 10) + (c - '0'); c = *fmt0++; } } else { right_prec = left_prec; } sign = '\0'; switch (c) { case 'd': case 'x': case 'X': val = va_arg(ap, long); switch (c) { case 'd': if (val < 0) { sign = '-'; val = -val; } length = _cvt(val, buf, 10, "0123456789"); break; case 'x': length = _cvt(val, buf, 16, "0123456789abcdef"); break; case 'X': length = _cvt(val, buf, 16, "0123456789ABCDEF"); break; } break; case 's': cp = va_arg(ap, char *); length = strlen(cp); break; case 'c': c = va_arg(ap, long /*char*/); (*putc)(c); continue; default: (*putc)('?'); } pad = left_prec - length; if (sign != '\0') { pad--; } if (zero_fill) { c = '0'; if (sign != '\0') { (*putc)(sign); sign = '\0'; } } else { c = ' '; } if (!pad_on_right) { while (pad-- > 0) { (*putc)(c); } } if (sign != '\0') { (*putc)(sign); } while (length-- > 0) { (*putc)(c = *cp++); if (c == '\n') { (*putc)('\r'); } } if (pad_on_right) { while (pad-- > 0) { (*putc)(' '); } } } else {
static int pack_printf( void (*putc)(char **pbs, char *be, char c), char **pbuf_start, char *buf_end, const char *fmt, const char *pack, uint8_t *msg, uint32_t msg_len) { char buf[sizeof(long long)*8]; char c, sign, *cp=buf; int32_t left_prec, right_prec, zero_fill, pad, pad_on_right, i, islong, islonglong; long long val = 0; int32_t res = 0, length = 0; while ((c = fmt_next_char(&fmt)) != '\0') { if (c == '%') { c = fmt_next_char(&fmt); left_prec = right_prec = pad_on_right = islong = islonglong = 0; if (c == '-') { c = fmt_next_char(&fmt); pad_on_right++; } if (c == '0') { zero_fill = 1; c = fmt_next_char(&fmt); } else { zero_fill = 0; } while (is_digit(c)) { left_prec = (left_prec * 10) + (c - '0'); c = fmt_next_char(&fmt); } if (c == '.') { c = fmt_next_char(&fmt); zero_fill++; while (is_digit(c)) { right_prec = (right_prec * 10) + (c - '0'); c = fmt_next_char(&fmt); } } else { right_prec = left_prec; } sign = '\0'; if (c == 'l') { /* 'long' qualifier */ c = fmt_next_char(&fmt); islong = 1; if (c == 'l') { /* long long qualifier */ c = fmt_next_char(&fmt); islonglong = 1; } } /* Fetch value [numeric descriptors only] */ switch (c) { case 'p': islong = 1; case 'd': case 'D': case 'x': case 'X': case 'u': case 'U': case 'b': case 'B': switch (fmt_next_char(&pack)) { case 'b': GET_8(val, msg, msg_len); break; case 'h': GET_LE16(val, msg, msg_len); break; case 'i': case 'I': GET_LE32(val, msg, msg_len); break; case 'q': GET_LE64(val, msg, msg_len); break; default: c = 0; break; } if ((c == 'd') || (c == 'D')) { if (val < 0) { sign = '-'; val = -val; } } else { /* Mask to unsigned, sized quantity */ if (!islonglong) { if (islong) { val &= ((long long)1 << (sizeof(long) * 8)) - 1; } else{ val &= ((long long)1 << (sizeof(int) * 8)) - 1; } } } break; default: break; } /* Process output */ switch (c) { case 'p': /* Pointer */ (*putc)(pbuf_start, buf_end,'0'); (*putc)(pbuf_start, buf_end,'x'); zero_fill = 1; left_prec = sizeof(unsigned long)*2; case 'd': case 'D': case 'u': case 'U': case 'x': case 'X': switch (c) { case 'd': case 'D': case 'u': case 'U': length = _cvt(val, buf, 10, "0123456789"); break; case 'p': case 'x': length = _cvt(val, buf, 16, "0123456789abcdef"); break; case 'X': length = _cvt(val, buf, 16, "0123456789ABCDEF"); break; } cp = buf; break; case 's': case 'S': cp = NULL; /* TODO string literals not supported yet */ if (cp == NULL) { cp = "<null>"; } length = 0; while (cp[length] != '\0') length++; break; case 'c': case 'C': switch (fmt_next_char(&pack)) { case 'b': GET_8(c, msg, msg_len); break; case 'h': GET_LE16(c, msg, msg_len); break; case 'i': case 'I': GET_LE32(c, msg, msg_len); break; case 'q': GET_LE64(c, msg, msg_len); break; default: c = 0; break; } (*putc)(pbuf_start, buf_end,c); res++; continue; case 'b': case 'B': length = left_prec; if (left_prec == 0) { if (islonglong) length = sizeof(long long)*8; else if (islong) length = sizeof(long)*8; else length = sizeof(uint32_t)*8; } for (i = 0; i < length-1; i++) { buf[i] = ((val & ((long long)1<<i)) ? '1' : '.'); } cp = buf; break; case '%': (*putc)(pbuf_start, buf_end,'%'); break; default: (*putc)(pbuf_start, buf_end,'%'); (*putc)(pbuf_start, buf_end,c); res += 2; } pad = left_prec - length; if (sign != '\0') { pad--; } if (zero_fill) { c = '0'; if (sign != '\0') { (*putc)(pbuf_start, buf_end,sign); res++; sign = '\0'; } } else { c = ' '; } if (!pad_on_right) { while (pad-- > 0) { (*putc)(pbuf_start, buf_end,c); res++; } } if (sign != '\0') { (*putc)(pbuf_start, buf_end,sign); res++; } while (length-- > 0) { c = *cp++; (*putc)(pbuf_start, buf_end,c); res++; } if (pad_on_right) { while (pad-- > 0) { (*putc)(pbuf_start, buf_end,' '); res++; } } } else { (*putc)(pbuf_start, buf_end,c); res++; } } (*putc)(pbuf_start, buf_end, '\0'); msg_error: return (res); }