Annotation of 43BSD/contrib/X/Xlib/XParseColor.c, revision 1.1.1.1

1.1       root        1: #include <X/mit-copyright.h>
                      2: 
                      3: /* $Header: XParseColor.c,v 10.4 86/02/01 15:37:40 tony Rel $ */
                      4: /* Copyright    Massachusetts Institute of Technology    1985  */
                      5: 
                      6: #include "XlibInternal.h"
                      7: 
                      8: Status XParseColor (spec, def)
                      9:        register char *spec;
                     10:        Color *def;
                     11: {
                     12:        register Display *dpy;
                     13:        register XReq *req;
                     14:        XRep rep;
                     15:        register int n, i;
                     16:        int r, g, b;
                     17:        char c;
                     18: 
                     19:        n = strlen (spec);
                     20:        if (*spec != '#') {
                     21:            GetReq (X_LookupColor, 0);
                     22:            req->param.s[0] = n;
                     23:            Data (dpy, spec, n);
                     24:            if (!_XReply (dpy, &rep))
                     25:                return (0);
                     26:            def->red = rep.param.u[0];
                     27:            def->green = rep.param.u[1];
                     28:            def->blue = rep.param.u[2];
                     29:            return (1);
                     30:        }
                     31:        spec++;
                     32:        n--;
                     33:        if (n != 3 && n != 6 && n != 9 && n != 12)
                     34:            return (0);
                     35:        n /= 3;
                     36:        r = g = b = 0;
                     37:        do {
                     38:            r = g;
                     39:            g = b;
                     40:            b = 0;
                     41:            for (i = n; --i >= 0; ) {
                     42:                c = *spec++;
                     43:                b <<= 4;
                     44:                if (c >= '0' && c <= '9')
                     45:                    b |= c - '0';
                     46:                else if (c >= 'A' && c <= 'F')
                     47:                    b |= c - ('A' - 10);
                     48:                else if (c >= 'a' && c <= 'f')
                     49:                    b |= c - ('a' - 10);
                     50:                else return (0);
                     51:            }
                     52:        } while (*spec);
                     53:        n <<= 2;
                     54:        n = 16 - n;
                     55:        def->red = r << n;
                     56:        def->green = g << n;
                     57:        def->blue = b << n;
                     58:        return (1);
                     59: }

unix.superglobalmegacorp.com

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