From a6fed35df2fddffc5b0397721fbdf46fb1b59399 Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Tue, 21 Apr 2009 04:11:03 +0000 Subject: Patch from Anders Kaseorg, use Xutf8DrawText et al. where available, and use XFontSet instead of XFontStruct * Tweaks to resource file to help the above pick some less wrong fonts. --- zwgc/X_fonts.c | 165 ++++-------- zwgc/X_fonts.h | 5 +- zwgc/X_gram.c | 231 ++++++++-------- zwgc/X_gram.h | 4 +- zwgc/main.c | 340 +++++++++++------------ zwgc/xmark.c | 205 +++++++------- zwgc/xshow.c | 830 +++++++++++++++++++++++++++++---------------------------- 7 files changed, 886 insertions(+), 894 deletions(-) (limited to 'zwgc') diff --git a/zwgc/X_fonts.c b/zwgc/X_fonts.c index 0d8e2b7..67ef488 100644 --- a/zwgc/X_fonts.c +++ b/zwgc/X_fonts.c @@ -35,13 +35,12 @@ static const char rcsid_X_fonts_c[] = "$Id$"; #include "zwgc.h" /* - * font_dict - Lookup cache for fonts (the value pointers are XFontStruct *'s) + * font_dict - Lookup cache for fonts (the value pointers are XFontSet's) */ static pointer_dictionary family_dict = NULL; static pointer_dictionary fontname_dict = NULL; static pointer_dictionary fontst_dict = NULL; -static pointer_dictionary fidst_dict = NULL; /* * {face,size}_to_string - lookup tables for converting {face,size} int @@ -53,7 +52,7 @@ static string size_to_string[] = { "small", "medium", "large" }; static char * get_family(char *style, - char *substyle) + char *substyle) { char *desc; pointer_dictionary_binding *binding; @@ -78,17 +77,17 @@ get_family(char *style, #undef STYLE_CLASS free(desc); if (family==NULL) - pointer_dictionary_Delete(family_dict,binding); + pointer_dictionary_Delete(family_dict,binding); else - binding->value=(pointer) family; + binding->value=(pointer) family; return(family); /* If resource returns NULL, return NULL also */ } } static char * get_specific_fontname(char *family, - int size, - int face) + int size, + int face) { char *desc; pointer_dictionary_binding *binding; @@ -113,104 +112,47 @@ get_specific_fontname(char *family, fontname=get_string_resource(desc,FAMILY_CLASS); free(desc); if (fontname==NULL) - pointer_dictionary_Delete(fontname_dict,binding); + pointer_dictionary_Delete(fontname_dict,binding); else - binding->value=(pointer) fontname; + binding->value=(pointer) fontname; return(fontname); /* If resource returns NULL, return NULL also */ } } -/* fast function to convert Font to hex. Return value - * is on the heap and must be freed. I'm cheating in - * that I know that Font us really an unsigned long. */ - -static char hexdigits[] = {"0123456789ABCDEF"}; -static char * -Font_to_hex(Font num) -{ - char *temp; - int i; - - temp=(char *) malloc((sizeof(Font)<<1)+2); - - for (i=0;i<((sizeof(Font)<<1)+1);i++) - temp[i] = hexdigits[(num>>(i*4))&0x0f]; - temp[i] = '\0'; - - return(temp); -} - -void -add_fid(XFontStruct *font) -{ - - char *fidstr; - pointer_dictionary_binding *binding; - int exists; - - if (!fidst_dict) - fidst_dict = pointer_dictionary_Create(37); - fidstr=Font_to_hex(font->fid); - binding = pointer_dictionary_Define(fidst_dict,fidstr,&exists); - free(fidstr); - - if (!exists) - binding->value=(pointer) font; -} - -/* requires that the font already be cached. */ -XFontStruct * -get_fontst_from_fid(Font fid) -{ - char *fidstr; - pointer_dictionary_binding *binding; - int exists; - - fidstr=Font_to_hex(fid); - - binding = pointer_dictionary_Define(fidst_dict,fidstr,&exists); - free(fidstr); -#ifdef DEBUG - if (exists) { - return((XFontStruct *) binding->value); - } else { - printf("Font fid=0x%s not cached. Oops.\n",fidstr); - abort(); - } -#else - return((XFontStruct *) binding->value); -#endif -} - -static XFontStruct * +static XFontSet get_fontst(Display *dpy, - char *fontname) + char *fontname) { pointer_dictionary_binding *binding; int exists; - XFontStruct *fontst; + XFontSet fontst; + char **missing_list; + int missing_count; + char *def_string; if (!fontst_dict) - fontst_dict = pointer_dictionary_Create(37); - binding = pointer_dictionary_Define(fontst_dict,fontname,&exists); + fontst_dict = pointer_dictionary_Create(37); + binding = pointer_dictionary_Define(fontst_dict, fontname, &exists); if (exists) { - return((XFontStruct *) binding->value); + return((XFontSet)binding->value); } else { - fontst=XLoadQueryFont(dpy,fontname); - if (fontst==NULL) { - pointer_dictionary_Delete(fontst_dict,binding); - } else { - binding->value=(pointer) fontst; - add_fid(fontst); - } return(fontst); /* If resource returns NULL, return NULL also */ + fontst = XCreateFontSet(dpy, fontname, &missing_list, &missing_count, + &def_string); + XFreeStringList(missing_list); + if (fontst == NULL) + pointer_dictionary_Delete(fontst_dict,binding); + else + binding->value = (pointer)fontst; + + return(fontst); /* If resource returns NULL, return NULL also */ } } static char * get_fontname(char *family, - int size, - int face) + int size, + int face) { char *fontname; @@ -221,55 +163,55 @@ get_fontname(char *family, return(fontname); } -static XFontStruct * +static XFontSet complete_get_fontst(Display *dpy, - string style, - string substyle, - int size, - int face) + string style, + string substyle, + int size, + int face) { char *family,*fontname; - XFontStruct *fontst; + XFontSet fontst; if ((family=get_family(style,substyle))) if ((fontname=get_fontname(family,size,face))) if ((fontst=get_fontst(dpy,fontname))) - return(fontst); + return(fontst); /* If any part fails, */ return(NULL); } /* - * XFontStruct *get_font(string style, substyle; int size, face) + * XFontSet get_font(string style, substyle; int size, face) * Requires: size is one of SMALL_SIZE, MEDIUM_SIZE, LARGE_SIZE and * face is one of ROMAN_FACE, BOLD_FACE, ITALIC_FACE, * BOLDITALIC_FACE. * Effects: unknown */ -XFontStruct * +XFontSet get_font(Display *dpy, - string style, - string substyle, - int size, - int face) + string style, + string substyle, + int size, + int face) { char *family,*fontname; - XFontStruct *fontst; + XFontSet fontst; if (size == SPECIAL_SIZE) { /* attempt to process @font explicitly */ if ((fontst = get_fontst(dpy, substyle))) - return(fontst); + return(fontst); } else { if ((family = get_family(style, substyle))) { - if ((fontname = get_fontname(family, size,face))) - if ((fontst = get_fontst(dpy, fontname))) - return(fontst); + if ((fontname = get_fontname(family, size,face))) + if ((fontst = get_fontst(dpy, fontname))) + return(fontst); } else { - if ((fontname = get_fontname(substyle, size, face))) - if ((fontst = get_fontst(dpy, fontname))) - return(fontst); + if ((fontname = get_fontname(substyle, size, face))) + if ((fontst = get_fontst(dpy, fontname))) + return(fontst); } /* At this point, the no-failure case didn't happen, and the case @@ -277,10 +219,10 @@ get_font(Display *dpy, fontst=NULL; if (!(fontst = complete_get_fontst(dpy,style,"text",size,face))) - if (!(fontst = complete_get_fontst(dpy,"default",substyle,size,face))) - if (!(fontst = complete_get_fontst(dpy,"default","text",size,face))) - if ((fontname = get_fontname("default",size,face))) - fontst = get_fontst(dpy,fontname); + if (!(fontst = complete_get_fontst(dpy,"default",substyle,size,face))) + if (!(fontst = complete_get_fontst(dpy,"default","text",size,face))) + if ((fontname = get_fontname("default",size,face))) + fontst = get_fontst(dpy,fontname); if (fontst) return(fontst); } @@ -299,4 +241,3 @@ get_font(Display *dpy, } #endif /* X_DISPLAY_MISSING */ - diff --git a/zwgc/X_fonts.h b/zwgc/X_fonts.h index 62469c8..8e40ed8 100644 --- a/zwgc/X_fonts.h +++ b/zwgc/X_fonts.h @@ -31,7 +31,7 @@ #define LARGE_SIZE 2 /* - * XFontStruct *get_font(string family; int size, face) + * XFontSet get_font(string family; int size, face) * Requires: size is one of SMALL_SIZE, MEDIUM_SIZE, LARGE_SIZE and * face is one of ROMAN_FACE, BOLD_FACE, ITALIC_FACE, * BOLDITALIC_FACE. @@ -41,7 +41,6 @@ * specified by default.medium.roman is used. <<<>>> */ -extern XFontStruct *get_font(Display *, string, string, int, int); -extern XFontStruct *get_fontst_from_fid(Font); +extern XFontSet get_font(Display *, string, string, int, int); #endif diff --git a/zwgc/X_gram.c b/zwgc/X_gram.c index 8b5d96a..bd3ab5b 100644 --- a/zwgc/X_gram.c +++ b/zwgc/X_gram.c @@ -60,8 +60,8 @@ static int enable_delete; static char *title_name,*icon_name; static Cursor cursor; static Window group_leader; /* In order to have transient windows, - * I need a top-level window to always exist - */ + * I need a top-level window to always exist + */ static XClassHint classhint; static XSetWindowAttributes xattributes; static unsigned long xattributes_mask; @@ -83,7 +83,7 @@ static Atom net_wm_window_type_utility = None; * and for individual zgrams: * * WM_TRANSIENT_FOR XSetTransientForHint(dpy,w,main_window); - * WM_PROTOCOLS XSetWMProtocols(dpy,w,protocols,cnt); + * WM_PROTOCOLS XSetWMProtocols(dpy,w,protocols,cnt); */ /* set all properties defined in ICCCM. If main_window == 0, @@ -93,12 +93,12 @@ static Atom net_wm_window_type_utility = None; /*ARGSUSED*/ void x_set_icccm_hints(Display *dpy, - Window w, - char *name, - char *icon_name, - XSizeHints *psizehints, - XWMHints *pwmhints, - Window main_window) + Window w, + char *name, + char *icon_name, + XSizeHints *psizehints, + XWMHints *pwmhints, + Window main_window) { XStoreName(dpy,w,name); XSetIconName(dpy,w,icon_name); @@ -109,7 +109,7 @@ x_set_icccm_hints(Display *dpy, e.g. Motif wm */ if (main_window != None) { if (set_transient) - XSetTransientForHint(dpy,w,main_window); + XSetTransientForHint(dpy,w,main_window); } if (enable_delete) XSetWMProtocols(dpy,w,&XA_WM_DELETE_WINDOW,1); @@ -183,42 +183,42 @@ x_gram_init(Display *dpy) temp = get_string_resource("pointerColor", "Foreground"); if (temp) { - char *temp2; - XColor cursor_fore, cursor_back; - /* XXX need to do our own parsing here, since the RecolorCursor - routine requires an XColor, not an unsigned long (pixel) */ - if (!(temp2 = get_string_resource("background","Background"))) { - if (default_bgcolor == WhitePixelOfScreen(DefaultScreenOfDisplay(dpy))) - temp2 = "white"; - else - temp2 = "black"; - } - if (XParseColor(dpy, - DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), - temp, &cursor_fore) && - XParseColor(dpy, - DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), - temp2, &cursor_back)) { - XRecolorCursor(dpy, cursor, &cursor_fore, &cursor_back); - } + char *temp2; + XColor cursor_fore, cursor_back; + /* XXX need to do our own parsing here, since the RecolorCursor + routine requires an XColor, not an unsigned long (pixel) */ + if (!(temp2 = get_string_resource("background","Background"))) { + if (default_bgcolor == WhitePixelOfScreen(DefaultScreenOfDisplay(dpy))) + temp2 = "white"; + else + temp2 = "black"; + } + if (XParseColor(dpy, + DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), + temp, &cursor_fore) && + XParseColor(dpy, + DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy)), + temp2, &cursor_back)) { + XRecolorCursor(dpy, cursor, &cursor_fore, &cursor_back); + } } if (!(title_name=get_string_resource("title","Title"))) if (!(title_name=get_string_resource("name","Name"))) - title_name=app_instance; + title_name=app_instance; if (!(icon_name=get_string_resource("iconName","IconName"))) if (!(icon_name=get_string_resource("name","Name"))) - icon_name=app_instance; + icon_name=app_instance; if (!(temp=get_string_resource("name","Name"))) if (!(temp=(char *) getenv("RESOURCE_NAME"))) - temp=app_instance; + temp=app_instance; classhint.res_name=string_Copy(temp); classhint.res_class="Zwgc"; if (set_transient) { group_leader=XCreateSimpleWindow(dpy,DefaultRootWindow(dpy),0,0,100,100, - 0,default_bordercolor,default_bgcolor); + 0,default_bordercolor,default_bgcolor); sizehints.x = 0; sizehints.y = 0; sizehints.width = 100; @@ -230,84 +230,84 @@ x_gram_init(Display *dpy) wmhints.flags = InputHint | StateHint; x_set_icccm_hints(dpy,group_leader,"ZwgcGroup","ZwgcGroup",&sizehints, - &wmhints,0); + &wmhints,0); } xattributes.border_pixel = default_bordercolor; xattributes.cursor = cursor; xattributes.event_mask = (ExposureMask|ButtonReleaseMask|ButtonPressMask - |LeaveWindowMask|Button1MotionMask + |LeaveWindowMask|Button1MotionMask #ifdef CMU_ZWGCPLUS - |KeyPressMask + |KeyPressMask #endif - |Button3MotionMask|StructureNotifyMask); + |Button3MotionMask|StructureNotifyMask); xattributes_mask = (CWBackPixel|CWBorderPixel|CWEventMask|CWCursor); set_all_desktops = get_bool_resource("allDesktops", "AllDesktops", True); net_wm_desktop = XInternAtom(dpy, "_NET_WM_DESKTOP", False); net_wm_window_type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); net_wm_window_type_utility = XInternAtom(dpy, - "_NET_WM_WINDOW_TYPE_UTILITY", - False); + "_NET_WM_WINDOW_TYPE_UTILITY", + False); temp = get_string_resource ("backingStore", "BackingStore"); if (!temp) - return; + return; xattributes_mask |= CWBackingStore; if (!strcasecmp (temp, "notuseful")) - xattributes.backing_store = NotUseful; + xattributes.backing_store = NotUseful; else if (!strcasecmp (temp, "whenmapped")) - xattributes.backing_store = WhenMapped; + xattributes.backing_store = WhenMapped; else if (!strcasecmp (temp, "always")) - xattributes.backing_store = Always; + xattributes.backing_store = Always; else if (!strcasecmp (temp, "default")) - xattributes_mask &= ~CWBackingStore; + xattributes_mask &= ~CWBackingStore; else { - switch (get_bool_resource ("backingStore", "BackingStore", -1)) { - case 0: - xattributes.backing_store = NotUseful; - break; - case 1: - xattributes.backing_store = WhenMapped; - break; - case -1: - fprintf (stderr, - "zwgc: Cannot interpret backing-store resource value `%s'.\n", - temp); - xattributes_mask &= ~CWBackingStore; - break; - } + switch (get_bool_resource ("backingStore", "BackingStore", -1)) { + case 0: + xattributes.backing_store = NotUseful; + break; + case 1: + xattributes.backing_store = WhenMapped; + break; + case -1: + fprintf (stderr, + "zwgc: Cannot interpret backing-store resource value `%s'.\n", + temp); + xattributes_mask &= ~CWBackingStore; + break; + } } } int x_calc_gravity(int xalign, - int yalign) + int yalign) { - if (yalign > 0) { /* North */ - return (xalign > 0) ? NorthWestGravity - : (xalign == 0) ? NorthGravity - : NorthEastGravity; - } else if (yalign == 0) { /* Center */ - return (xalign > 0) ? WestGravity - : (xalign == 0) ? CenterGravity - : EastGravity; - } else { /* South */ - return (xalign > 0) ? SouthWestGravity - : (xalign == 0) ? SouthGravity - : SouthEastGravity; + if (yalign > 0) { /* North */ + return (xalign > 0) ? NorthWestGravity + : (xalign == 0) ? NorthGravity + : NorthEastGravity; + } else if (yalign == 0) { /* Center */ + return (xalign > 0) ? WestGravity + : (xalign == 0) ? CenterGravity + : EastGravity; + } else { /* South */ + return (xalign > 0) ? SouthWestGravity + : (xalign == 0) ? SouthGravity + : SouthEastGravity; } } void x_gram_create(Display *dpy, - x_gram *gram, - int xalign, - int yalign, - int xpos, - int ypos, - int xsize, - int ysize, - int beepcount) + x_gram *gram, + int xalign, + int yalign, + int xpos, + int ypos, + int xsize, + int ysize, + int beepcount) { Window w; XSizeHints sizehints; @@ -320,17 +320,17 @@ x_gram_create(Display *dpy, */ if (xalign < 0) xpos = WidthOfScreen(DefaultScreenOfDisplay(dpy)) - - xpos - xsize - 2 * border_width; + - xpos - xsize - 2 * border_width; else if (xalign == 0) xpos = ((WidthOfScreen(DefaultScreenOfDisplay(dpy)) - - xsize - 2 * border_width) >> 1) + xpos; + - xsize - 2 * border_width) >> 1) + xpos; if (yalign<0) ypos = HeightOfScreen(DefaultScreenOfDisplay(dpy)) - - ypos - ysize - 2 * border_width; + - ypos - ysize - 2 * border_width; else if (yalign == 0) ypos = ((HeightOfScreen(DefaultScreenOfDisplay(dpy)) - - ysize - 2 * border_width) >> 1) + ypos; + - ysize - 2 * border_width) >> 1) + ypos; /* * Create the window: @@ -339,9 +339,9 @@ x_gram_create(Display *dpy, attributes.background_pixel = gram->bgcolor; gram->w = w = XCreateWindow (dpy, DefaultRootWindow (dpy), xpos, ypos, - xsize, ysize, border_width, 0, - CopyFromParent, CopyFromParent, - xattributes_mask, &attributes); + xsize, ysize, border_width, 0, + CopyFromParent, CopyFromParent, + xattributes_mask, &attributes); sizehints.x = xpos; sizehints.y = ypos; @@ -357,7 +357,7 @@ x_gram_create(Display *dpy, wmhints.flags = InputHint | StateHint | WindowGroupHint; x_set_icccm_hints(dpy, w, title_name, icon_name, &sizehints, &wmhints, - group_leader); + group_leader); } else { wmhints.flags = InputHint | StateHint; @@ -365,11 +365,11 @@ x_gram_create(Display *dpy, } if (net_wm_window_type != None && net_wm_window_type_utility != None) - XChangeProperty(dpy, w, net_wm_window_type, XA_ATOM, 32, PropModeReplace, - (unsigned char *) &net_wm_window_type_utility, 1); + XChangeProperty(dpy, w, net_wm_window_type, XA_ATOM, 32, PropModeReplace, + (unsigned char *) &net_wm_window_type_utility, 1); if (set_all_desktops && net_wm_desktop != None) - XChangeProperty(dpy, w, net_wm_desktop, XA_CARDINAL, 32, PropModeReplace, - (unsigned char *) &all_desktops, 1); + XChangeProperty(dpy, w, net_wm_desktop, XA_CARDINAL, 32, PropModeReplace, + (unsigned char *) &all_desktops, 1); XSaveContext(dpy, w, desc_context, (caddr_t)gram); @@ -378,7 +378,7 @@ x_gram_create(Display *dpy, XMapWindow(dpy, w); if (beepcount) - XBell(dpy, 0); + XBell(dpy, 0); xerror_happened = 0; if (reverse_stack && bottom_gram) { @@ -387,17 +387,17 @@ x_gram_create(Display *dpy, winchanges.sibling = bottom_gram->w; winchanges.stack_mode = Below; /* Metacity may use border_width even if it's not specified in - * the value mask, so we must initialize it. See: - * http://bugzilla.gnome.org/show_bug.cgi?id=305257 */ + * the value mask, so we must initialize it. See: + * http://bugzilla.gnome.org/show_bug.cgi?id=305257 */ winchanges.border_width = border_width; begin_xerror_trap (dpy); XReconfigureWMWindow (dpy, w, DefaultScreen (dpy), - CWSibling | CWStackMode, &winchanges); + CWSibling | CWStackMode, &winchanges); end_xerror_trap (dpy); if (xerror_happened) { - /* The event didn't go. Print an error message, and continue. */ - ERROR ("Error configuring window to the bottom of the stack.\n"); + /* The event didn't go. Print an error message, and continue. */ + ERROR ("Error configuring window to the bottom of the stack.\n"); } } /* we always need to keep a linked list of windows */ @@ -406,7 +406,7 @@ x_gram_create(Display *dpy, pull_to_top(gram); if (reset_saver) - XResetScreenSaver(dpy); + XResetScreenSaver(dpy); XFlush(dpy); /* Because the flushing/syncing/etc with the error trapping can cause @@ -431,7 +431,11 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) GC gc; XGCValues gcvals; xblock *xb; - XTextItem16 text; +#ifdef X_HAVE_UTF8_STRING + XmbTextItem text; +#else + XwcTextItem text; +#endif int startblock, endblock, startpixel = 0, endpixel = 0; gc = XCreateGC(dpy, w, 0, &gcvals); @@ -439,7 +443,7 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) if ((markgram == gram) && (STARTBLOCK != -1) && (ENDBLOCK != -1)) { if (xmarkSecond() == XMARK_END_BOUND) { - startblock = STARTBLOCK; + startblock = STARTBLOCK; endblock = ENDBLOCK; startpixel = STARTPIXEL; endpixel = ENDPIXEL; @@ -501,12 +505,20 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) for (i=0, xb = gram->blocks; i < gram->numblocks; i++, xb++) { if (XRectInRegion(region, xb->x1, xb->y1, xb->x2 - xb->x1, xb->y2 - xb->y1) != RectangleOut) { - SetFG(dpy, gc, gram->bgcolor ^ xb->fgcolor); - text.chars = (XChar2b *)xb->wstr; - text.nchars = xb->wlen / 2; - text.delta = 0; - text.font = xb->fid; - XDrawText16(dpy, w, gc, xb->x, xb->y, &text, 1); + SetFG(dpy, gc, gram->bgcolor ^ xb->fgcolor); +#ifdef X_HAVE_UTF8_STRING + text.chars = xb->wstr; +#else + text.chars = (XChar2b *)xb->wstr; +#endif + text.nchars = xb->wlen; + text.delta = 0; + text.font_set = xb->font; +#ifdef X_HAVE_UTF8_STRING + Xutf8DrawText(dpy, w, gc, xb->x, xb->y, &text, 1); +#else + XwcDrawText(dpy, w, gc, xb->x, xb->y, &text, 1); +#endif } } @@ -515,9 +527,9 @@ x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) void x_gram_expose(Display *dpy, - Window w, - x_gram *gram, - XExposeEvent *event) + Window w, + x_gram *gram, + XExposeEvent *event) { static Region region; static int partregion; @@ -530,7 +542,7 @@ x_gram_expose(Display *dpy, #ifdef MARK_DEBUG printf("----- xeventExpose:\nx=%d y=%d w=%d h=%d\n-----", - event->x,event->y,event->width,event->height); + event->x,event->y,event->width,event->height); #endif if (! partregion) { @@ -548,4 +560,3 @@ x_gram_expose(Display *dpy, } #endif /* X_DISPLAY_MISSING */ - diff --git a/zwgc/X_gram.h b/zwgc/X_gram.h index dfff8f1..fe591be 100644 --- a/zwgc/X_gram.h +++ b/zwgc/X_gram.h @@ -25,7 +25,7 @@ typedef struct _xblock { unsigned long fgcolor; - Font fid; + XFontSet font; int x,y; int x1,y1,x2,y2; /* bounds of block. used for cut and paste. */ int strindex; @@ -49,7 +49,7 @@ typedef struct _x_gram { typedef struct _xauxblock { int align; - XFontStruct *font; + XFontSet font; char *str; int len; int width; diff --git a/zwgc/main.c b/zwgc/main.c index 15ab264..1e47a87 100644 --- a/zwgc/main.c +++ b/zwgc/main.c @@ -27,6 +27,7 @@ static const char rcsid_main_c[] = "$Id$"; #endif #include #include +#include #include #include @@ -144,7 +145,7 @@ fake_startup_packet(void) notice->z_auth = ZAUTH_YES; notice->z_charset = ZCHARSET_UNKNOWN; sprintf(msgbuf,"Zwgc mark II version %s now running...", - zwgc_version_string); + zwgc_version_string); notice->z_message = msgbuf; notice->z_message_len = strlen(notice->z_message)+1; @@ -229,13 +230,13 @@ run_initprogs(void) status = system(progname); if (status == 127) { - perror("zwgc initprog exec"); - fprintf(stderr,"zwgc initprog of <%s> failed: no shell.\n", - progname); + perror("zwgc initprog exec"); + fprintf(stderr,"zwgc initprog of <%s> failed: no shell.\n", + progname); } else if (status!=-1 && status>>8) { - perror("zwgc initprog exec"); - fprintf(stderr,"zwgc initprog of <%s> failed with status [%d].\n", - progname, status>>8); + perror("zwgc initprog exec"); + fprintf(stderr,"zwgc initprog of <%s> failed with status [%d].\n", + progname, status>>8); } } @@ -253,6 +254,7 @@ main(int argc, char **argv) int status; #endif + setlocale(LC_ALL, ""); progname = argv[0]; /* @@ -261,33 +263,33 @@ main(int argc, char **argv) * arguments, removing then from argc, argv: */ for (new=current=argv+1; *current; current++) { - if (string_Eq(*current, "-debug")) { - argc--; + if (string_Eq(*current, "-debug")) { + argc--; #ifdef DEBUG - zwgc_debug = 1; + zwgc_debug = 1; #endif - } else if (string_Eq(*current, "-f")) { - argc -= 2; current++; - if (!*current) - usage(); - description_filename_override = *current; - } else if (string_Eq(*current, "-subfile")) { - argc -= 2; current++; - if (!*current) - usage(); - subscriptions_filename_override = *current; - } else if (string_Eq(*current, "-nofork")) { - argc--; - dofork = 0; - } else if (string_Eq(*current, "-reenter")) { - argc--; /* just throw it away */ - } else if (string_Eq(*current, "-loc")) { - argc -= 2; current++; - if (!*current) - usage(); - location_override = *current; - } else - *(new)++ = *current; + } else if (string_Eq(*current, "-f")) { + argc -= 2; current++; + if (!*current) + usage(); + description_filename_override = *current; + } else if (string_Eq(*current, "-subfile")) { + argc -= 2; current++; + if (!*current) + usage(); + subscriptions_filename_override = *current; + } else if (string_Eq(*current, "-nofork")) { + argc--; + dofork = 0; + } else if (string_Eq(*current, "-reenter")) { + argc--; /* just throw it away */ + } else if (string_Eq(*current, "-loc")) { + argc -= 2; current++; + if (!*current) + usage(); + location_override = *current; + } else + *(new)++ = *current; } *new = *current; @@ -297,9 +299,9 @@ main(int argc, char **argv) */ status = ares_init(&achannel); if (status != ARES_SUCCESS) { - fprintf(stderr, "Couldn't initialize resolver: %s\n", - ares_strerror(status)); - return(1); + fprintf(stderr, "Couldn't initialize resolver: %s\n", + ares_strerror(status)); + return(1); } #endif @@ -322,7 +324,7 @@ main(int argc, char **argv) zephyr_init(notice_handler); if (dofork) - detach(); + detach(); /* * Run the initprogs program(s) now that we are all set to deal: */ @@ -365,19 +367,19 @@ create_punt_reply(int_dictionary_binding *punt) char *tmp; if (!punt_reply.z_message) { - punt_reply.z_message = (char *)malloc(PUNT_INC); - punt_reply.z_message[0] = 0; + punt_reply.z_message = (char *)malloc(PUNT_INC); + punt_reply.z_message[0] = 0; } if ((punt_reply.z_message_len + key_len + 1) / PUNT_INC > - (punt_reply.z_message_len + PUNT_INC - 1) / PUNT_INC) { - char *new_message = (char *)malloc((punt_reply.z_message_len - / PUNT_INC + 1) * PUNT_INC); - - strcpy(new_message, punt_reply.z_message); - - free(punt_reply.z_message); - punt_reply.z_message = new_message; + (punt_reply.z_message_len + PUNT_INC - 1) / PUNT_INC) { + char *new_message = (char *)malloc((punt_reply.z_message_len + / PUNT_INC + 1) * PUNT_INC); + + strcpy(new_message, punt_reply.z_message); + + free(punt_reply.z_message); + punt_reply.z_message = new_message; } tmp = punt_reply.z_message + strlen(punt_reply.z_message); strcat (punt_reply.z_message, punt->key); @@ -402,18 +404,18 @@ notice_handler(ZNotice_t *notice) #ifdef HAVE_ARES ares_getnameinfo(achannel, - (const struct sockaddr *)&(notice->z_sender_sockaddr), - notice->z_sender_sockaddr.sa.sa_family == AF_INET ? - sizeof(struct sockaddr_in) : - notice->z_sender_sockaddr.sa.sa_family == AF_INET6 ? - sizeof(struct sockaddr_in6) : - sizeof(notice->z_sender_sockaddr), ARES_NI_LOOKUPHOST, - notice_callback, notice); + (const struct sockaddr *)&(notice->z_sender_sockaddr), + notice->z_sender_sockaddr.sa.sa_family == AF_INET ? + sizeof(struct sockaddr_in) : + notice->z_sender_sockaddr.sa.sa_family == AF_INET6 ? + sizeof(struct sockaddr_in6) : + sizeof(notice->z_sender_sockaddr), ARES_NI_LOOKUPHOST, + notice_callback, notice); #else getnameinfo((const struct sockaddr *)&(notice->z_sender_sockaddr), - sizeof(notice->z_sender_sockaddr), - node, sizeof(node), NULL, 0, 0); + sizeof(notice->z_sender_sockaddr), + node, sizeof(node), NULL, 0, 0); process_notice(notice, node); #ifdef CMU_ZWGCPLUS @@ -429,16 +431,16 @@ notice_handler(ZNotice_t *notice) /* static void notice_callback(void *arg, - int status, - int timeouts, - struct hostent *fromhost) + int status, + int timeouts, + struct hostent *fromhost) */ static void notice_callback(void *arg, - int status, - int timeouts, - char *node, - char *service) + int status, + int timeouts, + char *node, + char *service) { ZNotice_t *notice = (ZNotice_t *) arg; @@ -458,7 +460,7 @@ notice_callback(void *arg, static void process_notice(ZNotice_t *notice, - char *hostname) + char *hostname) { char *control_opcode; @@ -467,110 +469,110 @@ process_notice(ZNotice_t *notice, control_opcode = decode_notice(notice, hostname); if (control_opcode) { #ifdef DEBUG - printf("got control opcode <%s>.\n", control_opcode); + printf("got control opcode <%s>.\n", control_opcode); #endif - if (!strcasecmp(control_opcode, USER_REREAD)) { - read_in_description_file(); - } else if (!strcasecmp(control_opcode, USER_SHUTDOWN)) - zwgc_shutdown(); - else if (!strcasecmp(control_opcode, USER_STARTUP)) { + if (!strcasecmp(control_opcode, USER_REREAD)) { + read_in_description_file(); + } else if (!strcasecmp(control_opcode, USER_SHUTDOWN)) + zwgc_shutdown(); + else if (!strcasecmp(control_opcode, USER_STARTUP)) { #ifdef DEBUG_MEMORY - report_memory_usage(); /* <<<>>> */ + report_memory_usage(); /* <<<>>> */ #endif - zwgc_startup(); - } else if (!strcasecmp(control_opcode, USER_SUPPRESS)) { - string class = get_field(notice->z_message, - notice->z_message_len, 1); - string instance = get_field(notice->z_message, - notice->z_message_len, 2); - string recipient = get_field(notice->z_message, - notice->z_message_len, 3); - punt(class, instance, recipient); - free(class); - free(instance); - free(recipient); - } else if (!strcasecmp(control_opcode, USER_UNSUPPRESS)) { - string class = get_field(notice->z_message, - notice->z_message_len, 1); - string instance = get_field(notice->z_message, - notice->z_message_len, 2); - string recipient = get_field(notice->z_message, - notice->z_message_len, 3); - unpunt(class, instance, recipient); - free(class); - free(instance); - free(recipient); + zwgc_startup(); + } else if (!strcasecmp(control_opcode, USER_SUPPRESS)) { + string class = get_field(notice->z_message, + notice->z_message_len, 1); + string instance = get_field(notice->z_message, + notice->z_message_len, 2); + string recipient = get_field(notice->z_message, + notice->z_message_len, 3); + punt(class, instance, recipient); + free(class); + free(instance); + free(recipient); + } else if (!strcasecmp(control_opcode, USER_UNSUPPRESS)) { + string class = get_field(notice->z_message, + notice->z_message_len, 1); + string instance = get_field(notice->z_message, + notice->z_message_len, 2); + string recipient = get_field(notice->z_message, + notice->z_message_len, 3); + unpunt(class, instance, recipient); + free(class); + free(instance); + free(recipient); #ifdef CMU_ZCTL_PUNT } else if (!strcasecmp(control_opcode, USER_LIST_SUPPRESSED)) { - struct sockaddr_in old, to; - int retval; - - if (!notice->z_port) { - printf("zwgc: can't reply to LIST-SUPPRESSED request\n"); - return; - } - memset((char *) &punt_reply, 0, sizeof(ZNotice_t)); - punt_reply.z_kind = CLIENTACK; - punt_reply.z_class = WG_CTL_CLASS; - punt_reply.z_class_inst = "WG_REPLY"; - punt_reply.z_recipient = "zctl?"; - punt_reply.z_sender = "Zwgc"; - punt_reply.z_default_format = ""; - punt_reply.z_opcode = USER_LIST_SUPPRESSED; - punt_reply.z_port = notice->z_port; - punt_reply.z_message = NULL; - punt_reply.z_message_len = 0; - - if (puntable_addresses_dict) { - int_dictionary_Enumerate(puntable_addresses_dict, - create_punt_reply); - } - - old = ZGetDestAddr(); - to = old; - - to.sin_port = notice->z_port; - if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { - com_err("zwgc",retval,"while setting destination address"); - exit(1); - } - - ZSendNotice(&punt_reply, ZNOAUTH); - - if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { - com_err("zwgc",retval,"while resetting destination address"); - exit(1); - } - - if (punt_reply.z_message) { - free(punt_reply.z_message); - punt_reply.z_message = NULL; - } + struct sockaddr_in old, to; + int retval; + + if (!notice->z_port) { + printf("zwgc: can't reply to LIST-SUPPRESSED request\n"); + return; + } + memset((char *) &punt_reply, 0, sizeof(ZNotice_t)); + punt_reply.z_kind = CLIENTACK; + punt_reply.z_class = WG_CTL_CLASS; + punt_reply.z_class_inst = "WG_REPLY"; + punt_reply.z_recipient = "zctl?"; + punt_reply.z_sender = "Zwgc"; + punt_reply.z_default_format = ""; + punt_reply.z_opcode = USER_LIST_SUPPRESSED; + punt_reply.z_port = notice->z_port; + punt_reply.z_message = NULL; + punt_reply.z_message_len = 0; + + if (puntable_addresses_dict) { + int_dictionary_Enumerate(puntable_addresses_dict, + create_punt_reply); + } + + old = ZGetDestAddr(); + to = old; + + to.sin_port = notice->z_port; + if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { + com_err("zwgc",retval,"while setting destination address"); + exit(1); + } + + ZSendNotice(&punt_reply, ZNOAUTH); + + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { + com_err("zwgc",retval,"while resetting destination address"); + exit(1); + } + + if (punt_reply.z_message) { + free(punt_reply.z_message); + punt_reply.z_message = NULL; + } #endif - } else if (!strcasecmp(control_opcode, USER_EXIT)) { - signal_exit(0); - } else - printf("zwgc: unknown control opcode %s.\n", control_opcode); + } else if (!strcasecmp(control_opcode, USER_EXIT)) { + signal_exit(0); + } else + printf("zwgc: unknown control opcode %s.\n", control_opcode); - goto cleanup; + goto cleanup; } if (!zwgc_active) { #ifdef DEBUG - if (zwgc_debug) - printf("NON-ACTIVE: PUNTED <%s>!!!!\n", notice->z_class_inst); + if (zwgc_debug) + printf("NON-ACTIVE: PUNTED <%s>!!!!\n", notice->z_class_inst); #endif - goto cleanup; + goto cleanup; } if (puntable_address_p(notice->z_class, - notice->z_class_inst, - notice->z_recipient)) { + notice->z_class_inst, + notice->z_recipient)) { #ifdef DEBUG - if (zwgc_debug) - printf("PUNTED <%s>!!!!\n", notice->z_class_inst); + if (zwgc_debug) + printf("PUNTED <%s>!!!!\n", notice->z_class_inst); #endif - goto cleanup; + goto cleanup; } exec_process_packet(program, notice); @@ -639,15 +641,15 @@ setup_signals(int dofork) sa.sa_flags = 0; if (dofork) { - sa.sa_handler = SIG_IGN; - sigaction(SIGINT, &sa, (struct sigaction *)0); - sigaction(SIGTSTP, &sa, (struct sigaction *)0); - sigaction(SIGQUIT, &sa, (struct sigaction *)0); - sigaction(SIGTTOU, &sa, (struct sigaction *)0); + sa.sa_handler = SIG_IGN; + sigaction(SIGINT, &sa, (struct sigaction *)0); + sigaction(SIGTSTP, &sa, (struct sigaction *)0); + sigaction(SIGQUIT, &sa, (struct sigaction *)0); + sigaction(SIGTTOU, &sa, (struct sigaction *)0); } else { - /* clean up on SIGINT; exiting on logout is the user's problem, now. */ - sa.sa_handler = signal_exit; - sigaction(SIGINT, &sa, (struct sigaction *)0); + /* clean up on SIGINT; exiting on logout is the user's problem, now. */ + sa.sa_handler = signal_exit; + sigaction(SIGINT, &sa, (struct sigaction *)0); } /* behavior never changes */ @@ -666,21 +668,21 @@ setup_signals(int dofork) #else /* !POSIX */ if (dofork) { - /* Ignore keyboard signals if forking. Bad things will happen. */ - signal(SIGINT, SIG_IGN); - signal(SIGTSTP, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGQUIT, SIG_IGN); + /* Ignore keyboard signals if forking. Bad things will happen. */ + signal(SIGINT, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTOU, SIG_IGN); + signal(SIGQUIT, SIG_IGN); } else { - /* clean up on SIGINT; exiting on logout is the user's problem, now. */ - signal(SIGINT, signal_exit); + /* clean up on SIGINT; exiting on logout is the user's problem, now. */ + signal(SIGINT, signal_exit); } /* behavior never changes */ signal(SIGTERM, signal_exit); signal(SIGHUP, signal_exit); signal(SIGCHLD, signal_child); - signal(SIGPIPE, SIG_IGN); /* so that Xlib gets an error */ + signal(SIGPIPE, SIG_IGN); /* so that Xlib gets an error */ signal(SIGUSR1, signal_usr1); #endif } @@ -713,9 +715,9 @@ detach(void) i = fork(); if (i) { if (i < 0) { - perror("zwgc: cannot fork, aborting:"); - exit(1); + perror("zwgc: cannot fork, aborting:"); + exit(1); } exit(0); } -} +} diff --git a/zwgc/xmark.c b/zwgc/xmark.c index 1f4200a..a8f5c26 100644 --- a/zwgc/xmark.c +++ b/zwgc/xmark.c @@ -46,22 +46,24 @@ x_gram *oldgram = NULL; void xmarkSetBound(x_gram *gram, - int x, - int y, - int which) + int x, + int y, + int which) { int i,xofs,yofs; - XFontStruct *font; + XFontSet font; xblock *xb; unsigned char *s; + int num_chars; + XRectangle *ink, *logical; #ifdef MARK_DEBUG #define RETURN \ if ((oldblock[which] != markblock[which]) || \ (oldpixel[which] != markpixel[which])) { \ printf("----- SetBound:\noldblock[%d]=%d, oldpixel[%d]=%d\nmarkblock[%d]=%d, markpixel[%d]=%d\n-----", \ - which,oldblock[which],which,oldpixel[which], \ - which,markblock[which],which,markpixel[which]); \ + which,oldblock[which],which,oldpixel[which], \ + which,markblock[which],which,markpixel[which]); \ } \ return #else @@ -78,8 +80,8 @@ xmarkSetBound(x_gram *gram, /* Start at the top, fastforward to first span not too high. */ for (i=0,xb=gram->blocks ; - (inumblocks) && (xb->y2 < y) ; - i++,xb++) ; + (inumblocks) && (xb->y2 < y) ; + i++,xb++) ; /* the point is after the end */ if (i==gram->numblocks) { @@ -108,25 +110,41 @@ xmarkSetBound(x_gram *gram, for (yofs=xb->y1;(inumblocks) && (xb->y1 == yofs);i++,xb++) { if (x <= xb->x2) { - markblock[which]=i; - - xofs=xb->x1; - if ((x < xofs) || (y < xb->y1)) { - markchar[which]=0; - RETURN; - } - font=get_fontst_from_fid(xb->fid); - for (i=0,s=(unsigned char *)((gram->text)+(xb->strindex)); - xofsstrlen; - i++,s++) { - /* if font->per_char is NULL, then we should use min_bounds */ - short usewidth = font->per_char ? font->per_char[*s - font->min_char_or_byte2].width : font->min_bounds.width; - if (x <= (xofs+=usewidth)) { - markchar[which]=i; - markpixel[which]=xofs - xb->x1 - usewidth; - RETURN; - } - } + markblock[which]=i; + + xofs=xb->x1; + if ((x < xofs) || (y < xb->y1)) { + markchar[which]=0; + RETURN; + } + font = xb->font; +#ifdef X_HAVE_UTF8_STRING + Xutf8TextPerCharExtents(font, xb->wstr, xb->wlen, + NULL, NULL, -1, &num_chars, NULL, NULL); +#else + XwcTextPerCharExtents(font, (XChar2b *)xb->wstr, xb->wlen, + NULL, NULL, -1, &num_chars, NULL, NULL); +#endif + ink = malloc(num_chars * sizeof(XRectangle)); + logical = malloc(num_chars * sizeof(XRectangle)); +#ifdef X_HAVE_UTF8_STRING + Xutf8TextPerCharExtents(font, xb->wstr, xb->wlen, + ink, logical, num_chars, &num_chars, NULL, NULL); +#else + XwcTextPerCharExtents(font, (XChar2b *)xb->wstr, xb->wlen, + ink, logical, num_chars, &num_chars, NULL, NULL); +#endif + for (i=0;ix1; + free(ink); + free(logical); + RETURN; + } + } + free(ink); + free(logical); } } @@ -140,7 +158,7 @@ xmarkSetBound(x_gram *gram, /* needs both bounds to be valid (!= -1) */ static int xmarkNearest(int x, - int y) + int y) { int middle; @@ -154,20 +172,20 @@ xmarkNearest(int x, else { middle=(ENDCHAR+STARTCHAR)/2; if (markchar[XMARK_TEMP_BOUND] < middle) - return(XMARK_START_BOUND); + return(XMARK_START_BOUND); else - return(XMARK_END_BOUND); + return(XMARK_END_BOUND); } } void xmarkExpose(Display *dpy, - Window w, - x_gram *gram, - unsigned int b1, - unsigned int p1, - unsigned int b2, - unsigned int p2) + Window w, + x_gram *gram, + unsigned int b1, + unsigned int p1, + unsigned int b2, + unsigned int p2) { #define swap(x,y) temp=(x); (x)=(y); (y)=temp int i,temp; @@ -193,40 +211,40 @@ xmarkExpose(Display *dpy, for (i=b1;i<=b2;i++) { if (b1==b2) { - expose.x=gram->blocks[i].x1+p1; - expose.y=gram->blocks[i].y1; - expose.width=p2-p1; - expose.height=gram->blocks[i].y2-gram->blocks[i].y1; - expose.count=0; + expose.x=gram->blocks[i].x1+p1; + expose.y=gram->blocks[i].y1; + expose.width=p2-p1; + expose.height=gram->blocks[i].y2-gram->blocks[i].y1; + expose.count=0; } else if (i==b1) { - expose.x=gram->blocks[i].x1+p1; - expose.y=gram->blocks[i].y1; - expose.width=gram->blocks[i].x2-p1; - expose.height=gram->blocks[i].y2-gram->blocks[i].y1; - expose.count=b2-i; + expose.x=gram->blocks[i].x1+p1; + expose.y=gram->blocks[i].y1; + expose.width=gram->blocks[i].x2-p1; + expose.height=gram->blocks[i].y2-gram->blocks[i].y1; + expose.count=b2-i; } else if (i==b2) { - expose.x=gram->blocks[i].x1; - expose.y=gram->blocks[i].y1; - expose.width=p2; - expose.height=gram->blocks[i].y2-gram->blocks[i].y1; - expose.count=b2-i; + expose.x=gram->blocks[i].x1; + expose.y=gram->blocks[i].y1; + expose.width=p2; + expose.height=gram->blocks[i].y2-gram->blocks[i].y1; + expose.count=b2-i; } else { - expose.x=gram->blocks[i].x1; - expose.y=gram->blocks[i].y1; - expose.width=gram->blocks[i].x2-gram->blocks[i].x1; - expose.height=gram->blocks[i].y2-gram->blocks[i].y1; - expose.count=b2-i; + expose.x=gram->blocks[i].x1; + expose.y=gram->blocks[i].y1; + expose.width=gram->blocks[i].x2-gram->blocks[i].x1; + expose.height=gram->blocks[i].y2-gram->blocks[i].y1; + expose.count=b2-i; } #ifdef MARK_DEBUG if (expose.width && expose.height) { printf("---- markExpose:\nb1=%d p1=%d b2=%d p2=%d\n",b1,p1,b2,p2); printf("x=%d y=%d w=%d h=%d\n-----", - expose.x,expose.y,expose.width,expose.height); + expose.x,expose.y,expose.width,expose.height); } #endif if ((expose.width && expose.height) || (expose.count == 0)) - XSendEvent(dpy,w,True,ExposureMask,&event); + XSendEvent(dpy,w,True,ExposureMask,&event); } } @@ -234,9 +252,9 @@ xmarkExpose(Display *dpy, void xmarkRedraw(Display *dpy, - Window w, - x_gram *gram, - int range) + Window w, + x_gram *gram, + int range) { #define ob1 ((unsigned int) oldblock[XMARK_START_BOUND]) #define ob2 ((unsigned int) oldblock[XMARK_END_BOUND]) @@ -262,7 +280,7 @@ xmarkRedraw(Display *dpy, } #ifdef DEBUG else { - printf("xmarkRedraw: This shouldn't happen!\n"); + printf("xmarkRedraw: This shouldn't happen!\n"); } #endif } @@ -277,11 +295,11 @@ xmarkSecond(void) return(XMARK_END_BOUND); else { if (STARTCHAR > ENDCHAR) - return(XMARK_START_BOUND); + return(XMARK_START_BOUND); else if (STARTCHAR < ENDCHAR) - return(XMARK_END_BOUND); + return(XMARK_END_BOUND); else - return(XMARK_END_BOUND); + return(XMARK_END_BOUND); } } @@ -305,8 +323,8 @@ xmarkClear(void) int xmarkExtendFromFirst(x_gram *gram, - int x, - int y) + int x, + int y) { if (markgram != gram) { xmarkClear(); @@ -328,8 +346,8 @@ xmarkExtendFromFirst(x_gram *gram, int xmarkExtendFromNearest(x_gram *gram, - int x, - int y) + int x, + int y) { int bound; @@ -363,34 +381,34 @@ xmarkGetText(void) if (xmarkValid()) { if (xmarkSecond() == XMARK_END_BOUND) { - startblock=STARTBLOCK; - endblock=ENDBLOCK; - startchar=STARTCHAR; - endchar=ENDCHAR; + startblock=STARTBLOCK; + endblock=ENDBLOCK; + startchar=STARTCHAR; + endchar=ENDCHAR; } else { - startblock=ENDBLOCK; - endblock=STARTBLOCK; - startchar=ENDCHAR; - endchar=STARTCHAR; + startblock=ENDBLOCK; + endblock=STARTBLOCK; + startchar=ENDCHAR; + endchar=STARTCHAR; } for (i=startblock; i<=endblock; i++) { - if (last_y != -1 && last_y != markgram->blocks[i].y) - text_so_far = string_Concat2(text_so_far, "\n"); - index = markgram->blocks[i].strindex; - len = markgram->blocks[i].strlen; - if (startblock == endblock) - temp = string_CreateFromData(text+index+startchar, - endchar-startchar); - else if (i==startblock) - temp = string_CreateFromData(text+index+startchar,len-startchar); - else if (i==endblock) - temp = string_CreateFromData(text+index,endchar); - else - temp = string_CreateFromData(text+index,len); - text_so_far = string_Concat2(text_so_far, temp); - free(temp); - last_y = markgram->blocks[i].y; + if (last_y != -1 && last_y != markgram->blocks[i].y) + text_so_far = string_Concat2(text_so_far, "\n"); + index = markgram->blocks[i].strindex; + len = markgram->blocks[i].strlen; + if (startblock == endblock) + temp = string_CreateFromData(text+index+startchar, + endchar-startchar); + else if (i==startblock) + temp = string_CreateFromData(text+index+startchar,len-startchar); + else if (i==endblock) + temp = string_CreateFromData(text+index,endchar); + else + temp = string_CreateFromData(text+index,len); + text_so_far = string_Concat2(text_so_far, temp); + free(temp); + last_y = markgram->blocks[i].y; } } @@ -398,4 +416,3 @@ xmarkGetText(void) } #endif /* X_DISPLAY_MISSING */ - diff --git a/zwgc/xshow.c b/zwgc/xshow.c index 3521318..88226bd 100644 --- a/zwgc/xshow.c +++ b/zwgc/xshow.c @@ -57,14 +57,14 @@ xshowinit(void) } struct res_dict_type { - pointer_dictionary dict; - char * resname_suffix; - char * resclass; + pointer_dictionary dict; + char * resname_suffix; + char * resclass; }; static char * xres_get_resource(struct res_dict_type *restype, - char *style) + char *style) { char *desc; pointer_dictionary_binding *binding; @@ -85,9 +85,9 @@ xres_get_resource(struct res_dict_type *restype, value=get_string_resource(desc, restype->resclass); free(desc); if (value==NULL) - pointer_dictionary_Delete(restype->dict, binding); + pointer_dictionary_Delete(restype->dict, binding); else - binding->value=(pointer) value; + binding->value=(pointer) value; return value; /* If resource returns NULL, return NULL also */ } } @@ -111,8 +111,8 @@ static struct res_dict_type fgcolor_resources = { /*ARGSUSED*/ char * mode_to_colorname (Display *dpy, - char *style, - xmode *mode) + char *style, + xmode *mode) { char *desc, *result; @@ -125,13 +125,13 @@ mode_to_colorname (Display *dpy, void fixup_and_draw(Display *dpy, - char *style, - xauxblock *auxblocks, - xblock *blocks, - int num, - xlinedesc *lines, - int numlines, - int beepcount) + char *style, + xauxblock *auxblocks, + xblock *blocks, + int num, + xlinedesc *lines, + int numlines, + int beepcount) { int gram_xalign = 1; int gram_yalign = 1; @@ -150,6 +150,7 @@ fixup_and_draw(Display *dpy, int ystart,yend; char *bgstr, *geometry, xpos[10], ypos[10], xfrom, yfrom; + XFontSetExtents *fse; gram = (x_gram *)malloc(sizeof(x_gram)); @@ -157,96 +158,103 @@ fixup_and_draw(Display *dpy, length of the longest line and the total number of characters. */ for (line = 0; line < numlines; line++) { - lsize = csize = rsize = 0; - maxascent = maxdescent = 0; - - /* add up sizes for each block, get max ascent and descent */ - - for (i = 0; i < lines[line].numblock; i++, block++) { - chars += auxblocks[block].len; - ssize = XTextWidth16(auxblocks[block].font, - (XChar2b *)blocks[block].wstr, - blocks[block].wlen / 2); - auxblocks[block].width = ssize; - ascent = auxblocks[block].font->ascent; - descent = auxblocks[block].font->descent; - if (ascent > maxascent) - maxascent = ascent; - if (descent > maxdescent) - maxdescent = descent; - switch (auxblocks[block].align) { - case LEFTALIGN: - lsize += ssize; - break; - - case CENTERALIGN: - csize += ssize; - break; - - case RIGHTALIGN: - rsize += ssize; - break; - } - } - - /* save what we need to do size fixups */ - - if (maxascent > lines[line].ascent) - lines[line].ascent = maxascent; - if (maxdescent > lines[line].descent) - lines[line].descent = maxdescent; - lines[line].lsize = lsize; - lines[line].csize = csize; - lines[line].rsize = rsize; - - /* get width of line and see if it is bigger than the max width */ - - switch ((lsize ? 1 : 0) + (csize ?2 : 0) + (rsize ? 4 : 0)) { + lsize = csize = rsize = 0; + maxascent = maxdescent = 0; + + /* add up sizes for each block, get max ascent and descent */ + + for (i = 0; i < lines[line].numblock; i++, block++) { + chars += auxblocks[block].len; +#ifdef X_HAVE_UTF8_STRING + ssize = Xutf8TextEscapement(auxblocks[block].font, + blocks[block].wstr, + blocks[block].wlen); +#else + ssize = XwcTextEscapement(auxblocks[block].font, + (XChar2b *)blocks[block].wstr, + blocks[block].wlen); +#endif + auxblocks[block].width = ssize; + fse = XExtentsOfFontSet(auxblocks[block].font); + ascent = -fse->max_logical_extent.y; + descent = fse->max_logical_extent.y + fse->max_logical_extent.height; + if (ascent > maxascent) + maxascent = ascent; + if (descent > maxdescent) + maxdescent = descent; + switch (auxblocks[block].align) { + case LEFTALIGN: + lsize += ssize; + break; + + case CENTERALIGN: + csize += ssize; + break; + + case RIGHTALIGN: + rsize += ssize; + break; + } + } + + /* save what we need to do size fixups */ + + if (maxascent > lines[line].ascent) + lines[line].ascent = maxascent; + if (maxdescent > lines[line].descent) + lines[line].descent = maxdescent; + lines[line].lsize = lsize; + lines[line].csize = csize; + lines[line].rsize = rsize; + + /* get width of line and see if it is bigger than the max width */ + + switch ((lsize ? 1 : 0) + (csize ?2 : 0) + (rsize ? 4 : 0)) { #ifdef DEBUG - default: - abort(); + default: + abort(); #endif - - case 0: - width = 0; - break; - - case 1: - width = lsize; - break; - - case 2: - width = csize; - break; - - case 3: - /* in all these cases, we just want to add the width of *any* - space, so the first font will do just fine. */ - /* XXX implicit assumption that a line must have at least one - block, so that there is indeed a reasonable font in - auxblocks[0].font */ - width = lsize * 2 + csize + XTextWidth(auxblocks[0].font, " ", 1); - break; - - case 4: - width = rsize; - break; - - case 5: - width = lsize + rsize + XTextWidth(auxblocks[0].font, " ", 1); - break; - - case 6: - width = csize + rsize * 2 + XTextWidth(auxblocks[0].font, " ", 1); - break; - - case 7: - width = max(lsize, rsize) * 2 + csize + - XTextWidth(auxblocks[0].font, " ", 1) * 2; - break; - } - if (width > maxwidth) - maxwidth = width; + + case 0: + width = 0; + break; + + case 1: + width = lsize; + break; + + case 2: + width = csize; + break; + + case 3: + /* in all these cases, we just want to add the width of *any* + space, so the first font will do just fine. */ + /* XXX implicit assumption that a line must have at least one + block, so that there is indeed a reasonable font in + auxblocks[0].font */ + width = lsize * 2 + csize + XmbTextEscapement(auxblocks[0].font, " ", 1); + break; + + case 4: + width = rsize; + break; + + case 5: + width = lsize + rsize + XmbTextEscapement(auxblocks[0].font, " ", 1); + break; + + case 6: + width = csize + rsize * 2 + XmbTextEscapement(auxblocks[0].font, " ", 1); + break; + + case 7: + width = max(lsize, rsize) * 2 + csize + + XmbTextEscapement(auxblocks[0].font, " ", 1) * 2; + break; + } + if (width > maxwidth) + maxwidth = width; } /* fixup x,y for each block, create big string and indices into it */ @@ -256,49 +264,49 @@ fixup_and_draw(Display *dpy, block = 0; for (line = 0; line < numlines; line++) { - lofs = internal_border_width; - cofs = ((maxwidth - lines[line].csize) >> 1) + internal_border_width; - rofs = maxwidth - lines[line].rsize + internal_border_width; - ystart = yofs; - yofs += lines[line].ascent; - yend = yofs + lines[line].descent + 1; /* +1 because lines look scrunched - without it. */ - - for (i = 0; i < lines[line].numblock; i++, block++) { - blocks[block].fid = auxblocks[block].font->fid; - switch (auxblocks[block].align) { - case LEFTALIGN: - blocks[block].x = lofs; - blocks[block].x1 = lofs; - lofs += auxblocks[block].width; - blocks[block].x2 = lofs; - break; - - case CENTERALIGN: - blocks[block].x = cofs; - blocks[block].x1 = cofs; - cofs += auxblocks[block].width; - blocks[block].x2 = cofs; - break; - - case RIGHTALIGN: - blocks[block].x = rofs; - blocks[block].x1 = rofs; - rofs += auxblocks[block].width; - blocks[block].x2 = rofs; - break; - } - blocks[block].y = yofs; - blocks[block].y1 = ystart; - blocks[block].y2 = yend; - blocks[block].strindex = strindex; - blocks[block].strlen = auxblocks[block].len; - strncpy(gram->text + strindex, auxblocks[block].str, - auxblocks[block].len); - strindex += blocks[block].strlen; - } - - yofs = yend; + lofs = internal_border_width; + cofs = ((maxwidth - lines[line].csize) >> 1) + internal_border_width; + rofs = maxwidth - lines[line].rsize + internal_border_width; + ystart = yofs; + yofs += lines[line].ascent; + yend = yofs + lines[line].descent + 1; /* +1 because lines look scrunched + without it. */ + + for (i = 0; i < lines[line].numblock; i++, block++) { + blocks[block].font = auxblocks[block].font; + switch (auxblocks[block].align) { + case LEFTALIGN: + blocks[block].x = lofs; + blocks[block].x1 = lofs; + lofs += auxblocks[block].width; + blocks[block].x2 = lofs; + break; + + case CENTERALIGN: + blocks[block].x = cofs; + blocks[block].x1 = cofs; + cofs += auxblocks[block].width; + blocks[block].x2 = cofs; + break; + + case RIGHTALIGN: + blocks[block].x = rofs; + blocks[block].x1 = rofs; + rofs += auxblocks[block].width; + blocks[block].x2 = rofs; + break; + } + blocks[block].y = yofs; + blocks[block].y1 = ystart; + blocks[block].y2 = yend; + blocks[block].strindex = strindex; + blocks[block].strlen = auxblocks[block].len; + strncpy(gram->text + strindex, auxblocks[block].str, + auxblocks[block].len); + strindex += blocks[block].strlen; + } + + yofs = yend; } @@ -331,11 +339,11 @@ fixup_and_draw(Display *dpy, bgstr = var_get_variable("X_background"); if (bgstr[0] == '\0') - bgstr = xres_get_bgcolor(style); + bgstr = xres_get_bgcolor(style); if (bgstr == NULL) - bgstr = var_get_variable("default_X_background"); + bgstr = var_get_variable("default_X_background"); if (bgstr[0]=='\0') - gram->bgcolor = default_bgcolor; + gram->bgcolor = default_bgcolor; if (bgstr && bgstr[0]) gram->bgcolor = x_string_to_color(bgstr, default_bgcolor); @@ -369,10 +377,10 @@ no_dots_downcase_var(char *str) inline static XFontStruct * mode_to_font(Display *dpy, char *style, xmode *mode) { return get_font(dpy, - style, - mode->font ? mode->font : mode->substyle, - mode->size, - mode->bold + mode->italic * 2); + style, + mode->font ? mode->font : mode->substyle, + mode->size, + mode->bold + mode->italic * 2); } inline static int @@ -384,7 +392,8 @@ envmatch(desctype *desc, char *str) { void xshow(Display *dpy, desctype *desc, int numstr, int numnl) { - XFontStruct *font; + XFontSet font; + XFontSetExtents *fse; xmode_stack modes = xmode_stack_create(); xmode curmode; xlinedesc *lines; @@ -422,134 +431,148 @@ xshow(Display *dpy, desctype *desc, int numstr, int numnl) } for (; desc->code != DT_EOF; desc = desc->next) { - switch (desc->code) { - case DT_ENV: - xmode_stack_push(modes, curmode); - curmode.substyle = string_Copy(curmode.substyle); - if (curmode.font) - curmode.font = string_Copy(curmode.font); - if (envmatch(desc, "roman")) { - curmode.bold = 0; - curmode.italic = 0; - } else if (envmatch(desc, "bold") || envmatch(desc, "b")) - curmode.bold = 1; - else if (envmatch(desc, "italic") || envmatch(desc, "i")) - curmode.italic = 1; - else if (envmatch(desc, "large")) - curmode.size = LARGE_SIZE; - else if (envmatch(desc, "medium")) - curmode.size = MEDIUM_SIZE; - else if (envmatch(desc, "small")) - curmode.size = SMALL_SIZE; - else if (envmatch(desc, "left") || envmatch(desc, "l")) - curmode.align = LEFTALIGN; - else if (envmatch(desc, "center") || envmatch(desc, "c")) - curmode.align = CENTERALIGN; - else if (envmatch(desc, "right") || envmatch(desc, "r")) - curmode.align = RIGHTALIGN; - else if (envmatch(desc, "beep")) - beepcount++; - else if (envmatch(desc, "font")) { - /* lookahead needed. desc->next->str should be the - font name, and desc->next->next->code should be - a DT_END*/ - if ((desc->next) && - (desc->next->next) && - (desc->next->code == DT_STR) && - (desc->next->next->code == DT_END)) { - - /* Since @font mutates the current environment, we have - to pop the environment that this case usually pushes */ - free(curmode.substyle); - curmode = xmode_stack_top(modes); - xmode_stack_pop(modes); - - /* mutating... */ - curmode.size = SPECIAL_SIZE; /* This is an @font() */ - curmode.font = string_CreateFromData(desc->next->str, - desc->next->len); - /* skip over the rest of the @font */ - desc = desc->next->next; - } - } else if (envmatch(desc, "color")) { - /* lookahead needed. desc->next->str should be the - font name, and desc->next->next->code should be - a DT_END*/ - if ((desc->next) && - (desc->next->next) && - (desc->next->code == DT_STR) && - (desc->next->next->code == DT_END)) { - char *colorname; - - /* Since @font mutates the current environment, we have - to pop the environment that this case usually pushes */ - free(curmode.substyle); - curmode = xmode_stack_top(modes); - xmode_stack_pop(modes); - - /* mutating... */ - colorname = string_CreateFromData(desc->next->str, - desc->next->len); - curmode.color = x_string_to_color(colorname, default_fgcolor); - free(colorname); - curmode.expcolor = 1; - /* skip over the rest of the @font */ - desc = desc->next->next; - } - } else if (desc->len > 0) { /* avoid @{...} */ - free(curmode.substyle); - if (curmode.font) { - free(curmode.font); - curmode.font = NULL; - } - curmode.substyle = string_CreateFromData(desc->str, desc->len); - } - break; - - case DT_STR: - auxblocks[nextblock].align = curmode.align; - auxblocks[nextblock].font = mode_to_font(dpy, style, &curmode); - auxblocks[nextblock].str = desc->str; - auxblocks[nextblock].len = desc->len; - i = ZTransliterate(desc->str, desc->len, - strcmp(notice_charset, "UNKNOWN") ? - notice_charset : "ISO-8859-1", - "UTF-16BE", - &blocks[nextblock].wstr, - &blocks[nextblock].wlen); - if (i) { - var_set_variable("error", strerror(i)); - blocks[nextblock].wlen = desc->len * 2; - blocks[nextblock].wstr = malloc(blocks[nextblock].wlen); - for (i = 0; i < desc->len; i++) - *(short *)&(blocks[nextblock].wstr[i * 2]) = htons((short)(unsigned char)desc->str[i]); - /* XXX */ - } - if (curmode.expcolor) - blocks[nextblock].fgcolor = curmode.color; - else - blocks[nextblock].fgcolor = - x_string_to_color(mode_to_colorname(dpy, style, &curmode), - default_fgcolor); - nextblock++; - break; - - case DT_END: - free(curmode.substyle); - curmode = xmode_stack_top(modes); - xmode_stack_pop(modes); - break; - - case DT_NL: - lines[line].startblock = linestart; - lines[line].numblock = nextblock-linestart; - font = mode_to_font(dpy, style, &curmode); - lines[line].ascent = font->ascent; - lines[line].descent = font->descent; - line++; - linestart = nextblock; - break; - } + switch (desc->code) { + case DT_ENV: + xmode_stack_push(modes, curmode); + curmode.substyle = string_Copy(curmode.substyle); + if (curmode.font) + curmode.font = string_Copy(curmode.font); + if (envmatch(desc, "roman")) { + curmode.bold = 0; + curmode.italic = 0; + } else if (envmatch(desc, "bold") || envmatch(desc, "b")) + curmode.bold = 1; + else if (envmatch(desc, "italic") || envmatch(desc, "i")) + curmode.italic = 1; + else if (envmatch(desc, "large")) + curmode.size = LARGE_SIZE; + else if (envmatch(desc, "medium")) + curmode.size = MEDIUM_SIZE; + else if (envmatch(desc, "small")) + curmode.size = SMALL_SIZE; + else if (envmatch(desc, "left") || envmatch(desc, "l")) + curmode.align = LEFTALIGN; + else if (envmatch(desc, "center") || envmatch(desc, "c")) + curmode.align = CENTERALIGN; + else if (envmatch(desc, "right") || envmatch(desc, "r")) + curmode.align = RIGHTALIGN; + else if (envmatch(desc, "beep")) + beepcount++; + else if (envmatch(desc, "font")) { + /* lookahead needed. desc->next->str should be the + font name, and desc->next->next->code should be + a DT_END*/ + if ((desc->next) && + (desc->next->next) && + (desc->next->code == DT_STR) && + (desc->next->next->code == DT_END)) { + + /* Since @font mutates the current environment, we have + to pop the environment that this case usually pushes */ + free(curmode.substyle); + curmode = xmode_stack_top(modes); + xmode_stack_pop(modes); + + /* mutating... */ + curmode.size = SPECIAL_SIZE; /* This is an @font() */ + curmode.font = string_CreateFromData(desc->next->str, + desc->next->len); + /* skip over the rest of the @font */ + desc = desc->next->next; + } + } else if (envmatch(desc, "color")) { + /* lookahead needed. desc->next->str should be the + font name, and desc->next->next->code should be + a DT_END*/ + if ((desc->next) && + (desc->next->next) && + (desc->next->code == DT_STR) && + (desc->next->next->code == DT_END)) { + char *colorname; + + /* Since @font mutates the current environment, we have + to pop the environment that this case usually pushes */ + free(curmode.substyle); + curmode = xmode_stack_top(modes); + xmode_stack_pop(modes); + + /* mutating... */ + colorname = string_CreateFromData(desc->next->str, + desc->next->len); + curmode.color = x_string_to_color(colorname, default_fgcolor); + free(colorname); + curmode.expcolor = 1; + /* skip over the rest of the @font */ + desc = desc->next->next; + } + } else if (desc->len > 0) { /* avoid @{...} */ + free(curmode.substyle); + if (curmode.font) { + free(curmode.font); + curmode.font = NULL; + } + curmode.substyle = string_CreateFromData(desc->str, desc->len); + } + break; + + case DT_STR: + auxblocks[nextblock].align = curmode.align; + auxblocks[nextblock].font = mode_to_font(dpy, style, &curmode); + auxblocks[nextblock].str = desc->str; + auxblocks[nextblock].len = desc->len; + i = ZTransliterate(desc->str, desc->len, + strcmp(notice_charset, "UNKNOWN") ? + notice_charset : "ISO-8859-1", +#ifdef X_HAVE_UTF8_STRING- + "UTF-8", +#else + "UTF-16BE", +#endif + &blocks[nextblock].wstr, + &blocks[nextblock].wlen); + if (i) { + var_set_variable("error", strerror(i)); +#ifdef X_HAVE_UTF8_STRING + blocks[nextblock].wlen = desc->len; + blocks[nextblock].wstr = strdup(desc->str); +#else + blocks[nextblock].wlen = desc->len * 2; + blocks[nextblock].wstr = malloc(blocks[nextblock].wlen); + for (i = 0; i < desc->len; i++) + *(short *)&(blocks[nextblock].wstr[i * 2]) = htons((short)(unsigned char)desc->str[i]); + /* XXX */ +#endif + } +#ifndef X_HAVE_UTF8_STRING + blocks[nextblock].wlen /= 2; +#endif + if (curmode.expcolor) + blocks[nextblock].fgcolor = curmode.color; + else + blocks[nextblock].fgcolor = + x_string_to_color(mode_to_colorname(dpy, style, &curmode), + default_fgcolor); + nextblock++; + break; + + case DT_END: + free(curmode.substyle); + curmode = xmode_stack_top(modes); + xmode_stack_pop(modes); + break; + + case DT_NL: + lines[line].startblock = linestart; + lines[line].numblock = nextblock-linestart; + font = mode_to_font(dpy, style, &curmode); + fse = XExtentsOfFontSet(font); + lines[line].ascent = -fse->max_logical_extent.y; + lines[line].descent = fse->max_logical_extent.y + + fse->max_logical_extent.height; + line++; + linestart = nextblock; + break; + } } /* case DT_EOF: will drop through to here. */ @@ -565,7 +588,7 @@ xshow(Display *dpy, desctype *desc, int numstr, int numnl) free(curmode.substyle); fixup_and_draw(dpy, style, auxblocks, blocks, nextblock, lines, line, - beepcount); + beepcount); free(lines); free(auxblocks); if (free_style) @@ -574,8 +597,8 @@ xshow(Display *dpy, desctype *desc, int numstr, int numnl) static void xhandleevent(Display *dpy, - Window w, - XEvent *event) + Window w, + XEvent *event) { x_gram *gram; @@ -608,8 +631,8 @@ x_get_input(Display *dpy) XNoOp(dpy); /* Ensure server is still with us... */ while (XPending(dpy)) { - XNextEvent(dpy,&event); - xhandleevent(dpy, event.xany.window, &event); + XNextEvent(dpy,&event); + xhandleevent(dpy, event.xany.window, &event); } } @@ -633,88 +656,88 @@ plus_window_deletions(ZNotice_t *notice) if (val) { if (!strcmp(val, "this")) { do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (tmp->notice == notice) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (tmp->notice == notice) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "s")) { /* I cheated. This is really sender, not class */ strcpy(class_nm, notice->z_sender); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_sender, class_nm)) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_sender, class_nm)) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "ns")) { /* I cheated. This is really sender, not class */ strcpy(class_nm, notice->z_sender); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!!strcasecmp(((ZNotice_t *)(tmp->notice))->z_sender, class_nm)) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!!strcasecmp(((ZNotice_t *)(tmp->notice))->z_sender, class_nm)) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "r")) { strcpy(recip_nm, notice->z_recipient); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "nr")) { strcpy(recip_nm, notice->z_recipient); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!!strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!!strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "cir")) { @@ -722,87 +745,86 @@ plus_window_deletions(ZNotice_t *notice) strcpy(instance_nm, notice->z_class_inst); strcpy(recip_nm, notice->z_recipient); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class_inst, instance_nm) - && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm) - && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) - { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class_inst, instance_nm) + && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm) + && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) + { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "ci")) { strcpy(class_nm, notice->z_class); strcpy(instance_nm, notice->z_class_inst); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class_inst, instance_nm) - && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm)) - { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class_inst, instance_nm) + && !strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm)) + { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "cr")) { strcpy(class_nm, notice->z_class); strcpy(recip_nm, notice->z_recipient); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm) && - !strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) - { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm) && + !strcasecmp(((ZNotice_t *)(tmp->notice))->z_recipient, recip_nm)) + { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "c")) { strcpy(class_nm, notice->z_class); do { - done = 1; - tmp = bottom_gram; - while (tmp) { - if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm)) { - fry = tmp; - tmp = tmp->above; - xdestroygram(dpy, fry->w, desc_context, fry); - done = 0; - } else { - tmp = tmp->above; - } - } + done = 1; + tmp = bottom_gram; + while (tmp) { + if (!strcasecmp(((ZNotice_t *)(tmp->notice))->z_class, class_nm)) { + fry = tmp; + tmp = tmp->above; + xdestroygram(dpy, fry->w, desc_context, fry); + done = 0; + } else { + tmp = tmp->above; + } + } } while (!done); } else if (!strcmp(val, "all")) { while (bottom_gram) { - xdestroygram(dpy, bottom_gram->w, desc_context, bottom_gram); + xdestroygram(dpy, bottom_gram->w, desc_context, bottom_gram); } } } } #endif #endif /* X_DISPLAY_MISSING */ - -- cgit v1.2.3