1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* Plotting routines for meta-files |
6 |
*/ |
7 |
|
8 |
|
9 |
#include "meta.h" |
10 |
|
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 |
|
108 |
|
109 |
|
110 |
set(attrib, value) /* set attribute to value */ |
111 |
|
112 |
int attrib; |
113 |
char *value; |
114 |
|
115 |
{ |
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 |
|
147 |
unset(attrib) /* return attribute to previous setting */ |
148 |
|
149 |
int attrib; |
150 |
|
151 |
{ |
152 |
register int i; |
153 |
|
154 |
if (attrib == SALL) { |
155 |
if (context == 0) |
156 |
reset(SALL); |
157 |
else { |
158 |
context--; |
159 |
for (i = 0; i < 0200; i++) |
160 |
while (sets[i] != NULL && sets[i]->cnx > context) |
161 |
spop(i); |
162 |
} |
163 |
return; |
164 |
} |
165 |
spop(attrib); |
166 |
if (sets[attrib] == NULL) |
167 |
reset(attrib); |
168 |
|
169 |
switch (attrib) { |
170 |
case SPAT0: |
171 |
case SPAT1: |
172 |
case SPAT2: |
173 |
case SPAT3: |
174 |
spat(attrib, sets[attrib]->val); |
175 |
break; |
176 |
default: |
177 |
sprintf(errmsg, "Can't unset attribute: %o", attrib); |
178 |
error(WARNING, errmsg); |
179 |
return; |
180 |
} |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
reset(attrib) /* return attribute to default setting */ |
188 |
|
189 |
int attrib; |
190 |
|
191 |
{ |
192 |
switch (attrib) { |
193 |
case SALL: |
194 |
reset(SPAT0); |
195 |
reset(SPAT1); |
196 |
reset(SPAT2); |
197 |
reset(SPAT3); |
198 |
context = 0; |
199 |
return; |
200 |
case SPAT0: |
201 |
spat(SPAT0, "P0"); |
202 |
break; |
203 |
case SPAT1: |
204 |
spat(SPAT1, "P1"); |
205 |
break; |
206 |
case SPAT2: |
207 |
spat(SPAT2, "P2"); |
208 |
break; |
209 |
case SPAT3: |
210 |
spat(SPAT3, "P3"); |
211 |
break; |
212 |
default: |
213 |
sprintf(errmsg, "Can't reset attribute: %o", attrib); |
214 |
error(WARNING, errmsg); |
215 |
return; |
216 |
} |
217 |
while (sets[attrib] != NULL) |
218 |
spop(attrib); |
219 |
} |
220 |
|
221 |
|
222 |
|
223 |
|
224 |
static |
225 |
spop(attrib) /* pop top off attrib settings list */ |
226 |
|
227 |
int attrib; |
228 |
|
229 |
{ |
230 |
|
231 |
if (sets[attrib] != NULL) { |
232 |
if (sets[attrib]->val != NULL) |
233 |
freestr(sets[attrib]->val); |
234 |
free((char *)sets[attrib]); |
235 |
sets[attrib] = sets[attrib]->snext; |
236 |
} |
237 |
|
238 |
} |
239 |
|
240 |
|
241 |
|
242 |
|
243 |
static int |
244 |
spat(pat, patval) /* set a pattern */ |
245 |
|
246 |
int pat; |
247 |
char *patval; |
248 |
|
249 |
{ |
250 |
int n, i, j, v; |
251 |
char *nextscan(); |
252 |
register char *cp; |
253 |
|
254 |
if (patval == NULL) return(FALSE); |
255 |
|
256 |
if (patval[0] == 'P' || patval[0] == 'p') { |
257 |
if (nextscan(patval+1, "%d", &n) == NULL || n < 0 || n >= NPATS) |
258 |
return(FALSE); |
259 |
} else { |
260 |
n = NPATS + pat - SPAT0; |
261 |
cp = patval; |
262 |
for (i = 0; i < PATSIZE>>3; i++) |
263 |
for (j = 0; j < PATSIZE; j++) { |
264 |
if ((cp = nextscan(cp, "%o", &v)) == NULL || v < 0 || v > 0377) |
265 |
return(FALSE); |
266 |
pattern[n][i][j] = v; |
267 |
} |
268 |
} |
269 |
pati[pat-SPAT0] = n; |
270 |
return(TRUE); |
271 |
} |