diff --git a/ChangeLog b/ChangeLog index a314430d497aa2020b1e1099db5b4a11276272d6..d1c865a9e817fcda3c224903185c756aa89efac3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -754,3 +754,6 @@ 0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * lib/lib_*stream.c: Extend internal stream logic to support incoming streams. + + diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index a175a2d15e32807eacf742e613f21b3435b4d5e3..172f27998c3bc419fe987c5a3e3c9b2c8c4a4f66 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: May 29, 2009</p> + <p>Last Updated: May 30, 2009</p> </td> </tr> </table> @@ -1420,6 +1420,8 @@ buildroot-0.1.6 2009-xx-xx <spudmonkey@racsa.co.cr> <pre><ul> nuttx-0.4.8 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * lib/lib_*stream.c: Extend internal stream logic to support incoming streams. + pascal-0.1.3 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> buildroot-0.1.7 2009-xx-xx <spudmonkey@racsa.co.cr> diff --git a/lib/Makefile b/lib/Makefile index 47c410309c62e73d932e4e99cd752716ad07412e..32c2e620dec5bef3aa7ae92d1960bb171e148837 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -54,18 +54,19 @@ CTYPE_SRCS = STDIO_SRCS = lib_printf.c lib_rawprintf.c lib_lowprintf.c lib_dbg.c \ lib_sprintf.c lib_snprintf.c lib_libsprintf.c lib_vsprintf.c \ - lib_vsnprintf.c lib_libvsprintf.c lib_memstream.c \ - lib_lowstream.c lib_nullstream.c lib_sscanf.c + lib_vsnprintf.c lib_libvsprintf.c lib_meminstream.c \ + lib_memoutstream.c lib_lowinstream.c lib_lowoutstream.c \ + lib_nullinstream.c lib_nulloutstream.c lib_sscanf.c ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -STDIO_SRCS += lib_rawstream.c +STDIO_SRCS += lib_rawinstream.c lib_rawoutstream.c ifneq ($(CONFIG_NFILE_STREAMS),0) STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \ lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \ lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \ lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \ - lib_fprintf.c lib_vfprintf.c lib_stdstream.c + lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c endif endif diff --git a/lib/lib_internal.h b/lib/lib_internal.h index 0554db07e28f13af2a378e33ccc00b9e902ba3a1..d19812475b827baad52c7da7677b08e3ec2790db 100644 --- a/lib/lib_internal.h +++ b/lib/lib_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_internal.h * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -69,34 +69,62 @@ * to manage variable sized output. */ -struct lib_stream_s; +struct lib_instream_s; +struct lib_outstream_s; -typedef void (*lib_putc_t)(FAR struct lib_stream_s *this, int ch); +typedef int (*lib_getc_t)(FAR struct lib_instream_s *this); +typedef void (*lib_putc_t)(FAR struct lib_outstream_s *this, int ch); -struct lib_stream_s +struct lib_instream_s { - lib_putc_t put; /* Pointer to function to put one character */ - int nput; /* Total number of characters put. Written - * by put method, readable by user */ + lib_getc_t get; /* Pointer to function to get one character */ + int nget; /* Total number of characters gotten. Written + * by get method, readable by user */ }; -struct lib_memstream_s +struct lib_outstream_s { - struct lib_stream_s public; - FAR char *buffer; /* Address of first byte in the buffer */ - int buflen; /* Size of the buffer in bytes */ + lib_putc_t put; /* Pointer to function to put one character */ + int nput; /* Total number of characters put. Written + * by put method, readable by user */ }; -struct lib_stdstream_s +struct lib_meminstream_s { - struct lib_stream_s public; - FAR FILE *stream; + struct lib_instream_s public; + FAR char *buffer; /* Address of first byte in the buffer */ + int buflen; /* Size of the buffer in bytes */ }; -struct lib_rawstream_s +struct lib_memoutstream_s { - struct lib_stream_s public; - int fd; + struct lib_outstream_s public; + FAR char *buffer; /* Address of first byte in the buffer */ + int buflen; /* Size of the buffer in bytes */ +}; + +struct lib_stdinstream_s +{ + struct lib_instream_s public; + FAR FILE *stream; +}; + +struct lib_stdoutstream_s +{ + struct lib_outstream_s public; + FAR FILE *stream; +}; + +struct lib_rawoutstream_s +{ + struct lib_outstream_s public; + int fd; +}; + +struct lib_rawinstream_s +{ + struct lib_instream_s public; + int fd; }; /**************************************************************************** @@ -114,39 +142,64 @@ extern void stream_semtake(FAR struct streamlist *list); extern void stream_semgive(FAR struct streamlist *list); #endif -/* Defined in lib_memstream.c */ +/* Defined in lib_memoutstream.c */ -extern void lib_memstream(FAR struct lib_memstream_s *memstream, - FAR char *bufstart, int buflen); +extern void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, + FAR char *bufstart, int buflen); -/* Defined in lib_stdstream.c */ +/* Defined in lib_meminstream.c */ -extern void lib_stdstream(FAR struct lib_stdstream_s *stdstream, - FAR FILE *stream); +extern void lib_meminstream(FAR struct lib_meminstream_s *meminstream, + FAR char *bufstart, int buflen); -/* Defined in lib_rawstream.c */ +/* Defined in lib_stdinstream.c */ -extern void lib_rawstream(FAR struct lib_rawstream_s *rawstream, +extern void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, + FAR FILE *stream); + +/* Defined in lib_stdoutstream.c */ + +extern void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, + FAR FILE *stream); + +/* Defined in lib_rawinstream.c */ + +extern void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, + int fd); + +/* Defined in lib_rawoutstream.c */ + +extern void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd); -/* Defined in lib_lowstream.c */ +/* Defined in lib_lowinstream.c */ + +#ifdef CONFIG_ARCH_LOWGETC +extern void lib_lowinstream(FAR struct lib_instream_s *lowinstream); +#endif + +/* Defined in lib_lowoutstream.c */ #ifdef CONFIG_ARCH_LOWPUTC -extern void lib_lowstream(FAR struct lib_stream_s *rawstream); +extern void lib_lowoutstream(FAR struct lib_outstream_s *lowoutstream); #endif -/* Defined in lib_nullstream.c */ +/* Defined in lib_nullinstream.c */ + +extern void lib_nullinstream(FAR struct lib_instream_s *nullinstream); + +/* Defined in lib_nulloutstream.c */ -extern void lib_nullstream(FAR struct lib_stream_s *nullstream); +extern void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream); /* Defined in lib_libsprintf.c */ -extern int lib_sprintf (FAR struct lib_stream_s *obj, +extern int lib_sprintf (FAR struct lib_outstream_s *obj, const char *fmt, ...); /* Defined lib_libvsprintf.c */ -extern int lib_vsprintf(FAR struct lib_stream_s *obj, +extern int lib_vsprintf(FAR struct lib_outstream_s *obj, const char *src, va_list ap); /* Defined lib_rawprintf.c */ diff --git a/lib/lib_libsprintf.c b/lib/lib_libsprintf.c index 418ab7fc46aa61df4bacaed47a9b2c0b706eabaa..1f297fe45ef2947f071d912bba91f7d116e61c7c 100644 --- a/lib/lib_libsprintf.c +++ b/lib/lib_libsprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_libsprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -76,7 +76,7 @@ * Name: lib_sprintf ****************************************************************************/ -int lib_sprintf(FAR struct lib_stream_s *obj, const char *fmt, ...) +int lib_sprintf(FAR struct lib_outstream_s *obj, const char *fmt, ...) { va_list ap; int n; diff --git a/lib/lib_libvsprintf.c b/lib/lib_libvsprintf.c index ac3abc88e46bf2174788a3336fa3e72e1cd939f6..8e9742ef25a766da1be9a74b727c15f296d2f757 100644 --- a/lib/lib_libvsprintf.c +++ b/lib/lib_libvsprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib_libvsprintf.c * - * Copyright (C) 2007, 2008, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -109,7 +109,7 @@ enum /* Pointer to ASCII conversion */ #ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_stream_s *obj, ubyte flags, FAR void *p); +static void ptohex(FAR struct lib_outstream_s *obj, ubyte flags, FAR void *p); #ifndef CONFIG_NOPRINTF_FIELDWIDTH static int getsizesize(ubyte fmt, ubyte flags, FAR void *p) #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -117,11 +117,11 @@ static int getsizesize(ubyte fmt, ubyte flags, FAR void *p) /* Unsigned int to ASCII conversion */ -static void utodec(FAR struct lib_stream_s *obj, unsigned int n); -static void utohex(FAR struct lib_stream_s *obj, unsigned int n, ubyte a); -static void utooct(FAR struct lib_stream_s *obj, unsigned int n); -static void utobin(FAR struct lib_stream_s *obj, unsigned int n); -static void utoascii(FAR struct lib_stream_s *obj, ubyte fmt, +static void utodec(FAR struct lib_outstream_s *obj, unsigned int n); +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, ubyte a); +static void utooct(FAR struct lib_outstream_s *obj, unsigned int n); +static void utobin(FAR struct lib_outstream_s *obj, unsigned int n); +static void utoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned int lln); #ifndef CONFIG_NOPRINTF_FIELDWIDTH @@ -132,11 +132,11 @@ static int getusize(ubyte fmt, ubyte flags, unsigned int lln); /* Unsigned long int to ASCII conversion */ #ifdef CONFIG_LONG_IS_NOT_INT -static void lutodec(FAR struct lib_stream_s *obj, unsigned long ln); -static void lutohex(FAR struct lib_stream_s *obj, unsigned long ln, ubyte a); -static void lutooct(FAR struct lib_stream_s *obj, unsigned long ln); -static void lutobin(FAR struct lib_stream_s *obj, unsigned long ln); -static void lutoascii(FAR struct lib_stream_s *obj, ubyte fmt, +static void lutodec(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long ln, ubyte a); +static void lutooct(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutobin(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned long ln); #ifndef CONFIG_NOPRINTF_FIELDWIDTH static void lfixup(ubyte fmt, FAR ubyte *flags, long *ln); @@ -147,11 +147,11 @@ static int getlusize(ubyte fmt, FAR ubyte flags, unsigned long ln); /* Unsigned long long int to ASCII conversions */ #ifdef CONFIG_HAVE_LONG_LONG -static void llutodec(FAR struct lib_stream_s *obj, unsigned long long lln); -static void llutohex(FAR struct lib_stream_s *obj, unsigned long long lln, ubyte a); -static void llutooct(FAR struct lib_stream_s *obj, unsigned long long lln); -static void llutobin(FAR struct lib_stream_s *obj, unsigned long long lln); -static void llutoascii(FAR struct lib_stream_s *obj, ubyte fmt, +static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, ubyte a); +static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned long long lln); #ifndef CONFIG_NOPRINTF_FIELDWIDTH static void llfixup(ubyte fmt, FAR ubyte *flags, FAR long long *lln); @@ -160,9 +160,9 @@ static int getllusize(ubyte fmt, FAR ubyte flags, FAR unsigned long long lln); #endif #ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void prejustify(FAR struct lib_stream_s *obj, ubyte fmt, +static void prejustify(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, int fieldwidth, int numwidth); -static void postjustify(FAR struct lib_stream_s *obj, ubyte fmt, +static void postjustify(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, int fieldwidth, int numwidth); #endif @@ -193,7 +193,7 @@ static const char g_nullstring[] = "(null)"; ****************************************************************************/ #ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_stream_s *obj, ubyte flags, FAR void *p) +static void ptohex(FAR struct lib_outstream_s *obj, ubyte flags, FAR void *p) { union { @@ -236,11 +236,11 @@ static void ptohex(FAR struct lib_stream_s *obj, ubyte flags, FAR void *p) #ifndef CONFIG_NOPRINTF_FIELDWIDTH static int getpsize(ubyte flags, FAR void *p) { - struct lib_stream_s nullstream; - lib_nullstream(&nullstream); + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); - ptohex(&nullstream, flags, p); - return nullstream.nput; + ptohex(&nulloutstream, flags, p); + return nulloutstream.nput; } #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -250,7 +250,7 @@ static int getpsize(ubyte flags, FAR void *p) * Name: utodec ****************************************************************************/ -static void utodec(FAR struct lib_stream_s *obj, unsigned int n) +static void utodec(FAR struct lib_outstream_s *obj, unsigned int n) { unsigned int remainder = n % 10; unsigned int dividend = n / 10; @@ -267,7 +267,7 @@ static void utodec(FAR struct lib_stream_s *obj, unsigned int n) * Name: utohex ****************************************************************************/ -static void utohex(FAR struct lib_stream_s *obj, unsigned int n, ubyte a) +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, ubyte a) { boolean nonzero = FALSE; ubyte bits; @@ -300,7 +300,7 @@ static void utohex(FAR struct lib_stream_s *obj, unsigned int n, ubyte a) * Name: utooct ****************************************************************************/ -static void utooct(FAR struct lib_stream_s *obj, unsigned int n) +static void utooct(FAR struct lib_outstream_s *obj, unsigned int n) { unsigned int remainder = n & 0x7; unsigned int dividend = n >> 3; @@ -317,7 +317,7 @@ static void utooct(FAR struct lib_stream_s *obj, unsigned int n) * Name: utobin ****************************************************************************/ -static void utobin(FAR struct lib_stream_s *obj, unsigned int n) +static void utobin(FAR struct lib_outstream_s *obj, unsigned int n) { unsigned int remainder = n & 1; unsigned int dividend = n >> 1; @@ -334,7 +334,7 @@ static void utobin(FAR struct lib_stream_s *obj, unsigned int n) * Name: utoascii ****************************************************************************/ -static void utoascii(FAR struct lib_stream_s *obj, ubyte fmt, ubyte flags, unsigned int n) +static void utoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned int n) { /* Perform the integer conversion according to the format specifier */ @@ -490,11 +490,11 @@ static void fixup(ubyte fmt, FAR ubyte *flags, FAR int *n) static int getusize(ubyte fmt, ubyte flags, unsigned int n) { - struct lib_stream_s nullstream; - lib_nullstream(&nullstream); + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); - utoascii(&nullstream, fmt, flags, n); - return nullstream.nput; + utoascii(&nulloutstream, fmt, flags, n); + return nulloutstream.nput; } #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -503,7 +503,7 @@ static int getusize(ubyte fmt, ubyte flags, unsigned int n) * Name: lutodec ****************************************************************************/ -static void lutodec(FAR struct lib_stream_s *obj, unsigned long n) +static void lutodec(FAR struct lib_outstream_s *obj, unsigned long n) { unsigned int remainder = n % 10; unsigned long dividend = n / 10; @@ -520,7 +520,7 @@ static void lutodec(FAR struct lib_stream_s *obj, unsigned long n) * Name: lutohex ****************************************************************************/ -static void lutohex(FAR struct lib_stream_s *obj, unsigned long n, ubyte a) +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long n, ubyte a) { boolean nonzero = FALSE; ubyte bits; @@ -553,7 +553,7 @@ static void lutohex(FAR struct lib_stream_s *obj, unsigned long n, ubyte a) * Name: lutooct ****************************************************************************/ -static void lutooct(FAR struct lib_stream_s *obj, unsigned long n) +static void lutooct(FAR struct lib_outstream_s *obj, unsigned long n) { unsigned int remainder = n & 0x7; unsigned long dividend = n >> 3; @@ -570,7 +570,7 @@ static void lutooct(FAR struct lib_stream_s *obj, unsigned long n) * Name: lutobin ****************************************************************************/ -static void lutobin(FAR struct lib_stream_s *obj, unsigned long n) +static void lutobin(FAR struct lib_outstream_s *obj, unsigned long n) { unsigned int remainder = n & 1; unsigned long dividend = n >> 1; @@ -587,7 +587,7 @@ static void lutobin(FAR struct lib_stream_s *obj, unsigned long n) * Name: lutoascii ****************************************************************************/ -static void lutoascii(FAR struct lib_stream_s *obj, ubyte fmt, ubyte flags, unsigned long ln) +static void lutoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned long ln) { /* Perform the integer conversion according to the format specifier */ @@ -738,11 +738,11 @@ static void lfixup(ubyte fmt, FAR ubyte *flags, FAR long *ln) static int getlusize(ubyte fmt, ubyte flags, unsigned long ln) { - struct lib_stream_s nullstream; - lib_nullstream(&nullstream); + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); - lutoascii(&nullstream, fmt, flags, ln); - return nullstream.nput; + lutoascii(&nulloutstream, fmt, flags, ln); + return nulloutstream.nput; } #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -753,7 +753,7 @@ static int getlusize(ubyte fmt, ubyte flags, unsigned long ln) * Name: llutodec ****************************************************************************/ -static void llutodec(FAR struct lib_stream_s *obj, unsigned long long n) +static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long n) { unsigned int remainder = n % 10; unsigned long long dividend = n / 10; @@ -770,7 +770,7 @@ static void llutodec(FAR struct lib_stream_s *obj, unsigned long long n) * Name: llutohex ****************************************************************************/ -static void llutohex(FAR struct lib_stream_s *obj, unsigned long long n, ubyte a) +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long n, ubyte a) { boolean nonzero = FALSE; ubyte bits; @@ -803,7 +803,7 @@ static void llutohex(FAR struct lib_stream_s *obj, unsigned long long n, ubyte a * Name: llutooct ****************************************************************************/ -static void llutooct(FAR struct lib_stream_s *obj, unsigned long long n) +static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long n) { unsigned int remainder = n & 0x7; unsigned long long dividend = n >> 3; @@ -820,7 +820,7 @@ static void llutooct(FAR struct lib_stream_s *obj, unsigned long long n) * Name: llutobin ****************************************************************************/ -static void llutobin(FAR struct lib_stream_s *obj, unsigned long long n) +static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long n) { unsigned int remainder = n & 1; unsigned long long dividend = n >> 1; @@ -837,7 +837,7 @@ static void llutobin(FAR struct lib_stream_s *obj, unsigned long long n) * Name: llutoascii ****************************************************************************/ -static void llutoascii(FAR struct lib_stream_s *obj, ubyte fmt, ubyte flags, unsigned long long lln) +static void llutoascii(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, unsigned long long lln) { /* Perform the integer conversion according to the format specifier */ @@ -988,12 +988,12 @@ static void llfixup(ubyte fmt, FAR ubyte *flags, FAR long long *lln) static int getllusize(ubyte fmt, ubyte flags, unsigned long long lln) { - struct lib_stream_s nullstream; - lib_nullstream(&nullstream); + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); - llutoascii(&nullstream, fmt, flags, lln); - return nullstream.nput; + llutoascii(&nulloutstream, fmt, flags, lln); + return nulloutstream.nput; } #endif /* CONFIG_NOPRINTF_FIELDWIDTH */ @@ -1004,7 +1004,7 @@ static int getllusize(ubyte fmt, ubyte flags, unsigned long long lln) ****************************************************************************/ #ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void prejustify(FAR struct lib_stream_s *obj, ubyte fmt, +static void prejustify(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, int fieldwidth, int numwidth) { int i; @@ -1070,7 +1070,7 @@ static void prejustify(FAR struct lib_stream_s *obj, ubyte fmt, ****************************************************************************/ #ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void postjustify(FAR struct lib_stream_s *obj, ubyte fmt, +static void postjustify(FAR struct lib_outstream_s *obj, ubyte fmt, ubyte flags, int fieldwidth, int numwidth) { int i; @@ -1107,7 +1107,7 @@ static void postjustify(FAR struct lib_stream_s *obj, ubyte fmt, * lib_vsprintf ****************************************************************************/ -int lib_vsprintf(FAR struct lib_stream_s *obj, const char *src, va_list ap) +int lib_vsprintf(FAR struct lib_outstream_s *obj, const char *src, va_list ap) { char *ptmp; #ifndef CONFIG_NOPRINTF_FIELDWIDTH diff --git a/lib/lib_lowinstream.c b/lib/lib_lowinstream.c new file mode 100644 index 0000000000000000000000000000000000000000..f92fdb5ad0ec931b6b9c33a0dfd7fa62ecbcf3a7 --- /dev/null +++ b/lib/lib_lowinstream.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * lib_lowinstream.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifdef CONFIG_ARCH_LOWGETC + +#include <stdio.h> +#include <errno.h> +#include <nuttx/arch.h> + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lowinstream_getc + ****************************************************************************/ + +static int lowinstream_getc(FAR struct lib_outstream_s *this) +{ + if (this && up_getc(ch) != EOF) + { + this->nget++; + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_lowinstream + ****************************************************************************/ + +void lib_lowinstream(FAR struct lib_outstream_s *stream) +{ + stream->get = lowinstream_getc; + stream->nget = 0; +} + +#endif /* CONFIG_ARCH_LOWGETC */ diff --git a/lib/lib_lowstream.c b/lib/lib_lowoutstream.c similarity index 90% rename from lib/lib_lowstream.c rename to lib/lib_lowoutstream.c index 0045ed7cd527e38ad8768906830c49b52686536d..dad84ce85145438895ebbf96124ff43751c2d711 100644 --- a/lib/lib_lowstream.c +++ b/lib/lib_lowoutstream.c @@ -1,7 +1,7 @@ /**************************************************************************** - * lib_lowstream.c + * lib_lowoutstream.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -52,10 +52,10 @@ ****************************************************************************/ /**************************************************************************** - * Name: lowstream_putc + * Name: lowoutstream_putc ****************************************************************************/ -static void lowstream_putc(FAR struct lib_stream_s *this, int ch) +static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch) { if (this && up_putc(ch) != EOF) { @@ -68,12 +68,12 @@ static void lowstream_putc(FAR struct lib_stream_s *this, int ch) ****************************************************************************/ /**************************************************************************** - * Name: lib_lowstream + * Name: lib_lowoutstream ****************************************************************************/ -void lib_lowstream(FAR struct lib_stream_s *stream) +void lib_lowoutstream(FAR struct lib_outstream_s *stream) { - stream->put = lowstream_putc; + stream->put = lowoutstream_putc; stream->nput = 0; } diff --git a/lib/lib_lowprintf.c b/lib/lib_lowprintf.c index 0059389dfcd88173679c60f145b4e7258519664d..1b071331ffc8cb34e723bb3e0883d6076ee6e97a 100644 --- a/lib/lib_lowprintf.c +++ b/lib/lib_lowprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_lowprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -86,14 +86,14 @@ int lib_lowvprintf(const char *fmt, va_list ap) { - struct lib_stream_s stream; + struct lib_outstream_s stream; /* Wrap the stdout in a stream object and let lib_vsprintf * do the work. */ - lib_lowstream((FAR struct lib_stream_s *)&stream); - return lib_vsprintf((FAR struct lib_stream_s *)&stream, fmt, ap); + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); } /**************************************************************************** diff --git a/lib/lib_meminstream.c b/lib/lib_meminstream.c new file mode 100644 index 0000000000000000000000000000000000000000..ccbf1cec42335cb6f51634ee2efbd0cc8a34150a --- /dev/null +++ b/lib/lib_meminstream.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * lib/lib_meminstream.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: meminstream_getc + ****************************************************************************/ + +static int meminstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this; + int ret; + + if (this && this->nget < mthis->buflen - 1) + { + ret = mthis->buffer[this->nget]; + this->nget++; + } + else + { + ret = EOF; + } + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_meminstream + ****************************************************************************/ + +void lib_meminstream(FAR struct lib_meminstream_s *meminstream, + FAR char *bufstart, int buflen) +{ + meminstream->public.get = meminstream_getc; + meminstream->public.nget = 0; /* Will be buffer index */ + meminstream->buffer = bufstart; /* Start of buffer */ + meminstream->buflen = buflen; /* Length of the buffer */ +} + + diff --git a/lib/lib_memstream.c b/lib/lib_memoutstream.c similarity index 80% rename from lib/lib_memstream.c rename to lib/lib_memoutstream.c index 937408be4189da107dcdd05a902bd34b643376d2..7e6412304a7f2480d9d33a6781808de1e5dbcd82 100644 --- a/lib/lib_memstream.c +++ b/lib/lib_memoutstream.c @@ -1,7 +1,7 @@ /**************************************************************************** - * lib/lib_memstream.c + * lib/lib_memoutstream.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -44,12 +44,12 @@ ****************************************************************************/ /**************************************************************************** - * Name: memstream_putc + * Name: memoutstream_putc ****************************************************************************/ -static void memstream_putc(FAR struct lib_stream_s *this, int ch) +static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch) { - FAR struct lib_memstream_s *mthis = (FAR struct lib_memstream_s *)this; + FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this; if (this && this->nput < mthis->buflen - 1) { mthis->buffer[this->nput] = ch; @@ -63,16 +63,16 @@ static void memstream_putc(FAR struct lib_stream_s *this, int ch) ****************************************************************************/ /**************************************************************************** - * Name: lib_memstream + * Name: lib_memoutstream ****************************************************************************/ -void lib_memstream(FAR struct lib_memstream_s *memstream, - FAR char *bufstart, int buflen) +void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, + FAR char *bufstart, int buflen) { - memstream->public.put = memstream_putc; - memstream->public.nput = 0; /* Will be buffer index */ - memstream->buffer = bufstart; /* Start of buffer */ - memstream->buflen = buflen - 1; /* Save space for null terminator */ + memoutstream->public.put = memoutstream_putc; + memoutstream->public.nput = 0; /* Will be buffer index */ + memoutstream->buffer = bufstart; /* Start of buffer */ + memoutstream->buflen = buflen - 1; /* Save space for null terminator */ } diff --git a/lib/lib_nullinstream.c b/lib/lib_nullinstream.c new file mode 100644 index 0000000000000000000000000000000000000000..dec0a191e1bd8e9e9edf3aa06a12f6343fe845e3 --- /dev/null +++ b/lib/lib_nullinstream.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * lib/lib_nullinstream.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdio.h> +#include <errno.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int nullinstream_getc(FAR struct lib_instream_s *this) +{ + this->nget++; + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void lib_nullinstream(FAR struct lib_instream_s *nullinstream) +{ + nullinstream->get = nullinstream_getc; + nullinstream->nget = 0; +} + diff --git a/lib/lib_nullstream.c b/lib/lib_nulloutstream.c similarity index 88% rename from lib/lib_nullstream.c rename to lib/lib_nulloutstream.c index 52ba09f68df4e4a6a17c34d55bc9a13f14645d62..f2638fbcfb9219d057a76f234239eb2efede4671 100644 --- a/lib/lib_nullstream.c +++ b/lib/lib_nulloutstream.c @@ -1,7 +1,7 @@ /**************************************************************************** - * lib/lib_nullstream.c + * lib/lib_nulloutstream.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ * Private Functions ****************************************************************************/ -static void nullstream_putc(FAR struct lib_stream_s *this, int ch) +static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch) { this->nput++; } @@ -54,9 +54,9 @@ static void nullstream_putc(FAR struct lib_stream_s *this, int ch) * Public Functions ****************************************************************************/ -void lib_nullstream(FAR struct lib_stream_s *nullstream) +void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream) { - nullstream->put = nullstream_putc; - nullstream->nput = 0; + nulloutstream->put = nulloutstream_putc; + nulloutstream->nput = 0; } diff --git a/lib/lib_rawinstream.c b/lib/lib_rawinstream.c new file mode 100644 index 0000000000000000000000000000000000000000..39cfa0b1ebc99c7fdc168844f907dfc4adeb2465 --- /dev/null +++ b/lib/lib_rawinstream.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * lib/lib_rawinstream.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <unistd.h> +#include <errno.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rawinstream_getc + ****************************************************************************/ + +static int rawinstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this; + char ch; + + if (this && rthis->fd >= 0) + { + int nwritten; + do + { + nwritten = read(rthis->fd, &ch, 1); + if (nwritten == 1) + { + this->nget++; + return ch; + } + } + while (nwritten < 0 && errno == EINTR); + } + + return EOF; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_rawinstream + ****************************************************************************/ + +void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, int fd) +{ + rawinstream->public.get = rawinstream_getc; + rawinstream->public.nget = 0; + rawinstream->fd = fd; +} + diff --git a/lib/lib_rawstream.c b/lib/lib_rawoutstream.c similarity index 85% rename from lib/lib_rawstream.c rename to lib/lib_rawoutstream.c index 068199db5ac757dca3983970c8f64aa985b98d7a..1772f3927f81036fdd0a55fdd3067795ae3d2bcc 100644 --- a/lib/lib_rawstream.c +++ b/lib/lib_rawoutstream.c @@ -1,7 +1,7 @@ /**************************************************************************** - * lib/lib_rawstream.c + * lib/lib_rawoutstream.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -46,12 +46,12 @@ ****************************************************************************/ /**************************************************************************** - * Name: rawstream_putc + * Name: rawoutstream_putc ****************************************************************************/ -static void rawstream_putc(FAR struct lib_stream_s *this, int ch) +static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) { - FAR struct lib_rawstream_s *rthis = (FAR struct lib_rawstream_s *)this; + FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; char buffer = ch; if (this && rthis->fd >= 0) { @@ -73,13 +73,13 @@ static void rawstream_putc(FAR struct lib_stream_s *this, int ch) ****************************************************************************/ /**************************************************************************** - * Name: lib_rawstream + * Name: lib_rawoutstream ****************************************************************************/ -void lib_rawstream(FAR struct lib_rawstream_s *rawstream, int fd) +void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd) { - rawstream->public.put = rawstream_putc; - rawstream->public.nput = 0; - rawstream->fd = fd; + rawoutstream->public.put = rawoutstream_putc; + rawoutstream->public.nput = 0; + rawoutstream->fd = fd; } diff --git a/lib/lib_rawprintf.c b/lib/lib_rawprintf.c index 7b61c299dccd9fac3c999ab8a35b095e3a00ded4..9999b8ecc68f82e6af7d96668b402072a15f14ee 100644 --- a/lib/lib_rawprintf.c +++ b/lib/lib_rawprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_rawprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -85,25 +85,25 @@ int lib_rawvprintf(const char *fmt, va_list ap) { #if CONFIG_NFILE_DESCRIPTORS > 0 - struct lib_rawstream_s rawstream; + struct lib_rawoutstream_s rawoutstream; /* Wrap the stdout in a stream object and let lib_vsprintf * do the work. */ - lib_rawstream(&rawstream, 1); - return lib_vsprintf(&rawstream.public, fmt, ap); + lib_rawoutstream(&rawoutstream, 1); + return lib_vsprintf(&rawoutstream.public, fmt, ap); #elif defined(CONFIG_ARCH_LOWPUTC) - struct lib_stream_s stream; + struct lib_outstream_s stream; /* Wrap the low-level output in a stream object and let lib_vsprintf * do the work. */ - lib_lowstream((FAR struct lib_stream_s *)&stream); - return lib_vsprintf((FAR struct lib_stream_s *)&stream, fmt, ap); + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); #else return 0; diff --git a/lib/lib_snprintf.c b/lib/lib_snprintf.c index e1673161f1df9785336498b06ac0e2f01be92781..ecb4289993a371809cc133f09b87e6c597c67ae7 100644 --- a/lib/lib_snprintf.c +++ b/lib/lib_snprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_snprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -78,18 +78,18 @@ int snprintf(FAR char *buf, size_t size, const char *format, ...) { - struct lib_memstream_s memstream; + struct lib_memoutstream_s memoutstream; va_list ap; int n; /* Initialize a memory stream to write to the buffer */ - lib_memstream((FAR struct lib_memstream_s *)&memstream, buf, size); + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); /* Then let lib_vsprintf do the real work */ va_start(ap, format); - n = lib_vsprintf((FAR struct lib_stream_s *)&memstream.public, format, ap); + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); va_end(ap); return n; } diff --git a/lib/lib_sprintf.c b/lib/lib_sprintf.c index 0a5496b8822bb87afed9b2048e2d7eb3c6c004df..f5efe32354127bff05c85f0ad9a19f6b7bd4a4ab 100644 --- a/lib/lib_sprintf.c +++ b/lib/lib_sprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_sprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -78,18 +78,18 @@ int sprintf (FAR char *buf, const char *fmt, ...) { - struct lib_memstream_s memstream; + struct lib_memoutstream_s memoutstream; va_list ap; int n; /* Initialize a memory stream to write to the buffer */ - lib_memstream((FAR struct lib_memstream_s *)&memstream, buf, LIB_BUFLEN_UNKNOWN); + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, LIB_BUFLEN_UNKNOWN); /* Then let lib_vsprintf do the real work */ va_start(ap, fmt); - n = lib_vsprintf((FAR struct lib_stream_s *)&memstream.public, fmt, ap); + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap); va_end(ap); return n; } diff --git a/lib/lib_stdinstream.c b/lib/lib_stdinstream.c new file mode 100644 index 0000000000000000000000000000000000000000..1833f3a7ae993f8c80de03bd1dbe11e04ad668e9 --- /dev/null +++ b/lib/lib_stdinstream.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * lib/lib_stdinstream.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stdinstream_getc + ****************************************************************************/ + +static int stdinstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this; + int ret; + + if (this) + { + ret = getc(sthis->stream); + if (ret != EOF) + { + this->nget++; + } + } + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_stdinstream + ****************************************************************************/ + +void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, + FAR FILE *stream) +{ + stdinstream->public.get = stdinstream_getc; + stdinstream->public.nget = 0; + stdinstream->stream = stream; +} + + diff --git a/lib/lib_stdstream.c b/lib/lib_stdoutstream.c similarity index 85% rename from lib/lib_stdstream.c rename to lib/lib_stdoutstream.c index 9c696a97df926950243b753edd1ef41b998a9a6e..66864d07c325a50daecdb8a5fe89fcff696c02a4 100644 --- a/lib/lib_stdstream.c +++ b/lib/lib_stdoutstream.c @@ -1,7 +1,7 @@ /**************************************************************************** - * lib/lib_stdstream.c + * lib/lib_stdoutstream.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -44,12 +44,12 @@ ****************************************************************************/ /**************************************************************************** - * Name: stdstream_putc + * Name: stdoutstream_putc ****************************************************************************/ -static void stdstream_putc(FAR struct lib_stream_s *this, int ch) +static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) { - FAR struct lib_stdstream_s *sthis = (FAR struct lib_stdstream_s *)this; + FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; if (this) { if (putc(ch, sthis->stream) != EOF) @@ -64,15 +64,15 @@ static void stdstream_putc(FAR struct lib_stream_s *this, int ch) ****************************************************************************/ /**************************************************************************** - * Name: lib_stdstream + * Name: lib_stdoutstream ****************************************************************************/ -void lib_stdstream(FAR struct lib_stdstream_s *stdstream, +void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, FAR FILE *stream) { - stdstream->public.put = stdstream_putc; - stdstream->public.nput = 0; - stdstream->stream = stream; + stdoutstream->public.put = stdoutstream_putc; + stdoutstream->public.nput = 0; + stdoutstream->stream = stream; } diff --git a/lib/lib_vfprintf.c b/lib/lib_vfprintf.c index 197b27856bdfec7e8c2c049bb8334ad2a673bad0..38da9c0286f084bfc2718901dd40da66bbdf3f88 100644 --- a/lib/lib_vfprintf.c +++ b/lib/lib_vfprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_vfprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -77,7 +77,7 @@ int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) { - struct lib_stdstream_s stdstream; + struct lib_stdoutstream_s stdoutstream; int n = ERROR; if (stream) @@ -86,7 +86,7 @@ int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) * do the work. */ - lib_stdstream(&stdstream, stream); + lib_stdoutstream(&stdoutstream, stream); /* Hold the stream semaphore throughout the lib_vsprintf * call so that this thread can get its entire message out @@ -94,7 +94,7 @@ int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) */ lib_take_semaphore(stream); - n = lib_vsprintf(&stdstream.public, fmt, ap); + n = lib_vsprintf(&stdoutstream.public, fmt, ap); lib_give_semaphore(stream); } return n; diff --git a/lib/lib_vsnprintf.c b/lib/lib_vsnprintf.c index 3467cfd500e09ccd30c7dd178c26bcb275dc8ec8..ea6580bd4f0c5139ec13aca6af57e29f335680d4 100644 --- a/lib/lib_vsnprintf.c +++ b/lib/lib_vsnprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_vsnprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -78,15 +78,15 @@ int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap) { - struct lib_memstream_s memstream; + struct lib_memoutstream_s memoutstream; int n; /* Initialize a memory stream to write to the buffer */ - lib_memstream((FAR struct lib_memstream_s *)&memstream, buf, size); + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); /* Then let lib_vsprintf do the real work */ - n = lib_vsprintf((FAR struct lib_stream_s *)&memstream.public, format, ap); + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); return n; } diff --git a/lib/lib_vsprintf.c b/lib/lib_vsprintf.c index 2d8da2a430193b7691248bcdd89ceff6170c91d4..36cb9ac7f05b535ee5920581b6451ff834ba61be 100644 --- a/lib/lib_vsprintf.c +++ b/lib/lib_vsprintf.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_vsprintf.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -84,12 +84,12 @@ int vsprintf(FAR char *dest, const char *src, va_list ap) { - struct lib_memstream_s memstream; + struct lib_memoutstream_s memoutstream; /* Wrap the destination buffer in a stream object and let * lib_vsprintf do the work. */ - lib_memstream((FAR struct lib_memstream_s *)&memstream, dest, LIB_BUFLEN_UNKNOWN); - return lib_vsprintf((FAR struct lib_stream_s *)&memstream.public, src, ap); + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest, LIB_BUFLEN_UNKNOWN); + return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, src, ap); }