diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index be7b7e40d75..d9149cfd5ca 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -1,8 +1,8 @@ /**************************************************************************** * include/nuttx/streams.h * - * Copyright (C) 2009, 2011-2012, 2014-2016 Gregory Nutt. All rights - * reserved. + * Copyright (C) 2009, 2011-2012, 2014-2016, 2019 Gregory Nutt. All + * rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,10 +44,6 @@ #include #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Types ****************************************************************************/ @@ -447,30 +443,28 @@ int lib_noflush(FAR struct lib_outstream_s *stream); int lib_snoflush(FAR struct lib_sostream_s *this); /**************************************************************************** - * Name: lib_sprintf and lib_vsprintf + * Name: lib_vsprintf * * Description: - * Stream-oriented versions of sprintf and vsprintf. + * Stream-oriented implementation that underlies printf family: printf, + * fprint, sprint, etc. * ****************************************************************************/ -int lib_sprintf(FAR struct lib_outstream_s *obj, - FAR const IPTR char *fmt, ...); int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *src, va_list ap); /**************************************************************************** - * Name: lib_sscanf and lib_vsscanf + * Name: lib_vsscanf * * Description: - * Stream-oriented versions of sscanf and vsscanf. + * Stream-oriented implementation that underlies scanf family: fscanf, + * vfscanf, sscanf, and vsscanf * ****************************************************************************/ -int lib_sscanf(FAR struct lib_instream_s *obj, - FAR const IPTR char *fmt, ...); -int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc, - FAR const IPTR char *src, va_list ap); +int lib_vscanf(FAR struct lib_instream_s *obj, FAR int *lastc, + FAR const IPTR char *src, va_list ap); #undef EXTERN #if defined(__cplusplus) diff --git a/libs/libc/stdio/Make.defs b/libs/libc/stdio/Make.defs index cd2180edb7f..2ab83833a84 100644 --- a/libs/libc/stdio/Make.defs +++ b/libs/libc/stdio/Make.defs @@ -34,16 +34,15 @@ ############################################################################ # Add the stdio C files to the build -# This first group of C files do not depend on having file descriptors or -# C streams. +# This first group of C files do not depend on having C streams. CSRCS += lib_fileno.c lib_printf.c lib_sprintf.c lib_asprintf.c -CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_vasprintf.c -CSRCS += lib_vsnprintf.c lib_dprintf.c lib_vdprintf.c +CSRCS += lib_snprintf.c lib_vsprintf.c lib_vasprintf.c lib_vsnprintf.c +CSRCS += lib_dprintf.c lib_vdprintf.c CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c CSRCS += lib_memsostream.c lib_lowoutstream.c CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c -CSRCS += lib_sscanf.c lib_vsscanf.c lib_libsscanf.c lib_libnoflush.c +CSRCS += lib_sscanf.c lib_vsscanf.c lib_libvscanf.c lib_libnoflush.c CSRCS += lib_libsnoflush.c ifeq ($(CONFIG_NANO_PRINTF),y) @@ -62,12 +61,7 @@ CSRCS += lib_libvsprintf.c endif -# The remaining sources files depend upon file descriptors - -CSRCS += lib_rawinstream.c lib_rawoutstream.c lib_rawsistream.c -CSRCS += lib_rawsostream.c lib_remove.c - -# And these depend upon both file descriptors and C streams +# The remaining sources files depend upon C streams ifneq ($(CONFIG_NFILE_STREAMS),0) @@ -79,7 +73,9 @@ CSRCS += lib_rdflush.c lib_wrflush.c lib_fputc.c lib_puts.c lib_fputs.c CSRCS += lib_ungetc.c lib_vprintf.c lib_fprintf.c lib_vfprintf.c CSRCS += lib_stdinstream.c lib_stdoutstream.c lib_stdsistream.c CSRCS += lib_stdsostream.c lib_perror.c lib_feof.c lib_ferror.c -CSRCS += lib_clearerr.c lib_scanf.c lib_fscanf.c lib_vfscanf.c +CSRCS += lib_rawinstream.c lib_rawoutstream.c lib_rawsistream.c +CSRCS += lib_rawsostream.c lib_remove.c lib_clearerr.c lib_scanf.c +CSRCS += lib_fscanf.c lib_vfscanf.c endif diff --git a/libs/libc/stdio/lib_libsscanf.c b/libs/libc/stdio/lib_libvscanf.c similarity index 98% rename from libs/libc/stdio/lib_libsscanf.c rename to libs/libc/stdio/lib_libvscanf.c index f744dc89326..fac8e124111 100644 --- a/libs/libc/stdio/lib_libsscanf.c +++ b/libs/libc/stdio/lib_libvscanf.c @@ -200,34 +200,15 @@ doexit: ****************************************************************************/ /**************************************************************************** - * Name: lib_sscanf - * - * Description: - * Stream-oriented version of sscanf. - * - ****************************************************************************/ - -int lib_sscanf(FAR struct lib_instream_s *obj, FAR const IPTR char *fmt, ...) -{ - va_list ap; - int count; - - va_start(ap, fmt); - count = lib_vsscanf(obj, NULL, fmt, ap); - va_end(ap); - return count; -} - -/**************************************************************************** - * Name: lib_vsscanf + * Name: lib_vscanf * * Description: * Stream-oriented version of vsscanf. * ****************************************************************************/ -int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc, - FAR const IPTR char *fmt, va_list ap) +int lib_vscanf(FAR struct lib_instream_s *obj, FAR int *lastc, + FAR const IPTR char *fmt, va_list ap) { int c; FAR char *tv; diff --git a/libs/libc/stdio/lib_vfscanf.c b/libs/libc/stdio/lib_vfscanf.c index 3f2c1a3b2ae..0bb55985ba6 100644 --- a/libs/libc/stdio/lib_vfscanf.c +++ b/libs/libc/stdio/lib_vfscanf.c @@ -58,20 +58,20 @@ int vfscanf(FAR FILE *stream, FAR const IPTR char *fmt, va_list ap) if (stream) { - /* Wrap the stream in a stream object and let lib_vsscanf do the work. */ + /* Wrap the stream in a stream object and let lib_vscanf do the work. */ lib_stdinstream(&stdinstream, stream); - /* Hold the stream semaphore throughout the lib_vsscanf call so that + /* Hold the stream semaphore throughout the lib_vscanf call so that * this thread can get its entire message out before being pre-empted by * the next thread. */ lib_take_semaphore(stream); - n = lib_vsscanf(&stdinstream.public, &lastc, fmt, ap); + n = lib_vscanf(&stdinstream.public, &lastc, fmt, ap); - /* The lib_vsscanf function reads always one character more, this + /* The lib_vscanf function reads always one character more, this * character needs to be written back. */ diff --git a/libs/libc/stdio/lib_libsprintf.c b/libs/libc/stdio/lib_vsscanf.c similarity index 76% rename from libs/libc/stdio/lib_libsprintf.c rename to libs/libc/stdio/lib_vsscanf.c index 4d92143ec20..2e4b90647db 100644 --- a/libs/libc/stdio/lib_libsprintf.c +++ b/libs/libc/stdio/lib_vsscanf.c @@ -1,8 +1,8 @@ /**************************************************************************** - * libs/libc/stdio/lib_libsprintf.c + * libs/libc/stdio/lib_vscanf.c * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,27 +37,33 @@ * Included Files ****************************************************************************/ +#include + #include +#include + +#include + #include "libc.h" /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: lib_sprintf - ****************************************************************************/ - -int lib_sprintf(FAR struct lib_outstream_s *obj, FAR const IPTR char *fmt, - ...) +int vsscanf(FAR const char *buf, FAR const char *fmt, va_list ap) { - va_list ap; - int n; + struct lib_meminstream_s meminstream; + int n; - /* Let lib_vsprintf do the real work */ + /* Initialize a memory stream to freadm from the buffer */ - va_start(ap, fmt); - n = lib_vsprintf(obj, fmt, ap); - va_end(ap); + lib_meminstream((FAR struct lib_meminstream_s *)&meminstream, buf, + LIB_BUFLEN_UNKNOWN); + + /* Then let lib_vscanf do the real work */ + + + n = lib_vscanf((FAR struct lib_instream_s *)&meminstream.public, NULL, + fmt, ap); return n; }