changeset 43:4eb762fc1b4b

Menu: clang-style, c style
author ng0@n0.is
date Fri, 03 May 2019 19:43:42 +0000
parents 85214e687901
children 30c664d5bd22
files Menu.c
diffstat 1 files changed, 780 insertions(+), 564 deletions(-) [+]
line wrap: on
line diff
--- a/Menu.c	Fri May 03 19:34:16 2019 +0000
+++ b/Menu.c	Fri May 03 19:43:42 2019 +0000
@@ -1,6 +1,7 @@
 #ifndef lint
-static char *rcsid_Menu_c = "$XConsortium: Menu.c,v 1.25 88/09/30 11:41:11 jim Exp $";
-#endif	/* lint */
+static char *rcsid_Menu_c =
+  "$XConsortium: Menu.c,v 1.25 88/09/30 11:41:11 jim Exp $";
+#endif /* lint */
 
 /*
  * Copyright 1985, 1986, 1987, 1988, 1989 by the
@@ -42,7 +43,6 @@
  */
 
 
-
 /*
  * MODIFICATION HISTORY
  *
@@ -67,574 +67,740 @@
 #include <sys/wait.h>
 #include <stdbool.h>
 
-bool alternateGC = True;	/* true if only 2 colors are used */
+bool alternateGC = True; /* true if only 2 colors are used */
 
-#define DisplayLine(w, pane, width, height, str, fg, bg, inv) \
-         if (alternateGC) { \
-	     if (inv) \
-	         XFillRectangle(dpy, w, MenuInvGC, 0, pane, width, height); \
-	     else \
-                 XDrawString(dpy, w, MenuGC, HMenuPad, pane + VMenuPad + MFontInfo->ascent, str, strlen(str)); \
-         } else { \
-             XSetForeground(dpy, MenuGC, bg); \
-	     XFillRectangle(dpy, w, MenuGC, 0, pane, width, height); \
-             XSetForeground(dpy, MenuGC, fg); \
-             XDrawString(dpy, w, MenuGC, HMenuPad, pane + VMenuPad + MFontInfo->ascent, str, strlen(str)); \
-         }
+#define DisplayLine(w, pane, width, height, str, fg, bg, inv)             \
+        if (alternateGC)                                                  \
+        {                                                                 \
+                if (inv)                                                  \
+                        XFillRectangle (dpy,                              \
+                                        w,                                \
+                                        MenuInvGC,                        \
+                                        0,                                \
+                                        pane,                             \
+                                        width,                            \
+                                        height);                          \
+                else                                                      \
+                        XDrawString (dpy,                                 \
+                                     w,                                   \
+                                     MenuGC,                              \
+                                     HMenuPad,                            \
+                                     pane + VMenuPad + MFontInfo->ascent, \
+                                     str,                                 \
+                                     strlen (str));                       \
+        }                                                                 \
+        else                                                              \
+        {                                                                 \
+                XSetForeground (dpy, MenuGC, bg);                         \
+                XFillRectangle (dpy, w, MenuGC, 0, pane, width, height);  \
+                XSetForeground (dpy, MenuGC, fg);                         \
+                XDrawString (dpy,                                         \
+                             w,                                           \
+                             MenuGC,                                      \
+                             HMenuPad,                                    \
+                             pane + VMenuPad + MFontInfo->ascent,         \
+                             str,                                         \
+                             strlen (str));                               \
+        }
 
 /*
  * HP-UX does have vfork, but A/UX doesn't
  */
-#if (defined(SYSV) || defined(macII)) && !defined(hpux)
-#define vfork() fork()
+#if (defined(SYSV) || defined(macII)) && ! defined(hpux)
+#define vfork() fork ()
 #endif
 
 #ifdef X_NOT_STDC_ENV
-char *malloc();
+char *
+malloc ();
 #endif
 
-static void AdjustMaxColors(int pixel);
+static void
+AdjustMaxColors (int pixel);
 
-/* the following procedure is a copy of the implementation of system, 
+/*
+ * the following procedure is a copy of the implementation of system,
  * modified to reset the handling of SIGINT, SIGQUIT, and SIGHUP before
  * exec-ing
  */
-execute(s)
-char *s;
+execute (char *s)
 {
-	int status, pid, w;
-	register int (*istat)(), (*qstat)();
-	char **oldenviron;
-	extern char **environ, **newenviron;
+        int status, pid, w;
+        register int (*istat) (), (*qstat) ();
+        char **oldenviron;
+        extern char **environ, **newenviron;
 
 #ifdef SIGCHLD
-	/*
-	 * Children are now handled in uwm.c, but make sure
-	 * uwm blocks :-) for compatibility with other systems.
-	 */
+        /*
+         * Children are now handled in uwm.c, but make sure
+         * uwm blocks :-) for compatibility with other systems.
+         */
 
-	signal(SIGCHLD, SIG_DFL);
+        signal (SIGCHLD, SIG_DFL);
 #endif
-	
-	oldenviron = environ;
-	environ = newenviron;
-	if ((pid = vfork()) == 0) {
-		signal(SIGINT, SIG_DFL);
-		signal(SIGQUIT, SIG_DFL);
-		signal(SIGHUP, SIG_DFL);
-		execl("/bin/sh", "sh", "-c", s, 0);
-		_exit(127);
-	}
-	environ = oldenviron;
+
+        oldenviron = environ;
+        environ = newenviron;
+        if ((pid = vfork ()) == 0)
+        {
+                signal (SIGINT, SIG_DFL);
+                signal (SIGQUIT, SIG_DFL);
+                signal (SIGHUP, SIG_DFL);
+                execl ("/bin/sh", "sh", "-c", s, 0);
+                _exit (127);
+        }
+        environ = oldenviron;
 
-	/* 
-	 * The following cast is necessary because newer compilers declare
-	 * signal() to be (void (*)()) whereas old ones use (int (*)()).
-	 */
-	istat = (int (*)()) signal(SIGINT, SIG_IGN);
-	qstat = (int (*)()) signal(SIGQUIT, SIG_IGN);
-	while ((w = wait(&status)) != pid && w != -1)
-		;
-	if (w == -1)
-		status = -1;
-	signal(SIGINT, istat);
-	signal(SIGQUIT, qstat);
-	return(status);
+        /*
+         * The following cast is necessary because newer compilers declare
+         * signal() to be (void (*)()) whereas old ones use (int (*)()).
+         */
+        istat = (int (*) ()) signal (SIGINT, SIG_IGN);
+        qstat = (int (*) ()) signal (SIGQUIT, SIG_IGN);
+        while ((w = wait (&status)) != pid && w != -1)
+                ;
+        if (w == -1)
+                status = -1;
+        signal (SIGINT, istat);
+        signal (SIGQUIT, qstat);
+        return (status);
 }
 
