writef: split into writef() and writefv()

This commit is contained in:
Josh Holtrop 2023-10-21 16:45:41 -04:00
parent b2597fb5da
commit 4273c703e9
4 changed files with 25 additions and 8 deletions

View File

@ -33,9 +33,9 @@ struct Console
*/
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);
}
/**

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);
}
/**

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);
}
/**

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.
*