Removal of Mw/Error.h, addition of MwStringPrintIntoBuffer #14

Merged
IoI_xD merged 5 commits from printtobuf into master 2026-03-31 15:20:57 +09:00
11 changed files with 18 additions and 17 deletions
Showing only changes of commit 32842ca160 - Show all commits

document MwStringPrintIntoBuffer slightly better
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit

IoI_xD 2026-03-30 11:19:10 -07:00

View file

@ -82,7 +82,7 @@ static void activate(MwWidget handle, void* client, void* user) {
v = fv / sv; v = fv / sv;
} }
MwPrintIntoBuffer(buf, 256, "%g", v); MwStringPrintIntoBuffer(buf, 256, "%g", v);
MwVaApply(inp, MwVaApply(inp,
MwNtext, buf, MwNtext, buf,

View file

@ -15,7 +15,7 @@ void color_callback(MwWidget handle, void* user_data, void* call_data) {
rgb->red &= 0xff; rgb->red &= 0xff;
rgb->green &= 0xff; rgb->green &= 0xff;
rgb->blue &= 0xff; rgb->blue &= 0xff;
MwPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue); MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", rgb->red, rgb->green, rgb->blue);
MwSetText(window, MwNbackground, hexColor); MwSetText(window, MwNbackground, hexColor);
} }

View file

@ -16,7 +16,7 @@ void activate(MwWidget handle, void* user, void* call) {
(void)user; (void)user;
MwPrintIntoBuffer(msg, 256, "You pressed: %s", MwListBoxGet(handle, *(int*)call)); MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwListBoxGet(handle, *(int*)call));
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK); msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox); MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);
@ -48,7 +48,7 @@ int main() {
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
char sz[16]; char sz[16];
MwPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i])); MwStringPrintIntoBuffer(sz, 16, "%d", (int)strlen(harvard[i]));
index = MwListBoxPacketInsert(packet, -1); index = MwListBoxPacketInsert(packet, -1);
MwListBoxPacketSetIcon(packet, index, px); MwListBoxPacketSetIcon(packet, index, px);
MwListBoxPacketSet(packet, index, 0, harvard[i]); MwListBoxPacketSet(packet, index, 0, harvard[i]);

View file

@ -14,7 +14,7 @@ void activate(MwWidget handle, void* user, void* call) {
(void)user; (void)user;
MwPrintIntoBuffer(msg, 256, "You pressed: %s", MwTreeViewGet(handle, call)); MwStringPrintIntoBuffer(msg, 256, "You pressed: %s", MwTreeViewGet(handle, call));
msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK); msgbox = MwMessageBox(wmain, msg, "wow", MwMB_ICONINFO | MwMB_BUTTONOK);
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox); MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, destroy, msgbox);

View file

@ -32,10 +32,10 @@ void tick(MwWidget handle, void* user, void* call) {
char buf[512]; char buf[512];
tm = localtime(&t); tm = localtime(&t);
MwPrintIntoBuffer(buf, 512, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]); MwStringPrintIntoBuffer(buf, 512, "%s %02d %s", mon[tm->tm_mon], tm->tm_mday, wday[tm->tm_wday]);
MwSetText(ldate, MwNtext, buf); MwSetText(ldate, MwNtext, buf);
MwPrintIntoBuffer(buf, 512, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM"); MwStringPrintIntoBuffer(buf, 512, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM");
MwSetText(ltime, MwNtext, buf); MwSetText(ltime, MwNtext, buf);
render = 1; render = 1;

View file

@ -17,7 +17,7 @@
char buffer[512]; char buffer[512];
char* string_VkResult(VkResult res) { char* string_VkResult(VkResult res) {
MwPrintIntoBuffer(buffer, 512, "%d", res); MwStringPrintIntoBuffer(buffer, 512, "%d", res);
return &buffer[0]; return &buffer[0];
} }

View file

