Add printf.h

This commit is contained in:
Sergio R. Caprile 2023-03-27 14:11:39 -03:00
parent 2b325102f3
commit 8e14ad0536
19 changed files with 49 additions and 37 deletions

View File

@ -194,7 +194,7 @@ mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/tcpip/*.c)
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/tcpip/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@ (cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/tcpip/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
mongoose.h: $(HDRS) Makefile mongoose.h: $(HDRS) Makefile
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_*.h src/config.h src/str.h src/queue.h src/fmt.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/tcpip/tcpip.h src/tcpip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@ (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_*.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/tcpip/tcpip.h src/tcpip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
clean: clean_examples clean_embedded clean: clean_examples clean_embedded

View File

@ -117,6 +117,7 @@ int mg_base64_decode(const char *src, int n, char *dst) {
struct dns_data { struct dns_data {
struct dns_data *next; struct dns_data *next;
struct mg_connection *c; struct mg_connection *c;
@ -1305,6 +1306,7 @@ struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close, p_read,
// Chunk deletion marker is the MSB in the "processed" counter // Chunk deletion marker is the MSB in the "processed" counter
#define MG_DMARK ((size_t) 1 << (sizeof(size_t) * 8 - 1)) #define MG_DMARK ((size_t) 1 << (sizeof(size_t) * 8 - 1))
@ -3243,6 +3245,7 @@ struct mg_connection *mg_mqtt_listen(struct mg_mgr *mgr, const char *url,
size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) { size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) {
size_t old = c->send.len; size_t old = c->send.len;
mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap); mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
@ -3491,7 +3494,6 @@ void mg_mgr_init(struct mg_mgr *mgr) {
size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) { size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) {
size_t len = mg_snprintf(NULL, 0, fmt, ap); size_t len = mg_snprintf(NULL, 0, fmt, ap);
char *buf; char *buf;
@ -4103,6 +4105,7 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
#if MG_ENABLE_SOCKET #if MG_ENABLE_SOCKET
#ifndef closesocket #ifndef closesocket
@ -5775,6 +5778,7 @@ uint64_t mg_millis(void) {
struct ws_msg { struct ws_msg {
uint8_t flags; uint8_t flags;
size_t header_len; size_t header_len;

View File

@ -862,14 +862,17 @@ void mg_queue_del(struct mg_queue *, size_t); // Delete oldest message
typedef void (*mg_pfn_t)(char, void *); // Output function typedef void (*mg_pfn_t)(char, void *); // Output function
typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer
size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *); size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *);
size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...); size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...);
// Convenience wrappers around mg_xprintf // Convenience wrappers around mg_xprintf
size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap); size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap);
size_t mg_snprintf(char *, size_t, const char *fmt, ...); size_t mg_snprintf(char *, size_t, const char *fmt, ...);
@ -989,7 +992,6 @@ bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...);
#if MG_ENABLE_ASSERT #if MG_ENABLE_ASSERT
#include <assert.h> #include <assert.h>
#elif !defined(assert) #elif !defined(assert)

View File

@ -1,5 +1,6 @@
#include "dns.h" #include "dns.h"
#include "log.h" #include "log.h"
#include "printf.h"
#include "str.h" #include "str.h"
#include "timer.h" #include "timer.h"
#include "url.h" #include "url.h"

View File

@ -1,7 +1,7 @@
#include "event.h" #include "event.h"
#include "fmt.h"
#include "log.h" #include "log.h"
#include "net.h" #include "net.h"
#include "printf.h"
void mg_call(struct mg_connection *c, int ev, void *ev_data) { void mg_call(struct mg_connection *c, int ev, void *ev_data) {
// Run user-defined handler first, in order to give it an ability // Run user-defined handler first, in order to give it an ability

View File

@ -1,5 +1,5 @@
#include "fmt.h" #include "fmt.h"
#include "iobuf.h" #include "printf.h"
#include "util.h" #include "util.h"
static bool is_digit(int c) { return c >= '0' && c <= '9'; } static bool is_digit(int c) { return c >= '0' && c <= '9'; }

View File

@ -1,30 +1,9 @@
#pragma once #pragma once
#include "arch.h" #include "arch.h"
#include "iobuf.h"
#include "queue.h"
typedef void (*mg_pfn_t)(char, void *); // Output function typedef void (*mg_pfn_t)(char, void *); // Output function
typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer
size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *); size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *);
size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...); size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...);
// Convenience wrappers around mg_xprintf
size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap);
size_t mg_snprintf(char *, size_t, const char *fmt, ...);
char *mg_vmprintf(const char *fmt, va_list *ap);
char *mg_mprintf(const char *fmt, ...);
size_t mg_queue_vprintf(struct mg_queue *, const char *fmt, va_list *);
size_t mg_queue_printf(struct mg_queue *, const char *fmt, ...);
// %M print helper functions
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip4(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip6(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap);
// Various output functions
void mg_pfn_iobuf(char ch, void *param); // param: struct mg_iobuf *
void mg_pfn_stdout(char c, void *param); // param: ignored

View File

@ -1,5 +1,5 @@
#include "fs.h" #include "fs.h"
#include "fmt.h" #include "printf.h"
struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) { struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) {
struct mg_fd *fd = (struct mg_fd *) calloc(1, sizeof(*fd)); struct mg_fd *fd = (struct mg_fd *) calloc(1, sizeof(*fd));

View File

@ -1,5 +1,5 @@
#include "fmt.h"
#include "fs.h" #include "fs.h"
#include "printf.h"
#include "str.h" #include "str.h"
struct packed_file { struct packed_file {

View File

@ -5,6 +5,7 @@
#include "json.h" #include "json.h"
#include "log.h" #include "log.h"
#include "net.h" #include "net.h"
#include "printf.h"
#include "ssi.h" #include "ssi.h"
#include "util.h" #include "util.h"
#include "version.h" #include "version.h"

View File

@ -2,6 +2,7 @@
#include "fmt.h" #include "fmt.h"
#include "log.h" #include "log.h"
#include "net.h" #include "net.h"
#include "printf.h"
#include "timer.h" #include "timer.h"
#include "tls.h" #include "tls.h"

View File

@ -1,6 +1,5 @@
#include "fmt.h" #include "fmt.h"
#include "iobuf.h" #include "printf.h"
#include "queue.h"
#include "util.h" #include "util.h"
size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) { size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) {

24
src/printf.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "arch.h"
#include "iobuf.h"
#include "queue.h"
// Convenience wrappers around mg_xprintf
size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap);
size_t mg_snprintf(char *, size_t, const char *fmt, ...);
char *mg_vmprintf(const char *fmt, va_list *ap);
char *mg_mprintf(const char *fmt, ...);
size_t mg_queue_vprintf(struct mg_queue *, const char *fmt, va_list *);
size_t mg_queue_printf(struct mg_queue *, const char *fmt, ...);
// %M print helper functions
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip4(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_ip6(void (*out)(char, void *), void *arg, va_list *ap);
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap);
// Various output functions
void mg_pfn_iobuf(char ch, void *param); // param: struct mg_iobuf *
void mg_pfn_stdout(char c, void *param); // param: ignored

View File

@ -2,6 +2,7 @@
#include "event.h" #include "event.h"
#include "log.h" #include "log.h"
#include "net.h" #include "net.h"
#include "printf.h"
#include "str.h" #include "str.h"
#include "timer.h" #include "timer.h"
#include "tls.h" #include "tls.h"

View File

@ -1,6 +1,6 @@
#include "ssi.h"
#include "fmt.h"
#include "log.h" #include "log.h"
#include "printf.h"
#include "ssi.h"
#ifndef MG_MAX_SSI_DEPTH #ifndef MG_MAX_SSI_DEPTH
#define MG_MAX_SSI_DEPTH 5 #define MG_MAX_SSI_DEPTH 5

View File

@ -1,5 +1,5 @@
#include "fmt.h"
#include "fs.h" #include "fs.h"
#include "printf.h"
#include "tls.h" #include "tls.h"
#if MG_ENABLE_MBEDTLS #if MG_ENABLE_MBEDTLS

View File

@ -1,4 +1,4 @@
#include "fmt.h" #include "printf.h"
#include "tls.h" #include "tls.h"
#if MG_ENABLE_OPENSSL #if MG_ENABLE_OPENSSL

View File

@ -2,7 +2,6 @@
#include "arch.h" #include "arch.h"
#include "config.h" #include "config.h"
#include "fmt.h"
#include "net.h" #include "net.h"
#include "str.h" #include "str.h"

View File

@ -4,6 +4,7 @@
#include "fmt.h" #include "fmt.h"
#include "http.h" #include "http.h"
#include "log.h" #include "log.h"
#include "printf.h"
#include "sha1.h" #include "sha1.h"
#include "url.h" #include "url.h"
#include "util.h" #include "util.h"