summaryrefslogtreecommitdiff
path: root/dviware/quicspool/src/xxx.y
blob: 304851484e096c9368d1553bd0e87f15459a58f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
%{
#ifndef lint
static char *yrcs = "$Header: xxx.y,v 1.2 88/02/03 08:52:12 simpson Exp $";
#endif
/*
$Log:	xxx.y,v $
 * Revision 1.2  88/02/03  08:52:12  simpson
 * added tpic support
 * 
 * Revision 1.1  88/01/15  13:05:57  simpson
 * initial release
 * 
 * Revision 0.1  87/12/11  18:31:27  simpson
 * beta test
 * 
*/
#define	TPICRES		1000 		/* Tpic uses 1000 dots/inch */
static int	Coordinates[300][2];	/* Coordinates used by tpic */
static int	CoorCount;	        /* Count of # of coor in above array */
static int	PenWidth;
static int	GraphOrigin[2];
static double   Center[2], Cur[2], New[2];
static double   CurvePts[300][3], SplinePts[500][3];
static enum {none, white, shade, black} Color;
%}
%union {
    int	    i;
    double  f;
    char    s[81];
}
%token OVERLAY PENSIZE FLUSHPATH FLUSHDASHED FLUSHDOTTED ADDPATH DRAWARC
%token FLUSHSPLINE SHADELAST WHITENLAST BLACKENLAST TEXTURE
%token <s> STRING
%token <i> INTEGER
%token <f> FLOAT
%type <s> validfile
%%
keywords : 
    keyword ',' keywords
    | 
    keyword 
    |
    error ','
	{
	    yyerrok;
	}
    keywords
    ;

