| 1 | 
greg | 
1.1 | 
#ifndef lint | 
| 2 | 
schorsch | 
1.3 | 
static const char       RCSid[] = "$Id: plot.c,v 1.2 2003/06/08 12:03:10 schorsch Exp $"; | 
| 3 | 
greg | 
1.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 *  Plotting routines for meta-files | 
| 6 | 
  | 
  | 
 */ | 
| 7 | 
  | 
  | 
 | 
| 8 | 
  | 
  | 
 | 
| 9 | 
schorsch | 
1.3 | 
#include  "rtio.h" | 
| 10 | 
greg | 
1.1 | 
#include  "meta.h" | 
| 11 | 
  | 
  | 
#include  "plot.h" | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
 | 
| 14 | 
  | 
  | 
int  pati[4] = {0, 1, 2, 3};    /* pattern indices */ | 
| 15 | 
  | 
  | 
 | 
| 16 | 
  | 
  | 
/* | 
| 17 | 
  | 
  | 
 *  Patterns are 16 X 16, ordered left to right, bottom to top. | 
| 18 | 
  | 
  | 
 *  Each byte represents a column in an 8-bit high row. | 
| 19 | 
  | 
  | 
 */ | 
| 20 | 
  | 
  | 
 | 
| 21 | 
  | 
  | 
unsigned char   pattern[NPATS+4][PATSIZE/8][PATSIZE] = { | 
| 22 | 
  | 
  | 
    {                                           /* solid */ | 
| 23 | 
  | 
  | 
        { | 
| 24 | 
  | 
  | 
            0377,0377,0377,0377,0377,0377,0377,0377, | 
| 25 | 
  | 
  | 
            0377,0377,0377,0377,0377,0377,0377,0377 | 
| 26 | 
  | 
  | 
        }, { | 
| 27 | 
  | 
  | 
            0377,0377,0377,0377,0377,0377,0377,0377, | 
| 28 | 
  | 
  | 
            0377,0377,0377,0377,0377,0377,0377,0377 | 
| 29 | 
  | 
  | 
        } | 
| 30 | 
  | 
  | 
    }, {                                        /* thick \\\ (dashed) */ | 
| 31 | 
  | 
  | 
        { | 
| 32 | 
  | 
  | 
            0377,0177,077,037,017,0207,0303,0341, | 
| 33 | 
  | 
  | 
            0360,0370,0374,0376,0377,0377,0377,0377 | 
| 34 | 
  | 
  | 
        }, { | 
| 35 | 
  | 
  | 
            0360,0370,0374,0376,0377,0377,0377,0377, | 
| 36 | 
  | 
  | 
            0377,0177,077,037,017,0207,0303,0341 | 
| 37 | 
  | 
  | 
        } | 
| 38 | 
  | 
  | 
    }, {                                        /* thin \\\ (dotted) */ | 
| 39 | 
  | 
  | 
        { | 
| 40 | 
  | 
  | 
            0314,0146,063,0231,0314,0146,063,0231, | 
| 41 | 
  | 
  | 
            0314,0146,063,0231,0314,0146,063,0231 | 
| 42 | 
  | 
  | 
        }, { | 
| 43 | 
  | 
  | 
            0314,0146,063,0231,0314,0146,063,0231, | 
| 44 | 
  | 
  | 
            0314,0146,063,0231,0314,0146,063,0231 | 
| 45 | 
  | 
  | 
        } | 
| 46 | 
  | 
  | 
    }, {                                        /* mix \\\ (dotted-dashed) */ | 
| 47 | 
  | 
  | 
        { | 
| 48 | 
  | 
  | 
            0376,0177,077,037,0217,0307,0343,0161, | 
| 49 | 
  | 
  | 
            070,034,0216,0307,0343,0361,0370,0374 | 
| 50 | 
  | 
  | 
        }, { | 
| 51 | 
  | 
  | 
            070,034,0216,0307,0343,0361,0370,0374, | 
| 52 | 
  | 
  | 
            0376,0177,077,037,0217,0307,0343,0161 | 
| 53 | 
  | 
  | 
        } | 
| 54 | 
  | 
  | 
    }, {                                        /* thick /// (dashed) */ | 
| 55 | 
  | 
  | 
        { | 
| 56 | 
  | 
  | 
            0377,0377,0377,0377,0376,0374,0370,0360, | 
| 57 | 
  | 
  | 
            0341,0303,0207,017,037,077,0177,0377 | 
| 58 | 
  | 
  | 
        }, { | 
| 59 | 
  | 
  | 
            0341,0303,0207,017,037,077,0177,0377, | 
| 60 | 
  | 
  | 
            0377,0377,0377,0377,0376,0374,0370,0360 | 
| 61 | 
  | 
  | 
        } | 
| 62 | 
  | 
  | 
    }, {                                        /* thin /// (dotted) */ | 
| 63 | 
  | 
  | 
        { | 
| 64 | 
  | 
  | 
            0231,063,0146,0314,0231,063,0146,0314, | 
| 65 | 
  | 
  | 
            0231,063,0146,0314,0231,063,0146,0314 | 
| 66 | 
  | 
  | 
        }, { | 
| 67 | 
  | 
  | 
            0231,063,0146,0314,0231,063,0146,0314, | 
| 68 | 
  | 
  | 
            0231,063,0146,0314,0231,063,0146,0314 | 
| 69 | 
  | 
  | 
        } | 
| 70 | 
  | 
  | 
    }, {                                        /* mix /// (dotted-dashed) */ | 
| 71 | 
  | 
  | 
        { | 
| 72 | 
  | 
  | 
            0374,0370,0361,0343,0307,0216,034,070, | 
| 73 | 
  | 
  | 
            0161,0343,0307,0217,037,077,0177,0376 | 
| 74 | 
  | 
  | 
        }, { | 
| 75 | 
  | 
  | 
            0161,0343,0307,0217,037,077,0177,0376, | 
| 76 | 
  | 
  | 
            0374,0370,0361,0343,0307,0216,034,070 | 
| 77 | 
  | 
  | 
        } | 
| 78 | 
  | 
  | 
    }, {                                        /* crisscross */ | 
| 79 | 
  | 
  | 
        { | 
| 80 | 
  | 
  | 
            0201,0102,044,030,030,044,0102,0201, | 
| 81 | 
  | 
  | 
            0201,0102,044,030,030,044,0102,0201 | 
| 82 | 
  | 
  | 
        }, { | 
| 83 | 
  | 
  | 
            0201,0102,044,030,030,044,0102,0201, | 
| 84 | 
  | 
  | 
            0201,0102,044,030,030,044,0102,0201 | 
| 85 | 
  | 
  | 
        } | 
| 86 | 
  | 
  | 
    }, {                                        /* web */ | 
| 87 | 
  | 
  | 
        { | 
| 88 | 
  | 
  | 
            0377,0300,0240,0220,0210,0204,0202,0201, | 
| 89 | 
  | 
  | 
            0201,0202,0204,0210,0220,0240,0300,0200 | 
| 90 | 
  | 
  | 
        }, { | 
| 91 | 
  | 
  | 
            0377,02,04,010,020,040,0100,0200, | 
| 92 | 
  | 
  | 
            0200,0100,040,020,010,04,02,01 | 
| 93 | 
  | 
  | 
        } | 
| 94 | 
  | 
  | 
    } | 
| 95 | 
  | 
  | 
}; | 
| 96 | 
  | 
  | 
 | 