@ -42,11 +42,12 @@ MWDECL void MwStringSize(char* out, MwOffset size);
MWDECL void MwStringTime(char* out, time_t t); MWDECL void MwStringTime(char* out, time_t t);
/*! /*!
* @brief Prints up to n characters into a buffer * @brief Prints up to n characters into a bufferMwStringPrintIntoBuffer.
* @note On compilers that support C99, this uses vsnprintf to safely print into a buffer; on compilers that don't, vsprintf is used.
* @param out Buffer * @param out Buffer
* @param size Max size * @param size Max size
*/ */
MWDECL void MwPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...); MWDECL void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -173,13 +173,13 @@ static void color_picker_click(MwWidget handle, void* user, void* call) {
picker->chosen_color.green = picker->color_picker_image_data[i + 1]; picker->chosen_color.green = picker->color_picker_image_data[i + 1];
picker->chosen_color.blue = picker->color_picker_image_data[i + 2]; picker->chosen_color.blue = picker->color_picker_image_data[i + 2];
MwPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff); MwStringPrintIntoBuffer(hexColor, 8, "#%02X%02X%02X", picker->chosen_color.red & 0xff, picker->chosen_color.green & 0xff, picker->chosen_color.blue & 0xff);
fr = picker->chosen_color.red > 128 ? 0 : 255; fr = picker->chosen_color.red > 128 ? 0 : 255;
fg = picker->chosen_color.green > 128 ? 0 : 255; fg = picker->chosen_color.green > 128 ? 0 : 255;
fb = picker->chosen_color.blue > 128 ? 0 : 255; fb = picker->chosen_color.blue > 128 ? 0 : 255;
MwPrintIntoBuffer(fgColor, 8, "#%02X%02X%02X", fr, fg, fb); MwStringPrintIntoBuffer(fgColor, 8, "#%02X%02X%02X", fr, fg, fb);
MwSetText(picker->color_display_text, MwNforeground, fgColor); MwSetText(picker->color_display_text, MwNforeground, fgColor);
MwSetText(picker->color_display_text, MwNbackground, hexColor); MwSetText(picker->color_display_text, MwNbackground, hexColor);
@ -247,7 +247,7 @@ static void color_display_text_change(MwWidget handle, void* user,
fg = color->common.green > 128 ? 0 : 255; fg = color->common.green > 128 ? 0 : 255;
fb = color->common.blue > 128 ? 0 : 255; fb = color->common.blue > 128 ? 0 : 255;
MwPrintIntoBuffer(fgColor, 9, "#%02X%02X%02X", fr, fg, fb); MwStringPrintIntoBuffer(fgColor, 9, "#%02X%02X%02X", fr, fg, fb);
MwSetText(picker->color_display_text, MwNforeground, fgColor); MwSetText(picker->color_display_text, MwNforeground, fgColor);
MwSetText(picker->color_display_text, MwNbackground, hexColor); MwSetText(picker->color_display_text, MwNbackground, hexColor);

View file

@ -37,7 +37,7 @@ void MwStringTime(char* out, time_t t) {
sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year); sprintf(out, "%s %2d %02d:%02d %d", months[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, 1900 + tm->tm_year);
} }
} }
void MwPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) { void MwStringPrintIntoBuffer(char* out, MwU32 size, const char* fmt, ...) {
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);

View file

@ -103,9 +103,9 @@ static void mouse_up(MwWidget handle, void* ptr) {
if(e->mouse.x >= (w - e->right)) { if(e->mouse.x >= (w - e->right)) {
char s[512]; char s[512];
if(e->mouse.y >= (h / 2)) { if(e->mouse.y >= (h / 2)) {
MwPrintIntoBuffer(s, 512, "%g", atof(str) - 1); MwStringPrintIntoBuffer(s, 512, "%g", atof(str) - 1);
} else { } else {
MwPrintIntoBuffer(s, 512, "%g", atof(str) + 1); MwStringPrintIntoBuffer(s, 512, "%g", atof(str) + 1);
} }
MwSetText(handle, MwNtext, s); MwSetText(handle, MwNtext, s);
} }

View file

@ -521,7 +521,7 @@ static void* mwVulkanGetFieldImpl(MwWidget handle, MwVulkanField field, MwErrorE
case MwVulkanField_PresentQueue: case MwVulkanField_PresentQueue:
return o->vkPresentQueue; return o->vkPresentQueue;
default: default:
MwPrintIntoBuffer(buf, 1024, "Unknown vulkan field request (%d given)", field); MwStringPrintIntoBuffer(buf, 1024, "Unknown vulkan field request (%d given)", field);
MwDispatchError(1, buf); MwDispatchError(1, buf);
if(out != NULL) { if(out != NULL) {
*out = 1; *out = 1;