keyword : 
    OVERLAY 
    '('
    validfile
	{
	    FILE    *f;
	    char    filename[81], *expandtilde(), *strcpy();
	    int	    c;

	    (void)strcpy(filename, $3);
            (void)expandtilde(filename);
	    if (f = fopen(filename, "r")) {
		while ((c = getc(f)) != EOF)
		    (void)putchar(c);
		(void)fclose(f);
	    }
	}
    ')'
    |
    PENSIZE
    INTEGER
	{
	    /* A pen command designates the start of a new graph */
	    PenWidth = ROUND($2 / 1000.0 * RESOLUTION);
	    GraphOrigin[0] = Origin[0], GraphOrigin[1] = Origin[1];
	    CoorCount = 0;
	    Color = none;
	}
    |
    FLUSHPATH
	{
    	    if (CoorCount > 1) {
		int i;

		fputs(VECTORON, stdout);
		printf("%s%05d:%05d", PENUP, 
		ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[0][0]/(double)TPICRES)*1000),
		ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[0][1]/(double)TPICRES)*1000));
		printf("%s%02d", PENWIDTH, PenWidth);
		for (i = 1; i < CoorCount; i++)
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[i][0]/(double)TPICRES)*1000),
		    ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[i][1]/(double)TPICRES)*1000));
		fputs(VECTOROFF, stdout);
	    }
	    if (CoorCount >=4 && Color != none) {
		/* Find midpoint of diagonal */
		Center[0] = ((GraphOrigin[0]/(double)RESOLUTION+
		Coordinates[0][0]/(double)TPICRES)+(GraphOrigin[0]/
		(double)RESOLUTION+Coordinates[2][0]/(double)TPICRES))/2.0;
		Center[1] = ((GraphOrigin[1]/(double)RESOLUTION+
		Coordinates[0][1]/(double)TPICRES)+(GraphOrigin[1]/
		(double)RESOLUTION+Coordinates[2][1]/(double)TPICRES))/2.0;
		printf("%s%05d%05d", AREAFILL,
		ROUND(Center[0]*1000),ROUND(Center[1]*1000));
		switch (Color) {
		case white:
		    printf("%02d", 0);
		    break;
		case shade:
		    printf("%02d", 19);
		    break;
		case black:
		    printf("%02d", 20);
		    break;
		}
		printf("%s", ENDCMD);
	    }
	    CoorCount = 0;
	    Color = none;
	}
    |
    FLUSHDASHED
    FLOAT
	{
    	    if (CoorCount > 1) {
		int i;

		fputs(VECTORON, stdout);
		printf("%s%05d:%05d", PENUP, 
		ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[0][0]/(double)TPICRES)*1000),
		ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[0][1]/(double)TPICRES)*1000));
		printf("%s%02d", PENWIDTH, PenWidth);
		printf("%s%d", "^V", 4);
		for (i = 1; i < CoorCount; i++)
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[i][0]/(double)TPICRES)*1000),
		    ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[i][1]/(double)TPICRES)*1000));
		fputs(VECTOROFF, stdout);
	    }
	    CoorCount = 0;
	    Color = none;
	}
    |
    FLUSHDOTTED
    FLOAT
	{
    	    if (CoorCount > 1) {
		int i;

		fputs(VECTORON, stdout);
		printf("%s%05d:%05d", PENUP, 
		ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[0][0]/(double)TPICRES)*1000),
		ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[0][1]/(double)TPICRES)*1000));
		printf("%s%02d", PENWIDTH, PenWidth);
		printf("%s%d", "^V", 2);
		for (i = 1; i < CoorCount; i++)
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((GraphOrigin[0]/(double)RESOLUTION+Coordinates[i][0]/(double)TPICRES)*1000),
		    ROUND((GraphOrigin[1]/(double)RESOLUTION+Coordinates[i][1]/(double)TPICRES)*1000));
		fputs(VECTOROFF, stdout);
	    }
	    CoorCount = 0;
	    Color = none;
	}
    |
    ADDPATH
    INTEGER
    INTEGER
	{
	    Coordinates[CoorCount][0] = $2, Coordinates[CoorCount++][1] = $3;
	}
    |
    DRAWARC
    INTEGER
    INTEGER
    INTEGER
    INTEGER
    FLOAT
    FLOAT
	{
	    Center[0] = GraphOrigin[0] / (double)RESOLUTION + $2 /
	    (double)TPICRES,
	    Center[1] = GraphOrigin[1] / (double)RESOLUTION + $3 /
	    (double)TPICRES;
    	    if ($4 != $5) {	/* Ellipse */
		int i;

		/* Ellipses satisfy the equation (x^2)/(a^2)+(y^2)/(b^2)=1
		 * where 'a' is the length of the semimajor axis and 'b'
		 * is the length of the semiminor axis.  We divide each
		 * quadrant into 200 line segments and connect the line
		 * segments.
		 */
		/* Cur and New are relative to the origin */
		Cur[0] = $4 / (double)TPICRES, Cur[1] = 0.0;
		fputs(VECTORON, stdout);
		printf("%s%02d", PENWIDTH, PenWidth);
		for (i = 1; i <= 200; i++, Cur[0] = New[0], Cur[1] = New[1]) {
		    New[0] = ($4/(double)TPICRES)*cos((i/200.0)*(PI/2.0)),
		    New[1] = ($5/(double)TPICRES)*sin((i/200.0)*(PI/2.0));
		    /* First quadrant */
		    printf("%s%05d:%05d", PENUP,
		    ROUND((Center[0]+Cur[0])*1000.0),
		    ROUND((Center[1]+Cur[1])*1000.0));
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((Center[0]+New[0])*1000.0),
		    ROUND((Center[1]+New[1])*1000.0));
		    /* Second quadrant */
		    printf("%s%05d:%05d", PENUP,
		    ROUND((Center[0]-Cur[0])*1000.0),
		    ROUND((Center[1]+Cur[1])*1000.0));
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((Center[0]-New[0])*1000.0),
		    ROUND((Center[1]+New[1])*1000.0));
		    /* Third quadrant */
		    printf("%s%05d:%05d", PENUP,
		    ROUND((Center[0]-Cur[0])*1000.0),
		    ROUND((Center[1]-Cur[1])*1000.0));
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((Center[0]-New[0])*1000.0),
		    ROUND((Center[1]-New[1])*1000.0));
		    /* Fourth quadrant */
		    printf("%s%05d:%05d", PENUP,
		    ROUND((Center[0]+Cur[0])*1000.0),
		    ROUND((Center[1]-Cur[1])*1000.0));
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((Center[0]+New[0])*1000.0),
		    ROUND((Center[1]-New[1])*1000.0));
		    if (Color != none) {
			printf("%s%05d%05d", AREAFILL,
			ROUND(Center[0]*1000),ROUND(Center[1]*1000));
			switch (Color) {
			case white:
			    printf("%02d", 0);
			    break;
			case shade:
			    printf("%02d", 19);
			    break;
			case black:
			    printf("%02d", 20);
			    break;
			}
			printf("%s", ENDCMD);
			Color = none;
		    }
		}
		fputs(VECTOROFF, stdout);
	    } else {	/* Arc */
		printf("%s%c%05d%c%05d%05d%03d%03d%02d%s", DECIMALARC,
		Center[0]>0?'+':'-',
		Center[0]>0?ROUND(Center[0]*1000):
		ROUND(-Center[0]*1000),Center[1]>0?'+':'-',
		Center[1]>0?ROUND(Center[1]*1000):
		ROUND(-Center[1]*1000),$4,ROUND($6/PI*500.0)>999?999:
		ROUND($6/PI*500.0),ROUND($7/PI*500.0)>999?999:
		ROUND($7/PI*500.0), PenWidth, ENDCMD);
		if ($6 == 0 && ABS($7-2*PI) < 0.01)
		    if (Color != none) {
			printf("%s%05d%05d", AREAFILL,
			ROUND(Center[0]*1000),ROUND(Center[1]*1000));
			switch (Color) {
			case white:
			    printf("%02d", 0);
			    break;
			case shade:
			    printf("%02d", 19);
			    break;
			case black:
			    printf("%02d", 20);
			    break;
			}
			printf("%s", ENDCMD);
			Color = none;
		    }
	    }
	}
								  
    |
    FLUSHSPLINE
	{
	    if (CoorCount > 1) {
		int i;

		for (i = 0; i < CoorCount; i++) {
		    CurvePts[i][0] = Coordinates[i][0] / (double)TPICRES;
		    CurvePts[i][1] = Coordinates[i][1] / (double)TPICRES;
		    CurvePts[i][2] = 0.0;	/* z-axis not used */
		}
		spline(CurvePts,CoorCount-1,SplinePts,499,3); /* 2nd degree */
		fputs(VECTORON, stdout);
		printf("%s%05d:%05d", PENUP,
		ROUND((GraphOrigin[0]/(double)RESOLUTION+SplinePts[0][0])*1000),
		ROUND((GraphOrigin[1]/(double)RESOLUTION+SplinePts[0][1])*1000));
		printf("%s%02d", PENWIDTH, PenWidth);
		for (i = 1; i < 500; i++)
		    printf("%s%05d:%05d", PENDOWN,
		    ROUND((GraphOrigin[0]/(double)RESOLUTION+SplinePts[i][0])*1000),
		    ROUND((GraphOrigin[1]/(double)RESOLUTION+SplinePts[i][1])*1000));
		fputs(VECTOROFF, stdout);
	    }
	    CoorCount = 0;
	}
    |
    TEXTURE
    textureargs		/* Ignore - Imagen only */
    |
    SHADELAST
	{
	    Color = shade;
	}
    |
    WHITENLAST
	{
	    Color = white;
	}
    |
    BLACKENLAST
	{
	    Color = black;
	}
    ;