-bool Menu(window, mask, button, x, y, menu)
-Window window;				/* Event window. */
-int mask;				/* Button/key mask. */
-int button;				/* Button event detail. */
-int x, y;				/* Event mouse position. */
-MenuInfo *menu;
+/*
+ * Window window: Event window.
+ * int mask: Button/key mask.
+ * int button: Button event detail.
+ * int x, y: Event mouse position.
+ * MenuInfo *menu
+ */
+bool
+Menu (Window window, int mask, int button, int x, int y, MenuInfo *menu)
 {
-    XEvent button_event;		/* Button event packet. */
-    int event_x, event_y;		/* location of button event */
-    bool func_stat;			/* Function status return. */
-    Window sub_window;			/* Current subwindow. */
-    int cur_item = 0;			/* Current menu item. */
-    int hi_lite = 0;			/* Current highlighted item. */
-    int i;				/* Iteration counter. */
-    int hlfg, hlbg;			/* Hi-liter pixels. */
-    MenuLine *ml;			/* Menu lines pointer. */
-    char *hlname;			/* Pointer to hi-liter name. */
-    char *strbuf;			/* String buffer for IsTextNL. */
-    bool checkMotion = TRUE;		/* To Restore Cursor Position */
-    int funcbutton;			/* function button for window select */
+        XEvent button_event; /* Button event packet. */
+        int event_x, event_y; /* location of button event */
+        bool func_stat; /* Function status return. */
+        Window sub_window; /* Current subwindow. */
+        int cur_item = 0; /* Current menu item. */
+        int hi_lite = 0; /* Current highlighted item. */
+        int i; /* Iteration counter. */
+        int hlfg, hlbg; /* Hi-liter pixels. */
+        MenuLine *ml; /* Menu lines pointer. */
+        char *hlname; /* Pointer to hi-liter name. */
+        char *strbuf; /* String buffer for IsTextNL. */
+        bool checkMotion = TRUE; /* To Restore Cursor Position */
+        int funcbutton; /* function button for window select */
 
-    /*
-     * Change the cursor.
-     */
-    XChangeActivePointerGrab(dpy, EVENTMASK, MenuCursor, CurrentTime);
+        /*
+         * Change the cursor.
+         */
+        XChangeActivePointerGrab (dpy, EVENTMASK, MenuCursor, CurrentTime);
 
-    /*
-     * Map the menu.
-     */
-    MapMenu(menu, x, y);
-    if (Autoselect) {
-        event_x = (menu->width >> 2) * 3;
-        event_y = (menu->iheight >> 1) * 3;
-        XWarpPointer(dpy, None, menu->w, 0, 0, 0, 0, event_x, event_y);
-	goto hilite;
-    }
-    else {
-        XWarpPointer(dpy, None, menu->w, 0, 0, 0, 0, 
-    		(menu->width >> 2) * 3, menu->iheight >> 1);
-        XFlush(dpy);
-    }
-
-    /*
-     * Main loop.
-     */
-    while (TRUE) {
+        /*
+         * Map the menu.
+         */
+        MapMenu (menu, x, y);
+        if (Autoselect)
+        {
+                event_x = (menu->width >> 2) * 3;
+                event_y = (menu->iheight >> 1) * 3;
+                XWarpPointer (dpy, None, menu->w, 0, 0, 0, 0, event_x, event_y);
+                goto hilite;
+        }
+        else
+        {
+                XWarpPointer (dpy,
+                              None,
+                              menu->w,
+                              0,
+                              0,
+                              0,
+                              0,
+                              (menu->width >> 2) * 3,
+                              menu->iheight >> 1);
+                XFlush (dpy);
+        }
 
         /*
-         *  Get next event for menu.
+         * Main loop.
          */
-        if (!GetButton(&button_event)) continue;
-	switch (button_event.type) {
+        while (TRUE)
+        {
+
+                /*
+                 *  Get next event for menu.
+                 */
+                if (! GetButton (&button_event))
+                        continue;
+                switch (button_event.type)
+                {
 
-            case LeaveNotify:
-	        /*
-	         * If the mouse has moved out of the menu sideways, abort
-	         * the menu operation. Reset the cursor and unmap the menu.
-		 * An extraneous LeaveNotify can come through if you are
-		 * popping up menu from a menu. If you moved the cursor toward
-		 * the edge of the original menu without going outside and
-		 * the new menu is smaller in width than the old menu, the
-		 * new menu will pop up and then disappear.
-	         */
-		if (((XAnyEvent *)&button_event)->window == menu->w) {
-			event_x = ((XLeaveWindowEvent * )&button_event)->x;
-	       		event_y = ((XLeaveWindowEvent * )&button_event)->y;
-			if (event_x < 0 || event_x > menu->width) {
-            		   ResetCursor(button);
-			   UnmapMenu(menu);
-          	  	   return(FALSE);
-        		}
-		}
-		goto hilite;
+                case LeaveNotify:
+                        /*
+                         * If the mouse has moved out of the menu sideways,
+                         * abort the menu operation. Reset the cursor and unmap
+                         * the menu. An extraneous LeaveNotify can come through
+                         * if you are popping up menu from a menu. If you moved
+                         * the cursor toward the edge of the original menu
+                         * without going outside and the new menu is smaller in
+                         * width than the old menu, the new menu will pop up and
+                         * then disappear.
+                         */
+                        if (((XAnyEvent *) &button_event)->window == menu->w)
+                        {
+                                event_x =
+                                  ((XLeaveWindowEvent *) &button_event)->x;
+                                event_y =
+                                  ((XLeaveWindowEvent *) &button_event)->y;
+                                if (event_x < 0 || event_x > menu->width)
+                                {
+                                        ResetCursor (button);
+                                        UnmapMenu (menu);
+                                        return (FALSE);
+                                }
+                        }
+                        goto hilite;
+
+                case EnterNotify:
+                        event_x = ((XEnterWindowEvent *) &button_event)->x;
+                        event_y = ((XEnterWindowEvent *) &button_event)->y;
+                        goto hilite;
+                case MotionNotify: {
+                        event_x = ((XPointerMovedEvent *) &button_event)->x;
+                        event_y = ((XPointerMovedEvent *) &button_event)->y;
+                        if ((checkMotion == TRUE) &&
+                            ((event_x != (menu->width >> 2) * 3) ||
+                             (event_y != (menu->iheight >> 1))))
+                                checkMotion =
+                                  FALSE; /* Mouse Has Moved From Top Pane */
+                hilite:
+                        /*
+                         * If the mouse has moved below or above the menu, but
+                         * is still within the same vertical plane, then simply
+                         * adjust the values so the user doesn't fall off the
+                         * edge.
+                         */
+                        if (event_y >= menu->height)
+                                event_y = menu->height - 1;
+                        else if (event_y < 0)
+                                event_y = 0;
+
+                        /*
+                         * If the mouse has moved to another item in the menu,
+                         * highlight the new item.
+                         */
+                        cur_item = event_y / menu->iheight;
+                        if (cur_item != hi_lite)
+                        {
 
-            case EnterNotify:
-	        event_x = ((XEnterWindowEvent * )&button_event)->x;
-	        event_y = ((XEnterWindowEvent * )&button_event)->y;
-		goto hilite;
-            case MotionNotify:
-		{
-	        event_x = ((XPointerMovedEvent * )&button_event)->x;
-	        event_y = ((XPointerMovedEvent * )&button_event)->y;
-		if ((checkMotion == TRUE) &&
-		    ((event_x != (menu->width >> 2) * 3) ||
-		     (event_y != (menu->iheight >> 1))))
-		   checkMotion = FALSE;	 /* Mouse Has Moved From Top Pane */
-hilite:
-        	/*
-         	* If the mouse has moved below or above the menu, but is still
-         	* within the same vertical plane, then simply adjust the values
-         	* so the user doesn't fall off the edge.
-         	*/
-        	if (event_y >= menu->height) 
-		  event_y = menu->height - 1;
-        	else if (event_y < 0) 
-		  event_y = 0;
-		  
-        	/*
-         	* If the mouse has moved to another item in the menu,
-         	* highlight the new item.
-         	*/
-        	cur_item = event_y / menu->iheight;
-        	if (cur_item != hi_lite) {
-
-            	/*
-             	* Remove highlighting on old item.
-             	*/
-            	if (hi_lite) {
-                	DisplayLine(menu->w, hi_lite * menu->iheight,
-                            menu->width, menu->iheight, hlname,
-                            hlfg, hlbg, 1);
-			XFlush(dpy);
-            	}
+                                /*
+                                 * Remove highlighting on old item.
+                                 */
+                                if (hi_lite)
+                                {
+                                        DisplayLine (menu->w,
+                                                     hi_lite * menu->iheight,
+                                                     menu->width,
+                                                     menu->iheight,
+                                                     hlname,
+                                                     hlfg,
+                                                     hlbg,
+                                                     1);
+                                        XFlush (dpy);
+                                }
 
-           	/*
-             	* Highlight new item.
-             	*/
-            	hi_lite = cur_item;
-            	if (cur_item) {
-                	for(i = 1, ml = menu->line; ml; i++, ml = ml->next) {
-                    		if (i == cur_item) break;
-               	 	}
-                	DisplayLine(menu->w, cur_item * menu->iheight,
-                            menu->width, menu->iheight, ml->name,
-                            menu->hlfg.pixel, menu->hlbg.pixel, 1);
-/*                	XSetForeground(dpy, MenuGC, menu->hlfg.pixel );
-			XDrawRectangle(dpy, menu->w, MenuGC, 1, 
-				cur_item * menu->iheight + 1, 
-				menu->width - 3, menu->iheight - 3);
-*/
-			XFlush(dpy);
-             		hlfg = ml->fg.pixel;
-            		hlbg = ml->bg.pixel;
-            		hlname = ml->name;
-            	}
-		}
-        	break;
+                                /*
+                                 * Highlight new item.
+                                 */
+                                hi_lite = cur_item;
+                                if (cur_item)
+                                {
+                                        for (i = 1, ml = menu->line; ml;
+                                             i++, ml = ml->next)
+                                        {
+                                                if (i == cur_item)
+                                                        break;
+                                        }
+                                        DisplayLine (menu->w,
+                                                     cur_item * menu->iheight,
+                                                     menu->width,
+                                                     menu->iheight,
+                                                     ml->name,
+                                                     menu->hlfg.pixel,
+                                                     menu->hlbg.pixel,
+                                                     1);
+                                        /*                	XSetForeground(dpy,
+                                           MenuGC, menu->hlfg.pixel );
+                                              XDrawRectangle(dpy, menu->w,
+                                           MenuGC, 1, cur_item * menu->iheight +
+                                           1, menu->width - 3, menu->iheight -
+                                           3);
+                                        */
+                                        XFlush (dpy);
+                                        hlfg = ml->fg.pixel;
+                                        hlbg = ml->bg.pixel;
+                                        hlname = ml->name;
+                                }
+                        }
+                        break;
 
-            case ButtonRelease:
-	        /* have we released the invoking button? */
-	        if (((XButtonReleasedEvent *)&button_event)->button == button) {
-		    /*
-		     * If no item was selected, 
-		     * close the menu, reset the pointer's position and return
-		     */
-		    if (!cur_item) {
-			/* If Needed Reset The Cursor Position */
-			if (checkMotion == TRUE)
-			  XWarpPointer (dpy, None, RootWindow(dpy, scr),
-					0, 0, 0, 0, x, y);
-		         ResetCursor(button);
-			 UnmapMenu(menu);
-		         return(TRUE);
-		     }
+                case ButtonRelease:
+                        /* have we released the invoking button? */
+                        if (((XButtonReleasedEvent *) &button_event)->button ==
+                            button)
+                        {
+                                /*
+                                 * If no item was selected,
+                                 * close the menu, reset the pointer's position
+                                 * and return
+                                 */
+                                if (! cur_item)
+                                {
+                                        /* If Needed Reset The Cursor Position
+                                         */
+                                        if (checkMotion == TRUE)
+                                                XWarpPointer (dpy,
+                                                              None,
+                                                              RootWindow (dpy,
+                                                                          scr),
+                                                              0,
+                                                              0,
+                                                              0,
+                                                              0,
+                                                              x,
+                                                              y);
+                                        ResetCursor (button);
+                                        UnmapMenu (menu);
+                                        return (TRUE);
+                                }
 
-		     /*
-		      * Get a pointer to the menu line selected.
-		      */
-		     --cur_item;
-		     for(i = 0, ml = menu->line; ml; i++, ml = ml->next) {
-		         if (i == cur_item) break;
-		     }
+                                /*
+                                 * Get a pointer to the menu line selected.
+                                 */
+                                --cur_item;
+                                for (i = 0, ml = menu->line; ml;
+                                     i++, ml = ml->next)
+                                {
+                                        if (i == cur_item)
+                                                break;
+                                }
 
-		     /*
-		      * Perform the selected menu line action.
-		      */
-		     switch (ml->type) {
+                                /*
+                                 * Perform the selected menu line action.
+                                 */
+                                switch (ml->type)
+                                {
 
-		         case IsShellCommand:
-		             UnmapMenu(menu);
-		             execute(ml->text);
-		             break;
+                                case IsShellCommand:
+                                        UnmapMenu (menu);
+                                        execute (ml->text);
+                                        break;
+
+                                case IsText:
+                                        UnmapMenu (menu);
+                                        XStoreBytes (dpy,
+                                                     ml->text,
+                                                     strlen (ml->text));
+                                        break;
 
-		         case IsText:
-		             UnmapMenu(menu);
-		             XStoreBytes(dpy, ml->text, strlen(ml->text));
-		             break;
-
-		         case IsTextNL:
-		             UnmapMenu(menu);
-		             strbuf = (char *)malloc(strlen(ml->text) + 2);
-		             strcpy(strbuf, ml->text);
-		             strcat(strbuf, "\n");
-		             XStoreBytes(dpy, strbuf, strlen(strbuf));
-		             free(strbuf);
-		             break;
+                                case IsTextNL:
+                                        UnmapMenu (menu);
+                                        strbuf = (char *) malloc (
+                                          strlen (ml->text) + 2);
+                                        strcpy (strbuf, ml->text);
+                                        strcat (strbuf, "\n");
+                                        XStoreBytes (dpy,
+                                                     strbuf,
+                                                     strlen (strbuf));
+                                        free (strbuf);
+                                        break;
 
-		         case IsUwmFunction:
-			     /* change cursor and grab next button event
-			      * to select the target window */
-			     if (XGrabPointer( dpy, RootWindow(dpy, scr),
-					       TRUE, EVENTMASK, GrabModeAsync,
-					       GrabModeAsync, None,
-					       TargetCursor, CurrentTime )
-				   != GrabSuccess )
-			         Error( "Could not grab pointer" );
-		             funcbutton = GetContext (&sub_window,
-						      &event_x, &event_y);
-		             UnmapMenu(menu);
-		             if (sub_window != menu->w)
-			       func_stat =
-		                 (*ml->func) (sub_window, mask, funcbutton,
-					      event_x, event_y);
-			     else func_stat = FALSE;
-			     if (!func_stat) {
-			       /* eat the next ButtonRelease */
-			       while (TRUE) {
-				   if (GetButton(&button_event) &&
-				       button_event.type == ButtonRelease)
-				     break;
-			       }
-			     }
-			     XUngrabPointer( dpy, CurrentTime );
-		             break;
+                                case IsUwmFunction:
+                                        /* change cursor and grab next button
+                                         * event to select the target window */
+                                        if (XGrabPointer (dpy,
+                                                          RootWindow (dpy, scr),
+                                                          TRUE,
+                                                          EVENTMASK,
+                                                          GrabModeAsync,
+                                                          GrabModeAsync,
+                                                          None,
+                                                          TargetCursor,
+                                                          CurrentTime) !=
+                                            GrabSuccess)
+                                                Error (
+                                                  "Could not grab pointer");
+                                        funcbutton = GetContext (&sub_window,
+                                                                 &event_x,
+                                                                 &event_y);
+                                        UnmapMenu (menu);
+                                        if (sub_window != menu->w)
+                                                func_stat =
+                                                  (*ml->func) (sub_window,
+                                                               mask,
+                                                               funcbutton,
+                                                               event_x,
+                                                               event_y);
+                                        else
+                                                func_stat = FALSE;
+                                        if (! func_stat)
+                                        {
+                                                /* eat the next ButtonRelease */
+                                                while (TRUE)
+                                                {
+                                                        if (GetButton (
+                                                              &button_event) &&
+                                                            button_event.type ==
+                                                              ButtonRelease)
+                                                                break;
+                                                }
+                                        }
+                                        XUngrabPointer (dpy, CurrentTime);
+                                        break;
+
+                                case IsImmFunction:
+                                        UnmapMenu (menu);
+                                        (*ml->func) (sub_window,
+                                                     mask,
+                                                     button,
+                                                     event_x,
+                                                     event_y);
+                                        break;
 
-		         case IsImmFunction:
-		             UnmapMenu(menu);
- 		            (*ml->func) (
-			      sub_window, mask, button, event_x, 
-			      event_y);
-		             break;
-		 
-		         case IsMenuFunction:
-		             while (TRUE) {
-		                if (!GetButton(&button_event)) continue;
-		                if (button_event.type != ButtonPress) continue;
-		                if ((((XButtonPressedEvent *)&button_event)->state != mask) 
-				 || (((XButtonPressedEvent *)&button_event)->button != button)) 
-				 {
-		                     UnmapMenu(menu);
-		                     return(TRUE);
-		                 }
-		                 break;
-		             }
-		             UnmapMenu(menu);
-		             func_stat = 
-			     	Menu(menu->w, mask, button, x, y, ml->menu);
-		             return(func_stat);
-		             break;
+                                case IsMenuFunction:
+                                        while (TRUE)
+                                        {
+                                                if (! GetButton (&button_event))
+                                                        continue;
+                                                if (button_event.type !=
+                                                    ButtonPress)
+                                                        continue;
+                                                if ((((XButtonPressedEvent
+                                                         *) &button_event)
+                                                       ->state != mask) ||
+                                                    (((XButtonPressedEvent
+                                                         *) &button_event)
+                                                       ->button != button))
+                                                {
+                                                        UnmapMenu (menu);
+                                                        return (TRUE);
+                                                }
+                                                break;
+                                        }
+                                        UnmapMenu (menu);
+                                        func_stat = Menu (menu->w,
+                                                          mask,
+                                                          button,
+                                                          x,
+                                                          y,
+                                                          ml->menu);
+                                        return (func_stat);
+                                        break;
 
-		         default:
- 		            Error("Menu -> Internal type error.");
-		     }
-		     return(TRUE);
-		  
-                 } 
-		 /* else a different button was released. Fall through: */
-            default:
-                    /*
-                     * Some other button event occurred, so abort the menu
-                     * operation.
-                     */
-		    ResetCursor(button);
-		    /* If Needed Reset The Cursor Position */
-		    if (checkMotion == TRUE)
-		      XWarpPointer (dpy, None, RootWindow(dpy, scr),
-				    0, 0, 0, 0, x, y);
-                    UnmapMenu(menu);
-                    return(TRUE);
-		
-	}
-     }
-  }
+                                default:
+                                        Error ("Menu -> Internal type error.");
+                                }
+                                return (TRUE);
+                        }
+                        /* else a different button was released. Fall through:
+                         */
+                default:
+                        /*
+                         * Some other button event occurred, so abort the menu
+                         * operation.
+                         */
+                        ResetCursor (button);
+                        /* If Needed Reset The Cursor Position */
+                        if (checkMotion == TRUE)
+                                XWarpPointer (dpy,
+                                              None,
+                                              RootWindow (dpy, scr),
+                                              0,
+                                              0,
+                                              0,
+                                              0,
+                                              x,
+                                              y);
+                        UnmapMenu (menu);
+                        return (TRUE);
+                }
+                }
+        }
 }
 
 
 /*
  * Create the menu windows for later use.
  */
