tcolors (Gregor Asplund) - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 3167fce5ce254c0cd71891b929c324ced2fd5325
 (DIR) parent dff99a80b6e4c4b2024b346cc4e39db35f877d91
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sun, 21 May 2006 15:56:16 +0000
       
       colors (Gregor Asplund)
       
       Diffstat:
         M man/man1/graph.1                    |       7 +++++++
         M src/cmd/graph/graph.c               |      42 +++++++++++++++++++++++++++++++
       
       2 files changed, 49 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/man/man1/graph.1 b/man/man1/graph.1
       t@@ -85,6 +85,13 @@ with each abscissa value.
        The next argument is
        .IR n .
        .TP
       +.B -p
       +Next argument is one or more of the characters
       +.B bcgkmrwy,
       +choosing pen colors by their initial letter, as in
       +.IR plot (6).
       +Successive curves will cycle through the colors in the given order.
       +.TP
        .B  -s
        Save screen; no new page for this graph.
        .TP
 (DIR) diff --git a/src/cmd/graph/graph.c b/src/cmd/graph/graph.c
       t@@ -63,6 +63,22 @@ double ident(double x){
        struct z {
                float lb,ub,mult,quant;
        };
       +
       +struct {
       +        char *name;
       +        int next;
       +} palette[] = {
       +        ['b']        { "blue", 'b' },
       +        ['c']        { "cyan", 'c' },
       +        ['g']        { "green", 'g' },
       +        ['k']        { "kblack", 'k' },
       +        ['m']        { "magenta", 'm' },
       +        ['r']        { "red", 'r' },
       +        ['w']        { "white", 'w' },
       +        ['y']        { "yellow", 'y' }
       +};
       +int pencolor = 'k';
       +
        void init(struct xy *);
        void setopt(int, char *[]);
        void readin(void);
       t@@ -72,6 +88,7 @@ void equilibrate(struct xy *, struct xy *);
        void scale(struct xy *);
        void limread(struct xy *, int *, char ***);
        int numb(float *, int *, char ***);
       +void colread(int *, char ***);
        int copystring(int);
        struct z setloglim(int, int, float, float);
        struct z setlinlim(int, int, float, float);
       t@@ -221,6 +238,9 @@ again:                switch(argv[0][0]) {
                                if(!numb(&yd.xoff,&argc,&argv))
                                        badarg();
                                break;
       +                case 'p': /*pen color*/
       +                        colread(&argc, &argv);
       +                        break;
                        default:
                                badarg();
                        }
       t@@ -266,6 +286,26 @@ numb(float *np, int *argcp, char ***argvp){
                return(1);
        }
        
       +void colread(int *argcp, char ***argvp){
       +        int c, cnext;
       +        int i, n;
       +
       +        if(*argcp<=1)
       +                return;
       +        n = strlen((*argvp)[1]);
       +        if(strspn((*argvp)[1], "bcgkmrwy")!=n)
       +                return;
       +        pencolor = cnext = (*argvp)[1][0];
       +        for(i=0; i<n-1; i++){
       +                c = (unsigned char)(*argvp)[1][i];
       +                cnext = (unsigned char)(*argvp)[1][i+1];
       +                palette[c].next = cnext;
       +        }
       +        palette[cnext].next = pencolor;
       +        (*argcp)--;
       +        (*argvp)++;
       +}
       +
        void readin(void){
                int i, t;
                struct val *temp;
       t@@ -599,6 +639,7 @@ void plot(void){
                        default:
                                pen(modes[mode]);
                        }
       +                color(palette[pencolor].name);
                        conn = 0;
                        for(i=j; i<n; i+=ovlay) {
                                if(!conv(xx[i].xv,&xd,&ix) ||
       t@@ -615,6 +656,7 @@ void plot(void){
                                }
                                conn &= symbol(ix,iy,xx[i].lblptr);
                        }
       +                pencolor = palette[pencolor].next;
                }
                pen(modes[1]);
        }