# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1320363250 0 # Node ID dbd507f4294764d629ed86cb07112a2fefaedd2a # Parent 18a31ab94e3d2a881e1c0432ceae28600e98b67f Added dw_debug() logging function which will output a message to the debugging console. On Windows this uses OutputDebugMessage(), on Mac it uses NSLog() ... The other platforms currently just dump it to stderr. Maybe more enhancements to come. diff -r 18a31ab94e3d -r dbd507f42947 dw.def --- a/dw.def Thu Nov 03 10:09:11 2011 +0000 +++ b/dw.def Thu Nov 03 23:34:10 2011 +0000 @@ -13,6 +13,7 @@ dw_exit @12 dw_beep @13 dw_messagebox @14 + dw_debug @15 dw_environment_query @16 dw_exec @17 diff -r 18a31ab94e3d -r dbd507f42947 dw.h --- a/dw.h Thu Nov 03 10:09:11 2011 +0000 +++ b/dw.h Thu Nov 03 23:34:10 2011 +0000 @@ -1673,6 +1673,7 @@ int API dw_pixmap_set_font(HPIXMAP pixmap, char *fontname); void API dw_pixmap_destroy(HPIXMAP pixmap); void API dw_beep(int freq, int dur); +void API dw_debug(char *format, ...); int API dw_messagebox(char *title, int flags, char *format, ...); void API dw_environment_query(DWEnv *env); int API dw_exec(char *program, int type, char **params); diff -r 18a31ab94e3d -r dbd507f42947 dwtest.c --- a/dwtest.c Thu Nov 03 10:09:11 2011 +0000 +++ b/dwtest.c Thu Nov 03 23:34:10 2011 +0000 @@ -610,7 +610,7 @@ int DWSIGNAL browse_folder_callback(HWND window, void *data) { char *tmp = dw_file_browse("Pick a folder", ".", "c", DW_DIRECTORY_OPEN ); - printf("Folder picked: %s\n", tmp ? tmp : "None"); + dw_debug("Folder picked: %s\n", tmp ? tmp : "None"); return 0; } @@ -781,11 +781,11 @@ /* Make the last inserted point the cursor location */ dw_mle_set_cursor(container_mle, mle_point); /* set the details of item 0 to new data */ - fprintf(stderr,"In cb: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), + dw_debug("In cb: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), DW_POINTER_TO_INT(containerinfo), DW_POINTER_TO_INT(fileicon)); dw_filesystem_change_file(container, 0, "new data", fileicon); size = 999; - fprintf(stderr,"In cb: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), + dw_debug("In cb: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), DW_POINTER_TO_INT(containerinfo), DW_POINTER_TO_INT(fileicon)); dw_filesystem_change_item(container, 1, 0, &size); return 0; @@ -793,13 +793,8 @@ int DWSIGNAL switch_page_cb( HWND window, unsigned long page_num, void *itemdata ) { - FILE *fp=fopen("log","a"); - if ( fp ) - { - fprintf(fp,"DW_SIGNAL_SWITCH_PAGE: Window: %x PageNum: %u Itemdata: %x\n", DW_POINTER_TO_UINT(window), - DW_POINTER_TO_UINT(page_num), DW_POINTER_TO_UINT(itemdata) ); - fclose(fp); - } + dw_debug("DW_SIGNAL_SWITCH_PAGE: Window: %x PageNum: %u Itemdata: %x\n", DW_POINTER_TO_UINT(window), + DW_POINTER_TO_UINT(page_num), DW_POINTER_TO_UINT(itemdata) ); return 0; } @@ -835,7 +830,7 @@ int DWSIGNAL combobox_select_event_callback(HWND window, int index) { - fprintf(stderr,"got combobox_select_event for index: %d, iteration: %d\n", index, iteration++); + dw_debug("got combobox_select_event for index: %d, iteration: %d\n", index, iteration++); return FALSE; } @@ -1123,8 +1118,8 @@ sprintf(buffer, "Filename %d",z+1); if (z == 0 ) thisicon = foldericon; else thisicon = fileicon; - fprintf(stderr,"Initial: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), - DW_POINTER_TO_INT(containerinfo), DW_POINTER_TO_INT(thisicon)); + dw_debug("Initial: container: %x containerinfo: %x icon: %x\n", DW_POINTER_TO_INT(container), + DW_POINTER_TO_INT(containerinfo), DW_POINTER_TO_INT(thisicon)); dw_filesystem_set_file(container, containerinfo, z, buffer, thisicon); dw_filesystem_set_item(container, containerinfo, 0, z, &thisicon); dw_filesystem_set_item(container, containerinfo, 1, z, &size); @@ -1233,13 +1228,13 @@ dw_signal_connect( combobox1, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(combobox_select_event_callback), NULL ); #if 0 /* add LOTS of items */ - fprintf(stderr,"before appending 100 items to combobox using dw_listbox_append()\n"); + dw_debug("before appending 100 items to combobox using dw_listbox_append()\n"); for( i = 0; i < 100; i++ ) { sprintf( buf, "item %d", i); dw_listbox_append( combobox1, buf ); } - fprintf(stderr,"after appending 100 items to combobox\n"); + dw_debug("after appending 100 items to combobox\n"); #endif combobox2 = dw_combobox_new( "joe", 0 ); /* no point in specifying an initial value */ @@ -1249,7 +1244,7 @@ */ dw_signal_connect( combobox2, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(combobox_select_event_callback), NULL ); /* add LOTS of items */ - fprintf(stderr,"before appending 500 items to combobox using dw_listbox_list_append()\n"); + dw_debug("before appending 500 items to combobox using dw_listbox_list_append()\n"); text = (char **)malloc(500*sizeof(char *)); for( i = 0; i < 500; i++ ) { @@ -1257,7 +1252,7 @@ sprintf( text[i], "item %d", i); } dw_listbox_list_append( combobox2, text, 500 ); - fprintf(stderr,"after appending 500 items to combobox\n"); + dw_debug("after appending 500 items to combobox\n"); for( i = 0; i < 500; i++ ) { free(text[i]); @@ -1384,7 +1379,7 @@ pos = dw_scrollbox_get_pos( scrollbox, DW_VERT ); range = dw_scrollbox_get_range( scrollbox, DW_VERT ); - fprintf( stderr, "Pos %d Range %d\n", pos, range ); + dw_debug("Pos %d Range %d\n", pos, range ); return 0; } diff -r 18a31ab94e3d -r dbd507f42947 dww.def --- a/dww.def Thu Nov 03 10:09:11 2011 +0000 +++ b/dww.def Thu Nov 03 23:34:10 2011 +0000 @@ -10,6 +10,7 @@ dw_exit @12 dw_beep @13 dw_messagebox @14 + dw_debug @15 dw_environment_query @16 dw_exec @17 diff -r 18a31ab94e3d -r dbd507f42947 gtk/dw.c --- a/gtk/dw.c Thu Nov 03 10:09:11 2011 +0000 +++ b/gtk/dw.c Thu Nov 03 23:34:10 2011 +0000 @@ -1221,17 +1221,17 @@ { int counter = GPOINTER_TO_INT(data); SignalHandler sh; - char text[100]; - - sprintf(text, "_dw_sigwindow%d", counter); + char text[101] = {0}; + + snprintf(text, 100, "_dw_sigwindow%d", counter); sh.window = (HWND)gtk_object_get_data(GTK_OBJECT(widget), text); - sprintf(text, "_dw_sigfunc%d", counter); + snprintf(text, 100, "_dw_sigfunc%d", counter); sh.func = (void *)gtk_object_get_data(GTK_OBJECT(widget), text); - sprintf(text, "_dw_intfunc%d", counter); + snprintf(text, 100, "_dw_intfunc%d", counter); sh.intfunc = (void *)gtk_object_get_data(GTK_OBJECT(widget), text); - sprintf(text, "_dw_sigdata%d", counter); + snprintf(text, 100, "_dw_sigdata%d", counter); sh.data = gtk_object_get_data(GTK_OBJECT(widget), text); - sprintf(text, "_dw_sigcid%d", counter); + snprintf(text, 100, "_dw_sigcid%d", counter); sh.cid = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), text)); return sh; @@ -1239,35 +1239,35 @@ static void _remove_signal_handler(GtkWidget *widget, int counter) { - char text[100]; + char text[101] = {0}; gint cid; - sprintf(text, "_dw_sigcid%d", counter); + snprintf(text, 100, "_dw_sigcid%d", counter); cid = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), text)); gtk_signal_disconnect(GTK_OBJECT(widget), cid); gtk_object_set_data(GTK_OBJECT(widget), text, NULL); - sprintf(text, "_dw_sigwindow%d", counter); + sbprintf(text, 100, "_dw_sigwindow%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, NULL); - sprintf(text, "_dw_sigfunc%d", counter); + sbprintf(text, 100, "_dw_sigfunc%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, NULL); - sprintf(text, "_dw_intfunc%d", counter); + sbprintf(text, 100, "_dw_intfunc%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, NULL); - sprintf(text, "_dw_sigdata%d", counter); + sbprintf(text, 100, "_dw_sigdata%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, NULL); } static int _set_signal_handler(GtkWidget *widget, HWND window, void *func, gpointer data, void *intfunc) { int counter = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), "_dw_sigcounter")); - char text[100]; - - sprintf(text, "_dw_sigwindow%d", counter); + char text[101] = {0}; + + snprintf(text, 100, "_dw_sigwindow%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, (gpointer)window); - sprintf(text, "_dw_sigfunc%d", counter); + snprintf(text, 100, "_dw_sigfunc%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, (gpointer)func); - sprintf(text, "_dw_intfunc%d", counter); + snprintf(text, 100, "_dw_intfunc%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, (gpointer)intfunc); - sprintf(text, "_dw_sigdata%d", counter); + snprintf(text, 100, "_dw_sigdata%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, (gpointer)data); counter++; @@ -1278,9 +1278,9 @@ static void _set_signal_handler_id(GtkWidget *widget, int counter, gint cid) { - char text[100]; - - sprintf(text, "_dw_sigcid%d", counter); + char text[101] = {0}; + + snprintf(text, 100, "_dw_sigcid%d", counter); gtk_object_set_data(GTK_OBJECT(widget), text, GINT_TO_POINTER(cid)); } @@ -2039,10 +2039,10 @@ #ifdef USE_WEBKIT void init_webkit(void) { - char libname[100]; + char libname[101] = {0}; void *handle = NULL; - sprintf( libname, "lib%s.so", WEBKIT_LIB); + snprintf( libname, 100, "lib%s.so", WEBKIT_LIB); handle = dlopen( libname, RTLD_LAZY ); /* If we loaded it, grab the symbols we want */ @@ -2368,6 +2368,24 @@ } /* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + fprintf(stderr, "%s", outbuf); +} + +/* * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. @@ -2381,13 +2399,13 @@ ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; DWDialog *dwwait; va_list args; - char outbuf[1000]; + 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, 999, format, args); + vsnprintf(outbuf, 1024, format, args); va_end(args); entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); @@ -3711,9 +3729,10 @@ tmphandle=gtk_menu_item_new(); else { + char numbuf[11] = {0}; + if (check) { - char numbuf[10]; if (accel && accel_group) { tmphandle = gtk_check_menu_item_new_with_label(""); @@ -3725,12 +3744,11 @@ else tmphandle = gtk_check_menu_item_new_with_label(tempbuf); gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(tmphandle), TRUE); - sprintf(numbuf, "%lu", id); + snprintf(numbuf, 10, "%lu", id); gtk_object_set_data(GTK_OBJECT(menu), numbuf, (gpointer)tmphandle); } else { - char numbuf[10]; if (accel && accel_group) { tmphandle=gtk_menu_item_new_with_label(""); @@ -3741,7 +3759,7 @@ } else tmphandle=gtk_menu_item_new_with_label(tempbuf); - sprintf(numbuf, "%lu", id); + snprintf(numbuf, 10, "%lu", id); gtk_object_set_data(GTK_OBJECT(menu), numbuf, (gpointer)tmphandle); } } @@ -3750,9 +3768,9 @@ if (submenu) { - char tempbuf[100]; - - sprintf(tempbuf, "_dw_submenu%d", submenucount); + char tempbuf[101] = {0}; + + snprintf(tempbuf, 100, "_dw_submenu%d", submenucount); submenucount++; gtk_menu_item_set_submenu(GTK_MENU_ITEM(tmphandle), submenu); gtk_object_set_data(GTK_OBJECT(menu), tempbuf, (gpointer)submenu); @@ -3793,10 +3811,10 @@ for(z=0;z 1) gtk_clist_set_column_width(GTK_CLIST(clist), z, 50); - sprintf(numbuf, "%d", z); + snprintf(numbuf, 10, "%d", z); gtk_object_set_data(GTK_OBJECT(clist), numbuf, GINT_TO_POINTER(flags[z])); if(flags[z]&DW_CFA_RIGHT) justification = GTK_JUSTIFY_RIGHT; @@ -6943,7 +6961,7 @@ */ void _dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data, char *text) { - char numbuf[10], textbuffer[100]; + char numbuf[11], textbuffer[101]; int flag = 0; GtkWidget *clist; int _locked_by_me = FALSE; @@ -6956,7 +6974,7 @@ return; } - sprintf(numbuf, "%d", column); + snprintf(numbuf, 10, "%d", column); flag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), numbuf)); if(pointer) { @@ -6988,7 +7006,7 @@ { ULONG tmp = *((ULONG *)data); - sprintf(textbuffer, "%lu", tmp); + snprintf(textbuffer, 100, "%lu", tmp); gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); } @@ -7115,7 +7133,7 @@ */ int dw_container_get_column_type(HWND handle, int column) { - char numbuf[10]; + char numbuf[11] = {0}; int flag, rc; GtkWidget *clist; int _locked_by_me = FALSE; @@ -7128,7 +7146,7 @@ return 0; } - sprintf(numbuf, "%d", column); + snprintf(numbuf, 10, "%d", column); flag = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), numbuf)); if(flag & DW_CFA_BITMAPORICON) @@ -8928,7 +8946,7 @@ { int len; char *newname; - char errorbuf[1024]; + char errorbuf[1025] = {0}; if(!handle) @@ -9551,11 +9569,11 @@ */ HSHM dw_named_memory_new(void **dest, int size, char *name) { - char namebuf[1024]; + char namebuf[1025] = {0}; struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); - sprintf(namebuf, "/tmp/.dw/%s", name); + snprintf(namebuf, 1024, "/tmp/.dw/%s", name); if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) { @@ -9597,11 +9615,11 @@ */ HSHM dw_named_memory_get(void **dest, int size, char *name) { - char namebuf[1024]; + char namebuf[1025] = {0}; struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); - sprintf(namebuf, "/tmp/.dw/%s", name); + snprintf(namebuf, 1024, "/tmp/.dw/%s", name); if((handle->fd = open(namebuf, O_RDWR)) < 0) { @@ -10260,13 +10278,13 @@ { if(!pagearray[z]) { - char text[100]; + char text[101] = {0}; int num = z; if(front) num |= 1 << 16; - sprintf(text, "_dw_page%d", z); + snprintf(text, 100, "_dw_page%d", z); /* Save the real id and the creation flags */ gtk_object_set_data(GTK_OBJECT(handle), text, GINT_TO_POINTER(num)); DW_MUTEX_UNLOCK; @@ -10373,10 +10391,10 @@ realpage = _get_physical_page(handle, pageid); if(realpage < 0 || realpage > 255) { - char ptext[100]; + char ptext[101] = {0}; int num; - sprintf(ptext, "_dw_page%d", (int)pageid); + snprintf(ptext, 100, "_dw_page%d", (int)pageid); num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), ptext)); realpage = 0xFF & num; } @@ -10414,10 +10432,10 @@ GtkWidget *label, *child, *oldlabel, **pagearray; gchar *text = NULL; int num, z, realpage = -1, pad, _locked_by_me = FALSE; - char ptext[100]; - - DW_MUTEX_LOCK; - sprintf(ptext, "_dw_page%d", (int)pageid); + char ptext[101] = {0}; + + DW_MUTEX_LOCK; + snprintf(ptext, 100, "_dw_page%d", (int)pageid); num = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), ptext)); gtk_object_set_data(GTK_OBJECT(handle), ptext, NULL); pagearray = (GtkWidget **)gtk_object_get_data(GTK_OBJECT(handle), "_dw_pagearray"); diff -r 18a31ab94e3d -r dbd507f42947 gtk3/dw.c --- a/gtk3/dw.c Thu Nov 03 10:09:11 2011 +0000 +++ b/gtk3/dw.c Thu Nov 03 23:34:10 2011 +0000 @@ -119,8 +119,6 @@ # define min(a,b) (((a) < (b)) ? (a) : (b)) #endif -FILE *dbgfp = NULL; - pthread_key_t _dw_fg_color_key; pthread_key_t _dw_bg_color_key; pthread_key_t _dw_mutex_key; @@ -344,18 +342,6 @@ static GtkMdiChild *get_child(GtkMdi *mdi, GtkWidget * widget); -static void _dw_log( char *format, ... ) -{ - va_list args; - va_start(args, format); - if ( dbgfp != NULL ) - { - vfprintf( dbgfp, format, args ); - fflush( dbgfp ); - } - va_end(args); -} - static GType gtk_mdi_get_type(void) { static GType mdi_type = 0; @@ -1208,7 +1194,6 @@ SignalHandler work = _get_signal_handler((GtkWidget *)window, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*setfocusfunc)(HWND, void *) = work.func; @@ -1223,7 +1208,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*buttonfunc)(HWND, int, int, int, void *) = work.func; @@ -1244,7 +1228,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*buttonfunc)(HWND, int, int, int, void *) = work.func; @@ -1265,7 +1248,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*motionfunc)(HWND, int, int, int, void *) = work.func; @@ -1298,7 +1280,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*closefunc)(HWND, void *) = work.func; @@ -1313,7 +1294,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*keypressfunc)(HWND, char, int, int, void *) = work.func; @@ -1329,7 +1309,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*genericfunc)(HWND, void *) = work.func; @@ -1344,7 +1323,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window && !_dw_ignore_click) { int (*activatefunc)(HWND, void *) = work.func; @@ -1360,7 +1338,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*sizefunc)(HWND, int, int, void *) = work.func; @@ -1375,7 +1352,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { DWExpose exp; @@ -1395,7 +1371,6 @@ static int _dw_recursing = 0; int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(_dw_recursing) return FALSE; @@ -1439,7 +1414,6 @@ SignalHandler work = _get_signal_handler(widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { if(event->button == 3) @@ -1502,7 +1476,6 @@ GtkWidget *item = NULL, *widget = (GtkWidget *)gtk_tree_selection_get_tree_view(sel); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(widget) { SignalHandler work = _get_signal_handler(widget, data); @@ -1598,7 +1571,6 @@ SignalHandler work = _get_signal_handler((GtkWidget *)widget, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(!_dw_ignore_expand && work.window) { int (*treeexpandfunc)(HWND, HTREEITEM, void *) = work.func; @@ -1614,7 +1586,6 @@ GdkEventButton *buttonevent = (GdkEventButton *)event; int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { /* Handle both key and button events together */ @@ -1681,7 +1652,6 @@ SignalHandler work = _get_signal_handler((GtkWidget *)notebook, data); int retval = FALSE; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int (*switchpagefunc)(HWND, unsigned long, void *) = work.func; @@ -1701,7 +1671,6 @@ { work = _get_signal_handler(tree, GINT_TO_POINTER(handlerdata-1)); - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(work.window) { int column_num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "_dw_column")); @@ -1730,7 +1699,6 @@ GtkWidget *spinbutton = (GtkWidget *)g_object_get_data(G_OBJECT(adjustment), "_dw_spinbutton"); GtkWidget *scrollbar = (GtkWidget *)g_object_get_data(G_OBJECT(adjustment), "_dw_scrollbar"); - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if (slider) { SignalHandler work = _get_signal_handler((GtkWidget *)adjustment, data); @@ -1763,7 +1731,6 @@ { GtkWidget *next = (GtkWidget *)data; - if ( dbgfp != NULL ) _dw_log("%s %d: %s\n",__FILE__,__LINE__,__func__); if(next) { if(event->keyval == GDK_KEY_Return) @@ -1973,13 +1940,6 @@ #ifdef USE_WEBKIT init_webkit(); #endif - /* - * Setup logging/debugging - */ - if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) - { - dbgfp = fopen( fname, "w" ); - } return TRUE; } @@ -2190,6 +2150,24 @@ } /* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + fprintf(stderr, "%s", outbuf); +} + +/* * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. @@ -2203,13 +2181,13 @@ ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_SIZEBORDER; DWDialog *dwwait; va_list args; - char outbuf[1000]; + 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, 999, format, args); + vsnprintf(outbuf, 1024, format, args); va_end(args); entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); @@ -3350,10 +3328,10 @@ tmphandle=gtk_menu_item_new(); else { + char numbuf[11] = {0}; + if (check) { - char numbuf[10]; - tmphandle = gtk_check_menu_item_new_with_label(tempbuf); if (accel && accel_group) { @@ -3362,13 +3340,11 @@ gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0); #endif } - sprintf(numbuf, "%lu", id); + snprintf(numbuf, 10, "%lu", id); g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle); } else { - char numbuf[10]; - tmphandle=gtk_menu_item_new_with_label(tempbuf); if (accel && accel_group) { @@ -3377,7 +3353,7 @@ gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0); #endif } - sprintf(numbuf, "%lu", id); + snprintf(numbuf, 10, "%lu", id); g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle); } } @@ -3386,9 +3362,9 @@ if (submenu) { - char tempbuf[100]; - - sprintf(tempbuf, "_dw_submenu%d", submenucount); + char tempbuf[101] = {0}; + + snprintf(tempbuf, 100, "_dw_submenu%d", submenucount); submenucount++; gtk_menu_item_set_submenu(GTK_MENU_ITEM(tmphandle), submenu); g_object_set_data(G_OBJECT(menu), tempbuf, (gpointer)submenu); @@ -3429,10 +3405,10 @@ for(z=0;zfd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) { @@ -8158,11 +8134,11 @@ */ HSHM dw_named_memory_get(void **dest, int size, char *name) { - char namebuf[1024]; + char namebuf[1025]; struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); - sprintf(namebuf, "/tmp/.dw/%s", name); + snprintf(namebuf, 1024, "/tmp/.dw/%s", name); if((handle->fd = open(namebuf, O_RDWR)) < 0) { @@ -8257,10 +8233,6 @@ */ void dw_exit(int exitcode) { - if ( dbgfp != NULL ) - { - fclose( dbgfp ); - } exit(exitcode); } @@ -8806,13 +8778,13 @@ { if(!pagearray[z]) { - char text[100]; + char text[101] = {0}; int num = z; if(front) num |= 1 << 16; - sprintf(text, "_dw_page%d", z); + snprintf(text, 100, "_dw_page%d", z); /* Save the real id and the creation flags */ g_object_set_data(G_OBJECT(handle), text, GINT_TO_POINTER(num)); DW_MUTEX_UNLOCK; @@ -8919,10 +8891,10 @@ realpage = _get_physical_page(handle, pageid); if(realpage < 0 || realpage > 255) { - char ptext[100]; + char ptext[101] = {0}; int num; - sprintf(ptext, "_dw_page%d", (int)pageid); + snprintf(ptext, 100, "_dw_page%d", (int)pageid); num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), ptext)); realpage = 0xFF & num; } @@ -8960,10 +8932,10 @@ GtkWidget *label, *child, *oldlabel, **pagearray; const gchar *text = NULL; int num, z, realpage = -1, pad, _locked_by_me = FALSE; - char ptext[100]; - - DW_MUTEX_LOCK; - sprintf(ptext, "_dw_page%d", (int)pageid); + char ptext[101] = {0}; + + DW_MUTEX_LOCK; + snprintf(ptext, 100, "_dw_page%d", (int)pageid); num = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), ptext)); g_object_set_data(G_OBJECT(handle), ptext, NULL); pagearray = (GtkWidget **)g_object_get_data(G_OBJECT(handle), "_dw_pagearray"); @@ -10685,7 +10657,7 @@ { void (*sigfunc)(void *data) = NULL; void *sdata; - char tmpbuf[30]; + char tmpbuf[31] = {0}; int *tag = data; if(tag) @@ -10717,7 +10689,7 @@ int API dw_timer_connect(int interval, void *sigfunc, void *data) { int *tag, _locked_by_me = FALSE; - char tmpbuf[30]; + char tmpbuf[31] = {0}; tag = calloc(1, sizeof(int)); @@ -10739,7 +10711,7 @@ void API dw_timer_disconnect(int id) { int _locked_by_me = FALSE; - char tmpbuf[30]; + char tmpbuf[31] = {0}; snprintf(tmpbuf, 30, "_dw_timer%d", id); DW_MUTEX_LOCK; diff -r 18a31ab94e3d -r dbd507f42947 mac/dw.m --- a/mac/dw.m Thu Nov 03 10:09:11 2011 +0000 +++ b/mac/dw.m Thu Nov 03 23:34:10 2011 +0000 @@ -3029,6 +3029,24 @@ } /* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + NSLog(@"%s", outbuf); +} + +/* * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. @@ -3043,10 +3061,10 @@ NSString *button2 = nil; NSString *button3 = nil; va_list args; - char outbuf[1000]; + char outbuf[1025] = {0}; va_start(args, format); - vsprintf(outbuf, format, args); + vsnprintf(outbuf, 1024, format, args); va_end(args); if(flags & DW_MB_OKCANCEL) @@ -5794,13 +5812,13 @@ } else { - char textbuffer[100]; + char textbuffer[101] = {0}; if(type & DW_CFA_ULONG) { ULONG tmp = *((ULONG *)data); - sprintf(textbuffer, "%lu", tmp); + snprintf(textbuffer, 100, "%lu", tmp); } else if(type & DW_CFA_DATE) { @@ -6866,9 +6884,9 @@ { DWCalendar *calendar = handle; NSDate *date; - char buffer[100]; - - sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); + char buffer[101]; + + snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; [calendar setDateValue:date]; @@ -8795,7 +8813,7 @@ { int len; char *newname; - char errorbuf[1024]; + char errorbuf[1025]; if(!handle) @@ -9556,11 +9574,11 @@ */ HSHM dw_named_memory_new(void **dest, int size, char *name) { - char namebuf[1024]; + char namebuf[1025] = {0}; struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); - sprintf(namebuf, "/tmp/.dw/%s", name); + snprintf(namebuf, 1024, "/tmp/.dw/%s", name); if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) { @@ -9597,11 +9615,11 @@ */ HSHM dw_named_memory_get(void **dest, int size, char *name) { - char namebuf[1024]; + char namebuf[1025]; struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); - sprintf(namebuf, "/tmp/.dw/%s", name); + snprintf(namebuf, 1024, "/tmp/.dw/%s", name); if((handle->fd = open(namebuf, O_RDWR)) < 0) { diff -r 18a31ab94e3d -r dbd507f42947 os2/dw.c --- a/os2/dw.c Thu Nov 03 10:09:11 2011 +0000 +++ b/os2/dw.c Thu Nov 03 23:34:10 2011 +0000 @@ -3865,6 +3865,23 @@ return tmp; } +/* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1024]; + + va_start(args, format); + vsprintf(outbuf, format, args); + va_end(args); + + fprintf(stderr, "%s", outbuf); +} /* * Displays a Message Box with given text and title.. diff -r 18a31ab94e3d -r dbd507f42947 template/dw.c --- a/template/dw.c Thu Nov 03 10:09:11 2011 +0000 +++ b/template/dw.c Thu Nov 03 23:34:10 2011 +0000 @@ -480,6 +480,24 @@ } /* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + fprintf(stderr, "%s", outbuf); +} + +/* * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. diff -r 18a31ab94e3d -r dbd507f42947 win/dw.c --- a/win/dw.c Thu Nov 03 10:09:11 2011 +0000 +++ b/win/dw.c Thu Nov 03 23:34:10 2011 +0000 @@ -130,9 +130,7 @@ * an alternate temporary directory if TMP is not set, so we get the value * of TEMP and store it here. */ -static char _dw_alternate_temp_dir[MAX_PATH]; - -FILE *dbgfp = NULL; +static char _dw_alternate_temp_dir[MAX_PATH+1]; int main(int argc, char *argv[]); @@ -213,18 +211,6 @@ { TVN_ITEMEXPANDED,DW_SIGNAL_TREE_EXPAND } }; -static void _dw_log( char *format, ... ) -{ - va_list args; - va_start(args, format); - if ( dbgfp != NULL ) - { - vfprintf( dbgfp, format, args ); - fflush( dbgfp ); - } - va_end(args); -} - #ifdef BUILD_DLL void Win32_Set_Instance(HINSTANCE hInstance) { @@ -3739,13 +3725,7 @@ SetSecurityDescriptorDacl(&_dwsd, TRUE, (PACL) NULL, FALSE); OleInitialize(NULL); - /* - * Setup logging/debugging - */ - if ( (fname = getenv( "DWINDOWS_DEBUGFILE" ) ) != NULL ) - { - dbgfp = fopen( fname, "w" ); - } + /* * Get an alternate temporary directory in case TMP doesn't exist */ @@ -3755,7 +3735,7 @@ } else { - strcpy( _dw_alternate_temp_dir, alttmpdir ); + strncpy( _dw_alternate_temp_dir, alttmpdir, MAX_PATH ); } /* * Get screen size. Used to make calls to dw_screen_width() @@ -3920,6 +3900,24 @@ } /* + * Displays a debug message on the console... + * Parameters: + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +void API dw_debug(char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + OutputDebugString(outbuf); +} + +/* * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. @@ -3933,7 +3931,7 @@ int rc; va_start(args, format); - vsprintf(outbuf, format, args); + vsnprintf(outbuf, 1024, format, args); va_end(args); rc = MessageBox(HWND_DESKTOP, outbuf, title, flags); @@ -4102,7 +4100,7 @@ int Italic, Bold; char *myFontName; int z, size = 9; - LOGFONT lf; + LOGFONT lf = {0}; for(z=0;zfore = cinfo->back = -1; - strcpy(cinfo->fontname, fontname); + strncpy(cinfo->fontname, fontname, 127); cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); @@ -4271,7 +4269,7 @@ if(ChooseFont(&cf)) { - str = (char *)malloc( 100 ); + str = (char *)calloc( 101, 1 ); if ( str ) { int height; @@ -4283,7 +4281,7 @@ italic = " Italic"; height = MulDiv(abs(lf.lfHeight), 72, GetDeviceCaps (hdc, LOGPIXELSY)); ReleaseDC(NULL, hdc); - sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); + _snprintf( str, 100, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); } } return str; @@ -4318,7 +4316,7 @@ oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); if ( GetObject( oldfont, sizeof(lf), &lf ) ) { - str = (char *)malloc( 100 ); + str = (char *)calloc( 100, 1 ); if ( str ) { int height; @@ -4330,7 +4328,7 @@ italic = " Italic"; height = MulDiv(abs(lf.lfHeight), 72, GetDeviceCaps (hdc, LOGPIXELSY)); ReleaseDC(handle, hdc); - sprintf( str, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); + _snprintf( str, 100, "%d.%s%s%s", height, lf.lfFaceName, bold, italic ); } } if ( oldfont ) @@ -4820,7 +4818,7 @@ { MENUITEMINFO mii; HMENU mymenu = (HMENU)menux; - char buffer[30]; + char buffer[31] = {0}; int is_checked, is_disabled; /* @@ -4902,13 +4900,13 @@ InsertMenuItem(mymenu, 65535, TRUE, &mii); - sprintf(buffer, "_dw_id%ld", id); + _snprintf(buffer, 30, "_dw_id%ld", id); dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)mymenu ); - sprintf(buffer, "_dw_checkable%ld", id); + _snprintf(buffer, 30, "_dw_checkable%ld", id); dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)check ); - sprintf(buffer, "_dw_ischecked%ld", id); + _snprintf(buffer, 30, "_dw_ischecked%ld", id); dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)is_checked ); - sprintf(buffer, "_dw_isdisabled%ld", id); + _snprintf(buffer, 30, "_dw_isdisabled%ld", id); dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)is_disabled ); if (submenu) @@ -4960,7 +4958,7 @@ /* * Keep our internal state consistent */ - sprintf( buffer, "_dw_ischecked%ld", id ); + _snprintf( buffer, 30, "_dw_ischecked%ld", id ); dw_window_set_data( DW_HWND_OBJECT, buffer, (void *)check ); } @@ -4976,16 +4974,16 @@ { MENUITEMINFO mii; HMENU mymenu = (HMENU)menux; - char buffer1[30],buffer2[30]; + char buffer1[31] = {0},buffer2[31] = {0}; int check; int disabled; if (IsWindow(menux) && !IsMenu(mymenu)) mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); - sprintf( buffer1, "_dw_ischecked%ld", id ); + _snprintf( buffer1, 30, "_dw_ischecked%ld", id ); check = (int)dw_window_get_data( DW_HWND_OBJECT, buffer1 ); - sprintf( buffer2, "_dw_isdisabled%ld", id ); + _snprintf( buffer2, 30, "_dw_isdisabled%ld", id ); disabled = (int)dw_window_get_data( DW_HWND_OBJECT, buffer2 ); memset( &mii, 0, sizeof(mii) ); @@ -6071,11 +6069,11 @@ { if(handle < (HWND)65536) { - char buffer[30]; + char buffer[31] = {0}; HMENU mymenu; ULONG id = (ULONG)handle; - sprintf(buffer, "_dw_id%ld", id); + _snprintf(buffer, 30, "_dw_id%ld", id); mymenu = (HMENU)dw_window_get_data(DW_HWND_OBJECT, buffer); if(mymenu && IsMenu(mymenu)) @@ -6094,11 +6092,11 @@ { if(handle < (HWND)65536) { - char buffer[30]; + char buffer[31] = {0}; HMENU mymenu; ULONG id = (ULONG)handle; - sprintf(buffer, "_dw_id%ld", id); + _snprintf(buffer, 30, "_dw_id%ld", id); mymenu = (HMENU)dw_window_get_data(DW_HWND_OBJECT, buffer); if(mymenu && IsMenu(mymenu)) @@ -7369,10 +7367,10 @@ */ void API dw_spinbutton_set_pos(HWND handle, long position) { - char tmpbuf[100]; + char tmpbuf[101] = {0}; ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); - sprintf(tmpbuf, "%ld", position); + _snprintf(tmpbuf, 100, "%ld", position); if(cinfo && cinfo->buddy) SetWindowText(cinfo->buddy, tmpbuf); @@ -8049,7 +8047,7 @@ ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); ULONG *flags; LV_ITEM lvi; - char textbuffer[100], *destptr = textbuffer; + char textbuffer[101] = {0}, *destptr = textbuffer; int item = 0; if(pointer) @@ -8091,7 +8089,7 @@ { ULONG tmp = *((ULONG *)data); - sprintf(textbuffer, "%lu", tmp); + _snprintf(textbuffer, 100, "%lu", tmp); lvi.pszText = textbuffer; lvi.cchTextMax = strlen(textbuffer); @@ -9888,10 +9886,6 @@ void API dw_exit(int exitcode) { OleUninitialize(); - if ( dbgfp != NULL ) - { - fclose( dbgfp ); - } exit(exitcode); } @@ -10230,8 +10224,8 @@ char * API dw_file_browse(char *title, char *defpath, char *ext, int flags) { OPENFILENAME of; - char filenamebuf[1001] = ""; - char filterbuf[1000] = ""; + char filenamebuf[1001] = {0}; + char filterbuf[1001] = {0}; int rc; BROWSEINFO bi; @@ -10258,7 +10252,7 @@ { if (SHGetPathFromIDList(pidl,szDir)) { - strcpy(filenamebuf,szDir); + strncpy(filenamebuf,szDir,1000); } // In C++: pMalloc->Free(pidl); pMalloc->Release(); @@ -10795,10 +10789,10 @@ /* Handle special case of the menu item */ if (message == WM_COMMAND && window < (HWND)65536) { - char buffer[15]; + char buffer[16]; HWND owner; - sprintf(buffer, "_dw_id%d", (int)window); + _snprintf(buffer, 15, "_dw_id%d", (int)window); owner = (HWND)dw_window_get_data(DW_HWND_OBJECT, buffer); /* Make sure there are no dupes from popups */