-CreateMenus()
+CreateMenus ()
 {
-    MenuLink *ptr;
+        MenuLink *ptr;
 
-    /*
-     * If MaxColors isn't set, then jam it to an impossibly high
-     * number.
-     */
-    if (MaxColors == 0)
-        MaxColors = 25000;
+        /*
+         * If MaxColors isn't set, then jam it to an impossibly high
+         * number.
+         */
+        if (MaxColors == 0)
+                MaxColors = 25000;
 
-    for(ptr = Menus; ptr; ptr = ptr->next)
-        InitMenu(ptr->menu);
+        for (ptr = Menus; ptr; ptr = ptr->next)
+                InitMenu (ptr->menu);
 }
 
 /*
  * Initialize a menu.
  */
-InitMenu(menu)
-MenuInfo *menu;
+InitMenu (MenuInfo *menu)
 {
-    MenuLine *ml;		/* Menu lines pointer. */
-    int width;			/* Width of an item name. */
-    int maxwidth;		/* Maximum width of item names. */
-    int len;			/* Length of an item name. */
-    int count = 1;		/* Number of items + 1 for name. */
-    XSetWindowAttributes attr;
+        MenuLine *ml; /* Menu lines pointer. */
+        int width; /* Width of an item name. */
+        int maxwidth; /* Maximum width of item names. */
+        int len; /* Length of an item name. */
+        int count = 1; /* Number of items + 1 for name. */
+        XSetWindowAttributes attr;
 
-    /*
-     * Determine the name of the longest menu item.
-     */
-    maxwidth = XTextWidth(MFontInfo, menu->name, strlen(menu->name));
-    if (maxwidth == 0)
-        Error("InitMenu -> Couldn't get length of menu name");
+        /*
+         * Determine the name of the longest menu item.
+         */
+        maxwidth = XTextWidth (MFontInfo, menu->name, strlen (menu->name));
+        if (maxwidth == 0)
+                Error ("InitMenu -> Couldn't get length of menu name");
 
-    for(ml = menu->line; ml; ml = ml->next) {
-        if ((len = strlen(ml->name)) == 0)
-            break;
-        width = XTextWidth(MFontInfo, ml->name, strlen(ml->name));
-        if (width == 0) 
-	  Error("InitMenu -> Couldn't get length of menu item name");
-        if (width > maxwidth) maxwidth = width;
-        count++;
-    }
+        for (ml = menu->line; ml; ml = ml->next)
+        {
+                if ((len = strlen (ml->name)) == 0)
+                        break;
+                width = XTextWidth (MFontInfo, ml->name, strlen (ml->name));
+                if (width == 0)
+                        Error (
+                          "InitMenu -> Couldn't get length of menu item name");
+                if (width > maxwidth)
+                        maxwidth = width;
+                count++;
+        }
 
-    /*
-     * Get the color cells for the menu items.
-     */
-    GetMenuColors(menu);
+        /*
+         * Get the color cells for the menu items.
+         */
+        GetMenuColors (menu);
 
-    /*
-     * Stash the menu parameters in the menu info structure.
-     */
-    menu->iheight = MFontInfo->ascent + MFontInfo->descent + (VMenuPad << 1);
-    menu->height = menu->iheight * count;
-    menu->width = maxwidth + (HMenuPad << 1);
-    menu->image = NULL;
+        /*
+         * Stash the menu parameters in the menu info structure.
+         */
+        menu->iheight =
+          MFontInfo->ascent + MFontInfo->descent + (VMenuPad << 1);
+        menu->height = menu->iheight * count;
+        menu->width = maxwidth + (HMenuPad << 1);
+        menu->image = NULL;
 
-    /*
-     * Create the menu window.
-     */
-    attr.border_pixel = MBorder;
-    /*
-     * SaveUnders Enabled If The Server Supports It
-     */
-    attr.save_under = DoesSaveUnders( DefaultScreenOfDisplay( dpy ) );
-    /*
-     * We want enter, leave, and mouse motion events for menus.
-     */
-    attr.event_mask = ( EnterWindowMask | LeaveWindowMask | PointerMotionMask );
-    /*
-     * Define a cursor for the window
-     */
-    attr.cursor = MenuCursor;
-    menu->w = XCreateWindow( dpy, RootWindow( dpy, scr ),
-			     0, 0,
-			     menu->width, menu->height,
-			     MBorderWidth,
-			     DefaultDepth( dpy, scr ),
-			     InputOutput,
-			     DefaultVisual( dpy, scr ),
-	CWBorderPixel | CWSaveUnder | CWEventMask | CWCursor,
-			     &attr );
+        /*
+         * Create the menu window.
+         */
+        attr.border_pixel = MBorder;
+        /*
+         * SaveUnders Enabled If The Server Supports It
+         */
+        attr.save_under = DoesSaveUnders (DefaultScreenOfDisplay (dpy));
+        /*
+         * We want enter, leave, and mouse motion events for menus.
+         */
+        attr.event_mask =
+          (EnterWindowMask | LeaveWindowMask | PointerMotionMask);
+        /*
+         * Define a cursor for the window
+         */
+        attr.cursor = MenuCursor;
+        menu->w =
+          XCreateWindow (dpy,
+                         RootWindow (dpy, scr),
+                         0,
+                         0,
+                         menu->width,
+                         menu->height,
+                         MBorderWidth,
+                         DefaultDepth (dpy, scr),
+                         InputOutput,
+                         DefaultVisual (dpy, scr),
+                         CWBorderPixel | CWSaveUnder | CWEventMask | CWCursor,
+                         &attr);
 
-    uwmExpressInterest (menu->w, attr.event_mask);
+        uwmExpressInterest (menu->w, attr.event_mask);
 
-    if (menu->w == NULL) Error("InitMenu -> Couldn't create menu window");
+        if (menu->w == NULL)
+                Error ("InitMenu -> Couldn't create menu window");
 
-    /*
-     * For monochrome servers, we *do* want to set a background pixel
-     */
-    if (alternateGC) {
-	XSetWindowBackground( dpy, menu->w, MBackground );
-    }
+        /*
+         * For monochrome servers, we *do* want to set a background pixel
+         */
+        if (alternateGC)
+        {
+                XSetWindowBackground (dpy, menu->w, MBackground);
+        }
 
-    /*
-     * Store the window name.
-     */
-    XStoreName(dpy, menu->w, menu->name);
-
+        /*
+         * Store the window name.
+         */
+        XStoreName (dpy, menu->w, menu->name);
 }
 
 /*
  * Map a menu.
  */
