Xyris  0.5
stdio.hpp
Go to the documentation of this file.
1 /**
2  * @file stdio.hpp
3  * @author Keeton Feavel ([email protected])
4  * @brief
5  * @version 0.3
6  * @date 2020-07-09
7  *
8  * @copyright Copyright Keeton Feavel et al (c) 2020
9  *
10  */
11 #pragma once
12 #include <stdarg.h>
13 
14 typedef int (*printf_cb_fnptr_t)(unsigned c, void** helper);
15 
16 /**
17  * @brief Perform all printf operations on the format string using the provided
18  * argument list and uses the callback function to perform the character printing
19  * operation. This allows for adding printf capabilities to a wide range of
20  * text output applications, such as an RS232 debug driver, or a framebuffer
21  * console.
22  *
23  * @param fmt Format string
24  * @param args Arguments list
25  * @param fn Character printing callback function pointer
26  * @param ptr User-provided data / handle pointer
27  * @return int Returns number of characters written
28  */
29 int printf_helper(const char* fmt, va_list args, printf_cb_fnptr_t fn, void* ptr);
30 
31 /**
32  * @brief Sends formatted output to a string using an argument list.
33  *
34  * @param buf Pointer to a buffer where the result is stored
35  * @param fmt C string that contains a format string
36  * @param args A value identifying a variable arguments list
37  * @return int The total number of characters written.
38  * The number of characters not written if negative.
39  */
40 int kvsprintf(char* buf, const char* fmt, va_list args);
41 
42 /**
43  * @brief Sends formatted output to a string.
44  *
45  * @param buf Pointer to a buffer where the result is stored
46  * @param fmt C string that contains a format string
47  * @param ... Sequence of additional arguments
48  * @return int The total number of characters written.
49  * The number of characters not written if negative.
50  */
51 int ksprintf(char* buf, const char* fmt, ...);
52 
53 /**
54  * @brief Prints a statement to serial debugger and the kernel framebuffer.
55  * Max message size is 1024 (including null terminator).
56  * @param fmt Formatted C string
57  * @param ... Sequence of additional arguments
58  */
59 #define log_all(fmt, ...) do { \
60  RS232::printf(fmt, ##__VA_ARGS__); \
61  Console::printf(fmt, ##__VA_ARGS__); \
62 } while (0)
printf_cb_fnptr_t
int(* printf_cb_fnptr_t)(unsigned c, void **helper)
Definition: stdio.hpp:14
kvsprintf
int kvsprintf(char *buf, const char *fmt, va_list args)
Sends formatted output to a string using an argument list.
Definition: printf.cpp:333
printf_helper
int printf_helper(const char *fmt, va_list args, printf_cb_fnptr_t fn, void *ptr)
Perform all printf operations on the format string using the provided argument list and uses the call...
Definition: printf.cpp:105
ksprintf
int ksprintf(char *buf, const char *fmt,...)
Sends formatted output to a string.
Definition: printf.cpp:342