| 97 | 
  | 
  | 
static int  context = 0; | 
| 98 | 
  | 
  | 
 | 
| 99 | 
  | 
  | 
struct setting { | 
| 100 | 
  | 
  | 
        int  cnx;               /* setting context */ | 
| 101 | 
  | 
  | 
        char  *val;             /* attribute value */ | 
| 102 | 
  | 
  | 
        struct setting  *snext; /* next setting in list */ | 
| 103 | 
  | 
  | 
}; | 
| 104 | 
  | 
  | 
 | 
| 105 | 
  | 
  | 
static struct setting  *sets[0200]; | 
| 106 | 
  | 
  | 
 | 
| 107 | 
schorsch | 
1.2 | 
static void spop(int attrib); | 
| 108 | 
  | 
  | 
static int spat(int  pat, char  *patval); | 
| 109 | 
greg | 
1.1 | 
 | 
| 110 | 
schorsch | 
1.2 | 
void | 
| 111 | 
  | 
  | 
set(            /* set attribute to value */ | 
| 112 | 
  | 
  | 
int  attrib, | 
| 113 | 
  | 
  | 
char  *value | 
| 114 | 
  | 
  | 
) | 
| 115 | 
greg | 
1.1 | 
{ | 
| 116 | 
  | 
  | 
    struct setting  *newset; | 
| 117 | 
  | 
  | 
 | 
| 118 | 
  | 
  | 
    switch (attrib) { | 
| 119 | 
  | 
  | 
        case SALL: | 
| 120 | 
  | 
  | 
            context++; | 
| 121 | 
  | 
  | 
            return; | 
| 122 | 
  | 
  | 
        case SPAT0: | 
| 123 | 
  | 
  | 
        case SPAT1: | 
| 124 | 
  | 
  | 
        case SPAT2: | 
| 125 | 
  | 
  | 
        case SPAT3: | 
| 126 | 
  | 
  | 
            if (!spat(attrib, value)) { | 
| 127 | 
  | 
  | 
                sprintf(errmsg, "Bad pattern set value: %s", value); | 
| 128 | 
  | 
  | 
                error(WARNING, errmsg); | 
| 129 | 
  | 
  | 
                return; | 
| 130 | 
  | 
  | 
            } | 
| 131 | 
  | 
  | 
            break; | 
| 132 | 
  | 
  | 
        default: | 
| 133 | 
  | 
  | 
            sprintf(errmsg, "Can't set attribute: %o", attrib); | 
| 134 | 
  | 
  | 
            error(WARNING, errmsg); | 
| 135 | 
  | 
  | 
            return; | 
| 136 | 
  | 
  | 
    } | 
| 137 | 
  | 
  | 
    newset = (struct setting *)malloc(sizeof(struct setting)); | 
| 138 | 
  | 
  | 
    newset->cnx = context; | 
| 139 | 
  | 
  | 
    newset->val = savestr(value); | 
| 140 | 
  | 
  | 
    newset->snext = sets[attrib]; | 
| 141 | 
  | 
  | 
    sets[attrib] = newset; | 
| 142 | 
  | 
  | 
} | 
| 143 | 
  | 
  | 
 | 