validfile :
    STRING
	{
	    (void)strcpy($$, $1);
	}
    |
    OVERLAY
	{
	    (void)strcpy($$, "overlay");
	}
    |
    PENSIZE
	{
	    (void)strcpy($$, "pn");
	}
    | 
    FLUSHPATH
	{
	    (void)strcpy($$, "fp");
	}
    |
    FLUSHDASHED
	{
	    (void)strcpy($$, "da");
	}
    |
    FLUSHDOTTED
	{
	    (void)strcpy($$, "dt");
	}
    |
    ADDPATH
	{
	    (void)strcpy($$, "pa");
	}
    |
    DRAWARC
	{
	    (void)strcpy($$, "ar");
	}
    |
    FLUSHSPLINE
	{
	    (void)strcpy($$, "sp");
	}
    |
    SHADELAST
	{
	    (void)strcpy($$, "sh");
	}
    |
    WHITENLAST
	{
	    (void)strcpy($$, "wh");
	}
    |
    BLACKENLAST
	{
	    (void)strcpy($$, "bk");
	}
    |
    TEXTURE
	{
	    (void)strcpy($$, "tx");
	}
    |
    INTEGER
	{
	    (void)sprintf($$, "%d", $1);
	}
/*  |		Unfortunately this won't work since the lexeme
    FLOAT	of a float has been lost when we converted it to a 
        {	real number.
 	    (void)sprintf($$, "%f", $1);
	}
*/
    ;

textureargs : texturearg textureargs | /* epsilon */ ;

texturearg : STRING | INTEGER  ;
%%
#include "xxxlex.c"

yyerror(s)
char *s;
{
    return;
}