Changeset 2913


Ignore:
Timestamp:
Dec 25, 2022, 1:20:49 AM (2 years ago)
Author:
bsmith
Message:

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.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/android/dw.cpp

    r2868 r2913  
    11671167{
    11681168    va_list args;
    1169     char outbuf[1025] = {0};
    1170     JNIEnv *env;
    11711169
    11721170    va_start(args, format);
    1173     vsnprintf(outbuf, 1024, format, args);
     1171    vfprintf(stderr, format, args);
    11741172    va_end(args);
     1173}
     1174
     1175void API dw_vdebug(const char *format, va_list args)
     1176{
     1177    JNIEnv *env;
    11751178
    11761179    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
    11771180    {
     1181        char outbuf[1025] = {0};
     1182
     1183        vsnprintf(outbuf, 1024, format, args);
     1184
    11781185        // Construct a String
    11791186        jstring jstr = env->NewStringUTF(outbuf);
     
    11921199         * on the implementation platform, change this.
    11931200         */
    1194         fprintf(stderr, "%s", outbuf);
     1201        vfprintf(stderr, format, args);
    11951202    }
    11961203}
     
    12101217{
    12111218    va_list args;
    1212     char outbuf[1025] = {0};
     1219    int rc;
     1220
     1221    va_start(args, format);
     1222    rc = dw_vmessagebox(title, flags, format, args);
     1223    va_end(args);
     1224    return rc;
     1225}
     1226
     1227int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
     1228{
    12131229    JNIEnv *env;
    12141230    int retval = 0;
    12151231
    1216     va_start(args, format);
    1217     vsnprintf(outbuf, 1024, format, args);
    1218     va_end(args);
    1219 
    12201232    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
    12211233    {
     1234        char outbuf[1025] = {0};
     1235
     1236        vsnprintf(outbuf, 1024, format, args);
     1237
    12221238        // Construct a String
    12231239        jstring jstr = env->NewStringUTF(outbuf);
  • TabularUnified trunk/dw.h

    r2876 r2913  
    21882188void API dw_beep(int freq, int dur);
    21892189void API dw_debug(const char *format, ...);
     2190void API dw_vdebug(const char *format, va_list args);
    21902191int API dw_messagebox(const char *title, int flags, const char *format, ...);
     2192int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args);
    21912193void API dw_environment_query(DWEnv *env);
    21922194int API dw_exec(const char *program, int type, char **params);
  • TabularUnified trunk/dw.hpp

    r2912 r2913  
    13961396    void MainQuit() { dw_main_quit(); }
    13971397    void Exit(int exitcode) { dw_exit(exitcode); }
    1398     int MessageBox(const char *title, int flags, const char *format) { return dw_messagebox(title, flags, format); }
     1398    int MessageBox(const char *title, int flags, const char *format, ...) {
     1399        int retval;
     1400        va_list args;
     1401
     1402        va_start(args, format);
     1403        retval = dw_vmessagebox(title, flags, format, args);
     1404        va_end(args);
     1405
     1406        return retval;
     1407    }
     1408    void Debug(const char *format, ...) {
     1409        va_list args;
     1410
     1411        va_start(args, format);
     1412        dw_vdebug(format, args);
     1413        va_end(args);
     1414    }
    13991415};
    14001416
  • TabularUnified trunk/gtk/dw.c

    r2872 r2913  
    25272527{
    25282528   va_list args;
    2529    char outbuf[1025] = {0};
    25302529
    25312530   va_start(args, format);
    2532    vsnprintf(outbuf, 1024, format, args);
     2531   vfprintf(stderr, format, args);
    25332532   va_end(args);
    2534 
    2535    fprintf(stderr, "%s", outbuf);
     2533}
     2534
     2535void API dw_vdebug(const char *format, va_list args)
     2536{
     2537   vfprintf(stderr, format, args);
    25362538}
    25372539
     
    25442546 *           ...: Additional variables for use in the format.
    25452547 */
    2546 int dw_messagebox(const char *title, int flags, const char *format, ...)
     2548int API dw_messagebox(const char *title, int flags, const char *format, ...)
     2549{
     2550   va_list args;
     2551   int rc;
     2552
     2553   va_start(args, format);
     2554   rc = dw_vmessagebox(title, flags, format, args);
     2555   va_end(args);
     2556   return rc;
     2557}
     2558
     2559int dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
    25472560{
    25482561   HWND entrywindow, texttargetbox, imagetextbox, mainbox, okbutton, nobutton, yesbutton, cancelbutton, buttonbox, stext;
    25492562   ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER;
    25502563   DWDialog *dwwait;
    2551    va_list args;
    25522564   char outbuf[1025] = {0};
    25532565   char **xpm_data = NULL;
     
    25552567   int width,height;
    25562568
    2557    va_start(args, format);
    25582569   vsnprintf(outbuf, 1024, format, args);
    2559    va_end(args);
    25602570
    25612571   entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle);
  • TabularUnified trunk/gtk3/dw.c

    r2872 r2913  
    23722372{
    23732373   va_list args;
    2374    char outbuf[1025] = {0};
    23752374
    23762375   va_start(args, format);
    2377    vsnprintf(outbuf, 1024, format, args);
     2376   vfprintf(stderr, format, args);
    23782377   va_end(args);
    2379 
    2380    fprintf(stderr, "%s", outbuf);
     2378}
     2379
     2380void API dw_vdebug(const char *format, va_list args)
     2381{
     2382   vfprintf(stderr, format, args);
    23812383}
    23822384
     
    23892391 *           ...: Additional variables for use in the format.
    23902392 */
    2391 int dw_messagebox(const char *title, int flags, const char *format, ...)
     2393int API dw_messagebox(const char *title, int flags, const char *format, ...)
     2394{
     2395   va_list args;
     2396   int rc;
     2397
     2398   va_start(args, format);
     2399   rc = dw_vmessagebox(title, flags, format, args);
     2400   va_end(args);
     2401   return rc;
     2402}
     2403
     2404int dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
    23922405{
    23932406   GtkMessageType gtkicon = GTK_MESSAGE_OTHER;
     
    23952408   GtkWidget *dialog;
    23962409   int response, _dw_locked_by_me = FALSE;
    2397    va_list args;
    23982410   char outbuf[1025] = {0};
    23992411
    2400    va_start(args, format);
    24012412   vsnprintf(outbuf, 1024, format, args);
    2402    va_end(args);
    24032413
    24042414   if(flags & DW_MB_ERROR)
  • TabularUnified trunk/gtk4/dw.c

    r2872 r2913  
    17811781{
    17821782   va_list args;
    1783    char outbuf[1025] = {0};
    17841783
    17851784   va_start(args, format);
    1786    vsnprintf(outbuf, 1024, format, args);
     1785   vfprintf(stderr, format, args);
    17871786   va_end(args);
    1788 
    1789    fprintf(stderr, "%s", outbuf);
     1787}
     1788
     1789void API dw_vdebug(const char *format, va_list args)
     1790{
     1791   vfprintf(stderr, format, args);
    17901792}
    17911793
     
    18681870{
    18691871   va_list args;
     1872   int rc;
     1873
     1874   va_start(args, format);
     1875   rc = dw_vmessagebox(title, flags, format, args);
     1876   va_end(args);
     1877   return rc;
     1878}
     1879
     1880int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
     1881{
    18701882   char outbuf[1025] = {0};
    18711883
    1872    va_start(args, format);
    18731884   vsnprintf(outbuf, 1024, format, args);
    1874    va_end(args);
    1875    
    18761885   return dw_messagebox_int(title, flags, outbuf);
    18771886}
  • TabularUnified trunk/ios/dw.m

    r2900 r2913  
    43674367{
    43684368   va_list args;
    4369    char outbuf[1025] = {0};
    43704369
    43714370   va_start(args, format);
    4372    vsnprintf(outbuf, 1024, format, args);
     4371   dw_vdebug(format, args);
    43734372   va_end(args);
    4374 
    4375    NSLog(@"%s", outbuf);
     4373}
     4374
     4375void API dw_vdebug(const char *format, va_list args)
     4376{
     4377   NSString *nformat = [[NSString stringWithUTF8String:format] autorelease];
     4378
     4379   NSLogv(nformat, args);
    43764380}
    43774381
     
    43854389 */
    43864390int API dw_messagebox(const char *title, int flags, const char *format, ...)
     4391{
     4392   va_list args;
     4393   int rc;
     4394
     4395   va_start(args, format);
     4396   rc = dw_vmessagebox(title, flags, format, args);
     4397   va_end(args);
     4398   return rc;
     4399}
     4400
     4401int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
    43874402{
    43884403    NSInteger iResponse;
     
    43944409    UIAlertControllerStyle mstyle = UIAlertControllerStyleAlert;
    43954410    NSArray *params;
    4396     va_list args;
    43974411    static int in_mb = FALSE;
    43984412
     
    44184432    }
    44194433
    4420     va_start(args, format);
    44214434    mtext = [[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args];
    4422     va_end(args);
    44234435
    44244436    params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil];
  • TabularUnified trunk/mac/dw.m

    r2899 r2913  
    43514351{
    43524352   va_list args;
    4353    char outbuf[1025] = {0};
    43544353
    43554354   va_start(args, format);
    4356    vsnprintf(outbuf, 1024, format, args);
     4355   dw_vdebug(format, args);
    43574356   va_end(args);
    4358 
    4359    NSLog(@"%s", outbuf);
     4357}
     4358
     4359void API dw_vdebug(const char *format, va_list args)
     4360{
     4361   NSString *nformat = [[NSString stringWithUTF8String:format] autorelease];
     4362
     4363   NSLogv(nformat, args);
    43604364}
    43614365
     
    43694373 */
    43704374int API dw_messagebox(const char *title, int flags, const char *format, ...)
     4375{
     4376   va_list args;
     4377   int rc;
     4378
     4379   va_start(args, format);
     4380   rc = dw_vmessagebox(title, flags, format, args);
     4381   va_end(args);
     4382   return rc;
     4383}
     4384
     4385int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
    43714386{
    43724387    NSInteger iResponse;
     
    43784393    NSAlertStyle mstyle = DWAlertStyleWarning;
    43794394    NSArray *params;
    4380     va_list args;
    43814395
    43824396    if(flags & DW_MB_OKCANCEL)
     
    43964410    }
    43974411
    4398     va_start(args, format);
    43994412    mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease];
    4400     va_end(args);
    44014413
    44024414    if(flags & DW_MB_ERROR)
  • TabularUnified trunk/os2/dw.c

    r2865 r2913  
    46744674{
    46754675   va_list args;
     4676
     4677   va_start(args, format);
     4678   vfprintf(stderr, format, args);
     4679   va_end(args);
     4680}
     4681
     4682void API dw_vdebug(const char *format, va_list args)
     4683{
    46764684   char outbuf[1025] = { 0 };
    46774685
    4678    va_start(args, format);
    46794686#if defined(__IBMC__)
    46804687   vsprintf(outbuf, format, args);
     
    46824689   vsnprintf(outbuf, 1024, format, args);
    46834690#endif
    4684    va_end(args);
    46854691
    46864692   if(_PmPrintfString)
     
    47084714{
    47094715   va_list args;
     4716   int rc;
     4717
     4718   va_start(args, format);
     4719   rc = dw_vmessagebox(title, flags, format, args);
     4720   va_end(args);
     4721   return rc;
     4722}
     4723
     4724int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
     4725{
    47104726   char outbuf[1025] = { 0 };
    47114727   int rc;
    47124728
    4713    va_start(args, format);
    47144729#if defined(__IBMC__)
    47154730   vsprintf(outbuf, format, args);
     
    47174732   vsnprintf(outbuf, 1024, format, args);
    47184733#endif
    4719    va_end(args);
    47204734
    47214735   rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (PSZ)outbuf, (PSZ)title, 0, flags | MB_MOVEABLE);
  • TabularUnified trunk/os2/dw.def

    r2543 r2913  
    2929  _dw_init_thread                        @30
    3030  _dw_deinit_thread                      @31
     31
     32  dw_vdebug                              @35
     33  dw_vmessagebox                         @36
    3134
    3235  dw_box_new                             @40
  • TabularUnified trunk/readme.txt

    r2887 r2913  
    6767Added C++ language bindings in dw.hpp and an example C++ test
    6868    application in the form of dwtestoo.cpp, similar to godwindows.
    69 
     69Added variadic versions of dw_debug() and dw_messagebox().
     70    This is how the standard library does it so we can call the new
     71    va_list versions from C++: dw_vdebug() and dw_vmessagebox().
    7072
    7173Dynamic Windows Documentation is available at:
  • TabularUnified trunk/template/dw.c

    r2864 r2913  
    361361{
    362362   va_list args;
    363    char outbuf[1025] = {0};
    364363
    365364   va_start(args, format);
    366    vsnprintf(outbuf, 1024, format, args);
     365   vfprintf(stderr, format, args);
    367366   va_end(args);
    368 
    369    /* Output to stderr, if there is another way to send it
    370     * on the implementation platform, change this.
    371     */
    372    fprintf(stderr, "%s", outbuf);
     367}
     368
     369void API dw_vdebug(const char *format, va_list args)
     370{
     371   vfprintf(stderr, format, args);
    373372}
    374373
     
    385384 */
    386385int API dw_messagebox(const char *title, int flags, const char *format, ...)
     386{
     387   va_list args;
     388   int rc;
     389
     390   va_start(args, format);
     391   rc = dw_vmessagebox(title, flags, format, args);
     392   va_end(args);
     393   return rc;
     394}
     395
     396int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
    387397{
    388398    return 0;
  • TabularUnified trunk/win/dw.c

    r2864 r2913  
    50585058{
    50595059   va_list args;
     5060
     5061   va_start(args, format);
     5062   dw_vdebug(format, args);
     5063   va_end(args);
     5064}
     5065
     5066void API dw_vdebug(const char *format, va_list args)
     5067{
    50605068   char outbuf[1025] = {0}, *thisbuf = outbuf;
    50615069
    5062    va_start(args, format);
    50635070   vsnprintf(outbuf, 1024, format, args);
    5064    va_end(args);
    5065 
    50665071   OutputDebugString(UTF8toWide(thisbuf));
    50675072}
     
    50775082{
    50785083   va_list args;
     5084   int rc;
     5085
     5086   va_start(args, format);
     5087   rc = dw_vmessagebox(title, flags, format, args);
     5088   va_end(args);
     5089   return rc;
     5090}
     5091
     5092int API dw_vmessagebox(const char *title, int flags, const char *format, va_list args)
     5093{
    50795094   char outbuf[1025] = { 0 }, *thisbuf = outbuf;
    50805095   int rc;
    50815096
    5082    va_start(args, format);
    50835097   vsnprintf(outbuf, 1024, format, args);
    5084    va_end(args);
    50855098
    50865099   rc = MessageBox(HWND_DESKTOP, UTF8toWide(thisbuf), UTF8toWide(title), flags);
  • TabularUnified trunk/win/dw.def

    r2543 r2913  
    2727  _dw_init_thread                        @30
    2828  _dw_deinit_thread                      @31
     29
     30  dw_vdebug                              @35
     31  dw_vmessagebox                         @36
    2932
    3033  dw_box_new                             @40
Note: See TracChangeset for help on using the changeset viewer.