Apply cosmetic changes
This commit is contained in:
parent
941d8457b4
commit
632ab90161
@ -1,21 +1,22 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <debug-uart.h>
|
||||
#include <string.h>
|
||||
#include <strformat.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatResult
|
||||
write_str(void *user_data, const char *data, unsigned int len)
|
||||
{
|
||||
if (len > 0) dbg_send_bytes((unsigned char*)data, len);
|
||||
return STRFORMAT_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatContext ctxt =
|
||||
{
|
||||
write_str,
|
||||
NULL
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
printf(const char *fmt, ...)
|
||||
{
|
||||
@ -26,5 +27,4 @@ printf(const char *fmt, ...)
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,26 +1,28 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <debug-uart.h>
|
||||
#include <string.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#undef putchar
|
||||
#undef putc
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
putchar(int c)
|
||||
{
|
||||
dbg_putchar(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
putc(int c, FILE *f)
|
||||
{
|
||||
dbg_putchar(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
__sp(struct _reent *_ptr, int c, FILE *_p) {
|
||||
dbg_putchar(c);
|
||||
return c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,7 +1,8 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <debug-uart.h>
|
||||
#include <string.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
puts(const char *str)
|
||||
{
|
||||
@ -9,3 +10,4 @@ puts(const char *str)
|
||||
dbg_putchar('\n');
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,13 +1,14 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <strformat.h>
|
||||
#include <string.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
struct FmtBuffer
|
||||
{
|
||||
char *pos;
|
||||
size_t left;
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatResult
|
||||
buffer_str(void *user_data, const char *data, unsigned int len)
|
||||
{
|
||||
@ -22,7 +23,7 @@ buffer_str(void *user_data, const char *data, unsigned int len)
|
||||
buffer->left -= len;
|
||||
return STRFORMAT_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int snprintf(char *str, size_t size, const char *format, ...)
|
||||
{
|
||||
int res;
|
||||
@ -32,7 +33,7 @@ int snprintf(char *str, size_t size, const char *format, ...)
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
{
|
||||
struct FmtBuffer buffer;
|
||||
@ -46,3 +47,4 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
*buffer.pos = '\0';
|
||||
return res;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,7 +1,8 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <strformat.h>
|
||||
#include <string.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatResult
|
||||
buffer_str(void *user_data, const char *data, unsigned int len)
|
||||
{
|
||||
@ -9,7 +10,7 @@ buffer_str(void *user_data, const char *data, unsigned int len)
|
||||
(*(char**)user_data) += len;
|
||||
return STRFORMAT_OK;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sprintf(char *str, const char *format, ...)
|
||||
{
|
||||
@ -24,3 +25,4 @@ sprintf(char *str, const char *format, ...)
|
||||
va_end(ap);
|
||||
return res;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <strformat.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define HAVE_DOUBLE
|
||||
|
||||
#define HAVE_LONGLONG
|
||||
@ -22,9 +23,9 @@
|
||||
#ifndef POINTER_INT
|
||||
#define POINTER_INT unsigned long
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef unsigned int FormatFlags;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define MAKE_MASK(shift,size) (((1 << size) - 1) << (shift))
|
||||
|
||||
#define JUSTIFY_SHIFT 0
|
||||
@ -33,7 +34,6 @@ typedef unsigned int FormatFlags;
|
||||
#define JUSTIFY_LEFT 0x0001
|
||||
#define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT,JUSTIFY_SIZE)
|
||||
|
||||
|
||||
/* How a positive number is prefixed */
|
||||
#define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE)
|
||||
#define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT)
|
||||
@ -99,6 +99,7 @@ typedef unsigned int FormatFlags;
|
||||
#define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT)
|
||||
#define FLOAT_HEX (0x0003 << FLOAT_SHIFT)
|
||||
#define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static FormatFlags
|
||||
parse_flags(const char **posp)
|
||||
@ -130,7 +131,7 @@ parse_flags(const char **posp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned int
|
||||
parse_uint(const char **posp)
|
||||
{
|
||||
@ -151,6 +152,7 @@ parse_uint(const char **posp)
|
||||
*/
|
||||
#define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3 )
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned int
|
||||
output_uint_decimal(char **posp, LARGEST_UNSIGNED v)
|
||||
{
|
||||
@ -164,7 +166,7 @@ output_uint_decimal(char **posp, LARGEST_UNSIGNED v)
|
||||
*posp = pos;
|
||||
return len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned int
|
||||
output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags)
|
||||
{
|
||||
@ -179,7 +181,7 @@ output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags)
|
||||
*posp = pos;
|
||||
return len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned int
|
||||
output_uint_octal(char **posp, LARGEST_UNSIGNED v)
|
||||
{
|
||||
@ -193,7 +195,7 @@ output_uint_octal(char **posp, LARGEST_UNSIGNED v)
|
||||
*posp = pos;
|
||||
return len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatResult
|
||||
fill_space(const StrFormatContext *ctxt, unsigned int len)
|
||||
{
|
||||
@ -207,7 +209,7 @@ fill_space(const StrFormatContext *ctxt, unsigned int len)
|
||||
if (len == 0) return STRFORMAT_OK;
|
||||
return ctxt->write_str(ctxt->user_data, buffer, len);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static StrFormatResult
|
||||
fill_zero(const StrFormatContext *ctxt, unsigned int len)
|
||||
{
|
||||
@ -221,9 +223,9 @@ fill_zero(const StrFormatContext *ctxt, unsigned int len)
|
||||
if (len == 0) return STRFORMAT_OK;
|
||||
return ctxt->write_str(ctxt->user_data, buffer, len);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CHECKCB(res) {if ((res) != STRFORMAT_OK) {va_end(ap); return -1;}}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
format_str(const StrFormatContext *ctxt, const char *format, ...)
|
||||
{
|
||||
@ -234,7 +236,7 @@ format_str(const StrFormatContext *ctxt, const char *format, ...)
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap)
|
||||
{
|
||||
@ -615,3 +617,4 @@ format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap)
|
||||
|
||||
return written;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -1,12 +1,14 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef STRFORMAT_H_
|
||||
#define STRFORMAT_H_
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdarg.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define STRFORMAT_OK 0
|
||||
#define STRFORMAT_FAILED 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef unsigned int StrFormatResult;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* The data argument may only be considered valid during the function call */
|
||||
typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len);
|
||||
|
||||
@ -15,11 +17,12 @@ typedef struct _StrFormatContext
|
||||
StrFormatWrite write_str;
|
||||
void *user_data;
|
||||
} StrFormatContext;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int format_str(const StrFormatContext *ctxt, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 2,3)));
|
||||
|
||||
int
|
||||
format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* STRFORMAT_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
Loading…
Reference in New Issue
Block a user