mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 13:52:22 +08:00
Extend lib to handle incoming streams
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1840 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
+5
-4
@@ -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
|
||||
|
||||
|
||||
+85
-32
@@ -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_LOWPUTC
|
||||
extern void lib_lowstream(FAR struct lib_stream_s *rawstream);
|
||||
#ifdef CONFIG_ARCH_LOWGETC
|
||||
extern void lib_lowinstream(FAR struct lib_instream_s *lowinstream);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_nullstream.c */
|
||||
/* Defined in lib_lowoutstream.c */
|
||||
|
||||
extern void lib_nullstream(FAR struct lib_stream_s *nullstream);
|
||||
#ifdef CONFIG_ARCH_LOWPUTC
|
||||
extern void lib_lowoutstream(FAR struct lib_outstream_s *lowoutstream);
|
||||
#endif
|
||||
|
||||
/* Defined in lib_nullinstream.c */
|
||||
|
||||
extern void lib_nullinstream(FAR struct lib_instream_s *nullinstream);
|
||||
|
||||
/* Defined in lib_nulloutstream.c */
|
||||
|
||||
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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
+54
-54
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+4
-4
@@ -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);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+7
-7
@@ -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;
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
+4
-4
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user