| 144 | 
  | 
  | 
 | 
| 145 | 
  | 
  | 
 | 
| 146 | 
schorsch | 
1.2 | 
void | 
| 147 | 
  | 
  | 
unset(                  /* return attribute to previous setting */ | 
| 148 | 
  | 
  | 
int  attrib | 
| 149 | 
  | 
  | 
) | 
| 150 | 
greg | 
1.1 | 
{ | 
| 151 | 
  | 
  | 
    register int  i; | 
| 152 | 
  | 
  | 
 | 
| 153 | 
  | 
  | 
    if (attrib == SALL) { | 
| 154 | 
  | 
  | 
        if (context == 0) | 
| 155 | 
  | 
  | 
            reset(SALL); | 
| 156 | 
  | 
  | 
        else { | 
| 157 | 
  | 
  | 
            context--; | 
| 158 | 
  | 
  | 
            for (i = 0; i < 0200; i++) | 
| 159 | 
  | 
  | 
                while (sets[i] != NULL && sets[i]->cnx > context) | 
| 160 | 
  | 
  | 
                    spop(i); | 
| 161 | 
  | 
  | 
        } | 
| 162 | 
  | 
  | 
        return; | 
| 163 | 
  | 
  | 
    } | 
| 164 | 
  | 
  | 
    spop(attrib); | 
| 165 | 
  | 
  | 
    if (sets[attrib] == NULL) | 
| 166 | 
  | 
  | 
        reset(attrib); | 
| 167 | 
  | 
  | 
 | 
| 168 | 
  | 
  | 
    switch (attrib) { | 
| 169 | 
  | 
  | 
        case SPAT0: | 
| 170 | 
  | 
  | 
        case SPAT1: | 
| 171 | 
  | 
  | 
        case SPAT2: | 
| 172 | 
  | 
  | 
        case SPAT3: | 
| 173 | 
  | 
  | 
            spat(attrib, sets[attrib]->val); | 
| 174 | 
  | 
  | 
            break; | 
| 175 | 
  | 
  | 
        default: | 
| 176 | 
  | 
  | 
            sprintf(errmsg, "Can't unset attribute: %o", attrib); | 
| 177 | 
  | 
  | 
            error(WARNING, errmsg); | 
| 178 | 
  | 
  | 
            return; | 
| 179 | 
  | 
  | 
    } | 
| 180 | 
  | 
  | 
} | 
| 181 | 
  | 
  | 
 | 
| 182 | 
  | 
  | 
 | 
| 183 | 
  | 
  | 
 | 
| 184 | 
schorsch | 
1.2 | 
void | 
| 185 | 
  | 
  | 