-MapMenu(menu, x, y)
-MenuInfo *menu;
-int x, y;
+MapMenu (MenuInfo *menu, int x, int y)
 {
-    int item;
-    Window w;
-    MenuLine *ml;
-    XWindowChanges values;
+        int item;
+        Window w;
+        MenuLine *ml;
+        XWindowChanges values;
 
-    w = menu->w;
+        w = menu->w;
 
-    /*
-     * Move the menu into place, normalizing the coordinates, if necessary;
-     * then map it.
-     */
-    x -= (menu->width >> 1);
-    if (x < 0) x = 0;
-    else if (x + menu->width >= ScreenWidth)
-        x = ScreenWidth - menu->width - (MBorderWidth << 1);
-    if (y < 0) y = 0;
-    else if (y + menu->height >= ScreenHeight)
-        y = ScreenHeight - menu->height - (MBorderWidth << 1);
-    values.x = x;
-    values.y = y;
-    values.stack_mode = Above;
-    XConfigureWindow(dpy, w, CWX|CWY|CWStackMode, &values);
+        /*
+         * Move the menu into place, normalizing the coordinates, if necessary;
+         * then map it.
+         */
+        x -= (menu->width >> 1);
+        if (x < 0)
+                x = 0;
+        else if (x + menu->width >= ScreenWidth)
+                x = ScreenWidth - menu->width - (MBorderWidth << 1);
+        if (y < 0)
+                y = 0;
+        else if (y + menu->height >= ScreenHeight)
+                y = ScreenHeight - menu->height - (MBorderWidth << 1);
+        values.x = x;
+        values.y = y;
+        values.stack_mode = Above;
+        XConfigureWindow (dpy, w, CWX | CWY | CWStackMode, &values);
+
+        /*
+         * Map the window and draw the text items.
+         */
+        XMapWindow (dpy, w);
+        DisplayLine (w,
+                     0,
+                     menu->width,
+                     menu->iheight,
+                     menu->name,
+                     menu->bg.pixel,
+                     menu->fg.pixel,
+                     0);
 
-    /*
-     * Map the window and draw the text items.
-     */
-    XMapWindow(dpy, w);
-    DisplayLine(w, 0, menu->width, menu->iheight, menu->name,
-                menu->bg.pixel, menu->fg.pixel, 0);
+        if (alternateGC)
+        {
+                XFillRectangle (dpy,
+                                menu->w,
+                                MenuInvGC,
+                                0,
+                                0,
+                                menu->width,
+                                menu->iheight);
+                XDrawRectangle (dpy,
+                                menu->w,
+                                MenuInvGC,
+                                1,
+                                1,
+                                menu->width - 3,
+                                menu->iheight - 3);
+        }
+        else
+        {
+                XSetForeground (dpy, MenuGC, menu->bg.pixel);
+                XDrawRectangle (dpy,
+                                menu->w,
+                                MenuGC,
+                                1,
+                                1,
+                                menu->width - 3,
+                                menu->iheight - 3);
+        }
 
-    if (alternateGC) {
-        XFillRectangle(dpy, menu->w, MenuInvGC, 0, 0,
-		       menu->width, menu->iheight);
-        XDrawRectangle(dpy, menu->w, MenuInvGC, 1, 1,
-		       menu->width - 3, menu->iheight - 3);
-    } else {
-        XSetForeground(dpy, MenuGC, menu->bg.pixel );
-        XDrawRectangle(dpy, menu->w, MenuGC, 1, 1, menu->width - 3, 
-		       menu->iheight - 3);
-    }
+        item = menu->iheight;
+        for (ml = menu->line; ml; ml = ml->next)
+        {
+                DisplayLine (w,
+                             item,
+                             menu->width,
+                             menu->iheight,
+                             ml->name,
+                             ml->fg.pixel,
+                             ml->bg.pixel,
+                             0);
+                item += menu->iheight;
+        }
 
-    item = menu->iheight;
-    for(ml = menu->line; ml; ml = ml->next) {
-        DisplayLine(w, item, menu->width, menu->iheight, ml->name,
-                    ml->fg.pixel, ml->bg.pixel, 0);
-        item += menu->iheight;
-    }
+        /*
+         * Position the mouse cursor in the menu header (or in the first item
+         * if "autoselect" is set).
+         */
 
-    /*
-     * Position the mouse cursor in the menu header (or in the first item
-     * if "autoselect" is set).
-     */
-
-    XFlush(dpy);
+        XFlush (dpy);
 }
 
 /*
  * Unmap a menu, restoring the contents of the screen underneath
  * if necessary. (Restore portion is a future.)
  */
