1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/fmt: uncrustify

This commit is contained in:
Marian Buschsieweke 2022-06-02 15:31:13 +02:00
parent 68dcf27eab
commit ceeb28fb69
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -74,6 +74,7 @@ size_t fmt_byte_hex(char *out, uint8_t byte)
size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n) size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n)
{ {
size_t len = n * 2; size_t len = n * 2;
if (out) { if (out) {
while (n--) { while (n--) {
out += fmt_byte_hex(out, *ptr++); out += fmt_byte_hex(out, *ptr++);
@ -86,7 +87,8 @@ size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n)
size_t fmt_strlen(const char *str) size_t fmt_strlen(const char *str)
{ {
const char *tmp = str; const char *tmp = str;
while(*tmp) {
while (*tmp) {
tmp++; tmp++;
} }
return (tmp - str); return (tmp - str);
@ -95,7 +97,8 @@ size_t fmt_strlen(const char *str)
size_t fmt_strnlen(const char *str, size_t maxlen) size_t fmt_strnlen(const char *str, size_t maxlen)
{ {
const char *tmp = str; const char *tmp = str;
while(*tmp && maxlen--) {
while (*tmp && maxlen--) {
tmp++; tmp++;
} }
return (tmp - str); return (tmp - str);
@ -104,9 +107,11 @@ size_t fmt_strnlen(const char *str, size_t maxlen)
size_t fmt_str(char *out, const char *str) size_t fmt_str(char *out, const char *str)
{ {
int len = 0; int len = 0;
if (!out) { if (!out) {
len = fmt_strlen(str); len = fmt_strlen(str);
} else { }
else {
char c; char c;
while ((c = *str++)) { while ((c = *str++)) {
*out++ = c; *out++ = c;
@ -119,10 +124,11 @@ size_t fmt_str(char *out, const char *str)
size_t fmt_bytes_hex_reverse(char *out, const uint8_t *ptr, size_t n) size_t fmt_bytes_hex_reverse(char *out, const uint8_t *ptr, size_t n)
{ {
size_t i = n; size_t i = n;
while (i--) { while (i--) {
out += fmt_byte_hex(out, ptr[i]); out += fmt_byte_hex(out, ptr[i]);
} }
return (n<<1); return (n << 1);
} }
static uint8_t _byte_mod25(uint8_t x) static uint8_t _byte_mod25(uint8_t x)
@ -169,17 +175,17 @@ size_t fmt_hex_bytes(uint8_t *out, const char *hex)
size_t fmt_u16_hex(char *out, uint16_t val) size_t fmt_u16_hex(char *out, uint16_t val)
{ {
return fmt_bytes_hex_reverse(out, (uint8_t*) &val, 2); return fmt_bytes_hex_reverse(out, (uint8_t *)&val, 2);
} }
size_t fmt_u32_hex(char *out, uint32_t val) size_t fmt_u32_hex(char *out, uint32_t val)
{ {
return fmt_bytes_hex_reverse(out, (uint8_t*) &val, 4); return fmt_bytes_hex_reverse(out, (uint8_t *)&val, 4);
} }
size_t fmt_u64_hex(char *out, uint64_t val) size_t fmt_u64_hex(char *out, uint64_t val)
{ {
return fmt_bytes_hex_reverse(out, (uint8_t*) &val, 8); return fmt_bytes_hex_reverse(out, (uint8_t *)&val, 8);
} }
size_t fmt_u64_dec(char *out, uint64_t val) size_t fmt_u64_dec(char *out, uint64_t val)
@ -189,9 +195,9 @@ size_t fmt_u64_dec(char *out, uint64_t val)
size_t len = 0; size_t len = 0;
d[0] = val & 0xFFFF; d[0] = val & 0xFFFF;
d[1] = (val>>16) & 0xFFFF; d[1] = (val >> 16) & 0xFFFF;
d[2] = (val>>32) & 0xFFFF; d[2] = (val >> 32) & 0xFFFF;
d[3] = (val>>48) & 0xFFFF; d[3] = (val >> 48) & 0xFFFF;
d[0] = 656 * d[3] + 7296 * d[2] + 5536 * d[1] + d[0]; d[0] = 656 * d[3] + 7296 * d[2] + 5536 * d[1] + d[0];
q = d[0] / 10000; q = d[0] / 10000;
@ -223,11 +229,11 @@ size_t fmt_u64_dec(char *out, uint64_t val)
if (out) { if (out) {
out += len; out += len;
memset(out, '0', total_len - len); memset(out, '0', total_len - len);
while(first) { while (first) {
first--; first--;
if (d[first]) { if (d[first]) {
size_t tmp = fmt_u32_dec(NULL, d[first]); size_t tmp = fmt_u32_dec(NULL, d[first]);
fmt_u32_dec(out+(4-tmp), d[first]); fmt_u32_dec(out + (4 - tmp), d[first]);
} }
out += 4; out += 4;
} }
@ -270,6 +276,7 @@ size_t fmt_s64_dec(char *out, int64_t val)
{ {
unsigned negative = (val < 0); unsigned negative = (val < 0);
uint64_t sval; uint64_t sval;
if (negative) { if (negative) {
if (out) { if (out) {
*out++ = '-'; *out++ = '-';
@ -286,6 +293,7 @@ size_t fmt_s32_dec(char *out, int32_t val)
{ {
unsigned negative = (val < 0); unsigned negative = (val < 0);
uint32_t sval; uint32_t sval;
if (negative) { if (negative) {
if (out) { if (out) {
*out++ = '-'; *out++ = '-';
@ -374,7 +382,7 @@ size_t fmt_float(char *out, float f, unsigned precision)
f = -f; f = -f;
} }
integer = (uint32_t) f; integer = (uint32_t)f;
f -= integer; f -= integer;
uint32_t fraction = f * _tenmap[precision]; uint32_t fraction = f * _tenmap[precision];
@ -413,9 +421,9 @@ size_t fmt_lpad(char *out, size_t in_len, size_t pad_len, char pad_char)
} }
else { else {
char *pos = out + pad_len - 1; char *pos = out + pad_len - 1;
out += in_len -1; out += in_len - 1;
while(in_len--) { while (in_len--) {
*pos-- = *out--; *pos-- = *out--;
} }
@ -460,7 +468,8 @@ size_t fmt_to_lower(char *out, const char *str)
uint32_t scn_u32_dec(const char *str, size_t n) uint32_t scn_u32_dec(const char *str, size_t n)
{ {
uint32_t res = 0; uint32_t res = 0;
while(n--) {
while (n--) {
char c = *str++; char c = *str++;
if (!fmt_is_digit(c)) { if (!fmt_is_digit(c)) {
break; break;
@ -527,6 +536,7 @@ void print_u32_dec(uint32_t val)
{ {
char buf[10]; /* "4294967295" */ char buf[10]; /* "4294967295" */
size_t len = fmt_u32_dec(buf, val); size_t len = fmt_u32_dec(buf, val);
print(buf, len); print(buf, len);
} }
@ -534,12 +544,14 @@ void print_s32_dec(int32_t val)
{ {
char buf[11]; /* "-2147483648" */ char buf[11]; /* "-2147483648" */
size_t len = fmt_s32_dec(buf, val); size_t len = fmt_s32_dec(buf, val);
print(buf, len); print(buf, len);
} }
void print_byte_hex(uint8_t byte) void print_byte_hex(uint8_t byte)
{ {
char buf[2]; char buf[2];
fmt_byte_hex(buf, byte); fmt_byte_hex(buf, byte);
print(buf, sizeof(buf)); print(buf, sizeof(buf));
} }
@ -547,13 +559,14 @@ void print_byte_hex(uint8_t byte)
void print_u32_hex(uint32_t val) void print_u32_hex(uint32_t val)
{ {
char buf[8]; char buf[8];
fmt_u32_hex(buf, val); fmt_u32_hex(buf, val);
print(buf, sizeof(buf)); print(buf, sizeof(buf));
} }
void print_u64_hex(uint64_t val) void print_u64_hex(uint64_t val)
{ {
print_u32_hex(val>>32); print_u32_hex(val >> 32);
print_u32_hex(val); print_u32_hex(val);
} }
@ -561,6 +574,7 @@ void print_u64_dec(uint64_t val)
{ {
char buf[20]; /* "18446744073709551615" */ char buf[20]; /* "18446744073709551615" */
size_t len = fmt_u64_dec(buf, val); size_t len = fmt_u64_dec(buf, val);
print(buf, len); print(buf, len);
} }
@ -568,6 +582,7 @@ void print_s64_dec(uint64_t val)
{ {
char buf[20]; /* "-9223372036854775808" */ char buf[20]; /* "-9223372036854775808" */
size_t len = fmt_s64_dec(buf, val); size_t len = fmt_s64_dec(buf, val);
print(buf, len); print(buf, len);
} }
@ -575,10 +590,11 @@ void print_float(float f, unsigned precision)
{ {
char buf[19]; char buf[19];
size_t len = fmt_float(buf, f, precision); size_t len = fmt_float(buf, f, precision);
print(buf, len); print(buf, len);
} }
void print_str(const char* str) void print_str(const char *str)
{ {
print(str, fmt_strlen(str)); print(str, fmt_strlen(str));
} }