reset(                  /* return attribute to default setting */ | 
| 186 | 
  | 
  | 
int  attrib | 
| 187 | 
  | 
  | 
) | 
| 188 | 
greg | 
1.1 | 
{ | 
| 189 | 
  | 
  | 
    switch (attrib) { | 
| 190 | 
  | 
  | 
        case SALL: | 
| 191 | 
  | 
  | 
            reset(SPAT0); | 
| 192 | 
  | 
  | 
            reset(SPAT1); | 
| 193 | 
  | 
  | 
            reset(SPAT2); | 
| 194 | 
  | 
  | 
            reset(SPAT3); | 
| 195 | 
  | 
  | 
            context = 0; | 
| 196 | 
  | 
  | 
            return; | 
| 197 | 
  | 
  | 
        case SPAT0: | 
| 198 | 
  | 
  | 
            spat(SPAT0, "P0"); | 
| 199 | 
  | 
  | 
            break; | 
| 200 | 
  | 
  | 
        case SPAT1: | 
| 201 | 
  | 
  | 
            spat(SPAT1, "P1"); | 
| 202 | 
  | 
  | 
            break; | 
| 203 | 
  | 
  | 
        case SPAT2: | 
| 204 | 
  | 
  | 
            spat(SPAT2, "P2"); | 
| 205 | 
  | 
  | 
            break; | 
| 206 | 
  | 
  | 
        case SPAT3: | 
| 207 | 
  | 
  | 
            spat(SPAT3, "P3"); | 
| 208 | 
  | 
  | 
            break; | 
| 209 | 
  | 
  | 
        default: | 
| 210 | 
  | 
  | 
            sprintf(errmsg, "Can't reset attribute: %o", attrib); | 
| 211 | 
  | 
  | 
            error(WARNING, errmsg); | 
| 212 | 
  | 
  | 
            return; | 
| 213 | 
  | 
  | 
    } | 
| 214 | 
  | 
  | 
    while (sets[attrib] != NULL) | 
| 215 | 
  | 
  | 
        spop(attrib); | 
| 216 | 
  | 
  | 
} | 
| 217 | 
  | 
  | 
 | 
| 218 | 
  | 
  | 
 | 
| 219 | 
  | 
  | 
 | 
| 220 | 
schorsch | 
1.2 | 
static void | 
| 221 | 
  | 
  | 
spop(                   /* pop top off attrib settings list */ | 
| 222 | 
  | 
  | 
int  attrib | 
| 223 | 
  | 
  | 
) | 
| 224 | 
greg | 
1.1 | 
{ | 
| 225 | 
  | 
  | 
 | 
| 226 | 
  | 
  | 
    if (sets[attrib] != NULL) { | 
| 227 | 
  | 
  | 
        if (sets[attrib]->val != NULL) | 
| 228 | 
  | 
  | 
            freestr(sets[attrib]->val); | 
| 229 | 
  | 
  | 
        free((char *)sets[attrib]); | 
| 230 | 
  | 
  | 
        sets[attrib] = sets[attrib]->snext; | 
| 231 | 
  | 
  | 
    } | 
| 232 | 
  | 
  | 
 | 
| 233 | 
  | 
  | 
} | 
| 234 | 
  | 
  | 
 | 
| 235 | 
  | 
  | 
 | 
| 236 | 
  | 
  | 
 | 
| 237 | 
  | 
  | 
static int | 
| 238 | 
schorsch | 
1.2 | 
spat(                   /* set a pattern */ | 
| 239 | 
  | 
  | 
int  pat, | 
| 240 | 
  | 
  | 
char  *patval | 
| 241 | 
  | 
  | 
) | 
| 242 | 
greg | 
1.1 | 
{ | 
| 243 | 
  | 
  | 
    int  n, i, j, v; | 
| 244 | 
  | 
  | 
    register char  *cp; | 
| 245 | 
  | 
  | 
 | 
| 246 | 
  | 
  | 
    if (patval == NULL) return(FALSE); | 
| 247 | 
  | 
  | 
 | 
| 248 | 
  | 
  | 
    if (patval[0] == 'P' || patval[0] == 'p') { | 
| 249 | 
schorsch | 
1.3 | 
        if (nextscan(patval+1, "%d", (char*)&n) == NULL || n < 0 || n >= NPATS) | 
| 250 | 
greg | 
1.1 | 
            return(FALSE); | 
| 251 | 
  | 
  | 
    } else { | 
| 252 | 
  | 
  | 
        n = NPATS + pat - SPAT0; | 
| 253 | 
  | 
  | 
        cp = patval; | 
| 254 | 
  | 
  | 
        for (i = 0; i < PATSIZE>>3; i++) | 
| 255 | 
  | 
  | 
            for (j = 0; j < PATSIZE; j++) { | 
| 256 | 
schorsch | 
1.3 | 
                if ((cp = nextscan(cp, "%o", (char*)&v)) == NULL || v < 0 || v > 0377) | 
| 257 | 
greg | 
1.1 | 
                    return(FALSE); | 
| 258 | 
  | 
  | 
                pattern[n][i][j] = v; | 
| 259 | 
  | 
  | 
            } | 
| 260 | 
  | 
  | 
    } | 
| 261 | 
  | 
  | 
    pati[pat-SPAT0] = n; | 
| 262 | 
  | 
  | 
    return(TRUE); | 
| 263 | 
  | 
  | 
} |