writef: split into writef() and writefv()

This commit is contained in:
josh committed 2023-10-21 16:45:41 -04:00
1 parent b2597fb5da
commit 4273c703e9
4 files changed
+25 -8

No files matched your search

+2 -2
View File
@@ -40,9 +40,9 @@ struct Klog
*/
public static void writef(string s, va_list args)
{
hulk.writef.writef(s, args, function void(ubyte ch) {
hulk.writef.writefv(function void(ubyte ch) {
Console.write(ch);
});
}, s, args);
}
/**
+2 -2
View File
@@ -40,9 +40,9 @@ struct Serial
*/
public static void writef(string s, va_list args)
{
hulk.writef.writef(s, args, function void(ubyte ch) {
hulk.writef.writefv(function void(ubyte ch) {
Serial.write(ch);
});
}, s, args);
}
/**
+19 -2
View File
@@ -10,13 +10,13 @@ alias ch_out_fn = void function(ubyte);
/**
* Format a string and write characters to the given output function.
*
* @param ch_out Character output function.
* @param s Format string.
* @param args Variable arguments structure.
* @param ch_out Character output function.
*
* @return Number of characters written.
*/
size_t writef(string s, va_list args, ch_out_fn ch_out)
size_t writefv(ch_out_fn ch_out, string s, va_list args)
{
size_t length_written;
bool escape = false;
@@ -90,6 +90,23 @@ size_t writef(string s, va_list args, ch_out_fn ch_out)
return length_written;
}
/**
* Format a string and write characters to the given output function.
*
* @param ch_out Character output function.
* @param s Format string.
*
* @return Number of characters written.
*/
extern(C) size_t writef(ch_out_fn ch_out, string s, ...)
{
va_list args;
va_start(args, s);
size_t rv = writefv(ch_out, s, args);
va_end(args);
return rv;
}
/**
* Format a value in hexadecimal to the given output function.
*