Apply cosmetic changes

This commit is contained in:
George Oikonomou 2017-11-22 00:53:42 +00:00
parent 941d8457b4
commit 632ab90161
7 changed files with 47 additions and 33 deletions

View File

@ -1,21 +1,22 @@
/*---------------------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <debug-uart.h> #include <debug-uart.h>
#include <string.h> #include <string.h>
#include <strformat.h> #include <strformat.h>
/*---------------------------------------------------------------------------*/
static StrFormatResult static StrFormatResult
write_str(void *user_data, const char *data, unsigned int len) write_str(void *user_data, const char *data, unsigned int len)
{ {
if (len > 0) dbg_send_bytes((unsigned char*)data, len); if (len > 0) dbg_send_bytes((unsigned char*)data, len);
return STRFORMAT_OK; return STRFORMAT_OK;
} }
/*---------------------------------------------------------------------------*/
static StrFormatContext ctxt = static StrFormatContext ctxt =
{ {
write_str, write_str,
NULL NULL
}; };
/*---------------------------------------------------------------------------*/
int int
printf(const char *fmt, ...) printf(const char *fmt, ...)
{ {
@ -26,5 +27,4 @@ printf(const char *fmt, ...)
va_end(ap); va_end(ap);
return res; return res;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,26 +1,28 @@
/*---------------------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <debug-uart.h> #include <debug-uart.h>
#include <string.h> #include <string.h>
/*---------------------------------------------------------------------------*/
#undef putchar #undef putchar
#undef putc #undef putc
/*---------------------------------------------------------------------------*/
int int
putchar(int c) putchar(int c)
{ {
dbg_putchar(c); dbg_putchar(c);
return c; return c;
} }
/*---------------------------------------------------------------------------*/
int int
putc(int c, FILE *f) putc(int c, FILE *f)
{ {
dbg_putchar(c); dbg_putchar(c);
return c; return c;
} }
/*---------------------------------------------------------------------------*/
int int
__sp(struct _reent *_ptr, int c, FILE *_p) { __sp(struct _reent *_ptr, int c, FILE *_p) {
dbg_putchar(c); dbg_putchar(c);
return c; return c;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,7 +1,8 @@
/*---------------------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <debug-uart.h> #include <debug-uart.h>
#include <string.h> #include <string.h>
/*---------------------------------------------------------------------------*/
int int
puts(const char *str) puts(const char *str)
{ {
@ -9,3 +10,4 @@ puts(const char *str)
dbg_putchar('\n'); dbg_putchar('\n');
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,13 +1,14 @@
/*---------------------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <strformat.h> #include <strformat.h>
#include <string.h> #include <string.h>
/*---------------------------------------------------------------------------*/
struct FmtBuffer struct FmtBuffer
{ {
char *pos; char *pos;
size_t left; size_t left;
}; };
/*---------------------------------------------------------------------------*/
static StrFormatResult static StrFormatResult
buffer_str(void *user_data, const char *data, unsigned int len) 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; buffer->left -= len;
return STRFORMAT_OK; return STRFORMAT_OK;
} }
/*---------------------------------------------------------------------------*/
int snprintf(char *str, size_t size, const char *format, ...) int snprintf(char *str, size_t size, const char *format, ...)
{ {
int res; int res;
@ -32,7 +33,7 @@ int snprintf(char *str, size_t size, const char *format, ...)
va_end(ap); va_end(ap);
return res; return res;
} }
/*---------------------------------------------------------------------------*/
int vsnprintf(char *str, size_t size, const char *format, va_list ap) int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ {
struct FmtBuffer buffer; struct FmtBuffer buffer;
@ -46,3 +47,4 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
*buffer.pos = '\0'; *buffer.pos = '\0';
return res; return res;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,7 +1,8 @@
/*---------------------------------------------------------------------------*/
#include <stdio.h> #include <stdio.h>
#include <strformat.h> #include <strformat.h>
#include <string.h> #include <string.h>
/*---------------------------------------------------------------------------*/
static StrFormatResult static StrFormatResult
buffer_str(void *user_data, const char *data, unsigned int len) 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; (*(char**)user_data) += len;
return STRFORMAT_OK; return STRFORMAT_OK;
} }
/*---------------------------------------------------------------------------*/
int int
sprintf(char *str, const char *format, ...) sprintf(char *str, const char *format, ...)
{ {
@ -24,3 +25,4 @@ sprintf(char *str, const char *format, ...)
va_end(ap); va_end(ap);
return res; return res;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,5 +1,6 @@
/*---------------------------------------------------------------------------*/
#include <strformat.h> #include <strformat.h>
/*---------------------------------------------------------------------------*/
#define HAVE_DOUBLE #define HAVE_DOUBLE
#define HAVE_LONGLONG #define HAVE_LONGLONG
@ -22,9 +23,9 @@
#ifndef POINTER_INT #ifndef POINTER_INT
#define POINTER_INT unsigned long #define POINTER_INT unsigned long
#endif #endif
/*---------------------------------------------------------------------------*/
typedef unsigned int FormatFlags; typedef unsigned int FormatFlags;
/*---------------------------------------------------------------------------*/
#define MAKE_MASK(shift,size) (((1 << size) - 1) << (shift)) #define MAKE_MASK(shift,size) (((1 << size) - 1) << (shift))
#define JUSTIFY_SHIFT 0 #define JUSTIFY_SHIFT 0
@ -33,7 +34,6 @@ typedef unsigned int FormatFlags;
#define JUSTIFY_LEFT 0x0001 #define JUSTIFY_LEFT 0x0001
#define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT,JUSTIFY_SIZE) #define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT,JUSTIFY_SIZE)
/* How a positive number is prefixed */ /* How a positive number is prefixed */
#define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE) #define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE)
#define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT) #define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT)
@ -99,6 +99,7 @@ typedef unsigned int FormatFlags;
#define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT) #define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT)
#define FLOAT_HEX (0x0003 << FLOAT_SHIFT) #define FLOAT_HEX (0x0003 << FLOAT_SHIFT)
#define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE) #define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE)
/*---------------------------------------------------------------------------*/
static FormatFlags static FormatFlags
parse_flags(const char **posp) parse_flags(const char **posp)
@ -130,7 +131,7 @@ parse_flags(const char **posp)
} }
} }
/*---------------------------------------------------------------------------*/
static unsigned int static unsigned int
parse_uint(const char **posp) parse_uint(const char **posp)
{ {
@ -151,6 +152,7 @@ parse_uint(const char **posp)
*/ */
#define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3 ) #define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3 )
/*---------------------------------------------------------------------------*/
static unsigned int static unsigned int
output_uint_decimal(char **posp, LARGEST_UNSIGNED v) output_uint_decimal(char **posp, LARGEST_UNSIGNED v)
{ {
@ -164,7 +166,7 @@ output_uint_decimal(char **posp, LARGEST_UNSIGNED v)
*posp = pos; *posp = pos;
return len; return len;
} }
/*---------------------------------------------------------------------------*/
static unsigned int static unsigned int
output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags) 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; *posp = pos;
return len; return len;
} }
/*---------------------------------------------------------------------------*/
static unsigned int static unsigned int
output_uint_octal(char **posp, LARGEST_UNSIGNED v) output_uint_octal(char **posp, LARGEST_UNSIGNED v)
{ {
@ -193,7 +195,7 @@ output_uint_octal(char **posp, LARGEST_UNSIGNED v)
*posp = pos; *posp = pos;
return len; return len;
} }
/*---------------------------------------------------------------------------*/
static StrFormatResult static StrFormatResult
fill_space(const StrFormatContext *ctxt, unsigned int len) 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; if (len == 0) return STRFORMAT_OK;
return ctxt->write_str(ctxt->user_data, buffer, len); return ctxt->write_str(ctxt->user_data, buffer, len);
} }
/*---------------------------------------------------------------------------*/
static StrFormatResult static StrFormatResult
fill_zero(const StrFormatContext *ctxt, unsigned int len) 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; if (len == 0) return STRFORMAT_OK;
return ctxt->write_str(ctxt->user_data, buffer, len); return ctxt->write_str(ctxt->user_data, buffer, len);
} }
/*---------------------------------------------------------------------------*/
#define CHECKCB(res) {if ((res) != STRFORMAT_OK) {va_end(ap); return -1;}} #define CHECKCB(res) {if ((res) != STRFORMAT_OK) {va_end(ap); return -1;}}
/*---------------------------------------------------------------------------*/
int int
format_str(const StrFormatContext *ctxt, const char *format, ...) format_str(const StrFormatContext *ctxt, const char *format, ...)
{ {
@ -234,7 +236,7 @@ format_str(const StrFormatContext *ctxt, const char *format, ...)
va_end(ap); va_end(ap);
return ret; return ret;
} }
/*---------------------------------------------------------------------------*/
int int
format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) 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; return written;
} }
/*---------------------------------------------------------------------------*/

