Annotation of researchv9/X11/src/X.V11R1/lib/X/XParseCol.c, revision 1.1

1.1     ! root        1: #include "copyright.h"
        !             2: 
        !             3: /* $Header: XParseCol.c,v 11.13 87/09/11 08:05:21 toddb Exp $ */
        !             4: /* Copyright    Massachusetts Institute of Technology    1985  */
        !             5: 
        !             6: #define NEED_REPLIES
        !             7: #include "Xlibint.h"
        !             8: 
        !             9: Status XParseColor (dpy, cmap, spec, def)
        !            10:        register Display *dpy;
        !            11:         Colormap cmap;
        !            12:        register char *spec;
        !            13:        XColor *def;
        !            14: {
        !            15:        register int n, i;
        !            16:        int r, g, b;
        !            17:        char c;
        !            18: 
        !            19:        n = strlen (spec);
        !            20:        if (*spec != '#') {
        !            21:            xLookupColorReply reply;
        !            22:            register xLookupColorReq *req;
        !            23:            LockDisplay(dpy);
        !            24:            GetReq (LookupColor, req);
        !            25:            req->cmap = cmap;
        !            26:            req->nbytes = n;
        !            27:            req->length += (n + 3) >> 2;
        !            28:            Data (dpy, spec, (long)n);
        !            29:            if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) {
        !            30:                UnlockDisplay(dpy);
        !            31:                SyncHandle();
        !            32:                return (0);
        !            33:                }
        !            34:            def->red = reply.exactRed;
        !            35:            def->green = reply.exactGreen;
        !            36:            def->blue = reply.exactBlue;
        !            37:            UnlockDisplay(dpy);
        !            38:            SyncHandle();
        !            39:            return (1);
        !            40:        }
        !            41:        spec++;
        !            42:        n--;
        !            43:        if (n != 3 && n != 6 && n != 9 && n != 12)
        !            44:            return (0);
        !            45:        n /= 3;
        !            46:        r = g = b = 0;
        !            47:        do {
        !            48:            r = g;
        !            49:            g = b;
        !            50:            b = 0;
        !            51:            for (i = n; --i >= 0; ) {
        !            52:                c = *spec++;
        !            53:                b <<= 4;
        !            54:                if (c >= '0' && c <= '9')
        !            55:                    b |= c - '0';
        !            56:                else if (c >= 'A' && c <= 'F')
        !            57:                    b |= c - ('A' - 10);
        !            58:                else if (c >= 'a' && c <= 'f')
        !            59:                    b |= c - ('a' - 10);
        !            60:                else return (0);
        !            61:            }
        !            62:        } while (*spec != '\0');
        !            63:        n <<= 2;
        !            64:        n = 16 - n;
        !            65:        def->red = r << n;
        !            66:        def->green = g << n;
        !            67:        def->blue = b << n;
        !            68:        return (1);
        !            69: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.