mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-22 17:47:04 +08:00
feat(esp8266): ets_printf supports format "%%"
This commit is contained in:
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ int __attribute__ ((weak)) ets_putc(int c)
|
|||||||
#define ALTERNATE 0x08
|
#define ALTERNATE 0x08
|
||||||
#define OUPUT_INT 0x10
|
#define OUPUT_INT 0x10
|
||||||
#define START 0x20
|
#define START 0x20
|
||||||
|
#define END 0x40
|
||||||
|
|
||||||
#define VINT_STR_MAX 10
|
#define VINT_STR_MAX 10
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ typedef union _val_cache {
|
|||||||
} val_cache_t;
|
} val_cache_t;
|
||||||
|
|
||||||
typedef struct _val_attr {
|
typedef struct _val_attr {
|
||||||
int8_t type;
|
uint8_t type;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t fillbytes;
|
uint8_t fillbytes;
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
@ -182,23 +184,10 @@ int ets_vprintf(const char *fmt, va_list va)
|
|||||||
|
|
||||||
fmt = ps;
|
fmt = ps;
|
||||||
|
|
||||||
attr.state = 0;
|
memset(&attr, 0, sizeof(val_attr_t));
|
||||||
attr.type = -1;
|
|
||||||
attr.fillbytes = 0;
|
|
||||||
attr.precision = 0;
|
|
||||||
|
|
||||||
for (; ;) {
|
for (; ;) {
|
||||||
switch (*++ps) {
|
switch (*++ps) {
|
||||||
case 'd':
|
|
||||||
case 'i':
|
|
||||||
case 'u':
|
|
||||||
case 'x':
|
|
||||||
case 'c':
|
|
||||||
case 's':
|
|
||||||
case 'p':
|
|
||||||
case '\0':
|
|
||||||
attr.type = *ps++;
|
|
||||||
break;
|
|
||||||
case '#':
|
case '#':
|
||||||
attr.state |= ALTERNATE;
|
attr.state |= ALTERNATE;
|
||||||
ps++;
|
ps++;
|
||||||
@ -220,14 +209,15 @@ int ets_vprintf(const char *fmt, va_list va)
|
|||||||
attr.state |= FILL_LEFT;
|
attr.state |= FILL_LEFT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
attr.type = -2;
|
attr.type = *ps++;
|
||||||
|
attr.state |= END;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.state |= START;
|
if (attr.state & END)
|
||||||
|
|
||||||
if (attr.type != -1)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
attr.state |= START;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (attr.type) {
|
switch (attr.type) {
|
||||||
@ -260,7 +250,13 @@ int ets_vprintf(const char *fmt, va_list va)
|
|||||||
ets_printf_buf("0x", 2);
|
ets_printf_buf("0x", 2);
|
||||||
attr.value.valcp = va_arg(va, const char *);
|
attr.value.valcp = va_arg(va, const char *);
|
||||||
ets_printf_int(&attr, 16);
|
ets_printf_int(&attr, 16);
|
||||||
|
break;
|
||||||
|
case '%':
|
||||||
|
ets_putc('%');
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
ets_putc('%');
|
||||||
|
ps = fmt + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user