View File

@ -1,12 +1,14 @@
/*---------------------------------------------------------------------------*/
#ifndef STRFORMAT_H_ #ifndef STRFORMAT_H_
#define STRFORMAT_H_ #define STRFORMAT_H_
/*---------------------------------------------------------------------------*/
#include <stdarg.h> #include <stdarg.h>
/*---------------------------------------------------------------------------*/
#define STRFORMAT_OK 0 #define STRFORMAT_OK 0
#define STRFORMAT_FAILED 1 #define STRFORMAT_FAILED 1
/*---------------------------------------------------------------------------*/
typedef unsigned int StrFormatResult; typedef unsigned int StrFormatResult;
/*---------------------------------------------------------------------------*/
/* The data argument may only be considered valid during the function call */ /* The data argument may only be considered valid during the function call */
typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len); typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len);
@ -15,11 +17,12 @@ typedef struct _StrFormatContext
StrFormatWrite write_str; StrFormatWrite write_str;
void *user_data; void *user_data;
} StrFormatContext; } StrFormatContext;
/*---------------------------------------------------------------------------*/
int format_str(const StrFormatContext *ctxt, const char *format, ...) int format_str(const StrFormatContext *ctxt, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2,3))); __attribute__ ((__format__ (__printf__, 2,3)));
int int
format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap); format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap);
/*---------------------------------------------------------------------------*/
#endif /* STRFORMAT_H_ */ #endif /* STRFORMAT_H_ */
/*---------------------------------------------------------------------------*/