[PATCH 1.12] A coding style for the server

Keith Packard keithp at keithp.com
Wed Jan 18 22:26:30 PST 2012


On Thu, 19 Jan 2012 15:49:06 +1100, Daniel Stone <daniel at fooishbar.org> wrote:

> Actually, non-cuddling else was slightly in the majority -- this was
> just based on a quick couple of greps, as was the decision to cuddle
> if/for/while statements with their opening greps.  For full
> disclosure, I prefer it this way, but was pleasantly surprised to see
> the numbers agree with my preference.  If the numbers didn't agree, I
> would've sucked it up and gone the other way.

I looked at some older X server code (X11R1) and found that it used this form:

        if ()
        {
        }
        else
        {
        }

almost exclusively, except for do, which was done as:

        do {
        } while();

Even switch shows a marked preference for this form:

        switch ()
        {
        case ..:
        }

However, about 1/3 of the switch cases use

        switch () {

instead.

What I can't figure out is how to get indent to format declarations
the way the original X server mi code did:

        static void
        miComputeClips (pParent, pScreen, universe)
            register WindowPtr	pParent;
            register ScreenPtr	pScreen;
            register RegionPtr	universe;
        {
            RegionPtr		childUniverse;
            register WindowPtr	pChild;
            int     	  	oldVis;
            BoxPtr  	  	borderSize;

All of the names are nicely lined up. Here's another longer one (the
code is completely broken, of course, as it doesn't follow X pixelization
rules, but...):

        void
        miFillSppPoly(dst, pgc, count, ptsIn, xTrans, yTrans)
            DrawablePtr 	dst;
            GCPtr		pgc;
            int			count;          /* number of points */
            SppPointPtr 	ptsIn;          /* the points */
            int			xTrans, yTrans;	/* Translate each point by this */
        {
            double		xl, xr,		/* x vals of left and right edges */
                                ml,       	/* left edge slope */
                                mr,             /* right edge slope */
                                dy,             /* delta y */
                                i;              /* loop counter */
            int			y,              /* current scanline */
                                j,
                                imin,           /* index of vertex with smallest y */
                                ymin,           /* y-extents of polygon */
                                ymax,
                                *width,
                                *FirstWidth,    /* output buffer */
                                *Marked;	/* set if this vertex has been used */
            register int	left, right,	/* indices to first endpoints */
                                nextleft,
                                nextright;	/* indices to second endpoints */
            DDXPointPtr 	ptsOut,
                                FirstPoint;	/* output buffer */
            double 		ceil();

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120118/dc81ed44/attachment.pgp>


More information about the xorg-devel mailing list