29 #include <memstreams.h> 37 BaseSequentialStream *chp;
42 size_wo_nul = size - 1;
48 msObjectInit(&ms, (uint8_t *)str, size_wo_nul, 0);
51 chp = (BaseSequentialStream *)(
void *)&ms;
53 retval = chvprintf(chp, fmt, ap);
82 char *buf =
calloc(len+1, 1);
102 #ifdef HAL_STDOUT_SERIAL 103 return chvprintf ((BaseSequentialStream*)&HAL_STDOUT_SERIAL, fmt, arg);
142 count =
vsscanf (buf, fmt, ap);
172 _atob (uint32_t *vp,
char *p,
int base)
174 uint32_t
value, v1, v2;
178 if (p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
183 if (base == 16 && (q = strchr (p,
'.')) != 0) {
184 if ((
unsigned)(q - p) > (
unsigned)(
sizeof(tmp) - 1))
187 strncpy (tmp, p, q - p);
189 if (!
_atob (&v1, tmp, 16))
196 if (!
_atob (&v2, q, 16))
198 *vp = (v1 << 16) + v2;
204 if (*p >=
'0' && *p <=
'9')
206 else if (*p >=
'a' && *p <=
'f')
207 digit = *p -
'a' + 10;
208 else if (*p >=
'A' && *p <=
'F')
209 digit = *p -
'A' + 10;
227 atob(uint32_t *vp,
char *p,
int base)
233 if (
_atob (&v, p, base)) {
241 #if defined(HAL_OS_FATFS_IO) && HAL_OS_FATFS_IO 246 vsscanf (
const char *buf,
const char *s, va_list
ap)
248 int count, noassign, base=0, lflag;
253 count = noassign = width = lflag = 0;
255 while (isspace ((
unsigned char)(*s)))
260 if (strchr (
"dibouxcsefg%", *s))
264 else if (*s ==
'l' || *s ==
'L')
266 else if (*s >=
'1' && *s <=
'9') {
267 for (tc = s; isdigit ((
unsigned)(*s)); s++);
268 strncpy (tmp, tc, s - tc);
270 atob (&width, tmp, 10);
275 while (isspace ((
unsigned char)(*buf)))
278 width = strcspn (buf, ISSPACE);
280 strncpy (t = va_arg (ap,
char *), buf, width);
284 }
else if (*s ==
'c') {
288 strncpy (t = va_arg (ap,
char *), buf, width);
292 }
else if (strchr (
"dobxu", *s)) {
293 while (isspace ((
unsigned char)(*buf)))
295 if (*s ==
'd' || *s ==
'u')
304 if (isspace ((
unsigned char)(*(s + 1))) || *(s + 1) == 0)
305 width = strcspn (buf, ISSPACE);
307 width = strchr (buf, *(s + 1)) - buf;
309 strncpy (tmp, buf, width);
313 atob (va_arg (ap, uint32_t *), tmp, base);
317 width = noassign = lflag = 0;
320 while (isspace ((
unsigned char)(*buf)))
331 static int vfscanf(FILE *stream,
const char *
fmt, va_list
ap);
336 int fscanf (FILE *stream,
const char *
fmt, ...)
342 count = vfscanf (stream,
fmt, ap);
350 static int vfscanf (FILE *stream,
const char *
fmt, va_list
ap)
355 if (
fgets (buf, MAXLN, stream) == 0) {
361 #endif // HAL_OS_FATFS_IO int printf(const char *fmt,...)
int vasprintf(char **strp, const char *fmt, va_list ap)
static int16_t _atob(uint32_t *vp, char *p, int base)
static char * _getbase(char *p, int *basep)
void * calloc(size_t nmemb, size_t size)
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
int(* vprintf_console_hook)(const char *fmt, va_list arg)
int sscanf(const char *buf, const char *fmt,...)
int vsscanf(const char *buf, const char *s, va_list ap)
int scanf(const char *fmt,...)
int vprintf(const char *fmt, va_list arg)
int16_t atob(uint32_t *vp, char *p, int base)
int snprintf(char *str, size_t size, const char *fmt,...)
int asprintf(char **strp, const char *fmt,...)
char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices