From fdbff6587f29048c85772f21d3647797f96d527f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 12 Jan 2013 18:53:47 -0800 Subject: Convert to X.Org standard coding style Signed-off-by: Alan Coopersmith --- LED.c | 320 ++++++++++++++++++++------------------- LED.h | 5 +- LEDP.h | 38 ++--- utils.c | 250 +++++++++++++++--------------- utils.h | 131 +++++++--------- xkbbell.c | 343 ++++++++++++++++++++++-------------------- xkbvleds.c | 501 ++++++++++++++++++++++++++++++++----------------------------- xkbwatch.c | 354 ++++++++++++++++++++++++------------------- 8 files changed, 1020 insertions(+), 922 deletions(-) diff --git a/LED.c b/LED.c index dd68803..73864f5 100644 --- a/LED.c +++ b/LED.c @@ -53,139 +53,148 @@ #define offset(field) XtOffsetOf(LEDRec, field) static XtResource resources[] = { {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(led.foreground), XtRString, XtDefaultForeground}, + offset(led.foreground), XtRString, XtDefaultForeground}, {XtNon, XtCOn, XtRBoolean, sizeof(Boolean), - offset(led.on), XtRImmediate, (XtPointer)False}, + offset(led.on), XtRImmediate, (XtPointer) False}, {XtNtopColor, XtCTopColor, XtRPixel, sizeof(Pixel), - offset(led.top_color), XtRString, "black"}, + offset(led.top_color), XtRString, "black"}, {XtNbottomColor, XtCBottomColor, XtRPixel, sizeof(Pixel), - offset(led.bottom_color), XtRString, "white"}, + offset(led.bottom_color), XtRString, "white"}, {XtNonColor, XtCOnColor, XtRPixel, sizeof(Pixel), - offset(led.on_color), XtRString, "green"}, + offset(led.on_color), XtRString, "green"}, {XtNoffColor, XtCOffColor, XtRPixel, sizeof(Pixel), - offset(led.off_color), XtRString, "#005000"}, + offset(led.off_color), XtRString, "#005000"}, {XtNbevel, XtCBevel, XtRDimension, sizeof(Dimension), - offset(led.bevel), XtRImmediate, (XtPointer)1}, + offset(led.bevel), XtRImmediate, (XtPointer) 1}, {XtNledWidth, XtCLedWidth, XtRDimension, sizeof(Dimension), - offset(led.led_width), XtRImmediate, (XtPointer)6}, + offset(led.led_width), XtRImmediate, (XtPointer) 6}, {XtNledHeight, XtCLedHeight, XtRDimension, sizeof(Dimension), - offset(led.led_height), XtRImmediate, (XtPointer)12} + offset(led.led_height), XtRImmediate, (XtPointer) 12} }; #undef offset -static void ClassInitialize ( void ); -static void Initialize ( Widget request, Widget new, ArgList args, - Cardinal *num_args ); -static void Realize ( Widget w, Mask * mask, XSetWindowAttributes * xswa ); -static void Resize ( Widget w ); -static Boolean SetValues ( Widget current, Widget request, Widget new, - ArgList args, Cardinal *num_args ); -static void Destroy ( Widget w ); -static XtGeometryResult QueryGeometry ( Widget w, XtWidgetGeometry *intended, - XtWidgetGeometry *preferred ); +static void ClassInitialize(void); +static void Initialize(Widget request, Widget new, ArgList args, + Cardinal *num_args); +static void Realize(Widget w, Mask *mask, XSetWindowAttributes *xswa); +static void Resize(Widget w); +static Boolean SetValues(Widget current, Widget request, Widget new, + ArgList args, Cardinal *num_args); +static void Destroy(Widget w); +static XtGeometryResult QueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred); LEDClassRec ledClassRec = { - { -/* core_class fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "LED", - /* widget_size */ sizeof(LEDRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL - }, + { +/* core_class fields */ + /* superclass */ (WidgetClass) & simpleClassRec, + /* class_name */ "LED", + /* widget_size */ sizeof(LEDRec), + /* class_initialize */ ClassInitialize, + /* class_part_initialize */ NULL, + /* class_inited */ FALSE, + /* initialize */ Initialize, + /* initialize_hook */ NULL, + /* realize */ Realize, + /* actions */ NULL, + /* num_actions */ 0, + /* resources */ resources, + /* num_resources */ XtNumber(resources), + /* xrm_class */ NULLQUARK, + /* compress_motion */ TRUE, + /* compress_exposure */ TRUE, + /* compress_enterleave */ TRUE, + /* visible_interest */ FALSE, + /* destroy */ Destroy, + /* resize */ Resize, + /* expose */ XtInheritExpose, + /* set_values */ SetValues, + /* set_values_hook */ NULL, + /* set_values_almost */ XtInheritSetValuesAlmost, + /* get_values_hook */ NULL, + /* accept_focus */ NULL, + /* version */ XtVersion, + /* callback_private */ NULL, + /* tm_table */ NULL, + /* query_geometry */ QueryGeometry, + /* display_accelerator */ XtInheritDisplayAccelerator, + /* extension */ NULL + }, /* Simple class fields initialization */ - { - /* change_sensitive */ XtInheritChangeSensitive - }, + { + /* change_sensitive */ XtInheritChangeSensitive + }, /* LED class fields initialization */ - { - /* ignore */ 0 - } + { + /* ignore */ 0 + } }; -WidgetClass ledWidgetClass = (WidgetClass)&ledClassRec; +WidgetClass ledWidgetClass = (WidgetClass) &ledClassRec; + /**************************************************************** * * Private Procedures * ****************************************************************/ -static void +static void ClassInitialize(void) { XawInitializeWidgetSet(); } -static void +static void GetPixmaps(LEDWidget lw) { - XGCValues values; - GC gc; - Display * dpy; - Window root; - Pixmap pix,on_pixmap,off_pixmap; - Dimension bevel,width,height; + XGCValues values; + GC gc; + Display *dpy; + Window root; + Pixmap pix, on_pixmap, off_pixmap; + Dimension bevel, width, height; - dpy= XtDisplay((Widget)lw); - root= RootWindowOfScreen(XtScreen((Widget)lw)); - if (lw->led.on_pixmap!=None) { - XFreePixmap(dpy,lw->led.on_pixmap); - lw->led.on_pixmap= None; + dpy = XtDisplay((Widget) lw); + root = RootWindowOfScreen(XtScreen((Widget) lw)); + if (lw->led.on_pixmap != None) { + XFreePixmap(dpy, lw->led.on_pixmap); + lw->led.on_pixmap = None; } - if (lw->led.off_pixmap!=None) { - XFreePixmap(dpy,lw->led.off_pixmap); - lw->led.off_pixmap= None; + if (lw->led.off_pixmap != None) { + XFreePixmap(dpy, lw->led.off_pixmap); + lw->led.off_pixmap = None; } - lw->led.on_pixmap= on_pixmap= XCreatePixmap(dpy,root, - lw->core.width,lw->core.height,lw->core.depth); - lw->led.off_pixmap= off_pixmap= XCreatePixmap(dpy,root, - lw->core.width,lw->core.height,lw->core.depth); + lw->led.on_pixmap = on_pixmap = + XCreatePixmap(dpy, root, lw->core.width, lw->core.height, + lw->core.depth); + lw->led.off_pixmap = off_pixmap = + XCreatePixmap(dpy, root, lw->core.width, lw->core.height, + lw->core.depth); - values.foreground = lw->led.top_color; - gc= XCreateGC(dpy,lw->led.on_pixmap,(unsigned)GCForeground,&values); - bevel= lw->led.bevel; - width= lw->core.width; - height= lw->core.height; - XFillRectangle(dpy,on_pixmap,gc,0,0,width,height); - XFillRectangle(dpy,off_pixmap,gc,0,0,width,height); - XSetForeground(dpy,gc,lw->led.bottom_color); - XFillRectangle(dpy,on_pixmap,gc,bevel,bevel,width-bevel,height-bevel); - XFillRectangle(dpy,off_pixmap,gc,bevel,bevel,width-bevel,height-bevel); - XSetForeground(dpy,gc,lw->led.on_color); - XFillRectangle(dpy,on_pixmap,gc,bevel,bevel,width-2*bevel,height-2*bevel); - XSetForeground(dpy,gc,lw->led.off_color); - XFillRectangle(dpy,off_pixmap,gc,bevel,bevel,width-2*bevel,height-2*bevel); - XFreeGC(dpy,gc); - if (lw->led.on) pix= on_pixmap; - else pix= off_pixmap; - if (XtWindow((Widget)lw)!=None) - XSetWindowBackgroundPixmap(dpy,XtWindow((Widget)lw),pix); + values.foreground = lw->led.top_color; + gc = XCreateGC(dpy, lw->led.on_pixmap, (unsigned) GCForeground, &values); + bevel = lw->led.bevel; + width = lw->core.width; + height = lw->core.height; + XFillRectangle(dpy, on_pixmap, gc, 0, 0, width, height); + XFillRectangle(dpy, off_pixmap, gc, 0, 0, width, height); + XSetForeground(dpy, gc, lw->led.bottom_color); + XFillRectangle(dpy, on_pixmap, gc, bevel, bevel, width - bevel, + height - bevel); + XFillRectangle(dpy, off_pixmap, gc, bevel, bevel, width - bevel, + height - bevel); + XSetForeground(dpy, gc, lw->led.on_color); + XFillRectangle(dpy, on_pixmap, gc, bevel, bevel, width - 2 * bevel, + height - 2 * bevel); + XSetForeground(dpy, gc, lw->led.off_color); + XFillRectangle(dpy, off_pixmap, gc, bevel, bevel, width - 2 * bevel, + height - 2 * bevel); + XFreeGC(dpy, gc); + if (lw->led.on) + pix = on_pixmap; + else + pix = off_pixmap; + if (XtWindow((Widget) lw) != None) + XSetWindowBackgroundPixmap(dpy, XtWindow((Widget) lw), pix); return; } @@ -199,32 +208,34 @@ Initialize(Widget request, Widget new, ArgList args, Cardinal *num_args) lw->core.height = lw->led.led_height; if (lw->core.width == 0) lw->core.width = lw->led.led_width; - lw->core.border_width= 0; - if (lw->led.bevel==0) - lw->led.bevel= 1; - lw->led.on_pixmap= lw->led.off_pixmap= None; - (*XtClass(new)->core_class.resize) ((Widget)lw); + lw->core.border_width = 0; + if (lw->led.bevel == 0) + lw->led.bevel = 1; + lw->led.on_pixmap = lw->led.off_pixmap = None; + (*XtClass(new)->core_class.resize) ((Widget) lw); GetPixmaps(lw); -} /* Initialize */ +} /* Initialize */ static void Realize(Widget w, Mask *mask, XSetWindowAttributes *xswa) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; WidgetClass super = simpleWidgetClass; - Pixmap pix; + Pixmap pix; - (*super->core_class.realize)(w,mask,xswa); - if (lw->led.on) pix= lw->led.on_pixmap; - else pix= lw->led.off_pixmap; - XSetWindowBackgroundPixmap(XtDisplay(w),XtWindow(w),pix); + (*super->core_class.realize) (w, mask, xswa); + if (lw->led.on) + pix = lw->led.on_pixmap; + else + pix = lw->led.off_pixmap; + XSetWindowBackgroundPixmap(XtDisplay(w), XtWindow(w), pix); return; } -static void +static void Resize(Widget w) { - GetPixmaps((LEDWidget)w); + GetPixmaps((LEDWidget) w); return; } @@ -232,71 +243,72 @@ Resize(Widget w) * Set specified arguments into widget */ -static Boolean -SetValues(Widget current, Widget request, Widget new, - ArgList args, Cardinal *num_args) +static Boolean +SetValues(Widget current, Widget request, Widget new, + ArgList args, Cardinal *num_args) { LEDWidget curlw = (LEDWidget) current; LEDWidget newlw = (LEDWidget) new; Boolean changed; - changed= FALSE; - if (curlw->led.foreground != newlw->led.foreground - || curlw->core.background_pixel != newlw->core.background_pixel - || curlw->led.on_color != newlw->led.on_color - || curlw->led.off_color != newlw->led.off_color - || curlw->core.width != newlw->core.width - || curlw->core.height != newlw->core.height) { - GetPixmaps(newlw); - changed= TRUE; + changed = FALSE; + if (curlw->led.foreground != newlw->led.foreground + || curlw->core.background_pixel != newlw->core.background_pixel + || curlw->led.on_color != newlw->led.on_color + || curlw->led.off_color != newlw->led.off_color + || curlw->core.width != newlw->core.width + || curlw->core.height != newlw->core.height) { + GetPixmaps(newlw); + changed = TRUE; } - if (curlw->led.on!=newlw->led.on) { - Pixmap pix; + if (curlw->led.on != newlw->led.on) { + Pixmap pix; - if (newlw->led.on) pix= newlw->led.on_pixmap; - else pix= newlw->led.off_pixmap; + if (newlw->led.on) + pix = newlw->led.on_pixmap; + else + pix = newlw->led.off_pixmap; - if (XtWindow(newlw)!=None) - XSetWindowBackgroundPixmap(XtDisplay(newlw),XtWindow(newlw),pix); - changed= TRUE; + if (XtWindow(newlw) != None) + XSetWindowBackgroundPixmap(XtDisplay(newlw), XtWindow(newlw), pix); + changed = TRUE; } return changed; } -static void +static void Destroy(Widget w) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; - if (lw->led.on_pixmap!=None) { - XFreePixmap(XtDisplay(w),lw->led.on_pixmap); - lw->led.on_pixmap= None; + if (lw->led.on_pixmap != None) { + XFreePixmap(XtDisplay(w), lw->led.on_pixmap); + lw->led.on_pixmap = None; } - if (lw->led.off_pixmap!=None) { - XFreePixmap(XtDisplay(w),lw->led.off_pixmap); - lw->led.off_pixmap= None; + if (lw->led.off_pixmap != None) { + XFreePixmap(XtDisplay(w), lw->led.off_pixmap); + lw->led.off_pixmap = None; } return; } - -static XtGeometryResult -QueryGeometry(Widget w, XtWidgetGeometry *intended, - XtWidgetGeometry *preferred) +static XtGeometryResult +QueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; preferred->request_mode = CWWidth | CWHeight; preferred->width = lw->led.led_height; preferred->height = lw->led.led_width; - if ( ((intended->request_mode & (CWWidth | CWHeight)) - == (CWWidth | CWHeight)) && - intended->width == preferred->width && - intended->height == preferred->height) - return XtGeometryYes; + if (((intended->request_mode & (CWWidth | CWHeight)) + == (CWWidth | CWHeight)) && + intended->width == preferred->width && + intended->height == preferred->height) + return XtGeometryYes; else if (preferred->width == w->core.width && - preferred->height == w->core.height) - return XtGeometryNo; + preferred->height == w->core.height) + return XtGeometryNo; else - return XtGeometryAlmost; + return XtGeometryAlmost; } diff --git a/LED.h b/LED.h index 0943ed5..82abc55 100644 --- a/LED.h +++ b/LED.h @@ -92,6 +92,7 @@ extern WidgetClass ledWidgetClass; typedef struct _LEDClassRec *LEDWidgetClass; -typedef struct _LEDRec *LEDWidget; -#endif /* _XawLED_h */ +typedef struct _LEDRec *LEDWidget; + +#endif /* _XawLED_h */ diff --git a/LEDP.h b/LEDP.h index 4f5f50c..52ffb1d 100644 --- a/LEDP.h +++ b/LEDP.h @@ -32,13 +32,15 @@ /* New fields for the Label widget class record */ -typedef struct {int foo;} LEDClassPart; +typedef struct { + int foo; +} LEDClassPart; /* Full class record declaration */ typedef struct _LEDClassRec { - CoreClassPart core_class; - SimpleClassPart simple_class; - LEDClassPart led_class; + CoreClassPart core_class; + SimpleClassPart simple_class; + LEDClassPart led_class; } LEDClassRec; extern LEDClassRec ledClassRec; @@ -46,18 +48,18 @@ extern LEDClassRec ledClassRec; /* New fields for the LED widget record */ typedef struct { /* resources */ - Pixel foreground; - Pixel on_color; - Pixel off_color; - Pixel top_color; - Pixel bottom_color; - Dimension bevel; - Dimension led_width; - Dimension led_height; - Boolean on; + Pixel foreground; + Pixel on_color; + Pixel off_color; + Pixel top_color; + Pixel bottom_color; + Dimension bevel; + Dimension led_width; + Dimension led_height; + Boolean on; /* private state */ - Pixmap on_pixmap; + Pixmap on_pixmap; Pixmap off_pixmap; } LEDPart; @@ -68,9 +70,9 @@ typedef struct { ****************************************************************/ typedef struct _LEDRec { - CorePart core; - SimplePart simple; - LEDPart led; + CorePart core; + SimplePart simple; + LEDPart led; } LEDRec; -#endif /* _XawLEDP_h */ +#endif /* _XawLEDP_h */ diff --git a/utils.c b/utils.c index 37eebee..8f43c1c 100644 --- a/utils.c +++ b/utils.c @@ -2,10 +2,10 @@ /*\ * $Xorg: utils.c,v 1.6 2000/08/17 19:54:51 cpqbld Exp $ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -38,7 +38,7 @@ unsigned int debugFlags; Opaque uAlloc(unsigned size) { - return((Opaque)malloc(size)); + return ((Opaque) malloc(size)); } /***====================================================================***/ @@ -46,7 +46,7 @@ uAlloc(unsigned size) Opaque uCalloc(unsigned n, unsigned size) { - return((Opaque)calloc(n,size)); + return ((Opaque) calloc(n, size)); } /***====================================================================***/ @@ -54,9 +54,10 @@ uCalloc(unsigned n, unsigned size) Opaque uRealloc(Opaque old, unsigned newSize) { - if (old==NULL) - return((Opaque)malloc(newSize)); - else return((Opaque)realloc((char *)old,newSize)); + if (old == NULL) + return ((Opaque) malloc(newSize)); + else + return ((Opaque) realloc((char *) old, newSize)); } /***====================================================================***/ @@ -64,17 +65,17 @@ uRealloc(Opaque old, unsigned newSize) Opaque uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize) { -char *rtrn; + char *rtrn; - if (old==NULL) - rtrn= (char *)calloc(nNew,itemSize); + if (old == NULL) + rtrn = (char *) calloc(nNew, itemSize); else { - rtrn= (char *)realloc((char *)old,nNew*itemSize); - if ((rtrn)&&(nNew>nOld)) { - bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize); - } + rtrn = (char *) realloc((char *) old, nNew * itemSize); + if ((rtrn) && (nNew > nOld)) { + bzero(&rtrn[nOld * itemSize], (nNew - nOld) * itemSize); + } } - return (Opaque)rtrn; + return (Opaque) rtrn; } /***====================================================================***/ @@ -82,8 +83,8 @@ char *rtrn; void uFree(Opaque ptr) { - if (ptr!=(Opaque)NULL) - free((char *)ptr); + if (ptr != (Opaque) NULL) + free((char *) ptr); return; } @@ -91,37 +92,40 @@ uFree(Opaque ptr) /*** FUNCTION ENTRY TRACKING ***/ /***====================================================================***/ -static FILE *entryFile= NULL; - int uEntryLevel; +static FILE *entryFile = NULL; + +int uEntryLevel; Boolean uSetEntryFile(char *name) { - if ((entryFile!=NULL)&&(entryFile!=stderr)) { - fprintf(entryFile,"switching to %s\n",name?name:"stderr"); - fclose(entryFile); + if ((entryFile != NULL) && (entryFile != stderr)) { + fprintf(entryFile, "switching to %s\n", name ? name : "stderr"); + fclose(entryFile); } - if (name!=NullString) entryFile= fopen(name,"w"); - else entryFile= stderr; - if (entryFile==NULL) { - entryFile= stderr; - return(False); + if (name != NullString) + entryFile = fopen(name, "w"); + else + entryFile = stderr; + if (entryFile == NULL) { + entryFile = stderr; + return (False); } - return(True); + return (True); } void -uEntry(int l, char *s,...) +uEntry(int l, char *s, ...) { -int i; -va_list ap; + int i; + va_list ap; va_start(ap, s); - for (i=0;i 0x%p\n",rtVal); + fprintf(entryFile, "---> 0x%p\n", rtVal); return; } @@ -144,49 +149,51 @@ int i; /*** PRINT FUNCTIONS ***/ /***====================================================================***/ - FILE *uDebugFile= NULL; - int uDebugIndentLevel= 0; - int uDebugIndentSize= 4; +FILE *uDebugFile = NULL; +int uDebugIndentLevel = 0; +int uDebugIndentSize = 4; Boolean uSetDebugFile(char *name) { - if ((uDebugFile!=NULL)&&(uDebugFile!=stderr)) { - fprintf(uDebugFile,"switching to %s\n",name?name:"stderr"); - fclose(uDebugFile); + if ((uDebugFile != NULL) && (uDebugFile != stderr)) { + fprintf(uDebugFile, "switching to %s\n", name ? name : "stderr"); + fclose(uDebugFile); } - if (name!=NullString) uDebugFile= fopen(name,"w"); - else uDebugFile= stderr; - if (uDebugFile==NULL) { - uDebugFile= stderr; - return(False); + if (name != NullString) + uDebugFile = fopen(name, "w"); + else + uDebugFile = stderr; + if (uDebugFile == NULL) { + uDebugFile = stderr; + return (False); } - return(True); + return (True); } void -uDebug(char *s,...) +uDebug(char *s, ...) { -int i; -va_list ap; + int i; + va_list ap; va_start(ap, s); - for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) { - putc(' ',uDebugFile); + for (i = (uDebugIndentLevel * uDebugIndentSize); i > 0; i--) { + putc(' ', uDebugFile); } - vfprintf(uDebugFile,s,ap); + vfprintf(uDebugFile, s, ap); fflush(uDebugFile); va_end(ap); return; } void -uDebugNOI(char *s,...) +uDebugNOI(char *s, ...) { -va_list ap; + va_list ap; va_start(ap, s); - vfprintf(uDebugFile,s,ap); + vfprintf(uDebugFile, s, ap); fflush(uDebugFile); va_end(ap); return; @@ -194,31 +201,33 @@ va_list ap; /***====================================================================***/ -static FILE *errorFile= NULL; +static FILE *errorFile = NULL; Boolean uSetErrorFile(char *name) { - if ((errorFile!=NULL)&&(errorFile!=stderr)) { - fprintf(errorFile,"switching to %s\n",name?name:"stderr"); - fclose(errorFile); + if ((errorFile != NULL) && (errorFile != stderr)) { + fprintf(errorFile, "switching to %s\n", name ? name : "stderr"); + fclose(errorFile); } - if (name!=NullString) errorFile= fopen(name,"w"); - else errorFile= stderr; - if (errorFile==NULL) { - errorFile= stderr; - return(False); + if (name != NullString) + errorFile = fopen(name, "w"); + else + errorFile = stderr; + if (errorFile == NULL) { + errorFile = stderr; + return (False); } - return(True); + return (True); } void -uInformation(char *s,...) +uInformation(char *s, ...) { va_list ap; va_start(ap, s); - vfprintf(errorFile,s,ap); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -227,13 +236,13 @@ uInformation(char *s,...) /***====================================================================***/ void -uAction(char *s,...) +uAction(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile," "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, " "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -242,13 +251,13 @@ uAction(char *s,...) /***====================================================================***/ void -uWarning(char *s,...) +uWarning(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Warning: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Warning: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -257,13 +266,13 @@ uWarning(char *s,...) /***====================================================================***/ void -uError(char *s,...) +uError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -272,14 +281,14 @@ uError(char *s,...) /***====================================================================***/ void -uFatalError(char *s,...) +uFatalError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Fatal Error: "); - vfprintf(errorFile,s,ap); - fprintf(errorFile," Exiting\n"); + fprintf(errorFile, "Fatal Error: "); + vfprintf(errorFile, s, ap); + fprintf(errorFile, " Exiting\n"); fflush(errorFile); va_end(ap); exit(1); @@ -289,13 +298,13 @@ uFatalError(char *s,...) /***====================================================================***/ void -uInternalError(char *s,...) +uInternalError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Internal error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Internal error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -307,12 +316,12 @@ uInternalError(char *s,...) char * uStringDup(char *str) { -char *rtrn; + char *rtrn; - if (str==NULL) - return NULL; - rtrn= (char *)uAlloc(strlen(str)+1); - strcpy(rtrn,str); + if (str == NULL) + return NULL; + rtrn = (char *) uAlloc(strlen(str) + 1); + strcpy(rtrn, str); return rtrn; } #endif @@ -321,24 +330,25 @@ char *rtrn; int uStrCaseCmp(char *str1, char *str2) { - char buf1[512],buf2[512]; + char buf1[512], buf2[512]; char c, *s; + register int n; - for (n=0, s = buf1; (c = *str1++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf1; (c = *str1++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; - for (n=0, s = buf2; (c = *str2++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf2; (c = *str2++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; return (strcmp(buf1, buf2)); @@ -349,15 +359,19 @@ uStrCasePrefix(char *prefix, char *str) { char c1; char c2; - while (((c1=*prefix)!='\0')&&((c2=*str)!='\0')) { - if (isupper(c1)) c1= tolower(c1); - if (isupper(c2)) c2= tolower(c2); - if (c1!=c2) - return 0; - prefix++; str++; + + while (((c1 = *prefix) != '\0') && ((c2 = *str) != '\0')) { + if (isupper(c1)) + c1 = tolower(c1); + if (isupper(c2)) + c2 = tolower(c2); + if (c1 != c2) + return 0; + prefix++; + str++; } - if (c1!='\0') - return 0; + if (c1 != '\0') + return 0; return 1; } diff --git a/utils.h b/utils.h index 2126f8a..6d5ec3b 100644 --- a/utils.h +++ b/utils.h @@ -4,10 +4,10 @@ /*\ * $Xorg: utils.h,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -40,7 +40,6 @@ _XFUNCPROTOBEGIN - #ifndef NUL #define NUL '\0' #endif @@ -48,24 +47,24 @@ _XFUNCPROTOBEGIN /***====================================================================***/ #ifndef OPAQUE_DEFINED -typedef void *Opaque; +typedef void *Opaque; #endif #ifndef NullOpaque #define NullOpaque ((Opaque)NULL) #endif #ifndef BOOLEAN_DEFINED -typedef char Boolean; +typedef char Boolean; #endif #ifndef True #define True ((Boolean)1) #define False ((Boolean)0) -#endif /* ndef True */ +#endif /* ndef True */ #define booleanText(b) ((b)?"True":"False") #ifndef COMPARISON_DEFINED -typedef int Comparison; +typedef int Comparison; #define Greater ((Comparison)1) #define Equal ((Comparison)0) @@ -76,35 +75,29 @@ typedef int Comparison; #ifdef notyet typedef union { - int i; - unsigned u; - void *p; - void *(*fp)(); + int i; + unsigned u; + void *p; + void *(*fp) (); } Union; #endif /***====================================================================***/ -extern Opaque uAlloc( - unsigned /* size */ -); -extern Opaque uCalloc( - unsigned /* n */, - unsigned /* size */ -); -extern Opaque uRealloc( - Opaque /* old */, - unsigned /* newSize */ -); -extern Opaque uRecalloc( - Opaque /* old */, - unsigned /* nOld */, - unsigned /* nNew */, - unsigned /* newSize */ -); -extern void uFree( - Opaque /* ptr */ -); +extern Opaque uAlloc(unsigned /* size */); + +extern Opaque uCalloc(unsigned /* n */, + unsigned /* size */); + +extern Opaque uRealloc(Opaque /* old */, + unsigned /* newSize */); + +extern Opaque uRecalloc(Opaque /* old */, + unsigned /* nOld */, + unsigned /* nNew */, + unsigned /* newSize */); + +extern void uFree(Opaque /* ptr */); #define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) #define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) @@ -120,13 +113,13 @@ extern void uFree( /***====================================================================***/ -extern Boolean uSetErrorFile ( char *name ); -extern void uInformation ( char *s, ...); -extern void uAction ( char *s, ... ); -extern void uWarning ( char *s, ... ); -extern void uError ( char *s, ... ); -extern void uFatalError(char *s,...); -extern void uInternalError ( char *s, ... ); +extern Boolean uSetErrorFile(char *name); +extern void uInformation(char *s, ...); +extern void uAction(char *s, ...); +extern void uWarning(char *s, ...); +extern void uError(char *s, ...); +extern void uFatalError(char *s, ...); +extern void uInternalError(char *s, ...); /***====================================================================***/ @@ -141,21 +134,16 @@ extern void uInternalError ( char *s, ... ); #define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) #define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) #else -extern int uStrCaseCmp( - char * /* s1 */, - char * /* s2 */ -); -extern int uStrCasePrefix( - char * /* p */, - char * /* str */ -); +extern int uStrCaseCmp(char * /* s1 */, + char * /* s2 */); + +extern int uStrCasePrefix(char * /* p */, + char * /* str */); #endif #ifdef HAVE_STRDUP #define uStringDup(s1) (strdup(s1)) #else -extern char *uStringDup( - char * /* s1 */ -); +extern char *uStringDup(char * /* s1 */); #endif /***====================================================================***/ @@ -174,16 +162,16 @@ extern char *uStringDup( #endif extern -unsigned int DEBUG_VAR; - -extern void uDebug( char *s, ... ); -extern void uDebugNOI( char *s, ... ); /* no indent */ -extern Boolean uSetDebugFile( - char *name -); -extern FILE *uDebugFile; -extern int uDebugIndentLevel; -extern int uDebugIndentSize; +unsigned int DEBUG_VAR; + +extern void uDebug(char *s, ...); +extern void uDebugNOI(char *s, ...); /* no indent */ +extern Boolean uSetDebugFile(char *name); + +extern FILE *uDebugFile; +extern int uDebugIndentLevel; +extern int uDebugIndentSize; + #define uDebugIndent(l) (uDebugIndentLevel+=(l)) #define uDebugOutdent(l) (uDebugIndentLevel-=(l)) #ifdef DEBUG_ON @@ -214,15 +202,13 @@ extern int uDebugIndentSize; #define uDEBUG_NOI5(f,s,a,b,c,d,e) #endif -extern Boolean uSetEntryFile( - char *name -); -extern void uEntry(int l, char *s, ... ); -extern void uExit( - int l,char *rtVal -); +extern Boolean uSetEntryFile(char *name); + +extern void uEntry(int l, char *s, ...); +extern void uExit(int l, char *rtVal); + +extern int uEntryLevel; -extern int uEntryLevel; #ifdef ENTRY_TRACKING_ON #define ENTRY_BIT 0x10 #define LOW_ENTRY_BIT 0x1000 @@ -272,10 +258,7 @@ extern int uEntryLevel; #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h) #define uFLAG_RETURN(v) { return(v);} #define uFLAG_VOIDRETURN { return; } -#endif +#endif _XFUNCPROTOEND - -#endif /* UTILS_H */ - - +#endif /* UTILS_H */ diff --git a/xkbbell.c b/xkbbell.c index cc30c8a..da69fb2 100644 --- a/xkbbell.c +++ b/xkbbell.c @@ -34,113 +34,118 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -static char *dpyName = NULL; -static int volume = 0; -static int devSpec = XkbUseCoreKbd; -static int class= -1; -static int id= -1; -static char * bellName; -static Atom nameAtom = None; -static int synch= 0; -static int win = None; -static int force = 0; -static int nobeep = 0; +static char *dpyName = NULL; +static int volume = 0; +static int devSpec = XkbUseCoreKbd; +static int class = -1; +static int id = -1; +static char *bellName; +static Atom nameAtom = None; +static int synch = 0; +static int win = None; +static int force = 0; +static int nobeep = 0; static int parseArgs(int argc, char *argv[]) { -int i; + int i; - for (i=1;i100)) { - fprintf(stderr,"Volume must be in the range -100..100\n"); - return 0; - } - } - else { - fprintf(stderr,"Must specify volume for -v\n"); - return 0; - } - } - else if ( strcmp(argv[i],"-w")==0 ) { - if ( ++i 100)) { + fprintf(stderr, "Volume must be in the range -100..100\n"); + return 0; + } + } + else { + fprintf(stderr, "Must specify volume for -v\n"); + return 0; + } + } + else if (strcmp(argv[i], "-w") == 0) { + if (++i < argc) { + if (sscanf(argv[i], " %i ", &win) != 1) { + fprintf(stderr, "Must specify a numeric window ID\n"); + return 0; + } + } + else { + fprintf(stderr, "Must specify a window ID for -w\n"); + return 0; + } + } + else { + if (i < argc - 1) { + fprintf(stderr, "Bell name must be the last argument\n"); + return 0; + } + bellName = argv[i]; + } } return 1; } @@ -148,74 +153,90 @@ int i; int main(int argc, char *argv[]) { -Display *dpy; -int i1,i2,i3,i4,i5; + Display *dpy; - - if (!parseArgs(argc,argv)) { - fprintf(stderr,"Usage: %s [ ] \n",argv[0]); - fprintf(stderr,"Where legal options are:\n"); - fprintf(stderr,"-help print this message\n"); - fprintf(stderr,"-usage print this message\n"); - fprintf(stderr,"-display specifies display to use\n"); - fprintf(stderr,"-synch turn on synchronization\n"); - fprintf(stderr,"-dev specifies device to use\n"); - fprintf(stderr,"-force force audible bell\n"); - fprintf(stderr,"-nobeep suppress server bell, event only\n"); - fprintf(stderr,"-bf specifies bell feedback to use\n"); - fprintf(stderr,"-kf specifies keyboard feedback to use\n"); - fprintf(stderr,"-v specifies volume to use\n"); - fprintf(stderr,"-w specifies window to use\n"); - fprintf(stderr,"If neither device nor feedback are specified, %s uses the\n",argv[0]); - fprintf(stderr,"default values for the core keyboard device.\n"); - return 1; + int i1, i2, i3, i4, i5; + + if (!parseArgs(argc, argv)) { + fprintf(stderr, "Usage: %s [ ] \n", argv[0]); + fprintf(stderr, "Where legal options are:\n"); + fprintf(stderr, "-help print this message\n"); + fprintf(stderr, "-usage print this message\n"); + fprintf(stderr, "-display specifies display to use\n"); + fprintf(stderr, "-synch turn on synchronization\n"); + fprintf(stderr, "-dev specifies device to use\n"); + fprintf(stderr, "-force force audible bell\n"); + fprintf(stderr, + "-nobeep suppress server bell, event only\n"); + fprintf(stderr, "-bf specifies bell feedback to use\n"); + fprintf(stderr, + "-kf specifies keyboard feedback to use\n"); + fprintf(stderr, "-v specifies volume to use\n"); + fprintf(stderr, "-w specifies window to use\n"); + fprintf(stderr, + "If neither device nor feedback are specified, %s uses the\n", + argv[0]); + fprintf(stderr, "default values for the core keyboard device.\n"); + return 1; } dpy = XOpenDisplay(dpyName); - if ( !dpy ) { - fprintf(stderr,"Couldn't open display \"%s\"\n",XDisplayName(dpyName)); - return 1; + if (!dpy) { + fprintf(stderr, "Couldn't open display \"%s\"\n", + XDisplayName(dpyName)); + return 1; } if (synch) - XSynchronize(dpy,1); - i1= XkbMajorVersion; - i2= XkbMinorVersion; - if ( !XkbLibraryVersion(&i1,&i2) ) { - fprintf(stderr,"Warning! X library built with XKB version %d.%02d\n", - i1,i2); - fprintf(stderr," but %s was built with %d.%02d\n",argv[0], - XkbMajorVersion,XkbMinorVersion); - fprintf(stderr," Trying anyway\n"); + XSynchronize(dpy, 1); + i1 = XkbMajorVersion; + i2 = XkbMinorVersion; + if (!XkbLibraryVersion(&i1, &i2)) { + fprintf(stderr, "Warning! X library built with XKB version %d.%02d\n", + i1, i2); + fprintf(stderr, " but %s was built with %d.%02d\n", argv[0], + XkbMajorVersion, XkbMinorVersion); + fprintf(stderr, " Trying anyway\n"); } - if ( !XkbQueryExtension(dpy,&i1,&i2,&i3,&i4,&i5)>0 ) { - if ((i4!=0)||(i5!=0)) - fprintf(stderr,"server supports incompatible XKB version %d.%02d\n", - i4,i5); - else fprintf(stderr,"XkbQueryExtension failed\n"); - fprintf(stderr,"Trying anyway\n"); + if (!XkbQueryExtension(dpy, &i1, &i2, &i3, &i4, &i5) > 0) { + if ((i4 != 0) || (i5 != 0)) + fprintf(stderr, + "server supports incompatible XKB version %d.%02d\n", i4, + i5); + else + fprintf(stderr, "XkbQueryExtension failed\n"); + fprintf(stderr, "Trying anyway\n"); } - if (force && (nameAtom!=None)) - fprintf(stderr,"Warning! Name ignored for forced bell requests\n"); - if (bellName!=NULL) - nameAtom = XInternAtom(dpy,bellName,0); - if ((devSpec==XkbUseCoreKbd)&&(class<0)) { - Bool ok; - if (force) ok= XkbForceBell(dpy,volume); - else if (nobeep) ok= XkbBellEvent(dpy,win,volume,nameAtom); - else ok= XkbBell(dpy,win,volume,nameAtom); - if (!ok) - fprintf(stderr,"XkbBell request failed\n"); + if (force && (nameAtom != None)) + fprintf(stderr, "Warning! Name ignored for forced bell requests\n"); + if (bellName != NULL) + nameAtom = XInternAtom(dpy, bellName, 0); + if ((devSpec == XkbUseCoreKbd) && (class < 0)) { + Bool ok; + + if (force) + ok = XkbForceBell(dpy, volume); + else if (nobeep) + ok = XkbBellEvent(dpy, win, volume, nameAtom); + else + ok = XkbBell(dpy, win, volume, nameAtom); + if (!ok) + fprintf(stderr, "XkbBell request failed\n"); } else { - Bool ok; - if (class<0) class= KbdFeedbackClass; - if (id<0) id= 0; - if (force) - ok= XkbForceDeviceBell(dpy,devSpec,class,id,volume); - else if (nobeep) - ok= XkbDeviceBellEvent(dpy,win,devSpec,class,id,volume,nameAtom); - else ok= XkbDeviceBell(dpy,win,devSpec,class,id,volume,nameAtom); - if (!ok) - fprintf(stderr,"XkbDeviceBell request failed\n"); + Bool ok; + + if (class < 0) + class = KbdFeedbackClass; + if (id < 0) + id = 0; + if (force) + ok = XkbForceDeviceBell(dpy, devSpec, class, id, volume); + else if (nobeep) + ok = XkbDeviceBellEvent(dpy, win, devSpec, class, id, volume, + nameAtom); + else + ok = XkbDeviceBell(dpy, win, devSpec, class, id, volume, nameAtom); + if (!ok) + fprintf(stderr, "XkbDeviceBell request failed\n"); } /* BAIL: */ XCloseDisplay(dpy); diff --git a/xkbvleds.c b/xkbvleds.c index 2bb1650..69bcac7 100644 --- a/xkbvleds.c +++ b/xkbvleds.c @@ -49,24 +49,24 @@ #define NO 0 #define DONT_CARE -1 -static Display * inDpy,*outDpy; -static unsigned long wanted,real,named,explicit,automatic,virtual; -static char * inDpyName; -static int wantNamed= DONT_CARE; -static int wantExplicit= DONT_CARE; -static int wantAutomatic= DONT_CARE; -static int wantReal= DONT_CARE; -static int wantVirtual= DONT_CARE; -static int evBase,errBase; -static Bool synch; -static Bool useUnion= True; +static Display *inDpy, *outDpy; +static unsigned long wanted, real, named, explicit, automatic, virtual; +static char *inDpyName; +static int wantNamed = DONT_CARE; +static int wantExplicit = DONT_CARE; +static int wantAutomatic = DONT_CARE; +static int wantReal = DONT_CARE; +static int wantVirtual = DONT_CARE; +static int evBase, errBase; +static Bool synch; +static Bool useUnion = True; /***====================================================================***/ static void usage(char *program) { - uInformation("Usage: %s \n",program); + uInformation("Usage: %s \n", program); uInformation("Legal options include the usual X toolkit options plus:\n"); uInformation(" -help Print this message\n"); uInformation(" -indpy Name of display to watch\n"); @@ -85,66 +85,70 @@ usage(char *program) static Bool parseArgs(int argc, char *argv[]) { -register int i; + register int i; - for (i=1;i1)&&(!parseArgs(argc,argv))) { - usage(argv[0]); - return 1; + if ((argc > 1) && (!parseArgs(argc, argv))) { + usage(argv[0]); + return 1; } - if ((wanted==0)&&(wantNamed==DONT_CARE)&&(wantExplicit==DONT_CARE)&& - (wantAutomatic==DONT_CARE)&&(wantReal==DONT_CARE)) { - wantNamed= YES; - wantReal= YES; - wantAutomatic= YES; + if ((wanted == 0) && (wantNamed == DONT_CARE) && (wantExplicit == DONT_CARE) + && (wantAutomatic == DONT_CARE) && (wantReal == DONT_CARE)) { + wantNamed = YES; + wantReal = YES; + wantAutomatic = YES; } - outDpy= XtDisplay(toplevel); - if (inDpyName!=NULL) { - inDpy= GetDisplay(argv[0],inDpyName); - if (!inDpy) - return 1; + outDpy = XtDisplay(toplevel); + if (inDpyName != NULL) { + inDpy = GetDisplay(argv[0], inDpyName); + if (!inDpy) + return 1; } else { - inDpy= outDpy; + inDpy = outDpy; } if (inDpy) { - int i1,mn,mj; - mj= XkbMajorVersion; - mn= XkbMinorVersion; - if (!XkbLibraryVersion(&mj,&mn)) { - uInformation("%s was compiled with XKB version %d.%02d\n", - argv[0],XkbMajorVersion,XkbMinorVersion); - uError("X library supports incompatible version %d.%02d\n", - mj,mn); - } - if (!XkbQueryExtension(inDpy,&i1,&evBase,&errBase,&mj,&mn)) { - uFatalError("Server doesn't support a compatible XKB\n"); - return 1; - } + int i1, mn, mj; + + mj = XkbMajorVersion; + mn = XkbMinorVersion; + if (!XkbLibraryVersion(&mj, &mn)) { + uInformation("%s was compiled with XKB version %d.%02d\n", + argv[0], XkbMajorVersion, XkbMinorVersion); + uError("X library supports incompatible version %d.%02d\n", mj, mn); + } + if (!XkbQueryExtension(inDpy, &i1, &evBase, &errBase, &mj, &mn)) { + uFatalError("Server doesn't support a compatible XKB\n"); + return 1; + } } else { - uFatalError("No input display\n"); - return 1; + uFatalError("No input display\n"); + return 1; } - panel= XtCreateManagedWidget("xkbleds",boxWidgetClass,toplevel,boxArgs,1); - if (panel==NULL) { - uFatalError("Couldn't create list of leds\n"); - return 1; + panel = + XtCreateManagedWidget("xkbleds", boxWidgetClass, toplevel, boxArgs, 1); + if (panel == NULL) { + uFatalError("Couldn't create list of leds\n"); + return 1; } - real= virtual= named= explicit= automatic= 0; + real = virtual = named = explicit = automatic = 0; if (wantReal || wantNamed || wantAutomatic || wantExplicit || wantVirtual) { - register int i,bit; - xkb= XkbGetMap(inDpy,0,XkbUseCoreKbd); - if (!xkb) { - uFatalError("Couldn't read keymap\n"); - return 1; - } - if (XkbGetIndicatorMap(inDpy,XkbAllIndicatorsMask,xkb)!=Success) { - uFatalError("Couldn't read indicator map\n"); - return 1; - } - if (XkbGetNames(inDpy,XkbAllNamesMask,xkb)!=Success) { - uFatalError("Couldn't read indicator names\n"); - return 1; - } - for (i=0,bit=1;iindicators->maps[i]; - if (xkb->names->indicators[i]!=None) - named|= bit; - if (xkb->indicators->phys_indicators&bit) - real|= bit; - if ((((map->which_groups!=0)&&(map->groups!=0))|| - ((map->which_mods!=0)&& - ((map->mods.real_mods!=0)||(map->mods.vmods!=0)))|| - (map->ctrls!=0))&& - ((map->flags&XkbIM_NoAutomatic)==0)) { - automatic|= bit; - } - else explicit|= bit; - } - virtual= ~real; - if (wantReal==NO) real= ~real; - else if (wantReal==DONT_CARE) real= (useUnion?0:~0); - if (wantVirtual==NO) virtual= ~virtual; - else if (wantVirtual==DONT_CARE) virtual= (useUnion?0:~0); - if (wantNamed==NO) named= ~named; - else if (wantNamed==DONT_CARE) named= (useUnion?0:~0); - if (wantAutomatic==NO) automatic= ~automatic; - else if (wantAutomatic==DONT_CARE) automatic= (useUnion?0:~0); - if (wantExplicit==NO) explicit= ~explicit; - else if (wantExplicit==DONT_CARE) explicit= (useUnion?0:~0); - if (useUnion) - wanted|= real|virtual|named|automatic|explicit; - else wanted&= real&virtual&named&automatic&explicit; + register int i, bit; + + xkb = XkbGetMap(inDpy, 0, XkbUseCoreKbd); + if (!xkb) { + uFatalError("Couldn't read keymap\n"); + return 1; + } + if (XkbGetIndicatorMap(inDpy, XkbAllIndicatorsMask, xkb) != Success) { + uFatalError("Couldn't read indicator map\n"); + return 1; + } + if (XkbGetNames(inDpy, XkbAllNamesMask, xkb) != Success) { + uFatalError("Couldn't read indicator names\n"); + return 1; + } + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + XkbIndicatorMapPtr map = &xkb->indicators->maps[i]; + + if (xkb->names->indicators[i] != None) + named |= bit; + if (xkb->indicators->phys_indicators & bit) + real |= bit; + if ((((map->which_groups != 0) && (map->groups != 0)) || + ((map->which_mods != 0) && + ((map->mods.real_mods != 0) || (map->mods.vmods != 0))) || + (map->ctrls != 0)) && + ((map->flags & XkbIM_NoAutomatic) == 0)) { + automatic |= bit; + } + else + explicit |= bit; + } + virtual = ~real; + if (wantReal == NO) + real = ~real; + else if (wantReal == DONT_CARE) + real = (useUnion ? 0 : ~0); + if (wantVirtual == NO) + virtual = ~virtual; + else if (wantVirtual == DONT_CARE) + virtual = (useUnion ? 0 : ~0); + if (wantNamed == NO) + named = ~named; + else if (wantNamed == DONT_CARE) + named = (useUnion ? 0 : ~0); + if (wantAutomatic == NO) + automatic = ~automatic; + else if (wantAutomatic == DONT_CARE) + automatic = (useUnion ? 0 : ~0); + if (wantExplicit == NO) + explicit = ~explicit; + else if (wantExplicit == DONT_CARE) + explicit = (useUnion ? 0 : ~0); + if (useUnion) + wanted |= real | virtual | named | automatic | explicit; + else + wanted &= real & virtual & named & automatic & explicit; } - else xkb= NULL; - if (wanted==0) { - uError("No indicator maps match the selected criteria\n"); - uAction("Exiting\n"); - return 1; + else + xkb = NULL; + if (wanted == 0) { + uError("No indicator maps match the selected criteria\n"); + uAction("Exiting\n"); + return 1; } - XkbSelectEvents(inDpy,XkbUseCoreKbd,XkbIndicatorStateNotifyMask, - XkbIndicatorStateNotifyMask); - XkbGetIndicatorState(inDpy,XkbUseCoreKbd,&n); - bit= (1<<(XkbNumIndicators-1)); - for (i=XkbNumIndicators-1;i>=0;i--,bit>>=1) { - if (wanted&bit) { - char buf[12]; - ArgList list; + XkbSelectEvents(inDpy, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, + XkbIndicatorStateNotifyMask); + XkbGetIndicatorState(inDpy, XkbUseCoreKbd, &n); + bit = (1 << (XkbNumIndicators - 1)); + for (i = XkbNumIndicators - 1; i >= 0; i--, bit >>= 1) { + if (wanted & bit) { + char buf[12]; + ArgList list; - sprintf(buf,"led%d",i+1); - if (n&bit) list= onArgs; - else list= offArgs; - leds[i]= XtCreateManagedWidget(buf,ledWidgetClass,panel,list,1); - } + sprintf(buf, "led%d", i + 1); + if (n & bit) + list = onArgs; + else + list = offArgs; + leds[i] = + XtCreateManagedWidget(buf, ledWidgetClass, panel, list, 1); + } } XtRealizeWidget(toplevel); while (1) { - XtAppNextEvent(app_con,&ev.core); - if (ev.core.type==evBase+XkbEventCode) { - if (ev.any.xkb_type==XkbIndicatorStateNotify) { - for (i=0,bit=1;i=0;i--,bit>>=1) { - ArgList list; - char buf[30]; - sprintf(buf,"base%d",i); - if (state.base_mods&bit) list= onArgs; - else list= offArgs; - base[i]= XtCreateManagedWidget(buf,ledWidgetClass,baseBox,list,1); - sprintf(buf,"latched%d",i); - if (state.latched_mods&bit) list= onArgs; - else list= offArgs; - latched[i]= XtCreateManagedWidget(buf,ledWidgetClass,latchBox,list,1); - sprintf(buf,"locked%d",i); - if (state.locked_mods&bit) list= onArgs; - else list= offArgs; - locked[i]= XtCreateManagedWidget(buf,ledWidgetClass,lockBox,list,1); - sprintf(buf,"effective%d",i); - if (state.mods&bit) list= onArgs; - else list= offArgs; - effective[i]= XtCreateManagedWidget(buf,ledWidgetClass,effBox,list,1); - sprintf(buf,"compat%d",i); - if (state.compat_state&bit) list= onArgs; - else list= offArgs; - compat[i]= XtCreateManagedWidget(buf,ledWidgetClass,compatBox,list,1); + baseBox = XtCreateManagedWidget("base", boxWidgetClass, panel, hArgs, 1); + if (baseBox == NULL) + uFatalError("Couldn't create base modifiers box\n"); + latchBox = + XtCreateManagedWidget("latched", boxWidgetClass, panel, hArgs, 1); + if (latchBox == NULL) + uFatalError("Couldn't create latched modifiers box\n"); + lockBox = XtCreateManagedWidget("locked", boxWidgetClass, panel, hArgs, 1); + if (lockBox == NULL) + uFatalError("Couldn't create locked modifiers box\n"); + effBox = + XtCreateManagedWidget("effective", boxWidgetClass, panel, hArgs, 1); + if (effBox == NULL) + uFatalError("Couldn't create effective modifiers box\n"); + compatBox = + XtCreateManagedWidget("compat", boxWidgetClass, panel, hArgs, 1); + if (compatBox == NULL) + uFatalError("Couldn't create compatibility state box\n"); + XkbSelectEvents(inDpy, XkbUseCoreKbd, XkbStateNotifyMask, + XkbStateNotifyMask); + XkbGetState(inDpy, XkbUseCoreKbd, &state); + for (i = XkbNumModifiers - 1, bit = 0x80; i >= 0; i--, bit >>= 1) { + ArgList list; + + char buf[30]; + + sprintf(buf, "base%d", i); + if (state.base_mods & bit) + list = onArgs; + else + list = offArgs; + base[i] = XtCreateManagedWidget(buf, ledWidgetClass, baseBox, list, 1); + sprintf(buf, "latched%d", i); + if (state.latched_mods & bit) + list = onArgs; + else + list = offArgs; + latched[i] = + XtCreateManagedWidget(buf, ledWidgetClass, latchBox, list, 1); + sprintf(buf, "locked%d", i); + if (state.locked_mods & bit) + list = onArgs; + else + list = offArgs; + locked[i] = + XtCreateManagedWidget(buf, ledWidgetClass, lockBox, list, 1); + sprintf(buf, "effective%d", i); + if (state.mods & bit) + list = onArgs; + else + list = offArgs; + effective[i] = + XtCreateManagedWidget(buf, ledWidgetClass, effBox, list, 1); + sprintf(buf, "compat%d", i); + if (state.compat_state & bit) + list = onArgs; + else + list = offArgs; + compat[i] = + XtCreateManagedWidget(buf, ledWidgetClass, compatBox, list, 1); } XtRealizeWidget(toplevel); while (1) { - XtAppNextEvent(app_con,&ev.core); - if (ev.core.type==evBase+XkbEventCode) { - if (ev.any.xkb_type==XkbStateNotify) { - unsigned changed; - if (ev.state.changed&XkbModifierBaseMask) { - changed= ev.state.base_mods^state.base_mods; - state.base_mods= ev.state.base_mods; - for (i=0,bit=1;i