# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1671927649 0 # Node ID 761b7a12b0796fe68541e7f3da4ff3b2d8cff3aa # Parent fe31d45352706f4933e87aef22f3cef8382300ad Add va_list versions of dw_debug() and dw_messagebox() for use in C++ bindings. dw_vdebug() and dw_vmessagebox() work similarly to the standard library versions. DW::App:Debug() and DW::App:MessageBox() use them for variable arguments. diff -r fe31d4535270 -r 761b7a12b079 android/dw.cpp --- a/android/dw.cpp Sat Dec 24 14:28:39 2022 +0000 +++ b/android/dw.cpp Sun Dec 25 00:20:49 2022 +0000 @@ -1166,15 +1166,22 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; - JNIEnv *env; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + vfprintf(stderr, format, args); va_end(args); +} + +void API dw_vdebug(const char *format, va_list args) +{ + JNIEnv *env; if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { + char outbuf[1025] = {0}; + + vsnprintf(outbuf, 1024, format, args); + // Construct a String jstring jstr = env->NewStringUTF(outbuf); // First get the class that contains the method you need to call @@ -1191,7 +1198,7 @@ /* Output to stderr, if there is another way to send it * on the implementation platform, change this. */ - fprintf(stderr, "%s", outbuf); + vfprintf(stderr, format, args); } } @@ -1209,16 +1216,25 @@ int API dw_messagebox(const char *title, int flags, const char *format, ...) { va_list args; - char outbuf[1025] = {0}; - JNIEnv *env; - int retval = 0; + int rc; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + rc = dw_vmessagebox(title, flags, format, args); va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ + JNIEnv *env; + int retval = 0; if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { + char outbuf[1025] = {0}; + + vsnprintf(outbuf, 1024, format, args); + // Construct a String jstring jstr = env->NewStringUTF(outbuf); jstring jstrtitle = env->NewStringUTF(title); diff -r fe31d4535270 -r 761b7a12b079 dw.h --- a/dw.h Sat Dec 24 14:28:39 2022 +0000 +++ b/dw.h Sun Dec 25 00:20:49 2022 +0000 @@ -2187,7 +2187,9 @@ void API dw_pixmap_destroy(HPIXMAP pixmap); void API dw_beep(int freq, int dur); void API dw_debug(const char *format, ...); +void API dw_vdebug(const char *format, va_list args); int API dw_messagebox(const char *title, int flags, const char *format, ...); +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args); void API dw_environment_query(DWEnv *env); int API dw_exec(const char *program, int type, char **params); int API dw_browse(const char *url); diff -r fe31d4535270 -r 761b7a12b079 dw.hpp --- a/dw.hpp Sat Dec 24 14:28:39 2022 +0000 +++ b/dw.hpp Sun Dec 25 00:20:49 2022 +0000 @@ -1395,7 +1395,23 @@ void MainIteration() { dw_main_iteration(); } void MainQuit() { dw_main_quit(); } void Exit(int exitcode) { dw_exit(exitcode); } - int MessageBox(const char *title, int flags, const char *format) { return dw_messagebox(title, flags, format); } + int MessageBox(const char *title, int flags, const char *format, ...) { + int retval; + va_list args; + + va_start(args, format); + retval = dw_vmessagebox(title, flags, format, args); + va_end(args); + + return retval; + } + void Debug(const char *format, ...) { + va_list args; + + va_start(args, format); + dw_vdebug(format, args); + va_end(args); + } }; // Static singleton reference declared outside of the class diff -r fe31d4535270 -r 761b7a12b079 gtk/dw.c --- a/gtk/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/gtk/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -2526,13 +2526,15 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + vfprintf(stderr, format, args); va_end(args); - - fprintf(stderr, "%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + vfprintf(stderr, format, args); } /* @@ -2543,20 +2545,28 @@ * format: printf style format string. * ...: Additional variables for use in the format. */ -int dw_messagebox(const char *title, int flags, const char *format, ...) +int API dw_messagebox(const char *title, int flags, const char *format, ...) +{ + va_list args; + int rc; + + va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int dw_vmessagebox(const char *title, int flags, const char *format, va_list args) { HWND entrywindow, texttargetbox, imagetextbox, mainbox, okbutton, nobutton, yesbutton, cancelbutton, buttonbox, stext; ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; DWDialog *dwwait; - va_list args; char outbuf[1025] = {0}; char **xpm_data = NULL; int x, y, extra_width=0,text_width,text_height; int width,height; - va_start(args, format); vsnprintf(outbuf, 1024, format, args); - va_end(args); entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); mainbox = dw_box_new(DW_VERT, 10); diff -r fe31d4535270 -r 761b7a12b079 gtk3/dw.c --- a/gtk3/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/gtk3/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -2371,13 +2371,15 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + vfprintf(stderr, format, args); va_end(args); - - fprintf(stderr, "%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + vfprintf(stderr, format, args); } /* @@ -2388,18 +2390,26 @@ * format: printf style format string. * ...: Additional variables for use in the format. */ -int dw_messagebox(const char *title, int flags, const char *format, ...) +int API dw_messagebox(const char *title, int flags, const char *format, ...) +{ + va_list args; + int rc; + + va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int dw_vmessagebox(const char *title, int flags, const char *format, va_list args) { GtkMessageType gtkicon = GTK_MESSAGE_OTHER; GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; GtkWidget *dialog; int response, _dw_locked_by_me = FALSE; - va_list args; char outbuf[1025] = {0}; - va_start(args, format); vsnprintf(outbuf, 1024, format, args); - va_end(args); if(flags & DW_MB_ERROR) gtkicon = GTK_MESSAGE_ERROR; diff -r fe31d4535270 -r 761b7a12b079 gtk4/dw.c --- a/gtk4/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/gtk4/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -1780,13 +1780,15 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + vfprintf(stderr, format, args); va_end(args); - - fprintf(stderr, "%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + vfprintf(stderr, format, args); } /* Internal version that does not use variable arguments */ @@ -1867,12 +1869,19 @@ int API dw_messagebox(const char *title, int flags, const char *format, ...) { va_list args; - char outbuf[1025] = {0}; + int rc; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + rc = dw_vmessagebox(title, flags, format, args); va_end(args); - + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ + char outbuf[1025] = {0}; + + vsnprintf(outbuf, 1024, format, args); return dw_messagebox_int(title, flags, outbuf); } diff -r fe31d4535270 -r 761b7a12b079 ios/dw.m --- a/ios/dw.m Sat Dec 24 14:28:39 2022 +0000 +++ b/ios/dw.m Sun Dec 25 00:20:49 2022 +0000 @@ -4366,13 +4366,17 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + dw_vdebug(format, args); va_end(args); - - NSLog(@"%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + NSString *nformat = [[NSString stringWithUTF8String:format] autorelease]; + + NSLogv(nformat, args); } /* @@ -4385,6 +4389,17 @@ */ int API dw_messagebox(const char *title, int flags, const char *format, ...) { + va_list args; + int rc; + + va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ NSInteger iResponse; NSString *button1 = @"OK"; NSString *button2 = nil; @@ -4393,7 +4408,6 @@ NSString *mtext; UIAlertControllerStyle mstyle = UIAlertControllerStyleAlert; NSArray *params; - va_list args; static int in_mb = FALSE; /* Prevent recursion */ @@ -4417,9 +4431,7 @@ button3 = @"Cancel"; } - va_start(args, format); mtext = [[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args]; - va_end(args); params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; [DWObj safeCall:@selector(messageBox:) withObject:params]; diff -r fe31d4535270 -r 761b7a12b079 mac/dw.m --- a/mac/dw.m Sat Dec 24 14:28:39 2022 +0000 +++ b/mac/dw.m Sun Dec 25 00:20:49 2022 +0000 @@ -4350,13 +4350,17 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + dw_vdebug(format, args); va_end(args); - - NSLog(@"%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + NSString *nformat = [[NSString stringWithUTF8String:format] autorelease]; + + NSLogv(nformat, args); } /* @@ -4369,6 +4373,17 @@ */ int API dw_messagebox(const char *title, int flags, const char *format, ...) { + va_list args; + int rc; + + va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ NSInteger iResponse; NSString *button1 = @"OK"; NSString *button2 = nil; @@ -4377,7 +4392,6 @@ NSString *mtext; NSAlertStyle mstyle = DWAlertStyleWarning; NSArray *params; - va_list args; if(flags & DW_MB_OKCANCEL) { @@ -4395,9 +4409,7 @@ button3 = @"Cancel"; } - va_start(args, format); mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; - va_end(args); if(flags & DW_MB_ERROR) mstyle = DWAlertStyleCritical; diff -r fe31d4535270 -r 761b7a12b079 os2/dw.c --- a/os2/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/os2/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -4673,15 +4673,21 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = { 0 }; va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); +} + +void API dw_vdebug(const char *format, va_list args) +{ + char outbuf[1025] = { 0 }; + #if defined(__IBMC__) vsprintf(outbuf, format, args); #else vsnprintf(outbuf, 1024, format, args); #endif - va_end(args); if(_PmPrintfString) { @@ -4707,16 +4713,24 @@ int API dw_messagebox(const char *title, int flags, const char *format, ...) { va_list args; - char outbuf[1025] = { 0 }; int rc; va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ + char outbuf[1025] = { 0 }; + int rc; + #if defined(__IBMC__) vsprintf(outbuf, format, args); #else vsnprintf(outbuf, 1024, format, args); #endif - va_end(args); rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (PSZ)outbuf, (PSZ)title, 0, flags | MB_MOVEABLE); if(rc == MBID_OK) diff -r fe31d4535270 -r 761b7a12b079 os2/dw.def --- a/os2/dw.def Sat Dec 24 14:28:39 2022 +0000 +++ b/os2/dw.def Sun Dec 25 00:20:49 2022 +0000 @@ -29,6 +29,9 @@ _dw_init_thread @30 _dw_deinit_thread @31 + dw_vdebug @35 + dw_vmessagebox @36 + dw_box_new @40 dw_groupbox_new @41 dw_box_pack_start @42 diff -r fe31d4535270 -r 761b7a12b079 readme.txt --- a/readme.txt Sat Dec 24 14:28:39 2022 +0000 +++ b/readme.txt Sun Dec 25 00:20:49 2022 +0000 @@ -66,7 +66,9 @@ Currently affected: dw_window_set_bitmap(_from_data) Added C++ language bindings in dw.hpp and an example C++ test application in the form of dwtestoo.cpp, similar to godwindows. - +Added variadic versions of dw_debug() and dw_messagebox(). + This is how the standard library does it so we can call the new + va_list versions from C++: dw_vdebug() and dw_vmessagebox(). Dynamic Windows Documentation is available at: diff -r fe31d4535270 -r 761b7a12b079 template/dw.c --- a/template/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/template/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -360,16 +360,15 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + vfprintf(stderr, format, args); va_end(args); - - /* Output to stderr, if there is another way to send it - * on the implementation platform, change this. - */ - fprintf(stderr, "%s", outbuf); +} + +void API dw_vdebug(const char *format, va_list args) +{ + vfprintf(stderr, format, args); } /* @@ -385,6 +384,17 @@ */ int API dw_messagebox(const char *title, int flags, const char *format, ...) { + va_list args; + int rc; + + va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ return 0; } diff -r fe31d4535270 -r 761b7a12b079 win/dw.c --- a/win/dw.c Sat Dec 24 14:28:39 2022 +0000 +++ b/win/dw.c Sun Dec 25 00:20:49 2022 +0000 @@ -5057,12 +5057,17 @@ void API dw_debug(const char *format, ...) { va_list args; - char outbuf[1025] = {0}, *thisbuf = outbuf; va_start(args, format); - vsnprintf(outbuf, 1024, format, args); + dw_vdebug(format, args); va_end(args); - +} + +void API dw_vdebug(const char *format, va_list args) +{ + char outbuf[1025] = {0}, *thisbuf = outbuf; + + vsnprintf(outbuf, 1024, format, args); OutputDebugString(UTF8toWide(thisbuf)); } @@ -5076,12 +5081,20 @@ int API dw_messagebox(const char *title, int flags, const char *format, ...) { va_list args; - char outbuf[1025] = { 0 }, *thisbuf = outbuf; int rc; va_start(args, format); + rc = dw_vmessagebox(title, flags, format, args); + va_end(args); + return rc; +} + +int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args) +{ + char outbuf[1025] = { 0 }, *thisbuf = outbuf; + int rc; + vsnprintf(outbuf, 1024, format, args); - va_end(args); rc = MessageBox(HWND_DESKTOP, UTF8toWide(thisbuf), UTF8toWide(title), flags); if(rc == IDOK) diff -r fe31d4535270 -r 761b7a12b079 win/dw.def --- a/win/dw.def Sat Dec 24 14:28:39 2022 +0000 +++ b/win/dw.def Sun Dec 25 00:20:49 2022 +0000 @@ -27,6 +27,9 @@ _dw_init_thread @30 _dw_deinit_thread @31 + dw_vdebug @35 + dw_vmessagebox @36 + dw_box_new @40 dw_groupbox_new @41 dw_box_pack_start @42