-UnmapMenu(menu)
-MenuInfo *menu;
+UnmapMenu (MenuInfo *menu)
 {
-    /*
-     * Unmap and flush.
-     */
-    XUnmapWindow(dpy, menu->w);
-    XFlush(dpy);
+        /*
+         * Unmap and flush.
+         */
+        XUnmapWindow (dpy, menu->w);
+        XFlush (dpy);
 }
 
 /*
  * Get the context for invoking a window manager function; return the button
  * pressed.
  */
-int GetContext(w, x, y)
-Window *w;
-int *x, *y;
+int
+GetContext (Window *w, int *x, int *y)
 {
-    XEvent button_event;  /* Button input event. */
+        XEvent button_event; /* Button input event. */
 
-    while (TRUE) {
+        while (TRUE)
+        {
 
-        /*
-         * Get the next mouse button event.  Spin our wheels until
-         * a button event is returned (ie. GetButton == TRUE).
-         * Note that mouse events within an icon window are handled
-         * in the "GetButton" function or by the icon's owner if
-         * it is not uwm.
-         */
-        if (!GetButton(&button_event)) continue;
+                /*
+                 * Get the next mouse button event.  Spin our wheels until
+                 * a button event is returned (ie. GetButton == TRUE).
+                 * Note that mouse events within an icon window are handled
+                 * in the "GetButton" function or by the icon's owner if
+                 * it is not uwm.
+                 */
+                if (! GetButton (&button_event))
+                        continue;
 
-        /*
-         * If the button event received is not a ButtonPress event
-         * then continue until we find one.
-         */
-        if (button_event.type != ButtonPress) continue;
+                /*
+                 * If the button event received is not a ButtonPress event
+                 * then continue until we find one.
+                 */
+                if (button_event.type != ButtonPress)
+                        continue;
 
-        /*
-         * Okay, determine the event window and mouse coordinates.
-         */
-        status = XTranslateCoordinates(dpy, 
-				    RootWindow(dpy, scr), 
-				    RootWindow(dpy, scr),
-                                    ((XButtonPressedEvent *)&button_event)->x, 
-                                    ((XButtonPressedEvent *)&button_event)->y, 
-                                    x, y,
-                                    w);
+                /*
+                 * Okay, determine the event window and mouse coordinates.
+                 */
+                status =
+                  XTranslateCoordinates (dpy,
+                                         RootWindow (dpy, scr),
+                                         RootWindow (dpy, scr),
+                                         ((XButtonPressedEvent *) &button_event)
+                                           ->x,
+                                         ((XButtonPressedEvent *) &button_event)
+                                           ->y,
+                                         x,
+                                         y,
+                                         w);
 
-        if (status == FAILURE) continue;
+                if (status == FAILURE)
+                        continue;
 
-        if (*w == 0)
-            *w = RootWindow(dpy, scr);
+                if (*w == 0)
+                        *w = RootWindow (dpy, scr);
 
-        return (((XButtonPressedEvent *) &button_event)->button);
-    }
+                return (((XButtonPressedEvent *) &button_event)->button);
+        }
 }
 
 /*
@@ -643,109 +809,159 @@
  * more colors, even though the colors may have already been allocated.  It
  * probably ought to be done right someday.
  */
