#include <stdarg.h>
Go to the source code of this file.
- Author
- Keeton Feavel (keeto.nosp@m.nfea.nosp@m.vel@c.nosp@m.edar.nosp@m.ville.nosp@m..edu)
- Version
- 0.3
- Date
- 2020-07-09
- Copyright
- Copyright Keeton Feavel et al (c) 2020
Definition in file stdio.hpp.
◆ log_all
#define log_all |
( |
|
fmt, |
|
|
|
... |
|
) |
| |
Value:
Prints a statement to serial debugger and the kernel framebuffer. Max message size is 1024 (including null terminator).
- Parameters
-
fmt | Formatted C string |
... | Sequence of additional arguments |
Definition at line 59 of file stdio.hpp.
◆ printf_cb_fnptr_t
typedef int(* printf_cb_fnptr_t) (unsigned c, void **helper) |
◆ ksprintf()
int ksprintf |
( |
char * |
buf, |
|
|
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Sends formatted output to a string.
- Parameters
-
buf | Pointer to a buffer where the result is stored |
fmt | C string that contains a format string |
... | Sequence of additional arguments |
- Returns
- int The total number of characters written. The number of characters not written if negative.
Definition at line 342 of file printf.cpp.
◆ kvsprintf()
int kvsprintf |
( |
char * |
buf, |
|
|
const char * |
fmt, |
|
|
va_list |
args |
|
) |
| |
Sends formatted output to a string using an argument list.
- Parameters
-
buf | Pointer to a buffer where the result is stored |
fmt | C string that contains a format string |
args | A value identifying a variable arguments list |
- Returns
- int The total number of characters written. The number of characters not written if negative.
Definition at line 333 of file printf.cpp.
337 ret_val =
printf_helper(fmt, args, vsprintf_help, (
void*)buf);
◆ 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 callback function to perform the character printing operation. This allows for adding printf capabilities to a wide range of text output applications, such as an RS232 debug driver, or a framebuffer console.
- Parameters
-
fmt | Format string |
args | Arguments list |
fn | Character printing callback function pointer |
ptr | User-provided data / handle pointer |
- Returns
- int Returns number of characters written
Definition at line 105 of file printf.cpp.
107 unsigned char radix, *where, buf[
PR_BUFLEN];
108 unsigned int state, flags, actual_wd, count, given_wd;
111 state = flags = count = given_wd = 0;
113 for (; *fmt; fmt++) {
133 state = flags = given_wd = 0;
138 state = flags = given_wd = 0;
153 if (*fmt >=
'0' && *fmt <=
'9') {
154 given_wd = 10 * given_wd + (*fmt -
'0');
170 #if (UINTPTR_MAX == UINT32_MAX)
172 #elif (UINTPTR_MAX == UINT64_MAX)
175 #error "Unknown UINTPTR_MAX value! Cannot compile printf_helper!"
220 num = va_arg(args,
unsigned long long);
221 else if (flags &
PR_32)
222 num = va_arg(args,
unsigned long);
224 else if (flags &
PR_16) {
226 num = va_arg(args,
int);
228 num = va_arg(args,
int);
233 num = va_arg(args,
int);
235 num = va_arg(args,
unsigned int);
249 temp = (
unsigned long)num % radix;
252 *where = (
unsigned char)(temp +
'0');
253 else if (flags &
PR_CA)
254 *where = (
unsigned char)(temp - 10 +
'A');
256 *where = (
unsigned char)(temp - 10 +
'a');
257 num = (
unsigned long)num / radix;
264 *where = (
unsigned char)va_arg(args,
int);
270 where = va_arg(args,
unsigned char*);
272 actual_wd =
strlen((
const char*)where);
282 if ((flags &
PR_LJ) == 0) {
283 while (given_wd > actual_wd) {
284 fn(flags &
PR_LZ ?
'0' :
' ', &ptr);
295 while (*where !=
'\0') {
300 if (given_wd < actual_wd)
303 given_wd -= actual_wd;
304 for (; given_wd; given_wd--) {
316 state = flags = given_wd = 0;