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 
27 using nputs_callback_t = Delegate<size_t(const char* str, size_t length)>;
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) __attribute__((format(printf, 3, 0)));
41 int m_snprintf(char* buf, int length, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
42 int m_printf(char const*, ...) __attribute__((format(printf, 1, 2)));
43 int m_vprintf(const char* format, va_list arg) __attribute__((format(printf, 1, 0)));
44 
49 size_t m_putc(char c);
50 
57 size_t m_nputs(const char* str, size_t length);
58 
59 size_t m_puts(const char* str);
60 
61 #ifdef __cplusplus
62 }
63 
64 extern "C++" {
65 
66 template <typename... Args> int snprintf(char* buf, int length, const char* fmt, Args... args)
67 {
68  return m_snprintf(buf, length, fmt, args...);
69 }
70 
71 template <typename... Args> int printf(const char* fmt, Args... args)
72 {
73  return m_printf(fmt, args...);
74 }
75 
84 extern "C" void m_printHex(const char* tag, const void* data, size_t len, int addr = -1, size_t bytesPerLine = 16);
85 }
86 
87 #else
88 
89 void m_printHex(const char* tag, const void* data, size_t len, int addr, size_t bytesPerLine);
90 
91 #endif
Definition: Delegate.h:20
size_t m_nputs(const char *str, size_t length)
output a text string
nputs_callback_t m_setPuts(nputs_callback_t callback)
set the character output routine
int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args)
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
int m_vprintf(const char *format, va_list arg)
int m_printf(char const *,...)
size_t m_putc(char c)
output a single character
int printf(const char *fmt, Args... args)
Definition: m_printf.h:71
size_t m_puts(const char *str)
int snprintf(char *buf, int length, const char *fmt, Args... args)
Definition: m_printf.h:66
int m_snprintf(char *buf, int length, const char *fmt,...)
#define str(s)
Definition: testrunner.h:124