-GetMenuColors(menu)
-MenuInfo *menu;
+GetMenuColors (MenuInfo *menu)
 {
-    register MenuLine *ml;		/* Menu lines pointer. */
-
-    /*
-     * If we have more than 2 colors available, then attempt to get
-     * the color map entries requested by the user.
-     * Otherwise, default to standard black and white.
-     *
-     * The boolean "alternateGC" is true iff we can use just two colors.
-     */
-
-    if (DisplayCells(dpy, scr) > 2) {
-        /*
-         * Get the menu header colors first.
-         */
-        if (!(menu->foreground && menu->background && MaxColors > 1 &&
-              XParseColor(dpy, DefaultColormap(dpy, scr), menu->foreground, &menu->fg) &&
-              XAllocColor(dpy, DefaultColormap(dpy, scr), &menu->fg) &&
-              XParseColor(dpy, DefaultColormap(dpy, scr), menu->background, &menu->bg) &&
-              XAllocColor(dpy, DefaultColormap(dpy, scr), &menu->bg))) {
-            menu->fg.pixel = MTextForeground;
-            menu->bg.pixel = MTextBackground;
-        } else {
-            AdjustMaxColors(menu->fg.pixel);
-            AdjustMaxColors(menu->bg.pixel);
-	    alternateGC = False;	/* since we just allocated colors */
-        }
+        register MenuLine *ml; /* Menu lines pointer. */
 
         /*
-         * Get the menu highlight colors.
-         */
-        if (!(menu->fghighlight && menu->bghighlight && MaxColors > 1 &&
-              XParseColor(
-	        dpy, DefaultColormap(dpy, scr), menu->fghighlight, &menu->hlfg) &&
-              XAllocColor(dpy, DefaultColormap(dpy, scr), &menu->hlfg) &&
-              XParseColor(
-	        dpy, DefaultColormap(dpy, scr), menu->bghighlight, &menu->hlbg) &&
-              XAllocColor(dpy, DefaultColormap(dpy, scr), &menu->hlbg))) {
-            menu->hlfg.pixel = MTextBackground;
-            menu->hlbg.pixel = MTextForeground;
-        } else {
-            AdjustMaxColors(menu->hlfg.pixel);
-            AdjustMaxColors(menu->hlbg.pixel);
-	    alternateGC = False;
-        }
-
-        /*
-         * Get the menu item colors.
+         * If we have more than 2 colors available, then attempt to get
+         * the color map entries requested by the user.
+         * Otherwise, default to standard black and white.
+         *
+         * The boolean "alternateGC" is true iff we can use just two colors.
          */
-        for(ml = menu->line; ml; ml = ml->next) {
-            if (!(ml->foreground && ml->background && MaxColors > 1 &&
-                  XParseColor(dpy, DefaultColormap(dpy, scr), ml->foreground, &ml->fg) &&
-                  XAllocColor(dpy, DefaultColormap(dpy, scr), &ml->fg) &&
-                  XParseColor(dpy, DefaultColormap(dpy, scr), ml->background, &ml->bg) &&
-                  XAllocColor(dpy, DefaultColormap(dpy, scr), &ml->bg))) {
-                ml->fg.pixel = MTextForeground;
-                ml->bg.pixel = MTextBackground;
-            } else {
-                AdjustMaxColors(ml->fg.pixel);
-                AdjustMaxColors(ml->bg.pixel);
-            }
-        }
+
+        if (DisplayCells (dpy, scr) > 2)
+        {
+                /*
+                 * Get the menu header colors first.
+                 */
+                if (! (
+                      menu->foreground && menu->background && MaxColors > 1 &&
+                      XParseColor (dpy,
+                                   DefaultColormap (dpy, scr),
+                                   menu->foreground,
+                                   &menu->fg) &&
+                      XAllocColor (dpy,
+                                   DefaultColormap (dpy, scr),
+                                   &menu->fg) &&
+                      XParseColor (dpy,
+                                   DefaultColormap (dpy, scr),
+                                   menu->background,
+                                   &menu->bg) &&
+                      XAllocColor (dpy, DefaultColormap (dpy, scr), &menu->bg)))
+                {
+                        menu->fg.pixel = MTextForeground;
+                        menu->bg.pixel = MTextBackground;
+                }
+                else
+                {
+                        AdjustMaxColors (menu->fg.pixel);
+                        AdjustMaxColors (menu->bg.pixel);
+                        alternateGC =
+                          False; /* since we just allocated colors */
+                }
 
-    } else {
+                /*
+                 * Get the menu highlight colors.
+                 */
+                if (! (menu->fghighlight && menu->bghighlight &&
+                       MaxColors > 1 &&
+                       XParseColor (dpy,
+                                    DefaultColormap (dpy, scr),
+                                    menu->fghighlight,
+                                    &menu->hlfg) &&
+                       XAllocColor (dpy,
+                                    DefaultColormap (dpy, scr),
+                                    &menu->hlfg) &&
+                       XParseColor (dpy,
+                                    DefaultColormap (dpy, scr),
+                                    menu->bghighlight,
+                                    &menu->hlbg) &&
+                       XAllocColor (dpy,
+                                    DefaultColormap (dpy, scr),
+                                    &menu->hlbg)))
+                {
+                        menu->hlfg.pixel = MTextBackground;
+                        menu->hlbg.pixel = MTextForeground;
+                }
+                else
+                {
+                        AdjustMaxColors (menu->hlfg.pixel);
+                        AdjustMaxColors (menu->hlbg.pixel);
+                        alternateGC = False;
+                }
 
-        /*
-         * Only 2 colors available, so default to standard black and white.
-         */
-        menu->fg.pixel = MTextForeground;
-        menu->bg.pixel = MTextBackground;
-        menu->hlfg.pixel = MTextBackground;
-        menu->hlbg.pixel = MTextForeground;
-        for(ml = menu->line; ml; ml = ml->next) {
-            ml->fg.pixel = MTextForeground;
-            ml->bg.pixel = MTextBackground;
+                /*
+                 * Get the menu item colors.
+                 */
+                for (ml = menu->line; ml; ml = ml->next)
+                {
+                        if (! (ml->foreground && ml->background &&
+                               MaxColors > 1 &&
+                               XParseColor (dpy,
+                                            DefaultColormap (dpy, scr),
+                                            ml->foreground,
+                                            &ml->fg) &&
+                               XAllocColor (dpy,
+                                            DefaultColormap (dpy, scr),
+                                            &ml->fg) &&
+                               XParseColor (dpy,
+                                            DefaultColormap (dpy, scr),
+                                            ml->background,
+                                            &ml->bg) &&
+                               XAllocColor (dpy,
+                                            DefaultColormap (dpy, scr),
+                                            &ml->bg)))
+                        {
+                                ml->fg.pixel = MTextForeground;
+                                ml->bg.pixel = MTextBackground;
+                        }
+                        else
+                        {
+                                AdjustMaxColors (ml->fg.pixel);
+                                AdjustMaxColors (ml->bg.pixel);
+                        }
+                }
         }
-    }
+        else
+        {
+
+                /*
+                 * Only 2 colors available, so default to standard black and
+                 * white.
+                 */
+                menu->fg.pixel = MTextForeground;
+                menu->bg.pixel = MTextBackground;
+                menu->hlfg.pixel = MTextBackground;
+                menu->hlbg.pixel = MTextForeground;
+                for (ml = menu->line; ml; ml = ml->next)
+                {
+                        ml->fg.pixel = MTextForeground;
+                        ml->bg.pixel = MTextBackground;
+                }
+        }
 }
 
 /*
  * Decrement "MaxColors" if this pixel value has never been used in a
  * menu before.
  */
-AdjustMaxColors(pixel)
-int pixel;
+AdjustMaxColors (int pixel)
 {
-    register MenuLink *mptr;
-    register MenuLine *lptr;
-    int count = 0;
+        register MenuLink *mptr;
+        register MenuLine *lptr;
+        int count = 0;
 
-    for(mptr = Menus; mptr; mptr = mptr->next) {
-        if (mptr->menu->fg.pixel == pixel) ++count;
-        if (mptr->menu->bg.pixel == pixel) ++count;
-        if (mptr->menu->hlfg.pixel == pixel) ++count;
-        if (mptr->menu->hlbg.pixel == pixel) ++count;
-        for(lptr = mptr->menu->line; lptr; lptr = lptr->next) {
-            if (lptr->fg.pixel == pixel) ++count;
-            if (lptr->bg.pixel == pixel) ++count;
+        for (mptr = Menus; mptr; mptr = mptr->next)
+        {
+                if (mptr->menu->fg.pixel == pixel)
+                        ++count;
+                if (mptr->menu->bg.pixel == pixel)
+                        ++count;
+                if (mptr->menu->hlfg.pixel == pixel)
+                        ++count;
+                if (mptr->menu->hlbg.pixel == pixel)
+                        ++count;
+                for (lptr = mptr->menu->line; lptr; lptr = lptr->next)
+                {
+                        if (lptr->fg.pixel == pixel)
+                                ++count;
+                        if (lptr->bg.pixel == pixel)
+                                ++count;
+                }
+                if (count > 1)
+                        return;
         }
-        if (count > 1) return;
-    }
-    --MaxColors;
+        --MaxColors;
 }
-