m_printf.h
Go to the documentation of this file.
1 /*
2 Author: (github.com/)ADiea
3 Project: Sming for ESP8266 - https://github.com/SmingHub/Sming
4 License: MIT
5 Date: 21.12.2015
6 Descr: embedded very simple version of printf with float support
7 */
8 #pragma once
9 
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 #ifdef __cplusplus
15 
16 extern "C++" {
17 
18 #include <Delegate.h>
19 
28 
34 
35 } // extern "C++"
36 
37 extern "C" {
38 #endif
39 
40 int m_vsnprintf(char* buf, size_t maxLen, const char* fmt, va_list args);
41 int m_snprintf(char* buf, int length, const char* fmt, ...);
42 int m_printf(char const*, ...);
43 int m_vprintf(const char* format, va_list arg);
44 
49 size_t m_putc(char c);
50 
57 size_t m_nputs(const char* str, size_t length);
58 
59 static inline size_t m_puts(const char* str)
60 {
61  return m_nputs(str, strlen(str));
62 }
63 
64 #ifdef __cplusplus
65 }
66 
67 extern "C++" {
68 
69 template <typename... Args> int snprintf(char* buf, int length, const char* fmt, Args... args)
70 {
71  return m_snprintf(buf, length, fmt, args...);
72 }
73 
74 template <typename... Args> int printf(const char* fmt, Args... args)
75 {
76  return m_printf(fmt, args...);
77 }
78 
87 extern "C" void m_printHex(const char* tag, const void* data, size_t len, int addr = -1, size_t bytesPerLine = 16);
88 }
89 
90 #else
91 
92 void m_printHex(const char* tag, const void* data, size_t len, int addr, size_t bytesPerLine);
93 
94 #endif
static size_t m_puts(const char *str)
Definition: m_printf.h:59
int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args)
#define str(s)
Definition: testrunner.h:124
size_t m_nputs(const char *str, size_t length)
output a text string
int m_printf(char const *,...)
Definition: Delegate.h:20
int m_vprintf(const char *format, va_list arg)
int m_snprintf(char *buf, int length, const char *fmt,...)
int snprintf(char *buf, int length, const char *fmt, Args... args)
Definition: m_printf.h:69
nputs_callback_t m_setPuts(nputs_callback_t callback)
set the character output routine
int printf(const char *fmt, Args... args)
Definition: m_printf.h:74
void m_printHex(const char *tag, const void *data, size_t len, int addr=-1, size_t bytesPerLine=16)
output a block of data in hex format
size_t m_putc(char c)
output a single character