Debian Codegraph @

packages/seacas/libraries/svdi/cgi/x11_x11xlate.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2022, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 /*
9 * SUN DEC/ULTRIX ALLIANT : C routines must have underscores
10 * SGI CONVEX : C routines must have underscores
11 *
12 * VAX HP IBM/aix : C routines do not have underscores
13 *
14 * CRAY/UNICOS : C routines must be capitalized,
15 * and no underscores
16 */
17 #if !defined(CRA) && !defined(ADDC_) && !defined(COUGAR)
18 #define vdmova wx11mv
19 #define vdmoni wx11mo
20 #define vdgnam wx11gn
21 #define vbiqdv wx11iv
22 #define vbiqpk wx11qp
23 #define vdlina wx11ln
24 #define vdtext wx11tx
25 #define vdpnta wx11pt
26 #define vdpoly wx11py
27 #define vdiqcp wx11cp
28 #define vdstos wx11os
29 #define vdiqos wx11io
30 #define vdstfc wx11fc
31 #define vdstbc wx11bc
32 #define vdstin wx11in
33 #define vdstls wx11ls
34 #define vdstlw wx11lw
35 #define vdstcs wx11cs
36 #define vdaabu wx11bu
37 #define vdaloc wx11lo
38 #define vdabgl wx11bl
39 #define vdakgl wx11kl
40 #define vdstla wx11la
41 #define vdinit wx11nt
42 #define vdfram wx11fr
43 #define vdterm wx11tr
44 #define vdiqdc wx11dc
45 #define vdnwpg wx11pg
46 #define vdbell wx11be
47 #define vdwait wx11wt
48 #define vdbufl wx11fl
49 #define vdstco wx11co
50 #define vdiqco wx11ic
51 #define vdescp wx11es
52 #define vdiqes wx11ie
53 #define vdiqnd wx11id
54 #define vimova wx11im
55 #define vilina wx11il
56 #define vipnta wx11ip
57 #define vitext wx11ix
58 #define viinit wx11ii
59 #define viterm wx11it
60 #define vinwpg wx11ig
61 #define vcjob vcjob
62 #define vberrh wx11er
63 #define vdloge wx11le
64 #define cdrwfs wx11wf
65 #define cdrrfs wx11rf
66 #define cdrofs wx11of
67 #define cdrof3 wx11o3
68 #define cdrcfs wx11cf
69 #define cdroff wx11ff
70 #define cdroab wx11ab
71 #define bgpbuf wx11bf
72 #define qmsbuf wx11qm
73 #define qmsbu1 wx11bf
74 #define ddcbuf wx11bf
75 #define h75buf wx11bf
76 #define btkbuf wx11bf
77 #define nmtbuf wx11bf
78 #define vbimbf wx11ib
79 #define vbpkg wx11pk
80 #define vbdev wx11dv
81 #define vdiqrs wx11qr
82 #define vdstmp wx11mp
83 #define vdstrs wx11rs
84 #define vdstrv wx11rv
85 #define vdbrgb wx11bg
86 #define vdfrgb wx11fg
87 #define vdpixl wx11px
88 #define vdpixi wx11pi
89 #define vdrpix wx11rp
90 #define vdrpxi wx11ri
91 #define vdrscl wx11rl
92 #define vdiqci wx11ci
93 #define vbstmp wx1101
94 #define vifram wx1102
95 #define vcndcm wx1103
96 #define vcattr wx1104
97 #define vbini1 wx1105
98 #define vb2hls wx1106
99 #define vb2rgb wx1107
100 #define vccolt wx1108
101 #define vccrps wx1109
102 #define vcscal wx1110
103 #define vcddim wx1111
104 #define vipoly wx1112
105 #define vbout wx1113
106 #define cgixxx cgix11
107 #endif
108
109 #if defined(CRA)
110 #define vdmova WX11MV
111 #define vdmoni WX11MO
112 #define vdgnam WX11GN
113 #define vbiqdv WX11IV
114 #define vbiqpk WX11QP
115 #define vdlina WX11LN
116 #define vdtext WX11TX
117 #define vdpnta WX11PT
118 #define vdpoly WX11PY
119 #define vdiqcp WX11CP
120 #define vdstos WX11OS
121 #define vdiqos WX11IO
122 #define vdstfc WX11FC
123 #define vdstbc WX11BC
124 #define vdstin WX11IN
125 #define vdstls WX11LS
126 #define vdstlw WX11LW
127 #define vdstcs WX11CS
128 #define vdaabu WX11BU
129 #define vdaloc WX11LO
130 #define vdabgl WX11BL
131 #define vdakgl WX11KL
132 #define vdstla WX11LA
133 #define vdinit WX11NT
134 #define vdfram WX11FR
135 #define vdterm WX11TR
136 #define vdiqdc WX11DC
137 #define vdnwpg WX11PG
138 #define vdbell WX11BE
139 #define vdwait WX11WT
140 #define vdbufl WX11FL
141 #define vdstco WX11CO
142 #define vdiqco WX11IC
143 #define vdescp WX11ES
144 #define vdiqes WX11IE
145 #define vdiqnd WX11ID
146 #define vimova WX11IM
147 #define vilina WX11IL
148 #define vipnta WX11IP
149 #define vitext WX11IX
150 #define viinit WX11II
151 #define viterm WX11IT
152 #define vinwpg WX11IG
153 #define cdrcom CDRCOM
154 #define vcjob VCJOB
155 #define vconod VCONOD
156 #define vberrh WX11ER
157 #define vdloge WX11LE
158 #define cdrwfs WX11WF
159 #define cdrrfs WX11RF
160 #define cdrofs WX11OF
161 #define cdrof3 WX11O3
162 #define cdrcfs WX11CF
163 #define cdroff WX11FF
164 #define cdroab WX11AB
165 #define bgpbuf WX11BF
166 #define qmsbuf WX11QM
167 #define qmsbu1 WX11BF
168 #define ddcbuf WX11BF
169 #define h75buf WX11BF
170 #define btkbuf WX11BF
171 #define nmtbuf WX11BF
172 #define vbimbf WX11IB
173 #define vbpkg WX11PK
174 #define vbdev WX11DV
175 #define vdiqrs WX11QR
176 #define vdstmp WX11MP
177 #define vdstrs WX11RS
178 #define vdstrv WX11RV
179 #define vdbrgb WX11BG
180 #define vdfrgb WX11FG
181 #define vdpixl WX11PX
182 #define vdpixi WX11PI
183 #define vdrpix WX11RP
184 #define vdrpxi WX11RI
185 #define vdrscl WX11RL
186 #define vdiqci WX11CI
187 #define vbstmp WX1101
188 #define vifram WX1102
189 #define vcndcm WX1103
190 #define vcattr WX1104
191 #define vbini1 WX1105
192 #define vb2hls WX1106
193 #define vb2rgb WX1107
194 #define vccolt WX1108
195 #define vccrps WX1109
196 #define vcscal WX1110
197 #define vcddim WX1111
198 #define vipoly WX1112
199 #define vbout WX1113
200 #define wx11zz WX11ZZ
201 #define cgixxx CGIX11
202 #endif
203
204 #if defined(ADDC_) || defined(COUGAR)
205 #define vdmova wx11mv_
206 #define vdmoni wx11mo_
207 #define vdgnam wx11gn_
208 #define vbiqdv wx11iv_
209 #define vbiqpk wx11qp_
210 #define vdlina wx11ln_
211 #define vdtext wx11tx_
212 #define vdpnta wx11pt_
213 #define vdpoly wx11py_
214 #define vdiqcp wx11cp_
215 #define vdstos wx11os_
216 #define vdiqos wx11io_
217 #define vdstfc wx11fc_
218 #define vdstbc wx11bc_
219 #define vdstin wx11in_
220 #define vdstls wx11ls_
221 #define vdstlw wx11lw_
222 #define vdstcs wx11cs_
223 #define vdaabu wx11bu_
224 #define vdaloc wx11lo_
225 #define vdabgl wx11bl_
226 #define vdakgl wx11kl_
227 #define vdstla wx11la_
228 #define vdinit wx11nt_
229 #define vdfram wx11fr_
230 #define vdterm wx11tr_
231 #define vdiqdc wx11dc_
232 #define vdnwpg wx11pg_
233 #define vdbell wx11be_
234 #define vdwait wx11wt_
235 #define vdbufl wx11fl_
236 #define vdstco wx11co_
237 #define vdiqco wx11ic_
238 #define vdescp wx11es_
239 #define vdiqes wx11ie_
240 #define vdiqnd wx11id_
241 #define vimova wx11im_
242 #define vilina wx11il_
243 #define vipnta wx11ip_
244 #define vitext wx11ix_
245 #define viinit wx11ii_
246 #define viterm wx11it_
247 #define vinwpg wx11ig_
248 #define cdrcom cdrcom_
249 #define vcjob vcjob_
250 #define vconod vconod_
251 #define vberrh wx11er_
252 #define vdloge wx11le_
253 #define cdrwfs wx11wf_
254 #define cdrrfs wx11rf_
255 #define cdrofs wx11of_
256 #define cdrof3 wx11o3_
257 #define cdrcfs wx11cf_
258 #define cdroff wx11ff_
259 #define cdroab wx11ab_
260 #define bgpbuf wx11bf_
261 #define qmsbuf wx11qm_
262 #define qmsbu1 wx11bf_
263 #define ddcbuf wx11bf_
264 #define h75buf wx11bf_
265 #define btkbuf wx11bf_
266 #define nmtbuf wx11bf_
267 #define vbimbf wx11ib_
268 #define vbpkg wx11pk_
269 #define vbdev wx11dv_
270 #define vdiqrs wx11qr_
271 #define vdstmp wx11mp_
272 #define vdstrs wx11rs_
273 #define vdstrv wx11rv_
274 #define vdbrgb wx11bg_
275 #define vdfrgb wx11fg_
276 #define vdpixl wx11px_
277 #define vdpixi wx11pi_
278 #define vdrpix wx11rp_
279 #define vdrpxi wx11ri_
280 #define vdrscl wx11rl_
281 #define vdiqci wx11ci_
282 #define vbstmp wx1101_
283 #define vifram wx1102_
284 #define vcndcm wx1103_
285 #define vcattr wx1104_
286 #define vbini1 wx1105_
287 #define vb2hls wx1106_
288 #define vb2rgb wx1107_
289 #define vccolt wx1108_
290 #define vccrps wx1109_
291 #define vcscal wx1110_
292 #define vcddim wx1111_
293 #define vipoly wx1112_
294 #define vbout wx1113_
295 #define wx11bf wx11bf_
296 #define wx11zz wx11zz_
297 #define cgixxx cgix11_
298 #endif
299
300 #if defined(CONVEX)
301 #define cdrcom_ _cdrcom_
302 #define cdrcm2_ _cdrcm2_
303 #define vcjob_ _vcjob_
304 #define vconod_ _vconod_
305 #define cdrunx_ _cdrunx_
306 #endif
307 /* cgix11.h - header file to define device dependent stuff for driver
308 * X.11 (x11)
309 * Sandia National Laboratories, Div 2634
310 * Sun Nov 19 12:02:52 MST 1989 - last date modified
311 */
312
313 #include "svdi.h"
314
315 /******************************************************************************/
316 /* */
317 /* type and constant declarations */
318 /* */
319 /******************************************************************************/
320
321 #define MAX_DEVICE_SURFACES 1 /* num of surfaces device supports */
322 /* ...set to 1 for interactive device */
323 #define ERROR_LIST_SIZE 10 /* number of errors stored */
324 #define COLOR_TABLE_SIZE 256 /* max color table for SVDI is 256 */
325 #define MAX_TEXT_LENGTH 136 /* max text length for SVDI is 136 */
326 #define MAX_POLYLINE -1 /* -1 = no limit */
327 #define MAX_DJ_POLYLINE -1 /* -1 = no limit */
328 #define MAX_POLYMARKER -1 /* -1 = no limit */
329 #define MAX_POLYGON 256 /* uses min of this and SVDI limit */
330 #define MAX_ARRAY 1 /* for pixel array and cell array */
331 /* ...set to 1 for non raster device */
332 #define BUFFER_SIZE 1 /* for batch device buffer routines */
333 /* ...set to 1 for interactive device */
334 #define DEFAULT_OUTFILE_NAME "" /* not used, driver builds the name */
335
336 /* end cgix11.h */
337 #include "data_def.h"
338 #include <assert.h>
339 #include <ctype.h>
340 #include <math.h>
341 #include <stdio.h>
342 #include <stdlib.h>
343 #include <string.h>
344 #include <unistd.h>
345 #if defined(CRA) || (defined(SUN) && (defined(SYSV) || defined(SVR4)))
346 #include <fcntl.h>
347 #include <sys/types.h>
348 #endif
349 #include "cdrcom.h"
350 #include "cgi.h"
351 #include "cgidef.h"
352 #include "devid.h"
353 #include "fortyp.h"
354 #include "stdtyp.h"
355 #include <sys/file.h>
356
357 /* ------------------------------------------------------------*/
358 /* >> FUNCTION PROTOTYPES */
359 /*-------------------------------------------------------------*/
360 /* cgi/vdi routines */
361 static void xactivate(anything **surf_list);
362 static void xdeactivate(anything **surf_list);
363 static void xci(anything **params, int num_surfaces, anything **surf_list);
364 static void xct(int num_surfaces, anything **surf_list);
365 static void xcxdfac(int num_surfaces, anything **surf_list);
366 static void xcpds(anything **params, int num_surfaces, anything **surf_list);
367 static void xcendpg(int num_surfaces, anything **surf_list);
368 static void xcbc(anything **params, int num_surfaces, anything **surf_list);
369 static void xcvdcx(anything **params, int num_surfaces, anything **surf_list);
370 static void xcv(anything **params, int num_surfaces, anything **surf_list);
371 static void xccl(anything **params, int num_surfaces, anything **surf_list);
372 static void xcdscl(anything **params, int num_surfaces, anything **surf_list);
373 static void xcdqerr(anything **params, anything **surf_list);
374 static void xcerhct(anything **params, int num_surfaces, anything **surf_list);
375 static void xccixp(anything **params, int num_surfaces, anything **surf_list);
376 static void xcesc(anything **params, int num_surfaces, anything **surf_list);
377 static void xcqid(anything **params, anything **surf_list);
378 static void xcqd(anything **params, anything **surf_list);
379 static void xclf(anything **params, anything **surf_list);
380 #ifndef sgi
381 static void xclpr(anything **params, anything **surf_list);
382 #endif
383 static void xcqsp(anything **params, anything **surf_list);
384 static void xclesc(anything **params, anything **surf_list);
385 static void xcqp(anything **params, anything **surf_list);
386 static void xcqcl(anything **params, anything **surf_list);
387 static void xcpl(anything **params, int num_surfaces, anything **surf_list);
388 static void xcdjpl(anything **params, int num_surfaces, anything **surf_list);
389 static void xcpm(anything **params, int num_surfaces, anything **surf_list);
390 static void xctx(anything **params, int num_surfaces, anything **surf_list);
391 static void xcpg(anything **params, int num_surfaces, anything **surf_list);
392 static void xcca(anything **params, int num_surfaces, anything **surf_list);
393 static void xcpxa(anything **params, int num_surfaces, anything **surf_list);
394 static void xclnt(anything **params, int num_surfaces, anything **surf_list);
395 static void xclnw(anything **params, int num_surfaces, anything **surf_list);
396 static void xclnc(anything **params, int num_surfaces, anything **surf_list);
397 static void xcmkt(int num_surfaces, anything **surf_list);
398 static void xcmks(anything **params, int num_surfaces, anything **surf_list);
399 static void xcmkc(anything **params, int num_surfaces, anything **surf_list);
400 static void xctxp(anything **params, int num_surfaces, anything **surf_list);
401 static void xctxc(anything **params, int num_surfaces, anything **surf_list);
402 static void xcchh(anything **params, int num_surfaces, anything **surf_list);
403 static void xccho(anything **params, int num_surfaces, anything **surf_list);
404 static void xcis(anything **params, int num_surfaces, anything **surf_list);
405 static void xcflc(anything **params, int num_surfaces, anything **surf_list);
406 static void xccsm(anything **params, int num_surfaces, anything **surf_list);
407 static void xcct(anything **params, int num_surfaces, anything **surf_list);
408 static void xcgtxx(anything **params, anything **surf_list);
409 static void xcqprl(anything **params, anything **surf_list);
410 static void xcqln(anything **params, anything **surf_list);
411 static void xcqlnt(anything **params, anything **surf_list);
412 static void xcqslw(anything **params, anything **surf_list);
413 static void xcqmk(anything **params, anything **surf_list);
414 static void xcqmkt(anything **params, anything **surf_list);
415 static void xcqsms(anything **params, anything **surf_list);
416 static void xcqchh(anything **params, anything **surf_list);
417 static void xcqfl(anything **params, anything **surf_list);
418 static void xcqc(anything **params, anything **surf_list);
419 static void xcqlna(anything **params, anything **surf_list);
420 static void xcqmka(anything **params, anything **surf_list);
421 static void xcqtxa(anything **params, anything **surf_list);
422 static void xcqfla(anything **params, anything **surf_list);
423 static void xcqcte(anything **params, anything **surf_list);
424 static void xcili(anything **params, anything **surf_list);
425 static void xcrqlc(anything **params, anything **surf_list);
426 /* utility routines */
427 static void init_state(surf_statelist *surf_state);
428 static void set_dev_descrip(void);
429 static void reset_vdi(surf_statelist *surf_state);
430 static void set_mapping(surf_statelist *surf_state);
431 static void set_clipping(surf_statelist *cur_state);
432 static void set_foreground_color(surf_statelist *surf_state, int *colors);
433 static void set_background_color(surf_statelist *surf_state, int *colors);
434 static void report_error(surf_statelist *surf_state, int e_class, int e_num, int f_id);
435 static void gettoken(int *index_p, int *numrecs_p, char *data_p, int max_chars, char *outtoken_p);
436 static int poly_clip(point *cmin, point *cmax, float *vx, float *vy, int vlen, float *xout,
437 float *yout, int *lenout);
438 static int inside_bnd(point *v, point *bmin, point *bmax, int bound_num);
439 static point intersect_bnd(point *p1, point *p2, point *bmin, point *bmax, int bound_num);
440 /* cdr routines */
441 /* -- not used with interactive devices */
442 void cdrofs(int *);
443 void cdrof3(int *, int *);
444 void cdroff(int *, int *, int *, int *);
445 void cdrrfs(int *, int *, char *, int *);
446 void cdrwfs(int *, int *, char *, int *);
447 void cdrcfs(int *, int *);
448 void cdroab(int *, int *);
449
450 static char *copy_string(char *dest, char const *source, long int elements)
451 {
452 char *d;
453 for (d = dest; d + 1 < dest + elements && *source; d++, source++) {
454 *d = *source;
455 }
456 *d = '\0';
457 return d;
458 }
459
460 /*-------------------------------------------------------------*/
461 /* >> GLOBAL VARIABLE DECLARATIONS */
462 /*-------------------------------------------------------------*/
463
464 /* variables used to maintain state list, free list */
465 static int first_free_state = -1;
466 static int last_alloc_state = -1;
467
468 /* declare one statelist per surface */
469 static surf_statelist surf_states[MAX_DEVICE_SURFACES];
470
471 /* declare one description table per device */
472 static dev_descrip_table dev_descrip;
473
474 /* variable to keep track of current statelist */
475 /* -- this is global so CDR can know which state to look at */
476 static surf_statelist *cur_state;
477
478 /* These arrays are global because of size. Used in cell and pixel array */
479 static float rarray[MAX_ARRAY], garray[MAX_ARRAY], barray[MAX_ARRAY];
480 static int varray[MAX_ARRAY];
481
482 /*-------------------------------------------------------------*/
483 /* >> CGI/SVDI DEVICE DRIVER ROUTINES */
484 /*-------------------------------------------------------------*/
485
486 void cgixxx(anything *params[], int num_surfaces, anything *surf_list[])
487 {
488 /* Main entry point */
489 switch (*(short *)params[0]) {
490 case ACTIVATE_FN: xactivate(surf_list); break;
491 case DEACTIVATE_FN: xdeactivate(surf_list); break;
492 case CI_FN: xci(params, num_surfaces, surf_list); break;
493 case CT_FN: xct(num_surfaces, surf_list); break;
494 case CXDFAC_FN: xcxdfac(num_surfaces, surf_list); break;
495 case CPDS_FN: xcpds(params, num_surfaces, surf_list); break;
496 case CENDPG_FN: xcendpg(num_surfaces, surf_list); break;
497 case CBC_FN: xcbc(params, num_surfaces, surf_list); break;
498 case CVDCX_FN: xcvdcx(params, num_surfaces, surf_list); break;
499 case CV_FN: xcv(params, num_surfaces, surf_list); break;
500 case CCL_FN: xccl(params, num_surfaces, surf_list); break;
501 case CDSCL_FN: xcdscl(params, num_surfaces, surf_list); break;
502 case CDQERR_FN: xcdqerr(params, surf_list); break;
503 case CERHCT_FN: xcerhct(params, num_surfaces, surf_list); break;
504 case CCIXP_FN: xccixp(params, num_surfaces, surf_list); break;
505 case CESC_FN: xcesc(params, num_surfaces, surf_list); break;
506 case CQID_FN: xcqid(params, surf_list); break;
507 case CQD_FN: xcqd(params, surf_list); break;
508 case CLF_FN: xclf(params, surf_list); break;
509 #ifndef sgi
510 case CLPR_FN: xclpr(params, surf_list); break;
511 #endif
512 case CQSP_FN: xcqsp(params, surf_list); break;
513 case CLESC_FN: xclesc(params, surf_list); break;
514 case CQP_FN: xcqp(params, surf_list); break;
515 case CQCL_FN: xcqcl(params, surf_list); break;
516 case CPL_FN: xcpl(params, num_surfaces, surf_list); break;
517 case CDJPL_FN: xcdjpl(params, num_surfaces, surf_list); break;
518 case CPM_FN: xcpm(params, num_surfaces, surf_list); break;
519 case CTX_FN: xctx(params, num_surfaces, surf_list); break;
520 case CPG_FN: xcpg(params, num_surfaces, surf_list); break;
521 case CCA_FN: xcca(params, num_surfaces, surf_list); break;
522 case CPXA_FN: xcpxa(params, num_surfaces, surf_list); break;
523 case CLNT_FN: xclnt(params, num_surfaces, surf_list); break;
524 case CLNW_FN: xclnw(params, num_surfaces, surf_list); break;
525 case CLNC_FN: xclnc(params, num_surfaces, surf_list); break;
526 case CMKT_FN: xcmkt(num_surfaces, surf_list); break;
527 case CMKS_FN: xcmks(params, num_surfaces, surf_list); break;
528 case CMKC_FN: xcmkc(params, num_surfaces, surf_list); break;
529 case CTXP_FN: xctxp(params, num_surfaces, surf_list); break;
530 case CTXC_FN: xctxc(params, num_surfaces, surf_list); break;
531 case CCHH_FN: xcchh(params, num_surfaces, surf_list); break;
532 case CCHO_FN: xccho(params, num_surfaces, surf_list); break;
533 case CIS_FN: xcis(params, num_surfaces, surf_list); break;
534 case CFLC_FN: xcflc(params, num_surfaces, surf_list); break;
535 case CCSM_FN: xccsm(params, num_surfaces, surf_list); break;
536 case CCT_FN: xcct(params, num_surfaces, surf_list); break;
537 case CGTXX_FN: xcgtxx(params, surf_list); break;
538 case CQPRL_FN: xcqprl(params, surf_list); break;
539 case CQLN_FN: xcqln(params, surf_list); break;
540 case CQLNT_FN: xcqlnt(params, surf_list); break;
541 case CQSLW_FN: xcqslw(params, surf_list); break;
542 case CQMK_FN: xcqmk(params, surf_list); break;
543 case CQMKT_FN: xcqmkt(params, surf_list); break;
544 case CQSMS_FN: xcqsms(params, surf_list); break;
545 case CQCHH_FN: xcqchh(params, surf_list); break;
546 case CQFL_FN: xcqfl(params, surf_list); break;
547 case CQC_FN: xcqc(params, surf_list); break;
548 case CQLNA_FN: xcqlna(params, surf_list); break;
549 case CQMKA_FN: xcqmka(params, surf_list); break;
550 case CQTXA_FN: xcqtxa(params, surf_list); break;
551 case CQFLA_FN: xcqfla(params, surf_list); break;
552 case CQCTE_FN: xcqcte(params, surf_list); break;
553 case CILI_FN: xcili(params, surf_list); break;
554 case CRQLC_FN: xcrqlc(params, surf_list); break;
555 } /* end switch */
556 } /* end cgixxx */
557
558 /* ACTIVATE */
559 static void xactivate(anything **surf_list)
560 {
561 int new_state; /* index of new state to use */
562
563 if (first_free_state >= 0) { /* there is free one, use it */
564 new_state = first_free_state;
565 first_free_state = surf_states[new_state].next_free_state;
566 }
567 else if (last_alloc_state < MAX_DEVICE_SURFACES - 1) {
568 new_state = last_alloc_state + 1; /* can alloc one */
569 ++last_alloc_state;
570 }
571 else { /* none available */
572 new_state = -1;
573 } /* end if */
574
575 if (new_state < 0) { /* problem, report error & go away */
576 surf_list[0] = NULL;
577 return;
578 } /* end if problem */
579
580 /* got new state, init it */
581 surf_states[new_state].cgi_inited = CNO;
582 surf_states[new_state].this_index = new_state; /* save for dealloc */
583 /* -- for batch devices */
584 copy_string(surf_states[new_state].filename, DEFAULT_OUTFILE_NAME, 100);
585 surf_states[new_state].file_d = -1;
586
587 /* set surface state_list pointer to point to this state list */
588 surf_list[0] = (anything *)&(surf_states[new_state]);
589
590 } /* end xactivate */
591
592 /* DEACTIVATE */
593 static void xdeactivate(anything **surf_list)
594 {
595 /* deallocate memory allocated for cgi state list */
596
597 int index; /* which state is this surface linked to */
598
599 index = ((surf_statelist *)surf_list[0])->this_index;
600 if ((index >= 0) && (index < MAX_DEVICE_SURFACES)) {
601 surf_states[index].next_free_state = first_free_state;
602 first_free_state = index;
603 } /* end if */
604
605 /* unlink cgi state list from surface */
606 surf_list[0] = NULL;
607
608 } /* end xdeactivate */
609
610 /* INITIALIZE */
611 static void xci(anything **params, int num_surfaces, anything **surf_list)
612 {
613 int i; /* index for loop on surf_list */
614 float zero = 0.;
615 int izero = 0;
616
617 for (i = 0; i < num_surfaces; ++i) {
618
619 /* cur_state is global - points to current statelist */
620 cur_state = (surf_statelist *)surf_list[i];
621
622 /* initialize/reinit SVDI and/or set device descript table */
623 /* -- this needs to happen before calling init_state */
624
625 if (cur_state->cgi_inited == CNO) { /* this surface has never been
626 initialized */
627 vdinit(&zero, &izero);
628
629 /* set device descript table for this device only once */
630 if (dev_descrip.set_flag == FALSE) {
631 set_dev_descrip();
632 dev_descrip.set_flag = TRUE;
633 } /* end if set_flag */
634 } /* end if surface not initialized */
635
636 else { /* this surface has been initialized once already */
637
638 /* reset SVDI attributes */
639 reset_vdi(cur_state);
640
641 /* if prepare drawing surface, issue a new page */
642 if (*(int *)params[1] == CYES) {
643 vdnwpg();
644 }
645 } /* end else surface initialized */
646
647 /* initialize/reinitialize the default device state */
648 init_state(cur_state);
649
650 /* set cgi_inited to initialized */
651 cur_state->cgi_inited = CYES;
652
653 } /* end for each surface */
654 } /* end xci */
655
656 /* TERMINATE */
657 static void xct(int num_surfaces, anything **surf_list)
658 {
659 int i; /* index for loop on surfaces */
660
661 for (i = 0; i < num_surfaces; ++i) {
662
663 cur_state = (surf_statelist *)surf_list[i];
664 if (cur_state->cgi_inited != CYES) {
665 break;
666 }
667
668 /* terminate and set state to uninitialized */
669 vdterm();
670 cur_state->cgi_inited = CNO;
671
672 } /* end for each surface */
673 } /* end xct */
674
675 /* EXECUTE DEFERRED ACTIONS */
676 static void xcxdfac(int num_surfaces, anything **surf_list)
677 {
678 int i; /* index for loop on surfaces */
679
680 for (i = 0; i < num_surfaces; ++i) {
681
682 cur_state = (surf_statelist *)surf_list[i];
683 if (cur_state->cgi_inited != CYES) {
684 break;
685 }
686
687 vdbufl();
688
689 } /* end for each surface */
690 } /* end xcxdfac */
691
692 /* PREPARE DRAWING SURFACE */
693 static void xcpds(anything **params, int num_surfaces, anything **surf_list)
694 {
695 int i; /* index for loop on surfaces */
696
697 for (i = 0; i < num_surfaces; ++i) {
698
699 cur_state = (surf_statelist *)surf_list[i];
700 if (cur_state->cgi_inited != CYES) {
701 break;
702 }
703
704 /* new page if page has been marked or parameter is forced */
705 if (cur_state->pic_dirty == CDIRTY || *(int *)params[1] == CFORCC) {
706 vdnwpg();
707 cur_state->pic_dirty = CCLEAN;
708 }
709
710 } /* end for each surface */
711 } /* end xcpds */
712
713 /* END PAGE */
714 static void xcendpg(int num_surfaces, anything **surf_list)
715 {
716 int i; /* index for loop on surfaces */
717
718 for (i = 0; i < num_surfaces; ++i) {
719
720 cur_state = (surf_statelist *)surf_list[i];
721 if (cur_state->cgi_inited != CYES) {
722 break;
723 }
724
725 /* perform an implicit execute deferred actions */
726 vdbufl();
727
728 /* for hardcopy, call new page only if page has been marked */
729 if (dev_descrip.copy_class == CHARD) {
730 if (cur_state->pic_dirty == CDIRTY) {
731 vdnwpg();
732 cur_state->pic_dirty = CCLEAN;
733 } /* end if dirty page */
734 }
735
736 } /* end for each surface */
737 } /* end xcendpg */
738
739 /* BACKGROUND COLOR */
740 static void xcbc(anything **params, int num_surfaces, anything **surf_list)
741 {
742 int i; /* index for loop on surfaces */
743 int bg_color[3]; /* temporary array */
744
745 bg_color[0] = *(int *)params[1];
746 bg_color[1] = *(int *)params[2];
747 bg_color[2] = *(int *)params[3];
748
749 for (i = 0; i < num_surfaces; ++i) {
750
751 cur_state = (surf_statelist *)surf_list[i];
752 if (cur_state->cgi_inited != CYES) {
753 break;
754 }
755
756 set_background_color(cur_state, bg_color);
757
758 } /* end for each surface */
759 } /* end xcbc */
760
761 /* VDC EXTENT */
762 static void xcvdcx(anything **params, int num_surfaces, anything **surf_list)
763 {
764 int i; /* index for loop on surfaces */
765
766 for (i = 0; i < num_surfaces; ++i) {
767
768 cur_state = (surf_statelist *)surf_list[i];
769 if (cur_state->cgi_inited != CYES) {
770 break;
771 }
772
773 /* store the values in the state list */
774 /* default integer precision is 16 - check range */
775 if (*(float *)params[1] > 32767.0f || *(float *)params[2] > 32767.0f ||
776 *(float *)params[3] > 32767.0f || *(float *)params[4] > 32767.0f ||
777 *(float *)params[1] < -32767.0f || *(float *)params[2] < -32767.0f ||
778 *(float *)params[3] < -32767.0f || *(float *)params[4] < -32767.0f) {
779 /* error 1:-103 VDC Extent out of range. Function ignored */
780 report_error(cur_state, 1, -103, *(short *)params[0]);
781 return;
782 } /* end if error */
783
784 /* no error */
785 cur_state->vdc1.x = *(float *)params[1];
786 cur_state->vdc1.y = *(float *)params[2];
787 cur_state->vdc2.x = *(float *)params[3];
788 cur_state->vdc2.y = *(float *)params[4];
789 /* end else no error */
790
791 /* VDC to viewport (in NDC) mapping */
792 /* -- this routine sets effective viewport in VDC and
793 NDC (forcing isotropic mapping) and the mapping scale */
794 set_mapping(cur_state);
795
796 /* determine new effective clipping rectangle */
797 /* ..First figure out the min and max VDC points. Since
798 * the user cannot change the clip rectangle, the min and
799 * max clip rectangle points are known. (min = clip_rect1 = [0,0];
800 * max = clip_rect2 = [32767.,32767.])
801 */
802 /* need to check for degenerate case */
803 cur_state->eff_clip_rect1.x =
804 max(min(cur_state->vdc1.x, cur_state->vdc2.x), cur_state->clip_rect1.x);
805 cur_state->eff_clip_rect1.y =
806 max(min(cur_state->vdc1.y, cur_state->vdc2.y), cur_state->clip_rect1.y);
807 cur_state->eff_clip_rect2.x =
808 min(max(cur_state->vdc1.x, cur_state->vdc2.x), cur_state->clip_rect2.x);
809 cur_state->eff_clip_rect2.y =
810 min(max(cur_state->vdc1.y, cur_state->vdc2.y), cur_state->clip_rect2.y);
811
812 /* set clipping region */
813 set_clipping(cur_state);
814
815 } /* end for each surface */
816 } /* end xcvdcx */
817
818 /* DEVICE VIEWPORT */
819 static void xcv(anything **params, int num_surfaces, anything **surf_list)
820 {
821 int i; /* index for loop on surfaces */
822
823 for (i = 0; i < num_surfaces; ++i) {
824
825 cur_state = (surf_statelist *)surf_list[i];
826 if (cur_state->cgi_inited != CYES) {
827 break;
828 }
829
830 /* viewport - default viewport specification mode is FRACTION OF
831 * DRAWING SURFACE. Thus, the viewport (0,0),(1,1) corresponds to
832 * the lower and upper corners, respectively, of the default
833 * device viewport, which is the largest unrotated rectangular area
834 * visible on the drawing surface. Numbers outside the range
835 * [0.0...1.0] may be specified.
836 */
837
838 /* store values in state list */
839 cur_state->vp1.x = *(float *)params[1];
840 cur_state->vp1.y = *(float *)params[2];
841 cur_state->vp2.x = *(float *)params[3];
842 cur_state->vp2.y = *(float *)params[4];
843
844 /* do VDC to NDC mapping */
845 /* -- this routine sets effective viewports in VDC and
846 NDC (forcing isotropic mapping) and the mapping scale */
847 set_mapping(cur_state);
848
849 /* set clipping region */
850 set_clipping(cur_state);
851
852 } /* end for each surface */
853 } /* end xcv */
854
855 /* CLIP INDICATOR */
856 static void xccl(anything **params, int num_surfaces, anything **surf_list)
857 {
858 int i; /* index for loop on surfaces */
859
860 for (i = 0; i < num_surfaces; ++i) {
861
862 cur_state = (surf_statelist *)surf_list[i];
863 if (cur_state->cgi_inited != CYES) {
864 break;
865 }
866
867 /* check for a legal enumerated value, store in state table
868 and set the clipping region */
869 if (*(int *)params[1] == CON || *(int *)params[1] == COFF) {
870 cur_state->clip_indicator = *(int *)params[1];
871 set_clipping(cur_state);
872 }
873 else {
874 /* error 1:-101 Enumerated parameter out of range. Function ignored */
875 report_error(cur_state, 1, -101, *(short *)params[0]);
876 }
877
878 } /* end for each surface */
879 } /* end xccl */
880
881 /* DRAWING SURFACE CLIP INDICATOR */
882 static void xcdscl(anything **params, int num_surfaces, anything **surf_list)
883 {
884 int i; /* index for loop on surfaces */
885
886 for (i = 0; i < num_surfaces; ++i) {
887
888 cur_state = (surf_statelist *)surf_list[i];
889 if (cur_state->cgi_inited != CYES) {
890 break;
891 }
892
893 /* check for a legal enumerated value, store in state table
894 and set the clipping region */
895 if (*(int *)params[1] == CDCOFF || *(int *)params[1] == CDCREC || *(int *)params[1] == CVPORT) {
896 cur_state->ds_clip_indicator = *(int *)params[1];
897 set_clipping(cur_state);
898 }
899 else {
900 /* error 1:-101 Enumerated parameter out of range. Function ignored */
901 report_error(cur_state, 1, -101, *(short *)params[0]);
902 }
903
904 } /* end for each surface */
905 } /* end xcdscl */
906
907 /* DEQUEUE ERROR REPORTS */
908 static void xcdqerr(anything **params, anything **surf_list)
909 {
910 int i; /* loop variable */
911 int max_ret; /* max number of errors to return */
912
913 /* there is only one surface for inquiries */
914 cur_state = (surf_statelist *)surf_list[0];
915 if (cur_state->cgi_inited != CYES) {
916 return;
917 }
918
919 /* find the number of errors to be returned */
920 max_ret = (*(int *)params[1] < cur_state->err_count) ? *(int *)params[1] : cur_state->err_count;
921
922 for (i = 0; i < max_ret; i++) {
923
924 ((int *)params[5])[i] = cur_state->err_queue[cur_state->err_head_ptr].err_class;
925 ((int *)params[6])[i] = cur_state->err_queue[cur_state->err_head_ptr].err_num;
926 ((int *)params[7])[i] = cur_state->err_queue[cur_state->err_head_ptr].func_id;
927
928 /* update the head of list ptr */
929 cur_state->err_head_ptr++;
930 if (cur_state->err_head_ptr == ERROR_LIST_SIZE) {
931 cur_state->err_head_ptr = 0;
932 }
933
934 /* decrement the count of errors */
935 cur_state->err_count--;
936
937 } /* end for i */
938
939 /* number of reports remaining in the queue */
940 *(int *)params[3] = cur_state->err_count;
941
942 /* number of reports returned */
943 *(int *)params[4] = i;
944
945 /* validity flag */
946 *(int *)params[2] = CVAL;
947
948 } /* end xcdqerr */
949
950 /* ERROR HANDLING CONTROL */
951 static void xcerhct(anything **params, int num_surfaces, anything **surf_list)
952 {
953 int i, j; /* loop indices */
954
955 for (i = 0; i < num_surfaces; ++i) {
956
957 cur_state = (surf_statelist *)surf_list[i];
958 if (cur_state->cgi_inited != CYES) {
959 break;
960 }
961
962 /* store error control level in state list */
963 for (j = 0; j < *(int *)params[1]; j++) {
964
965 /* check enumeration types */
966 if (((int *)params[3])[j] != CEHON && ((int *)params[3])[j] != CEHROF &&
967 ((int *)params[3])[j] != CEHDOF) {
968 /* error 1:-101 Enumerated parameter out of range. Function ignored */
969 report_error(cur_state, 1, -101, *(short *)params[0]);
970
971 /* check for legal index */
972 }
973 else if (((int *)params[2])[j] < 1 || ((int *)params[2])[j] > MAX_ERROR_CLASS) {
974 /* error 1:-102 Index out of range. Function ignored */
975 report_error(cur_state, 1, -102, *(short *)params[0]);
976 }
977 else {
978 cur_state->err_flag[((int *)params[2])[j] - 1] = ((int *)params[3])[j];
979 }
980 } /* end for j */
981
982 } /* end for each surface */
983 } /* end xcerhct */
984
985 /* COLOR INDEX PRECISION */
986 static void xccixp(anything **params, int num_surfaces, anything **surf_list)
987 {
988 int i; /* index for loop on surfaces */
989
990 /* I'm not doing anything with color index precision now */
991
992 for (i = 0; i < num_surfaces; ++i) {
993
994 cur_state = (surf_statelist *)surf_list[i];
995 if (cur_state->cgi_inited != CYES) {
996 break;
997 }
998
999 if (*(int *)params[1] == 8 || *(int *)params[1] == 16 || *(int *)params[1] == 24 ||
1000 *(int *)params[1] == 32) {
1001 cur_state->color_index_prec = *(int *)params[1];
1002 }
1003 else {
1004 /* error 3:204 Selected precision not supported */
1005 report_error(cur_state, 3, 204, *(short *)params[0]);
1006 }
1007
1008 } /* end for each surface */
1009 } /* end xccixp */
1010
1011 /* ESCAPE */
1012 static void xcesc(anything **params, int num_surfaces, anything **surf_list)
1013 {
1014 int i; /* index for loop on surfaces */
1015 int j; /* loop index */
1016 int first; /* logical; TRUE = first time through */
1017 char data[80]; /* temp for parsing data record */
1018 char c; /* single character */
1019 int vdi_esc; /* used for SVDI escape call */
1020 int count; /* used for SVDI escape call */
1021 float args[10]; /* used for SVDI escape call */
1022 int tokenindex; /* index in data record of first char */
1023 /* after end of token*/
1024 first = TRUE;
1025
1026 for (i = 0; i < num_surfaces; ++i) {
1027
1028 cur_state = (surf_statelist *)surf_list[i];
1029
1030 switch (*(int *)params[1]) {
1031
1032 case XEMFNM: /* file name */
1033
1034 if (first) {
1035 tokenindex = 0; /* first char of data record */
1036
1037 /* params[4] is an added parameter - contains the string length */
1038 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1039
1040 first = FALSE;
1041 } /* end if first */
1042
1043 /* this function must be called before CI */
1044 /* ...error message if not?? check for legal file name?? */
1045 if (cur_state->cgi_inited != CYES) {
1046 copy_string(cur_state->filename, data, 100);
1047 }
1048
1049 break;
1050
1051 case XEAGMD: /* set terminal to alpha/graphics */
1052
1053 if (first) {
1054 tokenindex = 0; /* first char of data record */
1055
1056 /* params[4] is an added parameter - contains the string length */
1057 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1058
1059 /* SVDI takes care of 'graphics', check for 'alpha' */
1060 j = 0;
1061 while ((c = data[j++])) {
1062 if (isalpha(c) && isupper(c)) {
1063 data[j - 1] = tolower(c);
1064 }
1065 }
1066
1067 first = FALSE;
1068 } /* end if first */
1069
1070 if (strncmp(data, "alpha", 5) == 0) {
1071 vdbufl();
1072 }
1073
1074 break;
1075
1076 case XESVDI: /* SVDI escape */
1077
1078 if (first) {
1079 tokenindex = 0; /* first char of data record */
1080
1081 /* first token is SVDI escape number */
1082 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1083 vdi_esc = strtol(data, NULL, 10);
1084
1085 /* second token is number of parameters to SVDI escape */
1086 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1087 count = strtol(data, NULL, 10);
1088
1089 /* the rest of the tokens contain the arguments */
1090 for (j = 0; j < count && j < 10; j++) {
1091 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1092 args[j] = (float)strtod(data, NULL);
1093 }
1094
1095 first = FALSE;
1096 } /* end if first */
1097
1098 vdescp(&vdi_esc, &count, args);
1099
1100 break;
1101
1102 case XEPGSZ: /* Page size */
1103
1104 if (first) {
1105 tokenindex = 0; /* first char of data record */
1106
1107 /* first token is page size in x */
1108 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1109 args[0] = (float)strtod(data, NULL);
1110
1111 /* second token is page size in y */
1112 gettoken(&tokenindex, (int *)params[2], (char *)params[3], 80, data);
1113 args[1] = (float)strtod(data, NULL);
1114
1115 /* page size svdi number is 1400 */
1116 vdi_esc = 1400;
1117 count = 2;
1118
1119 first = FALSE;
1120 } /* end if first */
1121
1122 vdescp(&vdi_esc, &count, args);
1123
1124 break;
1125
1126 case XEBELL: /* Ring the bell */ vdbell(); break;
1127
1128 default:
1129 /* error 2:001 Request unsupported feature. Function ignored */
1130 report_error(cur_state, 2, 001, *(short *)params[0]);
1131 break;
1132
1133 } /* end switch */
1134 } /* end for i */
1135 } /* end xcesc */
1136
1137 /* INQUIRE DEVICE IDENTIFICATION */
1138 static void xcqid(anything **params, anything **surf_list)
1139 {
1140 char *cgi_devid; /* pointer to character device id */
1141 int maxchr; /* max number of chars in device id */
1142 int qdc_index = 23; /* index for inquiries to vdiqdc */
1143 float value; /* value returned by vdiqdc */
1144 static int set = FALSE; /* flag whether values have been set yet */
1145
1146 /* there is only one surface for inquiries */
1147 cur_state = (surf_statelist *)surf_list[0];
1148 if (cur_state->cgi_inited != CYES) {
1149 return;
1150 }
1151
1152 if (!set) { /* values have't been set, inquire SVDI */
1153
1154 set = TRUE;
1155
1156 /* device id */
1157 vdiqdc(&qdc_index, &value);
1158 cgi_devid = get_devid_char(value);
1159 if (cgi_devid != NULL) {
1160 copy_string(dev_descrip.dev_id, cgi_devid, 4);
1161 }
1162
1163 } /* end if not set */
1164
1165 /* response validity */
1166 *(int *)params[2] = CVAL;
1167
1168 /* return device class - this is set in set_dev_descrip() */
1169 *(int *)params[3] = dev_descrip.dev_class;
1170
1171 /* return device id */
1172 maxchr = (*(int *)params[1] > 3) ? 3 : *(int *)params[1];
1173 copy_string((char *)params[4], dev_descrip.dev_id, maxchr);
1174 *((char *)params[4] + maxchr) = '\0';
1175
1176 } /* end xcqid */
1177
1178 /* INQUIRE DEVICE DESCRIPTION */
1179 static void xcqd(anything **params, anything **surf_list)
1180 {
1181 int qdc_index; /* index for inquiries to vdiqdc */
1182 float value; /* value returned by vdiqdc */
1183 static int set = FALSE; /* flag whether values have been set */
1184
1185 /* there is only one surface for inquiries */
1186 cur_state = (surf_statelist *)surf_list[0];
1187 if (cur_state->cgi_inited != CYES) {
1188 return;
1189 }
1190
1191 if (!set) { /* values have't been set, inquire SVDI */
1192
1193 set = TRUE;
1194
1195 /* display type */
1196 qdc_index = 2;
1197 vdiqdc(&qdc_index, &value);
1198 if (value == 0.) {
1199 dev_descrip.display_type = CVECT;
1200 }
1201 else if (value == 1.) {
1202 dev_descrip.display_type = CRAST;
1203 }
1204 else {
1205 dev_descrip.display_type = COTHER;
1206 }
1207
1208 /* background color capability */
1209 qdc_index = 32;
1210 vdiqdc(&qdc_index, &value);
1211 dev_descrip.bcolor_cap = (value == 1.0) ? CYES : CNO;
1212
1213 /* dynamic modification for background color */
1214 dev_descrip.dynamic_mod_bg = CIRG;
1215
1216 /* dynamic modification for VDC to device mapping */
1217 dev_descrip.dynamic_mod_map = CIRG;
1218
1219 /* width and height in millimeters */
1220 /* ...SVDI returns 0 if it doesn't know. CGI does this also */
1221 qdc_index = 17;
1222 vdiqdc(&qdc_index, &dev_descrip.draw_surf_width);
1223 qdc_index = 18;
1224 vdiqdc(&qdc_index, &dev_descrip.draw_surf_height);
1225
1226 /* pixel location relative to coordinates */
1227 dev_descrip.pix_loc = CPXON;
1228
1229 } /* end haven't been set */
1230
1231 /* validity flag */
1232 *(int *)params[1] = CVAL;
1233
1234 /* stuff info into return values */
1235 /* ...copy_class and device corners are set in set_dev_descrip() */
1236 *(int *)params[2] = dev_descrip.copy_class;
1237 *(int *)params[3] = dev_descrip.display_type;
1238 *(int *)params[4] = dev_descrip.bcolor_cap;
1239 *(int *)params[5] = dev_descrip.dynamic_mod_bg;
1240 *(int *)params[6] = dev_descrip.dynamic_mod_map;
1241 *(int *)params[7] = dev_descrip.dc1.x;
1242 *(int *)params[8] = dev_descrip.dc1.y;
1243 *(int *)params[9] = dev_descrip.dc2.x;
1244 *(int *)params[10] = dev_descrip.dc2.y;
1245 *(float *)params[11] = dev_descrip.draw_surf_width;
1246 *(float *)params[12] = dev_descrip.draw_surf_height;
1247 *(int *)params[13] = dev_descrip.pix_loc;
1248
1249 } /* end xcqd */
1250
1251 /* LOOKUP FUNCTION SUPPORT */
1252 static void xclf(anything **params, anything **surf_list)
1253 {
1254 int i; /* index for loop on surfaces */
1255 int qdc_index = 24; /* for inquire SVDI */
1256 static float poly_support = -1.; /* level of SVDI poly support */
1257
1258 /* there is only one surface for inquiries */
1259 cur_state = (surf_statelist *)surf_list[0];
1260 if (cur_state->cgi_inited != CYES) {
1261 return;
1262 }
1263
1264 for (i = 0; i < *(int *)params[1]; i++) {
1265
1266 switch (*(short *)params[0]) {
1267 case ACTIVATE_FN: ((int *)params[5])[i] = CSYES; break;
1268 case DEACTIVATE_FN: ((int *)params[5])[i] = CSYES; break;
1269 case CI_FN: ((int *)params[5])[i] = CSYES; break;
1270 case CT_FN: ((int *)params[5])[i] = CSYES; break;
1271 case CXDFAC_FN: ((int *)params[5])[i] = CSYES; break;
1272 case CPDS_FN: ((int *)params[5])[i] = CSYES; break;
1273 case CENDPG_FN: ((int *)params[5])[i] = CSYES; break;
1274 case CBC_FN: ((int *)params[5])[i] = CSYES; break;
1275 case CVDCX_FN: ((int *)params[5])[i] = CSYES; break;
1276 case CV_FN: ((int *)params[5])[i] = CSYES; break;
1277 case CCL_FN: ((int *)params[5])[i] = CSYES; break;
1278 case CDSCL_FN: ((int *)params[5])[i] = CSYES; break;
1279 case CDQERR_FN: ((int *)params[5])[i] = CSYES; break;
1280 case CERHCT_FN: ((int *)params[5])[i] = CSYES; break;
1281 case CCIXP_FN: ((int *)params[5])[i] = CSNO; break;
1282 case CESC_FN: ((int *)params[5])[i] = CSYES; break;
1283 case CQID_FN: ((int *)params[5])[i] = CSYES; break;
1284 case CQD_FN: ((int *)params[5])[i] = CSYES; break;
1285 case CLF_FN: ((int *)params[5])[i] = CSYES; break;
1286 case CLPR_FN: ((int *)params[5])[i] = CSYES; break;
1287 case CQSP_FN: ((int *)params[5])[i] = CSYES; break;
1288 case CLESC_FN: ((int *)params[5])[i] = CSYES; break;
1289 case CQP_FN: ((int *)params[5])[i] = CSYES; break;
1290 case CQCL_FN: ((int *)params[5])[i] = CSYES; break;
1291 case CPL_FN: ((int *)params[5])[i] = CSYES; break;
1292 case CDJPL_FN: ((int *)params[5])[i] = CSYES; break;
1293 case CPM_FN: ((int *)params[5])[i] = CSYES; break;
1294 case CTX_FN: ((int *)params[5])[i] = CSYES; break;
1295 case CPG_FN:
1296 if (poly_support == -1.) {
1297 vdiqdc(&qdc_index, &poly_support);
1298 }
1299 if (poly_support < 3.) {
1300 ((int *)params[5])[i] = CSNO;
1301 }
1302 else {
1303 ((int *)params[5])[i] = CSYES;
1304 }
1305 break;
1306 case CCA_FN: ((int *)params[5])[i] = CSYES; break;
1307 case CPXA_FN: ((int *)params[5])[i] = CSYES; break;
1308 case CLNT_FN: ((int *)params[5])[i] = CSYES; break;
1309 case CLNW_FN: ((int *)params[5])[i] = CSYES; break;
1310 case CLNC_FN: ((int *)params[5])[i] = CSYES; break;
1311 case CMKT_FN: ((int *)params[5])[i] = CSYES; break;
1312 case CMKS_FN: ((int *)params[5])[i] = CSNO; break;
1313 case CMKC_FN: ((int *)params[5])[i] = CSYES; break;
1314 case CTXP_FN: ((int *)params[5])[i] = CSNO; break;
1315 case CTXC_FN: ((int *)params[5])[i] = CSNO; break;
1316 case CCHH_FN: ((int *)params[5])[i] = CSYES; break;
1317 case CCHO_FN: ((int *)params[5])[i] = CSNO; break;
1318 case CIS_FN: ((int *)params[5])[i] = CSYES; break;
1319 case CFLC_FN: ((int *)params[5])[i] = CSYES; break;
1320 case CCSM_FN: ((int *)params[5])[i] = CSYES; break;
1321 case CCT_FN: ((int *)params[5])[i] = CSYES; break;
1322 case CGTXX_FN: ((int *)params[5])[i] = CSYES; break;
1323 case CQPRL_FN: ((int *)params[5])[i] = CSYES; break;
1324 case CQLN_FN: ((int *)params[5])[i] = CSYES; break;
1325 case CQLNT_FN: ((int *)params[5])[i] = CSYES; break;
1326 case CQSLW_FN: ((int *)params[5])[i] = CSNO; break;
1327 case CQMK_FN: ((int *)params[5])[i] = CSNO; break;
1328 case CQMKT_FN: ((int *)params[5])[i] = CSYES; break;
1329 case CQSMS_FN: ((int *)params[5])[i] = CSNO; break;
1330 case CQCHH_FN: ((int *)params[5])[i] = CSYES; break;
1331 case CQFL_FN: ((int *)params[5])[i] = CSYES; break;
1332 case CQC_FN: ((int *)params[5])[i] = CSYES; break;
1333 case CQLNA_FN: ((int *)params[5])[i] = CSYES; break;
1334 case CQMKA_FN: ((int *)params[5])[i] = CSNO; break;
1335 case CQTXA_FN: ((int *)params[5])[i] = CSYES; break;
1336 case CQFLA_FN: ((int *)params[5])[i] = CSNO; break;
1337 case CQCTE_FN: ((int *)params[5])[i] = CSYES; break;
1338 case CILI_FN: ((int *)params[5])[i] = CSYES; break;
1339 case CRQLC_FN: ((int *)params[5])[i] = CSYES; break;
1340 default: ((int *)params[5])[i] = CSNO; break;
1341 } /* end switch */
1342 }
1343
1344 /* validity flag */
1345 *(int *)params[4] = CVAL;
1346
1347 } /* end xclf */
1348
1349 /* LOOKUP PROFILE SUPPORT */
1350 static void xclpr(anything **params, anything **surf_list)
1351 {
1352 int i; /* index for loop on surfaces */
1353
1354 /* there is only one surface for inquiries */
1355 cur_state = (surf_statelist *)surf_list[0];
1356 if (cur_state->cgi_inited != CYES) {
1357 return;
1358 }
1359
1360 for (i = 0; i < *(int *)params[1]; i++) {
1361 if (strncmp(((char **)params[2])[i], "1-WAY-OUTPUT", 12) != 0 ||
1362 strncmp(((char **)params[2])[i], "2-WAY-OUTPUT", 12) ||
1363 strncmp(((char **)params[2])[i], "SLATEC 1", 8) != 0) {
1364 ((int *)params[4])[i] = CSYES;
1365 }
1366 else {
1367 ((int *)params[4])[i] = CSNO;
1368 }
1369 }
1370
1371 /* validity flag */
1372 *(int *)params[3] = CVAL;
1373
1374 } /* end xclpr */
1375
1376 /* INQUIRE SUPPORTED PRECISIONS */
1377 static void xcqsp(anything **params, anything **surf_list)
1378 {
1379 /* there is only one surface for inquiries */
1380 cur_state = (surf_statelist *)surf_list[0];
1381 if (cur_state->cgi_inited != CYES) {
1382 return;
1383 }
1384
1385 /* this stuff is basically machine dependent. I return INVAL and
1386 leave it at that */
1387 *(int *)params[1] = CINVAL;
1388
1389 } /* end xcqsp */
1390
1391 /* LOOKUP ESCAPE SUPPORT */
1392 static void xclesc(anything **params, anything **surf_list)
1393 {
1394 int i; /* loop index */
1395 int esc = 1400; /* for inquire escape */
1396 int support; /* for inquire escape */
1397
1398 /* there is only one surface for inquiries */
1399 cur_state = (surf_statelist *)surf_list[0];
1400 if (cur_state->cgi_inited != CYES) {
1401 return;
1402 }
1403
1404 for (i = 0; i < *(int *)params[1]; i++) {
1405
1406 /* return YES for supported escapes, else return NO */
1407 switch (((int *)params[2])[i]) {
1408 case XEMFNM: ((int *)params[4])[i] = CSYES; break;
1409 case XEAGMD: ((int *)params[4])[i] = CSYES; break;
1410 case XESVDI: ((int *)params[4])[i] = CSYES; break;
1411 case XEBELL: ((int *)params[4])[i] = CSYES; break;
1412 case XEPGSZ:
1413 vdiqes(&esc, &support);
1414 if (support == 1 || support == 2) {
1415 ((int *)params[4])[i] = CSYES;
1416 }
1417 else {
1418 ((int *)params[4])[i] = CSNO;
1419 }
1420 break;
1421
1422 default: ((int *)params[4])[i] = CSNO; break;
1423 } /* end switch */
1424 }
1425
1426 /* validity flag */
1427 *(int *)params[3] = CVAL;
1428
1429 } /* end xclesc */
1430
1431 /* INQUIRE CURRENT PRECISIONS */
1432 static void xcqp(anything **params, anything **surf_list)
1433 {
1434 /* there is only one surface for inquiries */
1435 cur_state = (surf_statelist *)surf_list[0];
1436 if (cur_state->cgi_inited != CYES) {
1437 return;
1438 }
1439
1440 /* validity flag */
1441 *(int *)params[1] = CINVAL;
1442
1443 } /* end xcqp */
1444
1445 /* INQUIRE CLIPPING */
1446 static void xcqcl(anything **params, anything **surf_list)
1447 {
1448 /* there is only one surface for inquiries */
1449 cur_state = (surf_statelist *)surf_list[0];
1450 if (cur_state->cgi_inited != CYES) {
1451 return;
1452 }
1453
1454 /* clip indicator */
1455 *(int *)params[2] = cur_state->clip_indicator;
1456
1457 /* clip rectangle */
1458 ((float *)params[3])[0] = cur_state->clip_rect1.x;
1459 ((float *)params[3])[1] = cur_state->clip_rect1.y;
1460 ((float *)params[3])[2] = cur_state->clip_rect2.x;
1461 ((float *)params[3])[3] = cur_state->clip_rect2.y;
1462
1463 /* drawing surface clip indicator */
1464 *(int *)params[4] = cur_state->ds_clip_indicator;
1465
1466 /* drawing surface clip rectangle */
1467 /* Default is the whole drawing surface; routines to change the
1468 * drawing surface clip rectangle are not included. Since veiwport
1469 * specification mode is FRACTION OF DRAWING SURFACE, units for
1470 * rectangle are 0 - 1 */
1471 ((float *)params[5])[0] = 0.;
1472 ((float *)params[5])[1] = 0.;
1473 ((float *)params[5])[2] = 1.;
1474 ((float *)params[5])[3] = 1.;
1475
1476 /* validity flag */
1477 *(int *)params[1] = CVAL;
1478
1479 } /* end xcqcl */
1480
1481 /* POLYLINE */
1482 static void xcpl(anything **params, int num_surfaces, anything **surf_list)
1483 {
1484 int i, j; /* indices for loops */
1485 int np; /* number of points in polyline */
1486 float prev_x, prev_y; /* line end points */
1487 float cur_x, cur_y; /* line end points */
1488 float save_x, save_y; /* used for clipping */
1489 int prev_code, cur_code; /* encoded endpoints - for clipping */
1490 int mode = 0, done; /* stuff used for clipping */
1491 static unsigned mask = ~(~0u << 1); /* for masking off bits */
1492
1493 for (i = 0; i < num_surfaces; ++i) {
1494
1495 cur_state = (surf_statelist *)surf_list[i];
1496 if (cur_state->cgi_inited != CYES) {
1497 break;
1498 }
1499
1500 /* do some error checking */
1501 if (MAX_POLYLINE != -1 && *(int *)params[1] > MAX_POLYLINE) {
1502 /* error 6:301 - Number of points too large. Max is used */
1503 report_error(cur_state, 6, 301, *(short *)params[0]);
1504 np = MAX_POLYLINE;
1505 }
1506 else {
1507 np = *(int *)params[1];
1508 }
1509
1510 /* set SVDI foreground color if needed */
1511 set_foreground_color(cur_state, cur_state->line_color);
1512
1513 /* take a short cut if no clipping is on */
1514 if (!cur_state->clip_on) {
1515 for (j = 0; j < np; j++) {
1516
1517 /* map VDC to NDC */
1518 cur_x = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset;
1519 cur_y = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset;
1520 if (j == 0) {
1521 vdmova(&cur_x, &cur_y);
1522 }
1523 else {
1524 vdlina(&cur_x, &cur_y);
1525 }
1526 } /* end for j */
1527 } /* end no clipping on */
1528
1529 else { /* clipping is on */
1530
1531 /* This clipping algorithm is loosely based on the Cohen-
1532 * Sutherland algorithm. This algorithm takes into account
1533 * the fact that points are consecutive, ie., it tries to
1534 * encode each point only once. Everything is done
1535 * inline for efficiency
1536 */
1537
1538 /* convert VDC to NDC */
1539 prev_x = *((float *)params[2]) * cur_state->xscale + cur_state->xoffset;
1540 prev_y = *((float *)params[3]) * cur_state->yscale + cur_state->yoffset;
1541
1542 /* encode the point */
1543 prev_code = 0;
1544 if ((cur_state->clipmax.y - prev_y) < 0) {
1545 prev_code = prev_code | (1 << 3);
1546 }
1547 else if ((prev_y - cur_state->clipmin.y) < 0) {
1548 prev_code = prev_code | (1 << 2);
1549 }
1550
1551 if ((cur_state->clipmax.x - prev_x) < 0) {
1552 prev_code = prev_code | (1 << 1);
1553 }
1554 else if ((prev_x - cur_state->clipmin.x) < 0) {
1555 prev_code = prev_code | (1 << 0);
1556 }
1557
1558 if (!prev_code) {
1559 vdmova(&prev_x, &prev_y);
1560 }
1561
1562 j = 0;
1563 while (++j < np) {
1564
1565 /* convert VDC to NDC */
1566 cur_x = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset;
1567 cur_y = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset;
1568
1569 /* encode the endpoint */
1570 cur_code = 0;
1571 if ((cur_state->clipmax.y - cur_y) < 0) {
1572 cur_code = cur_code | (1 << 3);
1573 }
1574 else if ((cur_y - cur_state->clipmin.y) < 0) {
1575 cur_code = cur_code | (1 << 2);
1576 }
1577
1578 if ((cur_state->clipmax.x - cur_x) < 0) {
1579 cur_code = cur_code | (1 << 1);
1580 }
1581 else if ((cur_x - cur_state->clipmin.x) < 0) {
1582 cur_code = cur_code | (1 << 0);
1583 }
1584
1585 /* determine which case this is */
1586 if (!prev_code && !cur_code) { /* trivial accept */
1587 vdlina(&cur_x, &cur_y);
1588 prev_x = cur_x;
1589 prev_y = cur_y;
1590 done = TRUE;
1591 } /* end trivial accept */
1592
1593 else if (prev_code & cur_code) { /* trivial reject */
1594 prev_x = cur_x;
1595 prev_y = cur_y;
1596 prev_code = cur_code;
1597 done = TRUE;
1598 }
1599
1600 else {
1601 done = FALSE;
1602 if (prev_code) {
1603 if (cur_code) {
1604 mode = 2; /* both out */
1605 }
1606 else {
1607 mode = 1; /* prev out; cur in */
1608 }
1609 }
1610 else {
1611 mode = 3; /* prev in; cur out */
1612 }
1613 }
1614
1615 while (!done) {
1616
1617 switch (mode) {
1618
1619 case 1: /* prev out, cur in... clip */
1620 case 2: /* both out, clip prev first */
1621
1622 if (prev_code & mask) { /* clip at left edge */
1623 prev_y =
1624 prev_y + (cur_y - prev_y) * (cur_state->clipmin.x - prev_x) / (cur_x - prev_x);
1625 prev_x = cur_state->clipmin.x;
1626 }
1627 else if ((prev_code >> 1) & mask) { /* clip at right edge */
1628 prev_y =
1629 prev_y + (cur_y - prev_y) * (cur_state->clipmax.x - prev_x) / (cur_x - prev_x);
1630 prev_x = cur_state->clipmax.x;
1631 }
1632
1633 if ((prev_code >> 2) & mask) { /* clip at bottom edge */
1634 prev_x =
1635 prev_x + (cur_x - prev_x) * (cur_state->clipmin.y - prev_y) / (cur_y - prev_y);
1636 prev_y = cur_state->clipmin.y;
1637 }
1638 else if ((prev_code >> 3) & mask) { /* clip at top edge */
1639 prev_x =
1640 prev_x + (cur_x - prev_x) * (cur_state->clipmax.y - prev_y) / (cur_y - prev_y);
1641 prev_y = cur_state->clipmax.y;
1642 }
1643
1644 switch (mode) {
1645 case 1: /* not looping through, draw it */
1646 vdmova(&prev_x, &prev_y);
1647 vdlina(&cur_x, &cur_y);
1648 prev_x = cur_x;
1649 prev_y = cur_y;
1650 prev_code = cur_code;
1651 done = TRUE;
1652 break;
1653
1654 case 2: /* both were out, encode new point */
1655 prev_code = 0;
1656 if ((cur_state->clipmax.y - prev_y) < 0) {
1657 prev_code = prev_code | (1 << 3);
1658 }
1659 else if ((prev_y - cur_state->clipmin.y) < 0) {
1660 prev_code = prev_code | (1 << 2);
1661 }
1662
1663 if ((cur_state->clipmax.x - prev_x) < 0) {
1664 prev_code = prev_code | (1 << 1);
1665 }
1666 else if ((prev_x - cur_state->clipmin.x) < 0) {
1667 prev_code = prev_code | (1 << 0);
1668 }
1669
1670 if (prev_code) { /* reject it */
1671 prev_x = cur_x;
1672 prev_y = cur_y;
1673 prev_code = cur_code;
1674 done = TRUE;
1675 }
1676 else { /* prev is in */
1677 vdmova(&prev_x, &prev_y);
1678 mode = 3; /* cur is still out, go through again */
1679 }
1680 break;
1681 } /* end inner switch */
1682 break;
1683
1684 case 3: /* prev in, cur out...clip */
1685 save_x = cur_x;
1686 save_y = cur_y;
1687
1688 if (cur_code & mask) { /* clip at left edge */
1689 cur_y = cur_y + (prev_y - cur_y) * (cur_state->clipmin.x - cur_x) / (prev_x - cur_x);
1690 cur_x = cur_state->clipmin.x;
1691 }
1692 else if ((cur_code >> 1) & mask) { /* clip at right edge */
1693 cur_y = cur_y + (prev_y - cur_y) * (cur_state->clipmax.x - cur_x) / (prev_x - cur_x);
1694 cur_x = cur_state->clipmax.x;
1695 }
1696
1697 if ((cur_code >> 2) & mask) { /* clip at bottom edge */
1698 cur_x = cur_x + (prev_x - cur_x) * (cur_state->clipmin.y - cur_y) / (prev_y - cur_y);
1699 cur_y = cur_state->clipmin.y;
1700 }
1701 else if ((cur_code >> 3) & mask) { /* clip at top edge */
1702 cur_x = cur_x + (prev_x - cur_x) * (cur_state->clipmax.y - cur_y) / (prev_y - cur_y);
1703 cur_y = cur_state->clipmax.y;
1704 }
1705
1706 vdlina(&cur_x, &cur_y);
1707 prev_x = save_x;
1708 prev_y = save_y;
1709 prev_code = cur_code;
1710 done = TRUE;
1711 break;
1712
1713 default: done = TRUE; break;
1714 } /* end switch */
1715 } /* end while !done */
1716 } /* end while j*/
1717
1718 } /* end else clipping is on */
1719
1720 /* flag that the page has been marked */
1721 cur_state->pic_dirty = CDIRTY;
1722
1723 } /* end for i */
1724 } /* end xcpl */
1725
1726 /* DISJOINT POLYLINE */
1727 static void xcdjpl(anything **params, int num_surfaces, anything **surf_list)
1728 {
1729 int i, j; /* indices for loops */
1730 int np; /* number of points in polyline */
1731 float x1, y1, x2, y2; /* line endpoints in NDC */
1732 int code1, code2; /* encoded endpoints for clipping */
1733 int mode = 0, done; /* variables used for clipping */
1734 static unsigned mask = ~(~0u << 1); /* for masking off bits */
1735
1736 for (i = 0; i < num_surfaces; ++i) {
1737
1738 cur_state = (surf_statelist *)surf_list[i];
1739 if (cur_state->cgi_inited != CYES) {
1740 break;
1741 }
1742
1743 /* check for errors */
1744 if (MAX_DJ_POLYLINE != -1 && *(int *)params[1] > MAX_DJ_POLYLINE) {
1745 /* error 6:301 - Number of points too large. Max is used */
1746 report_error(cur_state, 6, 301, *(short *)params[0]);
1747 np = MAX_DJ_POLYLINE;
1748 }
1749 else {
1750 np = *(int *)params[1];
1751 }
1752
1753 /* set SVDI foreground color if needed */
1754 set_foreground_color(cur_state, cur_state->line_color);
1755
1756 /* if clipping is off, just do it */
1757 if (!cur_state->clip_on) {
1758
1759 for (j = 0; j < np - 1; j = j + 2) {
1760
1761 /* map VDC to NDC */
1762 x1 = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset;
1763 y1 = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset;
1764 x2 = *((float *)params[2] + j + 1) * cur_state->xscale + cur_state->xoffset;
1765 y2 = *((float *)params[3] + j + 1) * cur_state->yscale + cur_state->yoffset;
1766
1767 vdmova(&x1, &y1);
1768 vdlina(&x2, &y2);
1769
1770 } /* end for j */
1771 } /* end if clipping is off */
1772
1773 else { /* clipping is on */
1774
1775 /* Clip a line. Kind of based on Cohen-Sutherland algorithm.
1776 * Everything is done inline for efficiency.
1777 */
1778
1779 for (j = 0; j < np - 1; j = j + 2) {
1780
1781 /* map VDC to NDC */
1782 x1 = *((float *)params[2] + j) * cur_state->xscale + cur_state->xoffset;
1783 y1 = *((float *)params[3] + j) * cur_state->yscale + cur_state->yoffset;
1784 x2 = *((float *)params[2] + j + 1) * cur_state->xscale + cur_state->xoffset;
1785 y2 = *((float *)params[3] + j + 1) * cur_state->yscale + cur_state->yoffset;
1786
1787 /* encode the two points */
1788 code1 = 0;
1789 if ((cur_state->clipmax.y - y1) < 0) {
1790 code1 = code1 | (1 << 3);
1791 }
1792 else if ((y1 - cur_state->clipmin.y) < 0) {
1793 code1 = code1 | (1 << 2);
1794 }
1795
1796 if ((cur_state->clipmax.x - x1) < 0) {
1797 code1 = code1 | (1 << 1);
1798 }
1799 else if ((x1 - cur_state->clipmin.x) < 0) {
1800 code1 = code1 | (1 << 0);
1801 }
1802
1803 code2 = 0;
1804 if ((cur_state->clipmax.y - y2) < 0) {
1805 code2 = code2 | (1 << 3);
1806 }
1807 else if ((y2 - cur_state->clipmin.y) < 0) {
1808 code2 = code2 | (1 << 2);
1809 }
1810
1811 if ((cur_state->clipmax.x - x2) < 0) {
1812 code2 = code2 | (1 << 1);
1813 }
1814 else if ((x2 - cur_state->clipmin.x) < 0) {
1815 code2 = code2 | (1 << 0);
1816 }
1817
1818 /* determine which case this is */
1819 if (!code1 && !code2) { /* trivial accept - draw it */
1820 vdmova(&x1, &y1);
1821 vdlina(&x2, &y2);
1822 done = TRUE;
1823 } /* end trivial accept */
1824
1825 else if (code1 & code2) { /* trivial reject - do nothing */
1826 done = TRUE;
1827 }
1828 else {
1829 done = FALSE;
1830 if (code1) {
1831 if (code2) {
1832 mode = 2; /* both out */
1833 }
1834 else {
1835 mode = 1; /* x1,y1 out; x2,y2 in */
1836 }
1837 }
1838 else {
1839 mode = 3; /* x1,y1 in; x2,y2 out */
1840 }
1841 }
1842
1843 while (!done) {
1844
1845 switch (mode) {
1846
1847 case 1: /* x1,y1 out, x2,y2 in... clip x1,y1*/
1848 case 2: /* both out, clip x1,y1 first */
1849
1850 if (code1 & mask) { /* clip at left edge */
1851 y1 = y1 + (y2 - y1) * (cur_state->clipmin.x - x1) / (x2 - x1);
1852 x1 = cur_state->clipmin.x;
1853 }
1854 else if ((code1 >> 1) & mask) { /* clip at right edge */
1855 y1 = y1 + (y2 - y1) * (cur_state->clipmax.x - x1) / (x2 - x1);
1856 x1 = cur_state->clipmax.x;
1857 }
1858
1859 if ((code1 >> 2) & mask) { /* clip at bottom edge */
1860 x1 = x1 + (x2 - x1) * (cur_state->clipmin.y - y1) / (y2 - y1);
1861 y1 = cur_state->clipmin.y;
1862 }
1863 else if ((code1 >> 3) & mask) { /* clip at top edge */
1864 x1 = x1 + (x2 - x1) * (cur_state->clipmax.y - y1) / (y2 - y1);
1865 y1 = cur_state->clipmax.y;
1866 }
1867
1868 switch (mode) {
1869 case 1: /* not looping through, draw it */
1870 vdmova(&x1, &y1);
1871 vdlina(&x2, &y2);
1872 done = TRUE;
1873 break;
1874
1875 case 2: /* both were out, encode new point */
1876 code1 = 0;
1877 if ((cur_state->clipmax.y - y1) < 0) {
1878 code1 = code1 | (1 << 3);
1879 }
1880 else if ((y1 - cur_state->clipmin.y) < 0) {
1881 code1 = code1 | (1 << 2);
1882 }
1883
1884 if ((cur_state->clipmax.x - x1) < 0) {
1885 code1 = code1 | (1 << 1);
1886 }
1887 else if ((x1 - cur_state->clipmin.x) < 0) {
1888 code1 = code1 | (1 << 0);
1889 }
1890
1891 if (code1) {
1892 done = TRUE; /* new point is out, reject */
1893 }
1894 else {
1895 mode = 3; /* x1,y1 in; x2,y2 out; clip x2,y2 */
1896 }
1897 break;
1898
1899 } /* end inner switch */
1900
1901 break;
1902
1903 case 3: /* x1,y1 in, x2,y2 out...clip */
1904
1905 if (code2 & mask) { /* clip at left edge */
1906 y2 = y2 + (y1 - y2) * (cur_state->clipmin.x - x2) / (x1 - x2);
1907 x2 = cur_state->clipmin.x;
1908 }
1909 else if ((code2 >> 1) & mask) { /* clip at right edge */
1910 y2 = y2 + (y1 - y2) * (cur_state->clipmax.x - x2) / (x1 - x2);
1911 x2 = cur_state->clipmax.x;
1912 }
1913
1914 if ((code2 >> 2) & mask) { /* clip at bottom edge */
1915 x2 = x2 + (x1 - x2) * (cur_state->clipmin.y - y2) / (y1 - y2);
1916 y2 = cur_state->clipmin.y;
1917 }
1918
1919 else if ((code2 >> 3) & mask) { /* clip at top edge */
1920 x2 = x2 + (x1 - x2) * (cur_state->clipmax.y - y2) / (y1 - y2);
1921 y2 = cur_state->clipmax.y;
1922 }
1923
1924 vdmova(&x1, &y1);
1925 vdlina(&x2, &y2);
1926 done = TRUE;
1927 break;
1928
1929 default: done = TRUE; break;
1930
1931 } /* end switch */
1932 } /* end while !done */
1933 } /* end for j */
1934 } /* end else clipping is on */
1935
1936 /* flag that the page has been marked */
1937 cur_state->pic_dirty = CDIRTY;
1938
1939 } /* end for i */
1940 } /* end xcdjpl */
1941
1942 /* POLYMARKER */
1943 static void xcpm(anything **params, int num_surfaces, anything **surf_list)
1944 {
1945 int i, j; /* indices for loops */
1946 int np; /* number of points */
1947 float *x, *y; /* x,y values */
1948 float x_vdi, y_vdi; /* x,y values in NDC */
1949 int ok; /* flag TRUE =mark lies in clip region */
1950
1951 for (i = 0; i < num_surfaces; ++i) {
1952
1953 np = *(int *)params[1];
1954 x = (float *)params[2];
1955 y = (float *)params[3];
1956
1957 cur_state = (surf_statelist *)surf_list[i];
1958 if (cur_state->cgi_inited != CYES) {
1959 break;
1960 }
1961
1962 /* check for errors */
1963 if (MAX_POLYMARKER != -1 && *(int *)params[1] > MAX_POLYMARKER) {
1964 /* error 6:301 - Number of points too large. Max is used */
1965 report_error(cur_state, 6, 301, *(short *)params[0]);
1966 np = MAX_POLYMARKER;
1967 }
1968 else {
1969 np = *(int *)params[1];
1970 }
1971
1972 /* set SVDI foreground color if needed */
1973 set_foreground_color(cur_state, cur_state->mark_color);
1974
1975 /* set marker type */
1976 /* --only support "dot" for now - so nothing to set */
1977
1978 /* set marker size */
1979 /* --only support "dot" for now - so nothing to set */
1980
1981 for (j = 0; j < np; j++) {
1982
1983 /* map VDC to NDC */
1984 x_vdi = x[j] * cur_state->xscale + cur_state->xoffset;
1985 y_vdi = y[j] * cur_state->yscale + cur_state->yoffset;
1986
1987 ok = TRUE;
1988 if (cur_state->clip_on) { /* clip is on */
1989 /* ...clip the whole polymarker - it's in or it's out */
1990 ok = ((x_vdi <= cur_state->clipmax.x && x_vdi >= cur_state->clipmin.x) &&
1991 (y_vdi <= cur_state->clipmax.y && y_vdi >= cur_state->clipmin.y));
1992 }
1993
1994 if (ok) {
1995 vdpnta(&x_vdi, &y_vdi);
1996 }
1997
1998 } /* end for j */
1999
2000 /* flag that the page has been marked */
2001 cur_state->pic_dirty = CDIRTY;
2002
2003 } /* end for i */
2004 } /* end xcpm */
2005
2006 /* TEXT */
2007 static void xctx(anything **params, int num_surfaces, anything **surf_list)
2008 {
2009 int i, j; /* indices for loops */
2010 float x, y; /* x,y starting position */
2011 char *ch; /* input character string */
2012 char c; /* 1 character */
2013 int np; /* number of chars in text string */
2014 int ich[MAX_TEXT_LENGTH]; /* array of ascii chars to pass SVDI */
2015 int ok; /* flag TRUE =line lies in clip region */
2016 float temp_array[14]; /* used for SVDI inquiries */
2017 float char_height; /* char height, in VDC or NDC */
2018 float char_width; /* char width, in VDC or NDC */
2019 int skip; /* nbr of chars to skip when clipping */
2020
2021 for (i = 0; i < num_surfaces; ++i) {
2022
2023 cur_state = (surf_statelist *)surf_list[i];
2024 if (cur_state->cgi_inited != CYES) {
2025 break;
2026 }
2027
2028 /* error checking */
2029 if (*(int *)params[3] != CFINAL) {
2030 /* compound text not supported */
2031 /* error 2:001 - Request for unsupported feature. Function ignored */
2032 report_error(cur_state, 2, 001, *(short *)params[0]);
2033 break;
2034 }
2035 /* params[5] is an added parameter which is length of string */
2036 else if (MAX_TEXT_LENGTH != -1 && *(int *)params[5] > MAX_TEXT_LENGTH) {
2037 /* error 6:301 - Number of points too large. Max is used */
2038 report_error(cur_state, 6, 301, *(short *)params[0]);
2039 np = MAX_TEXT_LENGTH;
2040 }
2041 else {
2042 np = *(int *)params[5];
2043 }
2044
2045 /* if there is nothing to draw, break */
2046 if (np <= 0) {
2047 break;
2048 }
2049
2050 /* set SVDI foreground color if needed */
2051 set_foreground_color(cur_state, cur_state->text_color);
2052
2053 /* find out what the SVDI character height/width is */
2054 vdiqos(&temp_array[1]);
2055
2056 /* convert stuff to NDC */
2057 char_width = temp_array[7];
2058 char_height = temp_array[6];
2059 /* map VDC to NDC */
2060 x = *(float *)params[1] * cur_state->xscale + cur_state->xoffset;
2061 y = *(float *)params[2] * cur_state->yscale + cur_state->yoffset;
2062
2063 ok = TRUE;
2064 skip = 0;
2065
2066 /* this text clipping assumes no backspaces, etc.,and only the
2067 * default character orientation.
2068 */
2069 if (cur_state->clip_on) { /* clipping is on, do it */
2070
2071 /* if the string doesn't fit in y, reject it */
2072 ok = (y >= cur_state->clipmin.y && (y + char_height) <= cur_state->clipmax.y);
2073
2074 if (ok) { /* ok in y, check it in x */
2075
2076 /* check for trivial reject */
2077 ok = (x < cur_state->clipmax.x && (x + (np * char_width)) > cur_state->clipmin.x);
2078
2079 if (ok) { /* it's in there, clip it */
2080
2081 /* clip to left edge */
2082 if (x < cur_state->clipmin.x) {
2083
2084 /* ...compute how many chars to skip */
2085 skip = ceil((cur_state->clipmin.x - x) / char_width);
2086 /* ...compute new x */
2087 x = x + ((float)skip * char_width);
2088 /* ...compute new number of chars */
2089 np = np - skip;
2090 }
2091
2092 /* clip to right edge */
2093 if (x + (np * char_width) > cur_state->clipmax.x) {
2094
2095 /* ...compute how many chars fit */
2096 np = (int)((cur_state->clipmax.x - x) / char_width);
2097 }
2098 } /* end if ok in x */
2099 } /* end if ok in y */
2100 } /* end if clip_on */
2101
2102 ok = ok && np > 0; /* make sure there is still some text left */
2103
2104 if (ok) { /* everything is still ok */
2105
2106 /* move to position, and draw the text */
2107 vdmova(&x, &y);
2108
2109 ch = &(((char *)params[4])[skip]);
2110 for (j = 0; j < np; j++) {
2111 c = *ch++;
2112 /* this works for ASCII machines */
2113 ich[j] = (int)c;
2114 }
2115 vdtext(&j, ich);
2116
2117 } /* end if ok */
2118
2119 } /* end for each surface */
2120 } /* end xctx */
2121
2122 /* POLYGON */
2123 static void xcpg(anything **params, int num_surfaces, anything **surf_list)
2124 {
2125 int i, j; /* indices for loops */
2126 int np; /* number of points */
2127 float *x, *y; /* x,y VDC values */
2128 float xnew[MAX_POLYGON]; /* clipped x,y values (VDC or NDC) */
2129 float ynew[MAX_POLYGON];
2130 int npnew; /* number of points after clip */
2131 float temp_array[14]; /* temp used for SVDI inquire */
2132 int qdc_index; /* for inquire SVDI */
2133 int vdi_ls; /* SVDI linestyle */
2134 int ok; /* flag TRUE =line lies in clip region */
2135 static float poly_support = -1.; /* save whether SVDI does polygons */
2136 static float vdi_polymax = -1.; /* store SVDI polygon max value */
2137
2138 /* find out SVDI support for polygons. */
2139 if (poly_support == -1.) {
2140 qdc_index = 24;
2141 vdiqdc(&qdc_index, &poly_support);
2142 }
2143
2144 /* get and store max polygon points from SVDI */
2145 if (vdi_polymax == -1.) {
2146 qdc_index = 25;
2147 vdiqdc(&qdc_index, &vdi_polymax);
2148 }
2149
2150 for (i = 0; i < num_surfaces; ++i) {
2151
2152 cur_state = (surf_statelist *)surf_list[i];
2153 if (cur_state->cgi_inited != CYES) {
2154 break;
2155 }
2156
2157 /* error checking */
2158 if (MAX_POLYGON != -1 && (*(int *)params[1] > MAX_POLYGON || *(int *)params[1] > vdi_polymax)) {
2159 /* error 6:302 - Number of points in polygon too large. Max used */
2160 report_error(cur_state, 6, 302, *(short *)params[0]);
2161 np = (MAX_POLYGON < vdi_polymax) ? MAX_POLYGON : vdi_polymax;
2162 }
2163 else {
2164 np = *(int *)params[1];
2165 }
2166
2167 x = (float *)params[2];
2168 y = (float *)params[3];
2169
2170 /* set SVDI foreground color if needed */
2171 set_foreground_color(cur_state, cur_state->fill_color);
2172
2173 /* map VDC to NDC */
2174 for (j = 0; j < np; j++) {
2175
2176 xnew[j] = *x++ * cur_state->xscale + cur_state->xoffset;
2177 ynew[j] = *y++ * cur_state->yscale + cur_state->yoffset;
2178
2179 } /* end for j */
2180
2181 ok = TRUE;
2182 if (cur_state->clip_on) { /* clip is on */
2183
2184 /* poly clip returns new x,y values and a count */
2185 /* this routine should be done inline for efficiency */
2186 ok = poly_clip(&cur_state->clipmin, &cur_state->clipmax, xnew, ynew, np, xnew, ynew, &npnew);
2187 }
2188 else { /* no clpping */
2189 npnew = np;
2190 }
2191
2192 if (ok) { /* everything's ok, do the polygon */
2193
2194 /* if hollow or if no polygon support, draw the border lines.
2195 if solid, call vdpoly */
2196 if ((cur_state->interior_style == CHOLLO) || /* hallow OR */
2197 (poly_support < 3.)) { /*no poly supp */
2198
2199 vdiqos(&temp_array[1]); /* make sure line style is solid */
2200 if (temp_array[4] != 0) {
2201 vdi_ls = 0;
2202 vdstls(&vdi_ls);
2203 }
2204
2205 vdmova(&xnew[0], &ynew[0]);
2206 for (j = 1; j < npnew; j++) {
2207 vdlina(&xnew[j], &ynew[j]);
2208 }
2209 vdlina(&xnew[0], &ynew[0]);
2210 if (temp_array[4] != 0) { /* set line style back */
2211 vdi_ls = (int)temp_array[4];
2212 vdstls(&vdi_ls);
2213 }
2214 } /* end if hollow OR no poly support */
2215 else { /* solid polygon */
2216 vdpoly(xnew, ynew, &npnew);
2217 }
2218
2219 /* flag that the page has been marked */
2220 cur_state->pic_dirty = CDIRTY;
2221
2222 } /*end if ok */
2223
2224 } /* end for i */
2225 } /* end xcpg */
2226
2227 /* CELL ARRAY */
2228 static void xcca(anything **params, int num_surfaces, anything **surf_list)
2229 {
2230 int i; /* index for loop on surfaces */
2231 int j, k; /* loop indices */
2232 int index, index_inc, count; /* array indices */
2233 int nx, ny; /* number of cells in x,y */
2234 int nx1, ny1; /* number of cells in x,y after clipping */
2235 int *cells; /* color values */
2236 int ix, iy, yinc; /* SVDI logical raster coordinates */
2237 float x1, x2, y1, y2; /* corners of rectangle in NDC */
2238 float xmin, xmax, ymin, ymax; /* SVDI raster viewport (NDC) */
2239 int xdir, ydir; /* x,y directions on the device */
2240 int imap;
2241 float xcell, ycell; /* area per cell */
2242 int ok; /* flag TRUE =line lies in clip region */
2243 int skipx, skipy; /* number of cells clipped in xmin,ymin */
2244
2245 /* if there isn't anything to draw, return */
2246 if (*(int *)params[7] == 0 || *(int *)params[8] == 0) {
2247 return;
2248 }
2249
2250 /* if cell array has negative dimension, use absolute values */
2251 nx = nx1 = abs(*(int *)params[7]);
2252 ny = ny1 = abs(*(int *)params[8]);
2253
2254 cells = (int *)params[10];
2255
2256 for (i = 0; i < num_surfaces; ++i) {
2257
2258 cur_state = (surf_statelist *)surf_list[i];
2259 if (cur_state->cgi_inited != CYES) {
2260 break;
2261 }
2262
2263 /* if color selection mode is in error, ignore function */
2264 if (cur_state->csm == -1) {
2265 break;
2266 }
2267
2268 /* for now, only allow 4 cases (same as pixel array),
2269 * where nx runs only horizontal, and ny runs vertical.
2270 * this routine needs to be fixed to allow all 8 cases
2271 * Also, this routine does not allow skewing.
2272 */
2273 if (*(float *)params[2] != *(float *)params[6] || *(float *)params[3] != *(float *)params[5]) {
2274 /* error 1:-106 Illegal cell array. Function ignored */
2275 report_error(cur_state, 1, -106, *(short *)params[0]);
2276 return;
2277 }
2278
2279 /* map corners to NDC */
2280 x1 = *(float *)params[1] * cur_state->xscale + cur_state->xoffset;
2281 x2 = *(float *)params[3] * cur_state->xscale + cur_state->xoffset;
2282
2283 y1 = *(float *)params[2] * cur_state->yscale + cur_state->yoffset;
2284 y2 = *(float *)params[4] * cur_state->yscale + cur_state->yoffset;
2285
2286 /* figure out the raster viewport limits, and figure
2287 * out x and y directions based on mappings and
2288 * rectangle orientation.
2289 */
2290 if (x1 < x2) {
2291 xmin = x1;
2292 xmax = x2;
2293 xdir = CINCR;
2294 }
2295 else {
2296 xmin = x2;
2297 xmax = x1;
2298 xdir = CDECR;
2299 }
2300
2301 if (y1 < y2) {
2302 ymin = y1;
2303 ymax = y2;
2304 ydir = CINCR;
2305 }
2306 else {
2307 ymin = y2;
2308 ymax = y1;
2309 ydir = CDECR;
2310 }
2311
2312 ok = TRUE;
2313 skipx = skipy = 0;
2314
2315 if (cur_state->clip_on) { /* clipping is on, do it */
2316
2317 /* trivial reject */
2318 ok = ((xmin < cur_state->clipmax.x && xmax > cur_state->clipmin.x) &&
2319 (ymin < cur_state->clipmax.y && ymax > cur_state->clipmin.y));
2320
2321 if (ok) { /* it's in there, clip it */
2322
2323 /* clip in x first */
2324 xcell = (xmax - xmin) / nx; /* area per cell */
2325
2326 /* clip at left edge */
2327 if (xmin < cur_state->clipmin.x) {
2328
2329 /* ...compute how many cells to skip */
2330 skipx = ceil((cur_state->clipmin.x - xmin) / xcell);
2331 /* ...compute new xmin */
2332 xmin = xmin + ((float)skipx * xcell);
2333 /* ...compute new nx */
2334 nx1 = nx - skipx;
2335 } /* end clip at left edge */
2336
2337 /* clip at right edge */
2338 if (xmax > cur_state->clipmax.x) {
2339
2340 /* ...compute new nx - how much will fit */
2341 nx1 = (int)((cur_state->clipmax.x - xmin) / xcell);
2342 /* ...compute new xmax */
2343 xmax = xmin + (nx1 * xcell);
2344 } /* end clip at right edge */
2345
2346 /* now clip in y */
2347 ycell = (ymax - ymin) / ny; /* area per cell */
2348
2349 /* clip at bottom edge */
2350 if (ymin < cur_state->clipmin.y) {
2351
2352 /* ...compute how many cells to skip */
2353 skipy = ceil((cur_state->clipmin.y - ymin) / ycell);
2354 /* ...compute new ymin */
2355 ymin = ymin + ((float)skipy * ycell);
2356 /* ...compute new ny */
2357 ny1 = ny - skipy;
2358 } /* end clip at bottom edge */
2359
2360 /* clip at top edge */
2361 if (ymax > cur_state->clipmax.y) {
2362
2363 /* ...compute new ny - how much will fit */
2364 ny1 = (int)((cur_state->clipmax.y - ymin) / ycell);
2365 /* ...compute new ymax */
2366 ymax = ymin + (ny1 * ycell);
2367 } /* end clip at top edge */
2368
2369 } /* end if ok */
2370 } /* end if clip is on */
2371
2372 /* make sure there is still something left */
2373 ok = ok && (nx1 > 0 && ny1 > 0);
2374
2375 if (ok) { /* everything is still ok */
2376
2377 /* set the raster space */
2378 vdstrs(&nx1, &ny1);
2379
2380 imap = 3;
2381 vbstmp(&imap);
2382 imap = 5;
2383 vbstmp(&imap);
2384
2385 /* set the raster viewport */
2386 vdstrv(&xmin, &xmax, &ymin, &ymax);
2387
2388 /* direct color or indexed */
2389 if (cur_state->csm == CINDEX) { /* indexed color */
2390
2391 /* Indexing into the cell array is based on clipping info
2392 * and the orientation of the rectangle. SVDI+raster puts
2393 * [0,0] at the top left corner.
2394 */
2395
2396 /* There are 4 different cases based on the orientation
2397 * of the rectangle. ( really, there are 8, but I'm not
2398 * supporting the other 4 right now ). If x is increasing,
2399 * the most natural case, the cell array will be written
2400 * out one raster line at a time, either top to bottom or
2401 * bottom to top depending on the y direction. If x is
2402 * decreasing, the cell array will have to be copied and
2403 * reordered, so it will be written out in chunks. In this
2404 * case, it will always be written out top to bottom.
2405 */
2406
2407 if (xdir == CINCR) { /* x increasing */
2408
2409 ix = 0;
2410 /* compute iy and y increment based on y direction */
2411 if (ydir == CINCR) { /* y increasing */
2412 iy = ny1 - 1;
2413 yinc = -1;
2414 }
2415 else {
2416 iy = 0;
2417 yinc = 1;
2418 }
2419
2420 /* This special case is for efficiency, since is will probably
2421 * be most of the cases: If no clipping is on and [0,0] is at
2422 * the top left (like SVDI+raster) draw the whole cell array.
2423 */
2424 if (!cur_state->clip_on && iy == 0) {
2425 count = nx * ny;
2426 vdpixi(&ix, &iy, &cells[0], &count);
2427 } /* end special case */
2428
2429 else { /* special case doesn't apply, draw one line at a time */
2430
2431 /* starting index based on clipping info */
2432 index = (ny - ny1 - skipy) * nx + skipx;
2433
2434 /* output one raster line at a time */
2435 for (k = 0; k < ny1; k++) {
2436 vdpixi(&ix, &iy, &cells[index], &nx1);
2437 index = index + nx; /* compute next index */
2438 iy = iy + yinc; /* compute next raster line */
2439 } /* end for k */
2440 } /* end else no special case */
2441 } /* end x increasing */
2442
2443 else { /* x decreasing */
2444
2445 /* always write top to bottom */
2446 ix = iy = count = 0;
2447
2448 /* starting index and index increment are based on
2449 clipping info and the y direction*/
2450
2451 if (ydir == CINCR) { /* y increasing */
2452 index = (ny1 + skipy) * nx - skipx - 1;
2453 index_inc = -nx + nx1;
2454 yinc = -1;
2455 }
2456 else { /* y decreasing */
2457 index = (ny - ny1 - skipy) * nx + (nx - 1) - skipx;
2458 index_inc = nx + nx1;
2459 yinc = 1;
2460 }
2461
2462 /* reorder the cell colors */
2463 for (k = 0; k < ny1; k++) {
2464 for (j = 0; j < nx1; j++) {
2465 assert(count < MAX_ARRAY);
2466 varray[count++] = cells[index--];
2467 }
2468
2469 /* if another row won't fit, or done, output varray */
2470 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2471 vdpixi(&ix, &iy, varray, &count);
2472 count = 0; /* reset varray counter */
2473 iy = iy + (yinc * (k + 1)); /* update iy */
2474 }
2475
2476 /* compute next index */
2477 index = index + index_inc;
2478
2479 } /* end for k */
2480 } /* end x decreasing */
2481 } /* end if indexed color */
2482
2483 else { /* direct color */
2484
2485 /* Indexing into the cells array is based on clipping info,
2486 * and the orientation of the cell array. In SVDI+raster,
2487 * the top left corner is [0,0]. For direct color, the cell
2488 * array is always drawn from top to bottom. If the cell array
2489 * is oriented with [0,0] at the the bottom left corner, the
2490 * way the cells array is indexed takes care of the flipping.
2491 */
2492
2493 ix = iy = count = 0;
2494
2495 if (xdir == CINCR) { /* x increasing */
2496
2497 /* starting index and index increment are based on
2498 clipping info and the y direction */
2499 if (ydir == CINCR) { /* y increasing */
2500 index = ((ny1 + skipy - 1) * nx * 3) + (skipx * 3);
2501 index_inc = -(nx + nx1) * 3;
2502 }
2503 else { /* y decreasing */
2504 index = (ny - ny1 - skipy) * nx * 3 + (skipx * 3);
2505 index_inc = (nx - nx1) * 3;
2506 }
2507
2508 /* store as much info as possible before calling vdpixl */
2509 for (k = 0; k < ny1; k++) {
2510 for (j = 0; j < nx1; j++) {
2511 assert(count < MAX_ARRAY);
2512 rarray[count] = (float)cells[index++] / 255.0f;
2513 garray[count] = (float)cells[index++] / 255.0f;
2514 barray[count] = (float)cells[index++] / 255.0f;
2515 count++;
2516 } /* end for j */
2517
2518 /* if another row won't fit, or done, output rgb arrays */
2519 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2520 vdpixl(&ix, &iy, rarray, garray, barray, &count);
2521 count = 0; /* reset rgb array counter */
2522 iy = k + 1; /* update iy */
2523 }
2524
2525 /* compute next index into the cells array */
2526 index = index + index_inc;
2527
2528 } /* end for k */
2529 } /* end if x increasing */
2530
2531 else { /* x decreasing */
2532
2533 /* starting index and index increment are based on
2534 clipping info and the y direction */
2535 if (ydir == CINCR) { /* y increasing */
2536 index = (ny1 + skipy) * nx * 3 - (skipx * 3) - 3;
2537 index_inc = (-nx + nx1) * 3;
2538 }
2539 else { /* y decreasing */
2540 index = (ny - ny1 - skipy) * nx * 3 + ((nx - 1) * 3) - (skipx * 3);
2541 index_inc = (nx + nx1) * 3;
2542 }
2543
2544 /* store as much info as possible before calling vdpixl */
2545 for (k = 0; k < ny1; k++) {
2546 for (j = 0; j < nx1; j++) {
2547 assert(count < MAX_ARRAY);
2548 rarray[count] = (float)cells[index] / 255.0f;
2549 garray[count] = (float)cells[index + 1] / 255.0f;
2550 barray[count] = (float)cells[index + 2] / 255.0f;
2551 index = index - 3;
2552 count++;
2553 } /* end for j */
2554
2555 /* if another row won't fit, or done, output rgb arrays */
2556 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2557 vdpixl(&ix, &iy, rarray, garray, barray, &count);
2558 count = 0; /* reset rgb array counter */
2559 iy = k + 1; /* update iy */
2560 }
2561
2562 /* compute next index into the cells array */
2563 index = index + index_inc;
2564
2565 } /* end for k */
2566 } /* end else x decreasing */
2567 } /* end else direct color */
2568
2569 /* flag that the page has been marked */
2570 cur_state->pic_dirty = CDIRTY;
2571
2572 } /* end if ok */
2573 } /* end for each surface */
2574 } /* end xcca */
2575
2576 /* PIXEL ARRAY */
2577 static void xcpxa(anything **params, int num_surfaces, anything **surf_list)
2578 {
2579 int i; /* index for loop on surfaces */
2580 int j, k; /* loop indices */
2581 int *pxclrs; /* pixel color values */
2582 int nx, ny; /* size of pixel color array */
2583 int nx1, ny1; /* number of pixels after clipping */
2584 int index, index_inc; /* index into pxclrs array */
2585 int count; /* index into temp pixel arrays */
2586 int repx, repy; /* replication in x and y */
2587 int xdir, ydir; /* x and y direction on the DEVICE */
2588 float x_orig, y_orig; /* x and y origin */
2589 float x_dist, y_dist; /* distance pixels run from the origin */
2590 int ix, iy, yinc; /* SVDI logical raster coordinates */
2591 float xmin, xmax, ymin, ymax; /* SVDI raster viewport after clipping */
2592 int ok; /* flag TRUE =line lies in clip region */
2593 int skipx, skipy; /* count pixels skipped in xmin,ymin */
2594 int imap;
2595 int qrs_index; /* index for SVDI inquiries */
2596 float temp_array[2]; /* temporary array for SVDI inquiries */
2597 float x_pxl_scale; /* for converting pixels to NDC/VDC space */
2598 float y_pxl_scale;
2599 static float x_pixels = -1.; /* number of pixels in full NDC space */
2600 static float y_pixels = -1.;
2601 float zero = 0.0;
2602
2603 /* if nx,ny,repx,or repy are non positive, nothing is drawn */
2604 if (*(int *)params[3] < 0 || *(int *)params[4] < 0 || *(int *)params[5] < 0 ||
2605 *(int *)params[6] < 0) {
2606 return;
2607 }
2608
2609 /* set up initial values */
2610 nx = nx1 = *(int *)params[3];
2611 ny = ny1 = *(int *)params[4];
2612 repx = *(int *)params[5];
2613 repy = *(int *)params[6];
2614 pxclrs = (int *)params[9];
2615
2616 /* find (and save) the number of pixels in full NDC space */
2617 if (x_pixels == -1. && y_pixels == -1.) {
2618 vdstrv(&zero, &dev_descrip.xndc_max, &zero, &dev_descrip.yndc_max);
2619 qrs_index = 2;
2620 vdiqrs(&qrs_index, temp_array);
2621 x_pixels = temp_array[0];
2622 y_pixels = temp_array[1];
2623 } /* end find number of pixels */
2624
2625 /* loop through surfaces */
2626 for (i = 0; i < num_surfaces; ++i) {
2627
2628 cur_state = (surf_statelist *)surf_list[i];
2629 if (cur_state->cgi_inited != CYES) {
2630 break;
2631 }
2632
2633 /* if color selection mode is in error, ignore function */
2634 if (cur_state->csm == -1) {
2635 break;
2636 }
2637
2638 /* check enumerated types */
2639 if ((*(int *)params[7] != CINCR && *(int *)params[7] != CDECR) ||
2640 (*(int *)params[8] != CINCR && *(int *)params[8] != CDECR)) {
2641 /* error 1:-101 enumerated parameter out of range. Function ignored */
2642 report_error(cur_state, 1, -101, *(short *)params[0]);
2643 break;
2644 }
2645
2646 /* figure out what x direction and y direction are in terms
2647 * of the device, since x direction and y direction are dependent
2648 * on the VDC to device mapping. If xscale is positive, then
2649 * VDC and VP are either both increasing or both decreasing and
2650 * x direction on the device is the same as x direction in VDC.
2651 * If xscale is negative, one is increasing and one is decreasing,
2652 * and x direction on the device is opposite of x direction in
2653 * VDC. Same holds for y (where "increasing" means bottom to top)
2654 */
2655 if (cur_state->xscale > 0) {
2656 xdir = *(int *)params[7];
2657 }
2658 else {
2659 xdir = (*(int *)params[7] == CINCR) ? CDECR : CINCR;
2660 }
2661
2662 if (cur_state->yscale > 0) {
2663 ydir = *(int *)params[8];
2664 }
2665 else {
2666 ydir = (*(int *)params[8] == CINCR) ? CDECR : CINCR;
2667 }
2668
2669 /* map to NDC */
2670
2671 /* origin */
2672 x_orig = *(float *)params[1] * cur_state->xscale + cur_state->xoffset;
2673 y_orig = *(float *)params[2] * cur_state->yscale + cur_state->yoffset;
2674
2675 /* scale to convert pixels to NDC space */
2676 x_pxl_scale = dev_descrip.xndc_max / x_pixels;
2677 y_pxl_scale = dev_descrip.yndc_max / y_pixels;
2678
2679 /* figure out raster viewport mins and maxes */
2680 x_dist = nx * repx * x_pxl_scale;
2681 y_dist = ny * repy * y_pxl_scale;
2682
2683 /* ...x is increasing or decreasing */
2684 if (xdir == CINCR) {
2685 xmin = x_orig;
2686 xmax = x_orig + x_dist;
2687 }
2688 else {
2689 xmin = x_orig - x_dist;
2690 xmax = x_orig;
2691 }
2692 /* y is increasing or decreasing */
2693 if (ydir == CINCR) {
2694 ymin = y_orig;
2695 ymax = y_orig + y_dist;
2696 }
2697 else {
2698 ymin = y_orig - y_dist;
2699 ymax = y_orig;
2700 }
2701
2702 ok = TRUE;
2703 skipx = skipy = 0;
2704
2705 if (cur_state->clip_on) { /* do the clipping */
2706
2707 /* trivial reject */
2708 ok = ((xmin < cur_state->clipmax.x && xmax > cur_state->clipmin.x) &&
2709 (ymin < cur_state->clipmax.y && ymax > cur_state->clipmin.y));
2710
2711 if (ok) { /* it's in there, clip it */
2712
2713 /* clip in x first */
2714 if (xmin < cur_state->clipmin.x) { /* ...left edge */
2715
2716 /* ...compute how many pixels to skip */
2717 skipx = ceil((cur_state->clipmin.x - xmin) / (x_pxl_scale * repx));
2718 /* ...compute new xmin */
2719 xmin = xmin + ((float)skipx * x_pxl_scale * repx);
2720 /* ...compute new nx */
2721 nx1 = nx - skipx;
2722 } /* end clip left edge */
2723
2724 if (xmax > cur_state->clipmax.x) { /* ...right edge */
2725
2726 /* ...compute new nx */
2727 nx1 = (int)((cur_state->clipmax.x - xmin) / (x_pxl_scale * repx));
2728 /* ...compute new xmax */
2729 xmax = xmin + (nx1 * x_pxl_scale * repx);
2730 } /* end clip right edge */
2731
2732 /* now clip in y */
2733 if (ymin < cur_state->clipmin.y) { /* ...bottom edge */
2734
2735 /* ...compute how many pixels to skip */
2736 skipy = ceil((cur_state->clipmin.y - ymin) / (y_pxl_scale * repy));
2737 /* ...compute new ymin */
2738 ymin = ymin + ((float)skipy * y_pxl_scale * repy);
2739 /* ...compute new ny */
2740 ny1 = ny - skipy;
2741 } /* end bottom left edge */
2742
2743 if (ymax > cur_state->clipmax.y) { /* ...top edge */
2744
2745 /* ...compute new ny */
2746 ny1 = (int)((cur_state->clipmax.y - ymin) / (y_pxl_scale * repy));
2747 /* ...comput new ymax */
2748 ymax = ymin + (ny1 * y_pxl_scale * repy);
2749 } /* end clip top edge */
2750
2751 } /* end if ok */
2752 } /* end if clip_on */
2753
2754 /* make sure there is still something to draw */
2755 ok = ok && (nx1 > 0 && ny1 > 0);
2756
2757 if (ok) { /* everything is still ok */
2758
2759 /* set the raster viewport */
2760 vdstrv(&xmin, &xmax, &ymin, &ymax);
2761
2762 imap = 2;
2763 vbstmp(&imap);
2764 imap = 5;
2765 vbstmp(&imap);
2766
2767 /* set the raster space to number of device pixels in viewport */
2768 vdstrs(&nx1, &ny1);
2769
2770 /* direct color or indexed */
2771 if (cur_state->csm == CINDEX) { /* indexed color */
2772
2773 /* Indexing into the pixel array is based on clipping info
2774 * and the orientation of the pixel array, which is
2775 * determined by whether x and y are increasing or
2776 * decreasing in VDC from the origin. SVDI+raster puts
2777 * [0,0] at the top left corner.
2778 */
2779
2780 /* There are 4 different cases based on the x and y
2781 * directions. If x is increasing, the most natural
2782 * case, the pixel array will be written out one raster
2783 * line at a time, either top to bottom or bottom to
2784 * top depending on the y direction. If x is decreasing,
2785 * the pixel array will have to be copied and reordered,
2786 * so it will be written out in chunks. In this case,
2787 * it will always be written out top to bottom.
2788 */
2789
2790 if (xdir == CINCR) { /* x increasing */
2791
2792 ix = 0;
2793 /* compute iy and y increment based on y direction */
2794 if (ydir == CINCR) { /* y increasing */
2795 iy = ny1 - 1;
2796 yinc = -1;
2797 }
2798 else { /* y decreasing */
2799 iy = 0;
2800 yinc = 1;
2801 }
2802
2803 /* This special case is for efficiency, since is will probably
2804 * be most of the cases: If no clipping is on and [0,0] is at
2805 * the top left (like SVDI+raster) draw the whole pixel array.
2806 */
2807 if (!cur_state->clip_on && iy == 0) {
2808 count = nx * ny;
2809 vdpixi(&ix, &iy, &pxclrs[0], &count);
2810 } /* end special case */
2811
2812 else { /* special case doesn't apply, draw one line at a time */
2813
2814 /* starting index based on clipping info */
2815 index = (ny - ny1 - skipy) * nx + skipx;
2816
2817 /* output one raster line at a time */
2818 for (k = 0; k < ny1; k++) {
2819 vdpixi(&ix, &iy, &pxclrs[index], &nx1);
2820 index = index + nx; /* compute next index */
2821 iy = iy + yinc; /* compute next raster line */
2822 } /* end for k */
2823 } /* end else no special case */
2824 } /* end x increasing */
2825
2826 else { /* x decreasing */
2827
2828 /* always write top to bottom */
2829 ix = iy = count = 0;
2830
2831 /* starting index and index increment are based on
2832 clipping info and the y direction*/
2833
2834 if (ydir == CINCR) { /* y increasing */
2835 index = (ny1 + skipy) * nx - skipx - 1;
2836 index_inc = -nx + nx1;
2837 yinc = -1;
2838 }
2839 else { /* y decreasing */
2840 index = (ny - ny1 - skipy) * nx + (nx - 1) - skipx;
2841 index_inc = nx + nx1;
2842 yinc = 1;
2843 }
2844
2845 /* reorder the pixel colors */
2846 for (k = 0; k < ny1; k++) {
2847 for (j = 0; j < nx1; j++) {
2848 assert(count < MAX_ARRAY);
2849 varray[count++] = pxclrs[index--];
2850 }
2851
2852 /* if another row won't fit, or done, output varray */
2853 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2854 vdpixi(&ix, &iy, varray, &count);
2855 count = 0; /* reset varray counter */
2856 iy = iy + (yinc * (k + 1)); /* update iy */
2857 }
2858
2859 /* compute next index */
2860 index = index + index_inc;
2861
2862 } /* end for k */
2863 } /* end x decreasing */
2864 } /* end if indexed color */
2865
2866 else { /* direct color */
2867
2868 /* For direct color, the color values always have to be
2869 * copied, so the raster lines are written out in chucks.
2870 * The raster lines will always be written top to bottom;
2871 * indexing and reordering of the color values will be
2872 * based on x and y direction.
2873 */
2874
2875 ix = iy = count = 0;
2876
2877 if (xdir == CINCR) { /* x increasing */
2878
2879 /* starting index and index increment are based on
2880 clipping info and the y direction */
2881 if (ydir == CINCR) { /* y increasing */
2882 index = ((ny1 + skipy - 1) * nx * 3) + (skipx * 3);
2883 index_inc = -(nx + nx1) * 3;
2884 }
2885 else { /* y decreasing */
2886 index = (ny - ny1 - skipy) * nx * 3 + (skipx * 3);
2887 index_inc = (nx - nx1) * 3;
2888 }
2889
2890 /* store as much info as possible before calling vdpixl */
2891 for (k = 0; k < ny1; k++) {
2892 for (j = 0; j < nx1; j++) {
2893 assert(count < MAX_ARRAY);
2894 rarray[count] = (float)pxclrs[index++] / 255.0f;
2895 garray[count] = (float)pxclrs[index++] / 255.0f;
2896 barray[count] = (float)pxclrs[index++] / 255.0f;
2897 count++;
2898 } /* end for j */
2899
2900 /* if another row won't fit, or done, output rgb arrays */
2901 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2902 vdpixl(&ix, &iy, rarray, garray, barray, &count);
2903 count = 0; /* reset rgb array counter */
2904 iy = k + 1; /* update iy */
2905 }
2906
2907 /* compute next index into the pxclrs array */
2908 index = index + index_inc;
2909
2910 } /* end for k */
2911 } /* end if x increasing */
2912
2913 else { /* x decreasing */
2914
2915 /* starting index and index increment are based on
2916 clipping info and the y direction */
2917 if (ydir == CINCR) { /* y increasing */
2918 index = (ny1 + skipy) * nx * 3 - (skipx * 3) - 3;
2919 index_inc = (-nx + nx1) * 3;
2920 }
2921 else { /* y decreasing */
2922 index = (ny - ny1 - skipy) * nx * 3 + ((nx - 1) * 3) - (skipx * 3);
2923 index_inc = (nx + nx1) * 3;
2924 }
2925
2926 /* store as much info as possible before calling vdpixl */
2927 for (k = 0; k < ny1; k++) {
2928 for (j = 0; j < nx1; j++) {
2929 assert(count < MAX_ARRAY);
2930 rarray[count] = (float)pxclrs[index] / 255.0f;
2931 garray[count] = (float)pxclrs[index + 1] / 255.0f;
2932 barray[count] = (float)pxclrs[index + 2] / 255.0f;
2933 index = index - 3;
2934 count++;
2935 } /* end for j */
2936
2937 /* if another row won't fit, or done, output rgb arrays */
2938 if (count + nx1 > MAX_ARRAY || k == ny1 - 1) {
2939 vdpixl(&ix, &iy, rarray, garray, barray, &count);
2940 count = 0; /* reset rgb array counter */
2941 iy = k + 1; /* update iy */
2942 }
2943
2944 /* compute next index into the pxclrs array */
2945 index = index + index_inc;
2946
2947 } /* end for k */
2948 } /* end else x decreasing */
2949 } /* end else direct color */
2950
2951 /* flag that the page has been marked */
2952 cur_state->pic_dirty = CDIRTY;
2953
2954 } /* end if ok */
2955 } /* end for each surface */
2956 } /* end xcpxa */
2957
2958 /* LINE TYPE */
2959 static void xclnt(anything **params, int num_surfaces, anything **surf_list)
2960 {
2961
2962 int i; /* index for loop on surfaces */
2963 int vdi_style; /* SVDI linestyle */
2964
2965 /* CGI line types: */
2966 /* 1: solid - supported
2967 * 2: dash - supported
2968 * 3: dot - supported
2969 * 4: dash dot - supported
2970 * 5: dash dot dot - not supported
2971 */
2972
2973 /* SVDI linestyles: */
2974 /* 0: solid
2975 * 1: dotted
2976 * 2: dot dash
2977 * 3: short dash
2978 * 4: long dash
2979 * 5: medium dash
2980 */
2981
2982 for (i = 0; i < num_surfaces; ++i) {
2983
2984 cur_state = (surf_statelist *)surf_list[i];
2985 if (cur_state->cgi_inited != CYES) {
2986 break;
2987 }
2988
2989 /* let SVDI catch any out of range indices */
2990 cur_state->line_type = *(int *)params[1];
2991
2992 /* make sure it really needs to be set */
2993 if (cur_state->line_type != cur_state->vdi_attrib.line_type) {
2994
2995 cur_state->vdi_attrib.line_type = cur_state->line_type;
2996
2997 /* map to SVDI styles */
2998 switch (cur_state->line_type) {
2999 case 1: vdi_style = 0; break;
3000 case 2: vdi_style = 5; break;
3001 case 3: vdi_style = 1; break;
3002 case 4: vdi_style = 2; break;
3003 case 5: vdi_style = 0; break; /* not supported, set to solid */
3004 default: vdi_style = cur_state->line_type; break;
3005 } /* end switch */
3006
3007 vdstls(&vdi_style);
3008 } /* end it needs to be set */
3009
3010 } /* end for each surface */
3011 } /* end xclnt */
3012
3013 /* LINE WIDTH */
3014 static void xclnw(anything **params, int num_surfaces, anything **surf_list)
3015 {
3016
3017 int i; /* index for loop on surfaces */
3018 float vdi_lw; /* SVDI linewidth */
3019 float temp_array[14]; /* use for SVDI inquiry */
3020
3021 for (i = 0; i < num_surfaces; ++i) {
3022
3023 cur_state = (surf_statelist *)surf_list[i];
3024 if (cur_state->cgi_inited != CYES) {
3025 break;
3026 }
3027
3028 /* make sure it needs to be updated */
3029 if (*(float *)params[1] != cur_state->vdi_attrib.line_width) {
3030
3031 /* save the original in vdi_attrib array */
3032 cur_state->vdi_attrib.line_width = *(float *)params[1];
3033
3034 /* convert to NDC and set the linewidth */
3035 vdi_lw = dev_descrip.linewidth_nominal * *(float *)params[1] * fabs(cur_state->xscale);
3036 vdstlw(&vdi_lw);
3037
3038 /* find out what it really got set at */
3039 vdiqos(&temp_array[1]);
3040
3041 /* map it back to (scaled) VDC and store it in state table */
3042 cur_state->line_width =
3043 (temp_array[5] * fabs(cur_state->xscale) * 100) / dev_descrip.linewidth_nominal;
3044
3045 } /* end it needs to be updated */
3046
3047 } /* end for each surface */
3048 } /* end xclnw */
3049
3050 /* LINE COLOR */
3051 static void xclnc(anything **params, int num_surfaces, anything **surf_list)
3052 {
3053 int i; /* index for loop on surfaces */
3054
3055 for (i = 0; i < num_surfaces; ++i) {
3056
3057 cur_state = (surf_statelist *)surf_list[i];
3058 if (cur_state->cgi_inited != CYES) {
3059 break;
3060 }
3061
3062 /* if color selection mode is in error, ignore function */
3063 if (cur_state->csm == -1) {
3064 break;
3065 }
3066
3067 if (cur_state->csm == CINDEX) { /* indexed mode */
3068
3069 /* let SVDI catch out of range indices */
3070 cur_state->line_csm = CINDEX;
3071 cur_state->line_color[0] = *(int *)params[1];
3072 } /* end indexed mode */
3073
3074 else { /* direct color mode */
3075
3076 /* let SVDI catch illegal color values */
3077 cur_state->line_csm = CDRECT;
3078 cur_state->line_color[0] = *((int *)params[1] + 0);
3079 cur_state->line_color[1] = *((int *)params[1] + 1);
3080 cur_state->line_color[2] = *((int *)params[1] + 2);
3081 } /* end direct color mode */
3082
3083 } /* end for each surface */
3084 } /* end xclnc */
3085
3086 /* MARKER TYPE */
3087 static void xcmkt(int num_surfaces, anything **surf_list)
3088 {
3089 /* CGI marker types: */
3090 /* 1: dot - supported
3091 * 2: plus - not supported
3092 * 3: asterisk - not supported
3093 * 4: circle - not supported
3094 * 5: cross - not supported
3095 */
3096
3097 /* SVDI only supports a dot, which is the default */
3098
3099 /* An unsupported index is mapped to a supported value, such
3100 * as the default, without error. So can just ignore this
3101 * function.
3102 */
3103
3104 } /* end xcmkt */
3105
3106 /* MARKER SIZE */
3107 static void xcmks(anything **params, int num_surfaces, anything **surf_list)
3108 {
3109 /* marker size is mapped to nearest avail marker size on
3110 * the device. SVDI only supports 1 marker size, which is
3111 * the default size, so this function not supported.
3112 */
3113 /* error 4:001 - Function not supported. Function ignored */
3114 report_error(cur_state, 4, 001, *(short *)params[0]);
3115
3116 } /* end xcmks */
3117
3118 /* MARKER COLOR */
3119 static void xcmkc(anything **params, int num_surfaces, anything **surf_list)
3120 {
3121 int i; /* index for loop on surfaces */
3122
3123 for (i = 0; i < num_surfaces; ++i) {
3124
3125 cur_state = (surf_statelist *)surf_list[i];
3126 if (cur_state->cgi_inited != CYES) {
3127 break;
3128 }
3129
3130 /* if color selection mode is in error, ignore function */
3131 if (cur_state->csm == -1) {
3132 break;
3133 }
3134
3135 if (cur_state->csm == CINDEX) { /* indexed mode */
3136
3137 /* let SVDI catch out of range indices */
3138 cur_state->mark_csm = CINDEX;
3139 cur_state->mark_color[0] = *(int *)params[1];
3140 } /* end indexed mode */
3141
3142 else { /* direct color mode */
3143
3144 /* let SVDI catch illegal color values */
3145 cur_state->mark_csm = CDRECT;
3146 cur_state->mark_color[0] = *((int *)params[1] + 0);
3147 cur_state->mark_color[1] = *((int *)params[1] + 1);
3148 cur_state->mark_color[2] = *((int *)params[1] + 2);
3149 } /* end direct color mode */
3150
3151 } /* end for each surface */
3152 } /* end xcmkc */
3153
3154 /* TEXT PRECISION */
3155 static void xctxp(anything **params, int num_surfaces, anything **surf_list)
3156 {
3157 /* error 4:001 - Function not supported. Function ignored */
3158 report_error(cur_state, 4, 001, *(short *)params[0]);
3159
3160 } /* end xctxp */
3161
3162 /* TEXT COLOR */
3163 static void xctxc(anything **params, int num_surfaces, anything **surf_list)
3164 {
3165 int i; /* index for loop on surfaces */
3166
3167 for (i = 0; i < num_surfaces; ++i) {
3168
3169 cur_state = (surf_statelist *)surf_list[i];
3170 if (cur_state->cgi_inited != CYES) {
3171 break;
3172 }
3173
3174 /* if color selection mode is in error, ignore function */
3175 if (cur_state->csm == -1) {
3176 break;
3177 }
3178
3179 if (cur_state->csm == CINDEX) { /* indexed mode */
3180
3181 /* let SVDI catch out of range indices */
3182 cur_state->text_csm = CINDEX;
3183 cur_state->text_color[0] = *(int *)params[1];
3184 } /* end indexed mode */
3185
3186 else { /* direct color mode */
3187
3188 /* let SVDI catch illegal color values */
3189 cur_state->text_csm = CDRECT;
3190 cur_state->text_color[0] = *((int *)params[1] + 0);
3191 cur_state->text_color[1] = *((int *)params[1] + 1);
3192 cur_state->text_color[2] = *((int *)params[1] + 2);
3193 } /* end direct mode */
3194
3195 } /* end for each surface */
3196 } /* end xctxc */
3197
3198 /* CHARACTER HEIGHT */
3199 static void xcchh(anything **params, int num_surfaces, anything **surf_list)
3200 {
3201 int i; /* index for loop on surfaces */
3202 float vdi_cs; /* SVDI character size */
3203 float temp_array[14]; /* used for SVDI inquire */
3204
3205 for (i = 0; i < num_surfaces; ++i) {
3206
3207 cur_state = (surf_statelist *)surf_list[i];
3208 if (cur_state->cgi_inited != CYES) {
3209 break;
3210 }
3211
3212 /* set SVDI character size if needed */
3213 if (*(float *)params[1] != cur_state->vdi_attrib.char_x) {
3214
3215 /* let SVDI catch illegal character height */
3216 cur_state->vdi_attrib.char_x = *(float *)params[1];
3217
3218 /* map to NDC */
3219 vdi_cs = *(float *)params[1] * fabs(cur_state->xscale);
3220 vdstcs(&vdi_cs);
3221
3222 /* inquire to find out what it really got set to */
3223 vdiqos(&temp_array[1]);
3224
3225 /* map back to VDC and store in state table */
3226 cur_state->char_height = temp_array[6] / fabs(cur_state->xscale);
3227
3228 } /* end if char size needs to be set */
3229
3230 } /* end for each surface */
3231 } /* end xcchh */
3232
3233 /* CHARACTER ORIENTATION */
3234 static void xccho(anything **params, int num_surfaces, anything **surf_list)
3235 {
3236 /* error 4:001 - Function not supported. Function ignored */
3237 report_error(cur_state, 4, 001, *(short *)params[0]);
3238
3239 } /* end xccho */
3240
3241 /* INTERIOR STYLE */
3242 static void xcis(anything **params, int num_surfaces, anything **surf_list)
3243 {
3244 int i; /* index for loop on surfaces */
3245
3246 /* CGI interior styles: */
3247 /* hollow - supported
3248 * solid - supported
3249 * pattern - not supported
3250 * hatch - not supported
3251 * empty - not supported
3252 * bitmap - not supported
3253 */
3254
3255 for (i = 0; i < num_surfaces; ++i) {
3256
3257 cur_state = (surf_statelist *)surf_list[i];
3258 if (cur_state->cgi_inited != CYES) {
3259 break;
3260 }
3261
3262 /* check for legal enumerated value */
3263 if (*(int *)params[1] == CHOLLO || *(int *)params[1] == CSOLID) {
3264 cur_state->interior_style = *(int *)params[1];
3265 }
3266 else {
3267 /* error 1:-101 Enumerated parameter out of range. Function ignored */
3268 report_error(cur_state, 1, -101, *(short *)params[0]);
3269 }
3270
3271 } /* end for each surface */
3272 } /* end xcis */
3273
3274 /* FILL COLOR */
3275 static void xcflc(anything **params, int num_surfaces, anything **surf_list)
3276 {
3277 int i; /* index for loop on surfaces */
3278
3279 for (i = 0; i < num_surfaces; ++i) {
3280
3281 cur_state = (surf_statelist *)surf_list[i];
3282 if (cur_state->cgi_inited != CYES) {
3283 break;
3284 }
3285
3286 /* if color selection mode is in error, ignore function */
3287 if (cur_state->csm == -1) {
3288 break;
3289 }
3290
3291 if (cur_state->csm == CINDEX) { /* indexed mode */
3292
3293 /* let SVDI catch out of range indices */
3294 cur_state->fill_csm = CINDEX;
3295 cur_state->fill_color[0] = *(int *)params[1];
3296 } /* end indexed color */
3297
3298 else { /* direct color mode */
3299
3300 /* let SVDI catch illegal color values */
3301 cur_state->fill_csm = CDRECT;
3302 cur_state->fill_color[0] = *((int *)params[1] + 0);
3303 cur_state->fill_color[1] = *((int *)params[1] + 1);
3304 cur_state->fill_color[2] = *((int *)params[1] + 2);
3305 } /* end direct color mode */
3306
3307 } /* end for each surface */
3308 } /* end xcflc */
3309
3310 /* COLOR SELECTION MODE */
3311 static void xccsm(anything **params, int num_surfaces, anything **surf_list)
3312 {
3313 int i; /* index for loop on surfaces */
3314
3315 for (i = 0; i < num_surfaces; ++i) {
3316
3317 cur_state = (surf_statelist *)surf_list[i];
3318 if (cur_state->cgi_inited != CYES) {
3319 break;
3320 }
3321
3322 /* check enumerated parameters */
3323 if (*(int *)params[1] != CDRECT && *(int *)params[1] != CINDEX) {
3324 /* error 1:-101 enumerated parameter out of range. Function ignored */
3325 report_error(cur_state, 1, -101, *(short *)params[0]);
3326 }
3327 else {
3328
3329 /* if the device supports both index and direct, or the
3330 request if only for index, everything is honky-dory */
3331 if (dev_descrip.csm_avail == CCLRID || *(int *)params[1] == CINDEX) {
3332 cur_state->csm = *(int *)params[1];
3333 }
3334 else { /* must be an error */
3335 /* error 3:305 - Color selection mode not supported. All
3336 functions with affected parameters ignored until reset */
3337 report_error(cur_state, 3, 305, *(short *)params[0]);
3338 cur_state->csm = -1; /* flag error condition */
3339 } /* end else must be an error */
3340 } /* end else */
3341
3342 } /* end for each surface */
3343 } /* end xccsm */
3344
3345 /* COLOR TABLE */
3346 static void xcct(anything **params, int num_surfaces, anything **surf_list)
3347 {
3348 int i; /* index for loop on surfaces */
3349 int j, k; /* indices for looping */
3350 int starti; /* starting color index */
3351 int num_cols; /* number of colors in color list */
3352 int tmp_array[3]; /* temp array used for setting bg color */
3353 float color_array[256][3]; /* used for setting SVDI color table */
3354 int num_set; /* number of colors being set, for SVDI */
3355 int maxindex; /* max color index to set */
3356 int indx_ptr; /* for keeping track of color indices */
3357 int index1, index2; /* defines a range of indices to set */
3358 int one = 1;
3359
3360 /* starting color index and number of colors */
3361 starti = *(int *)params[1];
3362 num_cols = *(int *)params[2];
3363
3364 /* error checking */
3365 /* an out of range index in an index definition function should
3366 be ignored. should an error be reported ?? */
3367 if (starti < 0) {
3368 starti = 0;
3369 }
3370
3371 if ((starti + num_cols - 1) > dev_descrip.num_cols) {
3372 /* error 6:308 - Too many color specifiers. Discard extras */
3373 report_error(cur_state, 6, 308, *(short *)params[0]);
3374 num_cols = dev_descrip.num_cols - starti + 1;
3375 } /* end error */
3376
3377 /* convert rgb to lie between 0. and 1. */
3378 /* ...only do this once */
3379
3380 int *iparam = (int *)params[3];
3381 k = 0;
3382 for (j = starti; j < starti + num_cols; j++) {
3383 color_array[j][0] = (float)iparam[k++] / 255.0f;
3384 color_array[j][1] = (float)iparam[k++] / 255.0f;
3385 color_array[j][2] = (float)iparam[k++] / 255.0f;
3386 }
3387
3388 /* loop through surfaces */
3389 for (i = 0; i < num_surfaces; ++i) {
3390
3391 cur_state = (surf_statelist *)surf_list[i];
3392 if (cur_state->cgi_inited != CYES) {
3393 break;
3394 }
3395
3396 /* mark that the color table has been set */
3397 cur_state->color_set = TRUE;
3398
3399 /* update the current state color table */
3400 k = 0;
3401 for (j = starti; j < starti + num_cols; j++) {
3402 cur_state->color_table[j].r = ((int *)params[3])[k++];
3403 cur_state->color_table[j].g = ((int *)params[3])[k++];
3404 cur_state->color_table[j].b = ((int *)params[3])[k++];
3405 }
3406
3407 /* set the SVDI color table */
3408 /* color indices are mapped so that fg and bg colors are
3409 * 'reasonable' colors. If the user sets either the fg index
3410 * color or bg color index, map those colors so that the
3411 * fg and bg colors won't change
3412 */
3413 /* color index mappings:
3414 * if set index 0 --> set bg_index
3415 * if set index 1 --> set fg_index
3416 * if set bg_index --> set 0
3417 * if set fg_index --> set 1
3418 */
3419
3420 /* set the special cases first */
3421 /* 1. caller setting index 0 - set the background color */
3422 /* --set_background_color() will set color table entry bg_index */
3423 if (starti == 0) {
3424 tmp_array[0] = cur_state->color_table[0].r;
3425 tmp_array[1] = cur_state->color_table[0].g;
3426 tmp_array[2] = cur_state->color_table[0].b;
3427 set_background_color(cur_state, tmp_array);
3428 }
3429
3430 /* 2. caller setting index 1 - set index fg_index */
3431 if (starti <= 1 && (starti + num_cols > 1)) {
3432 vdstco(&one, &dev_descrip.index_array[cur_state->fg_index], &color_array[1],
3433 &dev_descrip.col_mode);
3434 }
3435
3436 /* 3. caller setting index bg_index - set index 0 */
3437 if (cur_state->bg_index != 0) { /* .. don't do it twice */
3438 if (starti <= cur_state->bg_index && (starti + num_cols > cur_state->bg_index)) {
3439 vdstco(&one, &dev_descrip.index_array[0], &color_array[cur_state->bg_index],
3440 &dev_descrip.col_mode);
3441 }
3442 }
3443
3444 /* 4. caller setting index fg_index - set index 1 */
3445 if (cur_state->fg_index != 1) { /* .. don't do it twice */
3446 if (starti <= cur_state->fg_index && (starti + num_cols > cur_state->fg_index)) {
3447 vdstco(&one, &dev_descrip.index_array[1], &color_array[cur_state->fg_index],
3448 &dev_descrip.col_mode);
3449 }
3450 }
3451 /* now do all the rest */
3452 /* ...sort for convenience */
3453 if (cur_state->fg_index < cur_state->bg_index) {
3454 index1 = cur_state->fg_index;
3455 index2 = cur_state->bg_index;
3456 }
3457 else {
3458 index1 = cur_state->bg_index;
3459 index2 = cur_state->fg_index;
3460 } /* end sort */
3461
3462 maxindex = starti + num_cols - 1;
3463 indx_ptr = starti;
3464 if (indx_ptr < 2) {
3465 indx_ptr = 2;
3466 }
3467
3468 /* 1. set color table between index 1 and index1 */
3469 if (indx_ptr <= 2) {
3470 num_set = min(index1 - 2, maxindex - 1);
3471 if (num_set > 0) {
3472 vdstco(&num_set, &dev_descrip.index_array[2], &color_array[2], &dev_descrip.col_mode);
3473 indx_ptr = index1 + 1;
3474 }
3475 }
3476
3477 if (indx_ptr == index1) { /* update indx_ptr */
3478 indx_ptr = indx_ptr + 1;
3479 }
3480
3481 /* 2. set color table between index1 and index2 */
3482 if (indx_ptr < index2) {
3483 num_set = min(index2 - indx_ptr, maxindex - indx_ptr + 1);
3484 if (num_set > 0) {
3485 vdstco(&num_set, &dev_descrip.index_array[indx_ptr], &color_array[indx_ptr],
3486 &dev_descrip.col_mode);
3487 indx_ptr = index2 + 1;
3488 }
3489 }
3490
3491 if (indx_ptr == index2) { /* update indx_ptr */
3492 indx_ptr = indx_ptr + 1;
3493 }
3494
3495 /* 3. set color table after index 2 */
3496 if (indx_ptr >= index2 + 1) {
3497 num_set = maxindex - indx_ptr + 1;
3498 if (num_set > 0) {
3499 vdstco(&num_set, &dev_descrip.index_array[indx_ptr], &color_array[indx_ptr],
3500 &dev_descrip.col_mode);
3501 }
3502 }
3503
3504 } /* end for each surface */
3505 } /* end xcct */
3506
3507 /* GET TEXT EXTENT */
3508 static void xcgtxx(anything **params, anything **surf_list)
3509 {
3510 float act_h, act_w; /* actual char height and width (VDC) */
3511 float x1, y1, x2; /* parrallelogram parts */
3512 float save, temp_h; /* temporary variables */
3513 float temp_array[14]; /* temp array used for SVDI inquires */
3514
3515 /* there is only one surface for inquiries */
3516 cur_state = (surf_statelist *)surf_list[0];
3517 if (cur_state->cgi_inited != CYES) {
3518 return;
3519 }
3520
3521 /* find out actual height and width from SVDI for this size */
3522 /* ..save the old value */
3523 vdiqos(&temp_array[1]);
3524 save = temp_array[6];
3525
3526 /* ..set current height value */
3527 temp_h = cur_state->char_height * fabs(cur_state->xscale);
3528 vdstcs(&temp_h);
3529
3530 /* ..find out actual height and width */
3531 vdiqos(&temp_array[1]);
3532 act_h = temp_array[6] / fabs(cur_state->xscale);
3533 act_w = temp_array[7] / fabs(cur_state->xscale);
3534
3535 /* set it back to original */
3536 vdstcs(&save);
3537
3538 /* parallelogram */
3539 /* x1, y1 = bottom left corner of string */
3540 x1 = *(float *)params[1];
3541 y1 = *(float *)params[2];
3542 *(float *)params[8] = x1;
3543 *(float *)params[9] = y1;
3544
3545 /* x2, y2 = bottom right corner of string */
3546 /* params[4] is an added parameter that contains string size */
3547 x2 = x1 + (*(int *)params[16] * act_w);
3548 *(float *)params[10] = x2;
3549 *(float *)params[11] = y1;
3550
3551 /* x3, y3 = top right corner of string ( x3 = x2 )*/
3552 *(float *)params[12] = x2;
3553 *(float *)params[13] = y1 + act_h;
3554
3555 /* x4, y4 = top left corner of string ( y4 = y3 )*/
3556 *(float *)params[14] = x1;
3557 *(float *)params[15] = y1 + act_h;
3558
3559 /* concatenation point is bottom right corner ( x2, y2 )*/
3560 *(float *)params[6] = x2;
3561 *(float *)params[7] = y1;
3562
3563 /* validity flags */
3564 *(int *)params[4] = CVAL;
3565 *(int *)params[5] = CVAL;
3566
3567 } /* end xcgtxx */
3568
3569 /* INQUIRE PRIMITIVE SUPPORT LEVELS */
3570 static void xcqprl(anything **params, anything **surf_list)
3571 {
3572 int qdc_index = 25; /* index for inquiries to vdiqdc */
3573 float value; /* value returned by vdiqdc */
3574 static int set = FALSE; /* flag whether values have been set */
3575
3576 /* there is only one surface for inquiries */
3577 cur_state = (surf_statelist *)surf_list[0];
3578 if (cur_state->cgi_inited != CYES) {
3579 return;
3580 }
3581
3582 if (!set) { /* values have't been set, inquire SVDI */
3583
3584 set = TRUE;
3585
3586 /* max points for a polyline */
3587 dev_descrip.max_pts_polyline = MAX_POLYLINE;
3588
3589 /* max points for a disjoint polyline */
3590 dev_descrip.max_pts_disj_polyline = MAX_DJ_POLYLINE;
3591
3592 /* max points for a polygon */
3593 vdiqdc(&qdc_index, &value);
3594 dev_descrip.max_pts_polygon = (value == 99999.) ? MAX_POLYGON : min((int)value, MAX_POLYGON);
3595
3596 /* max points for a polygon set */
3597 /* --not supported */
3598 dev_descrip.max_pts_polygon_set = 0;
3599
3600 /* max points for a polymarker */
3601 dev_descrip.max_pts_polymarker = MAX_POLYMARKER;
3602
3603 /* max number of points for a closed figure */
3604 /* --not supported */
3605 dev_descrip.max_pts_closed_fig = 0;
3606
3607 /* max characters of text */
3608 dev_descrip.max_chars_text = MAX_TEXT_LENGTH;
3609
3610 /* max number of cell color specifiers for cell array */
3611 dev_descrip.max_pts_cellarray = -1;
3612
3613 /* cell array fill capability */
3614 dev_descrip.cellarray_fill_cap = CFILLD;
3615
3616 /* cell array alignment */
3617 dev_descrip.cellarray_align_cap = CAXIS;
3618
3619 /* compound text capability */
3620 dev_descrip.compound_text_cap = CCNONE;
3621
3622 /* closed figure capability */
3623 dev_descrip.compound_fig_cap = CCNONE;
3624
3625 } /* end if not set */
3626
3627 /* validity flag */
3628 *(int *)params[1] = CVAL;
3629
3630 /* stuff all the values into the return parameters */
3631 *(int *)params[2] = dev_descrip.max_pts_polyline;
3632 *(int *)params[3] = dev_descrip.max_pts_disj_polyline;
3633 *(int *)params[4] = dev_descrip.max_pts_polygon;
3634 *(int *)params[5] = dev_descrip.max_pts_polygon_set;
3635 *(int *)params[6] = dev_descrip.max_pts_polymarker;
3636 *(int *)params[7] = dev_descrip.max_pts_closed_fig;
3637 *(int *)params[8] = dev_descrip.max_chars_text;
3638 *(int *)params[9] = dev_descrip.max_pts_cellarray;
3639 *(int *)params[10] = dev_descrip.cellarray_fill_cap;
3640 *(int *)params[11] = dev_descrip.cellarray_align_cap;
3641 *(int *)params[12] = dev_descrip.compound_text_cap;
3642 *(int *)params[13] = dev_descrip.compound_fig_cap;
3643
3644 } /* end xcqprl */
3645
3646 /* INQUIRE LINE CAPABILITY */
3647 static void xcqln(anything **params, anything **surf_list)
3648 {
3649
3650 /* there is only one surface for inquiries */
3651 cur_state = (surf_statelist *)surf_list[0];
3652 if (cur_state->cgi_inited != CYES) {
3653 return;
3654 }
3655
3656 /* set the validity flag */
3657 *(int *)params[1] = CVAL;
3658
3659 /* number of predefined line bundles - bundles not supported */
3660 *(int *)params[2] = 0;
3661
3662 /* number of settable line bundles - bundles not supported */
3663 *(int *)params[3] = 0;
3664
3665 /* max line bundle index - bundles not supported */
3666 *(int *)params[4] = 0;
3667
3668 /* dynamic modification for line bundles- bundles not supported */
3669 *(int *)params[5] = 0;
3670
3671 /* nom, min, max, get set in set_dev_descrip() at initialization */
3672 *(int *)params[6] = dev_descrip.linewidth_nominal;
3673 *(int *)params[7] = dev_descrip.linewidth_min;
3674 *(int *)params[8] = dev_descrip.linewidth_max;
3675
3676 } /* end xcqln */
3677
3678 /* INQUIRE LIST OF AVAILABLE LINE TYPES */
3679 static void xcqlnt(anything **params, anything **surf_list)
3680 {
3681 int i, j; /* loop indices */
3682 int qdc_index = 6; /* index for inquiries to vdiqdc */
3683 float value; /* value returned by vdiqdc */
3684 static int set = FALSE; /* flag whether values have been set */
3685 static int ntotal; /* save total nbr of linestyles */
3686
3687 static unsigned mask = ~(~0u << 1);
3688
3689 /* there is only one surface for inquiries */
3690 cur_state = (surf_statelist *)surf_list[0];
3691 if (cur_state->cgi_inited != CYES) {
3692 return;
3693 }
3694
3695 if (!set) { /* values have't been set, inquire SVDI */
3696
3697 set = TRUE;
3698
3699 /* inquire supported linestyles from SVDI */
3700 vdiqdc(&qdc_index, &value);
3701
3702 /* SVDI always supports linestyle 0 */
3703 ntotal = 0;
3704 dev_descrip.line_types[ntotal++] = 0;
3705
3706 /* find all SVDI linestyles supported by looking at bits */
3707 for (i = 0; i < 5; i++) {
3708 if (((int)value & mask << i) >> i == 1) {
3709 dev_descrip.line_types[ntotal++] = i + 1;
3710 }
3711 }
3712
3713 /* map to CGI linestyles */
3714 /* cgi linestyles: 1 - solid 2 - dash 3 - dot,
3715 * 4 - dashdot 5 - dash dot dot
3716 * vdi linestyles: 0 - solid 1 - dotted 2 - dot dash
3717 * 3 - short dash 4 - long dash 5 - medium dash
3718 */
3719 for (i = 0; i < ntotal; i++) {
3720 switch (dev_descrip.line_types[i]) {
3721 case 0: dev_descrip.line_types[i] = 1; break;
3722 case 1: dev_descrip.line_types[i] = 3; break;
3723 case 2: dev_descrip.line_types[i] = 4; break;
3724 /* ...all SVDI dashes map to cgi dash */
3725 case 3: dev_descrip.line_types[i] = 2; break;
3726 case 4: dev_descrip.line_types[i] = 2; break;
3727 case 5: dev_descrip.line_types[i] = 2; break;
3728 default: break;
3729 } /* end switch */
3730 }
3731
3732 /* take out duplicates */
3733 for (i = 0; i < ntotal; i++) {
3734 if (dev_descrip.line_types[i] == 2) {
3735 break;
3736 }
3737 }
3738 ntotal = i + 1;
3739
3740 } /* end if not set */
3741
3742 /* set the total */
3743 *(int *)params[4] = ntotal;
3744
3745 /* do some error checking */
3746 if (*(int *)params[2] < 1) {
3747 /* error - set validity flag to invalid */
3748 *(int *)params[3] = CINVAL;
3749 }
3750 else { /* send back only the ones requested - zero out the rest */
3751
3752 i = *(int *)params[2] - 1;
3753 j = 0;
3754 *(int *)params[5] = 0; /* actual number of list elements sent back */
3755 while (j < ntotal) {
3756 if (j < *(int *)params[1] && i < ntotal) {
3757 ((int *)params[6])[j++] = dev_descrip.line_types[i++];
3758 (*(int *)params[5])++;
3759 }
3760 else {
3761 ((int *)params[6])[j++] = 0;
3762 }
3763 }
3764
3765 /* set validity flag */
3766 *(int *)params[3] = CVAL;
3767 } /* end else send back */
3768
3769 } /* end xcqlnt */
3770
3771 /* INQUIRE LIST OF AVAILABLE SCALED LINE WIDTHS */
3772 static void xcqslw(anything **params, anything **surf_list)
3773 {
3774 int qdc_index = 5; /* index for inquiries to vdiqdc */
3775 float value; /* value returned by vdiqdc */
3776 static int set = FALSE; /* flag whether values have been set */
3777 static int ntotal; /* save total nbr of linewidths */
3778
3779 /* there is only one surface for inquiries */
3780 cur_state = (surf_statelist *)surf_list[0];
3781 if (cur_state->cgi_inited != CYES) {
3782 return;
3783 }
3784
3785 if (!set) { /* values have't been set, inquire SVDI */
3786
3787 set = TRUE;
3788
3789 /* number of linewidths available */
3790 vdiqdc(&qdc_index, &value);
3791 ntotal = (int)value;
3792
3793 } /* end if not set */
3794
3795 /* validity flag */
3796 *(int *)params[3] = CVAL;
3797 *(int *)params[4] = ntotal;
3798
3799 /* nlist = 0 means empty list ( continuous range ) */
3800 /* --leave list (params[6]) untouched */
3801 *(int *)params[5] = 0;
3802
3803 } /* end xcqslw */
3804
3805 /* INQUIRE MARKER CAPABILITY */
3806 static void xcqmk(anything **params, anything **surf_list)
3807 {
3808 /* there is only one surface for inquiries */
3809 cur_state = (surf_statelist *)surf_list[0];
3810 if (cur_state->cgi_inited != CYES) {
3811 return;
3812 }
3813
3814 /* set the validity flag */
3815 *(int *)params[1] = CVAL;
3816
3817 /* number of predefined marker bundles - bundles not supported */
3818 *(int *)params[2] = 0;
3819
3820 /* number of settable marker bundles - bundles not supported */
3821 *(int *)params[3] = 0;
3822
3823 /* max marker bundle index - bundles not supported */
3824 *(int *)params[4] = 0;
3825
3826 /* dynamic modification for marker bundles- bundles not supported */
3827 *(int *)params[5] = 0;
3828
3829 /* nom, min, max, get set in set_dev_descrip() at initialization */
3830 *(int *)params[6] = dev_descrip.mark_nominal;
3831 *(int *)params[7] = dev_descrip.mark_min;
3832 *(int *)params[8] = dev_descrip.mark_max;
3833
3834 } /* end xcqmk */
3835
3836 /* INQUIRE LIST OF AVAILABLE MARKER TYPES */
3837 static void xcqmkt(anything **params, anything **surf_list)
3838 {
3839 static int set = FALSE; /* flag whether values have been set */
3840 static int ntotal; /* save total nbr of linestyles */
3841
3842 /* there is only one surface for inquiries */
3843 cur_state = (surf_statelist *)surf_list[0];
3844 if (cur_state->cgi_inited != CYES) {
3845 return;
3846 }
3847
3848 if (!set) { /* values have't been set, inquire SVDI */
3849
3850 set = TRUE;
3851
3852 /* SVDI only supports 1 marker type - "dot" */
3853 ntotal = 1;
3854 dev_descrip.mark_types[0] = 1;
3855
3856 } /* end if not set */
3857
3858 /* set validity flag */
3859 *(int *)params[3] = CVAL;
3860
3861 *(int *)params[4] = ntotal;
3862
3863 if (*(int *)params[1] > 0) {
3864 *(int *)params[5] = 1;
3865 ((int *)params[6])[0] = dev_descrip.mark_types[0];
3866 }
3867 else {
3868 *(int *)params[5] = 0;
3869 }
3870
3871 } /* end xcqmkt */
3872
3873 /* INQUIRE LIST OF AVAILABLE SCALED MARKER SIZES */
3874 static void xcqsms(anything **params, anything **surf_list)
3875 {
3876 /* there is only one surface for inquiries */
3877 cur_state = (surf_statelist *)surf_list[0];
3878 if (cur_state->cgi_inited != CYES) {
3879 return;
3880 }
3881
3882 /* validity flag */
3883 *(int *)params[3] = CVAL;
3884
3885 /* there is only 1 size */
3886 *(int *)params[4] = 1;
3887 *(int *)params[5] = 1;
3888 ((int *)params[6])[0] = dev_descrip.mark_nominal;
3889
3890 } /* end xcqsms */
3891
3892 /* INQUIRE LIST OF AVAILABLE CHARACTER HEIGHTS */
3893 static void xcqchh(anything **params, anything **surf_list)
3894 {
3895 int qdc_index = 7; /* index for inquiries to vdiqdc */
3896 float value; /* value returned by vdiqdc */
3897 static int set = FALSE; /* flag whether values have been set */
3898 static int ntotal; /* save total nbr of char heights */
3899
3900 /* there is only one surface for inquiries */
3901 cur_state = (surf_statelist *)surf_list[0];
3902 if (cur_state->cgi_inited != CYES) {
3903 return;
3904 }
3905
3906 if (!set) { /* values have't been set, inquire SVDI */
3907
3908 set = TRUE;
3909
3910 /* number of char sizes */
3911 vdiqdc(&qdc_index, &value);
3912 ntotal = (int)value;
3913
3914 } /* end if not set */
3915
3916 /* font - SRCP does not support multiple fonts; use null string */
3917 /* I don't check for font, anything goes */
3918
3919 /* only string precision is supported */
3920 if (*(int *)params[2] == CSTRNG) {
3921
3922 /* total number of character heights */
3923 *(int *)params[6] = ntotal;
3924
3925 /* set nlist = 0 means empty list ( continuous range ) */
3926 /* --leave list (params[8]) untouched */
3927 *(int *)params[7] = 0;
3928
3929 /* validity flag */
3930 *(int *)params[5] = CVAL;
3931 } /* end if */
3932
3933 else {
3934 *(int *)params[5] = CINVAL;
3935 }
3936
3937 } /* end xcqchh */
3938
3939 /* INQUIRE FILL CAPABILITY */
3940 static void xcqfl(anything **params, anything **surf_list)
3941 {
3942 static int set = FALSE; /* flag whether values have been set */
3943 static int ntotal; /* save total nbr of fill styles */
3944
3945 /* there is only one surface for inquiries */
3946 cur_state = (surf_statelist *)surf_list[0];
3947 if (cur_state->cgi_inited != CYES) {
3948 return;
3949 }
3950
3951 if (!set) { /* values have't been set */
3952
3953 set = TRUE;
3954
3955 ntotal = 2;
3956 dev_descrip.interior_styles[0] = CHOLLO;
3957 dev_descrip.interior_styles[1] = CSOLID;
3958
3959 } /* end if not set */
3960
3961 /* set the validity flag */
3962 *(int *)params[1] = CVAL;
3963
3964 /* number of predefined fill bundles - bundles not supported */
3965 *(int *)params[2] = 0;
3966
3967 /* number of settable fill bundles - bundles not supported */
3968 *(int *)params[3] = 0;
3969
3970 /* max fill bundle index - bundles not supported */
3971 *(int *)params[4] = 0;
3972
3973 /* dynamic modification for fill bundles- bundles not supported */
3974 *(int *)params[5] = 0;
3975
3976 /* interior styles */
3977 *(int *)params[6] = ntotal;
3978 ((int *)params[7])[0] = dev_descrip.interior_styles[0];
3979 ((int *)params[7])[1] = dev_descrip.interior_styles[1];
3980
3981 /* number of predefined patterns - patterns not supported */
3982 *(int *)params[8] = 0;
3983
3984 /* number of settable patterns - patterns not supported */
3985 *(int *)params[9] = 0;
3986
3987 /* maximum pattern index - patterns not supported */
3988 *(int *)params[10] = 0;
3989
3990 /* preferred pattern size divisor - patterns not supported */
3991 *(int *)params[11] = 0;
3992
3993 /* maximum pattern size - patterns not supported */
3994 *(int *)params[12] = 0;
3995 *(int *)params[13] = 0;
3996
3997 /* pattern transformation support - patterns not supported */
3998 *(int *)params[14] = CPTNO;
3999
4000 } /* end xcqfl */
4001
4002 /* INQUIRE COLOR CAPABILITIES */
4003 static void xcqc(anything **params, anything **surf_list)
4004 {
4005 int qdc_index; /* index for inquiries to vdiqdc */
4006 float value; /* value returned by vdiqdc */
4007 static int set = FALSE; /* flag whether values have been set */
4008
4009 /* there is only one surface for inquiries */
4010 cur_state = (surf_statelist *)surf_list[0];
4011 if (cur_state->cgi_inited != CYES) {
4012 return;
4013 }
4014
4015 if (!set) { /* values have't been set, inquire SVDI */
4016
4017 set = TRUE;
4018
4019 /* number of simultaneous colors */
4020 dev_descrip.num_simul_colors = dev_descrip.num_cols;
4021
4022 /* number of available colors */
4023 qdc_index = 27;
4024 vdiqdc(&qdc_index, &value);
4025 dev_descrip.num_avail_colors = (int)value;
4026
4027 /* number of available intensities */
4028 /* --see 7.1.4 about direct color */
4029 qdc_index = 3;
4030 vdiqdc(&qdc_index, &value);
4031 dev_descrip.num_avail_int = (int)value;
4032
4033 /* dynamic modification accepted for color table */
4034 dev_descrip.dynamic_mod_ct = CIRG;
4035
4036 /* color overwrite capability */
4037 /* --what is the answer?? */
4038 /* dev_descrip.color_overwrite = ??; */
4039
4040 /* monochromatic device */
4041 qdc_index = 32;
4042 vdiqdc(&qdc_index, &value);
4043 dev_descrip.monochrome_device = (value == 0.0) ? CYES : CNO;
4044
4045 } /* end not set */
4046
4047 /* validity flag */
4048 *(int *)params[1] = CVAL;
4049
4050 /* return the answers */
4051 *(int *)params[2] = dev_descrip.num_simul_colors;
4052 *(int *)params[3] = dev_descrip.num_avail_colors;
4053 ((int *)params[4])[0] = dev_descrip.num_avail_int;
4054 *(int *)params[5] = dev_descrip.csm_avail; /* set in set_dev_descrip()*/
4055 *(int *)params[6] = dev_descrip.dynamic_mod_ct;
4056 *(int *)params[7] = dev_descrip.color_overwrite;
4057 *(int *)params[8] = dev_descrip.monochrome_device;
4058
4059 } /* end xcqc */
4060
4061 /* INQUIRE LINE ATTRIBUTES */
4062 static void xcqlna(anything **params, anything **surf_list)
4063 {
4064
4065 /* there is only one surface for inquiries */
4066 cur_state = (surf_statelist *)surf_list[0];
4067 if (cur_state->cgi_inited != CYES) {
4068 return;
4069 }
4070
4071 /* validity flag */
4072 *(int *)params[1] = CVAL;
4073
4074 /* line bundle index - bundles not supported */
4075 *(int *)params[2] = 0;
4076
4077 /* line type */
4078 *(int *)params[3] = cur_state->line_type;
4079
4080 /* line width specification mode - only support scaled */
4081 *(int *)params[4] = CSCA;
4082
4083 /* line width */
4084 *(float *)params[5] = cur_state->line_width;
4085
4086 /* color selection mode in which line color was last specified */
4087 *(int *)params[6] = cur_state->line_csm;
4088
4089 /* line color in color selection mode last specified */
4090 ((int *)params[7])[0] = cur_state->line_color[0];
4091 if (cur_state->line_csm == CDRECT) {
4092 ((int *)params[7])[1] = cur_state->line_color[1];
4093 ((int *)params[7])[2] = cur_state->line_color[2];
4094 }
4095
4096 /* line clipping mode */
4097 *(int *)params[8] = CLOCUS;
4098
4099 } /* end xcqlna */
4100
4101 /* INQUIRE MARKER ATTRIBUTES */
4102 static void xcqmka(anything **params, anything **surf_list)
4103 {
4104
4105 /* there is only one surface for inquiries */
4106 cur_state = (surf_statelist *)surf_list[0];
4107 if (cur_state->cgi_inited != CYES) {
4108 return;
4109 }
4110
4111 /* validity flag */
4112 *(int *)params[1] = CVAL;
4113
4114 /* marker bundle index - bundles not supported */
4115 *(int *)params[2] = 0;
4116
4117 /* marker type */
4118 *(int *)params[3] = cur_state->mark_type;
4119
4120 /* marker size specification mode - only support scaled */
4121 *(int *)params[4] = CSCA;
4122
4123 /* marker size */
4124 *(float *)params[5] = cur_state->mark_size;
4125
4126 /* color selection mode in which marker color was last specified */
4127 *(int *)params[6] = cur_state->mark_csm;
4128
4129 /* marker color in color selection mode last specified */
4130 ((int *)params[7])[0] = cur_state->mark_color[0];
4131 if (cur_state->mark_csm == CDRECT) {
4132 ((int *)params[7])[1] = cur_state->mark_color[1];
4133 ((int *)params[7])[2] = cur_state->mark_color[2];
4134 }
4135
4136 /* marker clipping mode */
4137 *(int *)params[8] = CLOCUS;
4138
4139 } /* end xcqmka */
4140
4141 /* INQUIRE TEXT ATTRIBUTES */
4142 static void xcqtxa(anything **params, anything **surf_list)
4143 {
4144
4145 /* there is only one surface for inquiries */
4146 cur_state = (surf_statelist *)surf_list[0];
4147 if (cur_state->cgi_inited != CYES) {
4148 return;
4149 }
4150
4151 /* validity flag */
4152 *(int *)params[1] = CVAL;
4153
4154 /* text bundle index - bundles not supported */
4155 *(int *)params[2] = 0;
4156
4157 /* font index - only the default font is supported */
4158 *(int *)params[3] = 1;
4159
4160 /* font precision */
4161 *(int *)params[4] = CSTRNG;
4162
4163 /* character expansion factor */
4164 *(float *)params[5] = 1.0;
4165
4166 /* character spacing */
4167 *(float *)params[6] = 0.0;
4168
4169 /* color selection mode in which text color was last specified */
4170 *(int *)params[7] = cur_state->text_csm;
4171
4172 /* text color in color selection mode last specified */
4173 ((int *)params[8])[0] = cur_state->text_color[0];
4174 if (cur_state->text_csm == CDRECT) {
4175 ((int *)params[8])[1] = cur_state->text_color[1];
4176 ((int *)params[8])[2] = cur_state->text_color[2];
4177 }
4178
4179 /* character height */
4180 *(float *)params[9] = cur_state->char_height;
4181
4182 /* character orientation */
4183 ((float *)params[10])[0] = 0.;
4184 ((float *)params[10])[1] = 1.;
4185 ((float *)params[10])[2] = 1.;
4186 ((float *)params[10])[3] = 0.;
4187
4188 /* text path */
4189 *(int *)params[11] = CTPRIT;
4190
4191 /* horizontal alignment */
4192 *(int *)params[12] = CTANH;
4193
4194 /* continuous horizontal alignment */
4195 *(float *)params[13] = 1.0;
4196
4197 /* vertical alignment */
4198 *(int *)params[14] = CTANV;
4199
4200 /* continuous horizontal alignment */
4201 *(float *)params[15] = 1.0;
4202
4203 /* character set index ?? */
4204 *(int *)params[16] = 1;
4205
4206 /* alternate character set index ?? */
4207 *(int *)params[17] = 1;
4208
4209 } /* end xcqtxa */
4210
4211 /* INQUIRE FILL ATTRIBUTES */
4212 static void xcqfla(anything **params, anything **surf_list)
4213 {
4214
4215 /* there is only one surface for inquiries */
4216 cur_state = (surf_statelist *)surf_list[0];
4217 if (cur_state->cgi_inited != CYES) {
4218 return;
4219 }
4220
4221 /* validity flag */
4222 *(int *)params[1] = CVAL;
4223
4224 /* fill bundle index - bundles not supported */
4225 *(int *)params[2] = 0;
4226
4227 /* interior style */
4228 *(int *)params[3] = cur_state->interior_style;
4229
4230 /* color selection mode in which fill color was last specified */
4231 *(int *)params[4] = cur_state->fill_csm;
4232
4233 /* fill color in color selection mode last specified */
4234 ((int *)params[5])[0] = cur_state->fill_color[0];
4235 if (cur_state->fill_csm == CDRECT) {
4236 ((int *)params[5])[1] = cur_state->fill_color[1];
4237 ((int *)params[5])[2] = cur_state->fill_color[2];
4238 }
4239
4240 /* hatch index - not supported */
4241 *(int *)params[6] = 0;
4242
4243 /* pattern index - not supported */
4244 *(int *)params[7] = 0;
4245
4246 /* --i don't know what any of the following means */
4247 /* fill bitmap identifier */
4248 *(int *)params[8] = 0;
4249
4250 /* fill bitmap region */
4251 *(float *)params[9] = 0.;
4252 *(float *)params[10] = 0.;
4253 *(float *)params[11] = 0.;
4254 *(float *)params[12] = 0.;
4255
4256 /* fill reference point */
4257 *(float *)params[13] = 0.;
4258 *(float *)params[14] = 0.;
4259
4260 /* pattern orientation and size */
4261 *(float *)params[15] = 0.;
4262 *(float *)params[16] = 0.;
4263 *(float *)params[17] = 0.;
4264 *(float *)params[18] = 0.;
4265
4266 } /* end xcqfla */
4267
4268 /* INQUIRE LIST OF COLOR TABLE ENTRIES */
4269 static void xcqcte(anything **params, anything **surf_list)
4270 {
4271 int i; /* loop index */
4272 int first; /* index of first element to return */
4273 int nreq; /* number of list elements requested */
4274 int j = 0; /* array index */
4275
4276 /* there is only one surface for inquiries */
4277 cur_state = (surf_statelist *)surf_list[0];
4278 if (cur_state->cgi_inited != CYES) {
4279 return;
4280 }
4281
4282 /* number of requested elements, and the first index */
4283 nreq = *(int *)params[1];
4284 first = *(int *)params[2];
4285
4286 /* error checking */
4287 if (first < 1) {
4288 first = 1;
4289 }
4290
4291 if ((first + nreq - 1) > dev_descrip.num_cols) {
4292 nreq = dev_descrip.num_cols - first + 1;
4293 }
4294
4295 /* actual number of colors returned */
4296 *(int *)params[5] = nreq;
4297
4298 for (i = first; i < (first + *(int *)params[5]); i++) {
4299
4300 ((int *)params[6])[j++] = cur_state->color_table[i - 1].r;
4301 ((int *)params[6])[j++] = cur_state->color_table[i - 1].g;
4302 ((int *)params[6])[j++] = cur_state->color_table[i - 1].b;
4303 } /* end for i */
4304
4305 /* return total number of colors */
4306 *(int *)params[4] = dev_descrip.num_cols;
4307
4308 /* validity flag */
4309 *(int *)params[3] = CVAL;
4310
4311 } /* end xcqcte */
4312
4313 /* INITIALIZE LOGICAL INPUT DEVICE */
4314 static void xcili(anything **params, anything **surf_list)
4315 {
4316 /* there is only one surface for input */
4317 cur_state = (surf_statelist *)surf_list[0];
4318 if (cur_state->cgi_inited != CYES) {
4319 return;
4320 }
4321
4322 /* only support locator */
4323 if (*(int *)params[1] != CLOCAT) {
4324 /* error 2:001 - Request for an unsupported feature. Function ignored */
4325 report_error(cur_state, 2, 001, *(short *)params[0]);
4326 }
4327 else if (*(int *)params[2] != 1) {
4328 /* error 3:501 - LID index exceeds number of this class of LID.
4329 Function ignored */
4330 report_error(cur_state, 3, 501, *(short *)params[0]);
4331 }
4332 else if (dev_descrip.dev_class == CINPUT ||
4333 dev_descrip.dev_class == COUTIN) { /* device does input */
4334
4335 cur_state->input_dev_class = CLOCAT;
4336 cur_state->input_dev_index = 1;
4337 cur_state->input_dev_state = CREADY;
4338
4339 } /* end if device does input */
4340
4341 } /* end xcili */
4342
4343 /* REQUEST LOCATOR */
4344 static void xcrqlc(anything **params, anything **surf_list)
4345 {
4346 float x, y; /* x,y values of locator */
4347
4348 /* there is only one surface for input */
4349 cur_state = (surf_statelist *)surf_list[0];
4350 if (cur_state->cgi_inited != CYES) {
4351 return;
4352 }
4353
4354 /* check if device has been initialized */
4355 /* ...only support input device index 1 */
4356 if (*(int *)params[1] != 1 || cur_state->input_dev_state != CREADY) {
4357 /* error 5:501 - Function illegal in LID state RELEASED.
4358 Function ignored */
4359 report_error(cur_state, 5, 501, *(short *)params[0]);
4360 *(int *)params[3] = CINVAL;
4361 }
4362
4363 else if (dev_descrip.dev_class == CINPUT ||
4364 dev_descrip.dev_class == COUTIN) { /* device does input */
4365
4366 /* for now only allow limited timeout */
4367 /* positive and negative values = wait forever, 0 = no wait */
4368 if (*(int *)params[2] == 0) {
4369 *(int *)params[3] = CINVAL;
4370 return;
4371 }
4372
4373 /* get location and trigger */
4374 vdakgl((int *)params[6], &x, &y);
4375
4376 /* convert location from NDC to VDC */
4377 *(float *)params[7] =
4378 (x - (cur_state->vp1.x * dev_descrip.xndc_max)) / cur_state->xscale + cur_state->vdc1.x;
4379
4380 *(float *)params[8] =
4381 (y - (cur_state->vp1.y * dev_descrip.yndc_max)) / cur_state->yscale + cur_state->vdc1.y;
4382
4383 /* response validity */
4384 *(int *)params[3] = CVAL;
4385
4386 /* request status, SVDI only has trigger */
4387 *(int *)params[4] = CTRIGR;
4388
4389 /* measure validity */
4390 /* --i'm not sure when measure validity is invalid */
4391 *(int *)params[5] = CVAL;
4392
4393 } /* end else device does input */
4394
4395 else { /* device doesn't do input */
4396 /* response validity */
4397 *(int *)params[3] = CVAL;
4398 }
4399
4400 } /* end xcrqlc */
4401
4402 /*-------------------------------------------------------------*/
4403 /* >> UTILITY ROUTINES */
4404 /*-------------------------------------------------------------*/
4405
4406 /* init_state */
4407 /* Initialize the state list */
4408 static void init_state(surf_statelist *surf_state)
4409 /* surface statelist to init */
4410 {
4411 int i; /* loop index */
4412 float tmp_array[1][3]; /* temp array to set SVDI color table */
4413 int one = 1;
4414
4415 /* set default error control: class 1 : DETECTION OFF
4416 class 2 - MAX_ERROR_CLASS : REPORTING OFF */
4417 surf_state->err_flag[0] = CEHDOF;
4418 for (i = 1; i < MAX_ERROR_CLASS; i++) {
4419 surf_state->err_flag[i] = CEHROF;
4420 }
4421
4422 /* initialize to 0 errors */
4423 surf_state->err_head_ptr = 0;
4424 surf_state->err_count = 0;
4425
4426 /* default vdc extent */
4427 surf_state->vdc1.x = 0.0;
4428 surf_state->vdc1.y = 0.0;
4429 surf_state->vdc2.x = 32767.;
4430 surf_state->vdc2.y = 32767.;
4431
4432 /* viewport - default viewport specification mode is FRACTION OF
4433 * DRAWING SURFACE. Thus, the viewport (0,0),(1,1) corresponds to
4434 * the lower and upper corners, respectively, of the default
4435 * device viewport, which is the largest unrotated rectangular area
4436 * visible on the drawing surface.
4437 */
4438 /* default viewport is (0,0),(1,1) */
4439 surf_state->vp1.x = 0.0;
4440 surf_state->vp1.y = 0.0;
4441 surf_state->vp2.x = 1.0;
4442 surf_state->vp2.y = 1.0;
4443
4444 /* VDC to viewport in NDC mapping */
4445 /* --device viewport mapping defaults are: isotropy forced,
4446 horizontal alignment left, vertical alignment bottom */
4447 /* -- this routine sets effective viewport in VDC and
4448 NDC (forcing isotropic mapping) and the mapping scale */
4449 set_mapping(surf_state);
4450
4451 /* default clip indicator is off (VDC clipping) */
4452 surf_state->clip_indicator = COFF;
4453
4454 /* default view surface clip indicator is viewport */
4455 surf_state->ds_clip_indicator = CVPORT;
4456
4457 /* default clip rectangle is (0,0) (32767,32767) */
4458 /* ...can't be changed in SS-CGI */
4459 surf_state->clip_rect1.x = 0.0;
4460 surf_state->clip_rect1.y = 0.0;
4461 surf_state->clip_rect2.x = 32767.;
4462 surf_state->clip_rect2.y = 32767.;
4463
4464 /* effective clip rectangle is intersection of VDC extent and
4465 clip rectangle */
4466 surf_state->eff_clip_rect1.x = 0.0;
4467 surf_state->eff_clip_rect1.y = 0.0;
4468 surf_state->eff_clip_rect2.x = 32767.;
4469 surf_state->eff_clip_rect2.y = 32767.;
4470
4471 /* set the clip region */
4472 set_clipping(surf_state);
4473
4474 /* default color mode is indexed */
4475 surf_state->csm = CINDEX;
4476
4477 /* default line, fill, text, and marker color indices */
4478 surf_state->line_color[0] = 1;
4479 surf_state->fill_color[0] = 1;
4480 surf_state->text_color[0] = 1;
4481 surf_state->mark_color[0] = 1;
4482
4483 /* default line type is solid */
4484 surf_state->line_type = 1;
4485
4486 /* default interior style is hollow */
4487 surf_state->interior_style = CHOLLO;
4488
4489 /* char size is in VDC - default is 1/100 of default VDC extent */
4490 surf_state->char_height = 327.;
4491
4492 /* default line width specification mode is scaled, default
4493 linewidth is 1.*/
4494 surf_state->line_width = 1.;
4495
4496 /* default marker specification mode is scaled, default
4497 marker size is 1. */
4498 surf_state->mark_size = 1.;
4499
4500 /* the only default colors defined in CGI are index 0 = background,
4501 * and index 1 = foreground. Use SVDI's bg and fg until the user
4502 * sets the color table.
4503 */
4504 if (dev_descrip.svdi_type == 0) { /* vector SVDI */
4505
4506 /* set up the fg and bg mappings */
4507 surf_state->bg_index = dev_descrip.att_array[2];
4508 surf_state->fg_index = dev_descrip.att_array[1];
4509
4510 /* set the current surface color table */
4511 vdiqco(&one, &dev_descrip.index_array[surf_state->bg_index], tmp_array, &dev_descrip.col_mode);
4512 surf_state->color_table[0].r = (int)(tmp_array[0][0] * 255.0f);
4513 surf_state->color_table[0].g = (int)(tmp_array[0][1] * 255.0f);
4514 surf_state->color_table[0].b = (int)(tmp_array[0][2] * 255.0f);
4515 vdiqco(&one, &dev_descrip.index_array[surf_state->fg_index], tmp_array, &dev_descrip.col_mode);
4516 surf_state->color_table[1].r = (int)(tmp_array[0][0] * 255.0f);
4517 surf_state->color_table[1].g = (int)(tmp_array[0][1] * 255.0f);
4518 surf_state->color_table[1].b = (int)(tmp_array[0][2] * 255.0f);
4519 } /* end if vector SVDI */
4520
4521 else { /* raster SVDI */
4522
4523 vdiqci(&dev_descrip.att_array[11], &dev_descrip.att_array[12], &dev_descrip.att_array[13],
4524 &surf_state->bg_index);
4525 vdiqci(&dev_descrip.att_array[8], &dev_descrip.att_array[9], &dev_descrip.att_array[10],
4526 &surf_state->fg_index);
4527
4528 /* set the current surface color table */
4529 surf_state->color_table[0].r = (int)(dev_descrip.att_array[8] * 255.0f);
4530 surf_state->color_table[0].g = (int)(dev_descrip.att_array[9] * 255.0f);
4531 surf_state->color_table[0].b = (int)(dev_descrip.att_array[10] * 255.0f);
4532 surf_state->color_table[1].r = (int)(dev_descrip.att_array[11] * 255.0f);
4533 surf_state->color_table[1].g = (int)(dev_descrip.att_array[12] * 255.0f);
4534 surf_state->color_table[1].b = (int)(dev_descrip.att_array[13] * 255.0f);
4535 } /* end else raster SVDI */
4536
4537 /* set/reset the SVDI attribute array */
4538 /* --set everything to -1 to force resetting of attributes */
4539 surf_state->vdi_attrib.fg_color = -1;
4540 surf_state->vdi_attrib.bg_color = -1;
4541 surf_state->vdi_attrib.intensity = -1.0;
4542 surf_state->vdi_attrib.line_type = -1;
4543 surf_state->vdi_attrib.line_width = -1.0;
4544 surf_state->vdi_attrib.char_x = -1.0;
4545 surf_state->vdi_attrib.char_y = -1.0;
4546 surf_state->vdi_attrib.fg_rgb[0] = -1.0;
4547 surf_state->vdi_attrib.fg_rgb[1] = -1.0;
4548 surf_state->vdi_attrib.fg_rgb[2] = -1.0;
4549 surf_state->vdi_attrib.bg_rgb[0] = -1.0;
4550 surf_state->vdi_attrib.bg_rgb[1] = -1.0;
4551 surf_state->vdi_attrib.bg_rgb[2] = -1.0;
4552
4553 /* set color_set flag to false = color table not set by user */
4554 surf_state->color_set = FALSE;
4555
4556 /* set picture state to clean */
4557 surf_state->pic_dirty = CCLEAN;
4558
4559 } /* end init_state */
4560
4561 /* set_dev_descrip */
4562 /* Set the device description table */
4563 static void set_dev_descrip(void)
4564 {
4565 /* dev_descrip is global */
4566 int j; /* loop index */
4567 int qdc_index; /* used for inquiring SVDI */
4568 float value; /* value returned from inquire SVDI */
4569
4570 /* set copy_class */
4571 qdc_index = 1;
4572 vdiqdc(&qdc_index, &value);
4573 if (value == 0.) {
4574 dev_descrip.copy_class = CHARD;
4575 }
4576 else {
4577 dev_descrip.copy_class = CSOFT;
4578 }
4579
4580 /* device corners in device coords */
4581 dev_descrip.dc1.x = 0;
4582 dev_descrip.dc1.y = 0;
4583 qdc_index = 15;
4584 vdiqdc(&qdc_index, &value);
4585 dev_descrip.dc2.x = (int)value;
4586 qdc_index = 16;
4587 vdiqdc(&qdc_index, &value);
4588 dev_descrip.dc2.y = (int)value;
4589
4590 /* vector or raster SVDI (0=vector, 1=raster) */
4591 qdc_index = 29;
4592 vdiqdc(&qdc_index, &value);
4593 dev_descrip.svdi_type = (int)value;
4594
4595 /* vector SVDI only does indexed color, raster does both */
4596 if (dev_descrip.svdi_type == 0) {
4597 dev_descrip.csm_avail = CCLRI;
4598 }
4599 else {
4600 dev_descrip.csm_avail = CCLRID;
4601 }
4602
4603 /* device class */
4604 qdc_index = 13;
4605 vdiqdc(&qdc_index, &value);
4606 dev_descrip.dev_class = (value == 0.) ? COUTPT : COUTIN;
4607
4608 /* NDC space */
4609 vdiqnd(&dev_descrip.xndc_max, &dev_descrip.yndc_max);
4610
4611 /* output status */
4612 vdiqos(&dev_descrip.att_array[1]);
4613
4614 /* min line width - SVDI returns value in DC */
4615 qdc_index = 19;
4616 vdiqdc(&qdc_index, &value);
4617 dev_descrip.linewidth_min = (int)value;
4618
4619 /* max line width - SVDI returns value in DC */
4620 qdc_index = 31;
4621 vdiqdc(&qdc_index, &value);
4622 dev_descrip.linewidth_max = (int)value;
4623
4624 /* use the default SVDI linewidth as nominal */
4625 /* --convert to device coordinates */
4626 value = (dev_descrip.att_array[5] / dev_descrip.xndc_max) * .01 *
4627 (dev_descrip.dc2.x - dev_descrip.dc1.x);
4628 dev_descrip.linewidth_nominal = (int)max(value, 1.);
4629
4630 /* --make sure that for some reason it isn't out of range */
4631 dev_descrip.linewidth_nominal =
4632 max(min(dev_descrip.linewidth_nominal, dev_descrip.linewidth_max), dev_descrip.linewidth_min);
4633
4634 /* nominal,min,max marker size - only one size */
4635 qdc_index = 20;
4636 vdiqdc(&qdc_index, &value);
4637 dev_descrip.mark_nominal = (int)value;
4638 dev_descrip.mark_min = (int)value;
4639 dev_descrip.mark_max = (int)value;
4640
4641 /* inquire the number of colors */
4642 qdc_index = 4;
4643 vdiqdc(&qdc_index, &value);
4644
4645 /* check for max colors */
4646 dev_descrip.num_cols = ((int)value > COLOR_TABLE_SIZE) ? COLOR_TABLE_SIZE : (int)value;
4647
4648 /* set up a color index array for use in color table stuff */
4649 for (j = 0; j < 256; j++) {
4650 dev_descrip.index_array[j] = j;
4651 }
4652
4653 /* set SVDI color mode */
4654 dev_descrip.col_mode = 0;
4655
4656 /* inquire default SVDI color table. */
4657 vdiqco(&dev_descrip.num_cols, dev_descrip.index_array, dev_descrip.color_array,
4658 &dev_descrip.col_mode);
4659
4660 } /* end set_dev_descrip */
4661
4662 /* reset_vdi */
4663 /* Reset SVDI values. Used if CI is called twice */
4664 static void reset_vdi(surf_statelist *surf_state)
4665 /* current surface statelist */
4666 {
4667
4668 /* reset the output status */
4669 vdstos(&dev_descrip.att_array[1]);
4670
4671 /* only reset color table is user has changed it */
4672 if (surf_state->color_set) {
4673 vdstco(&dev_descrip.num_cols, dev_descrip.index_array, dev_descrip.color_array,
4674 &dev_descrip.col_mode);
4675 }
4676 } /* end reset_vdi */
4677
4678 /* set_mapping */
4679 /* Set up the VDC to NDC mappings. Also sets the effective viewports
4680 * in NDC and VDC.
4681 */
4682 static void set_mapping(surf_statelist *surf_state)
4683 {
4684 point ndc_vp1, ndc_vp2;
4685
4686 /* viewport in NDC space */
4687 ndc_vp1.x = cur_state->vp1.x * dev_descrip.xndc_max;
4688 ndc_vp1.y = cur_state->vp1.y * dev_descrip.yndc_max;
4689 ndc_vp2.x = cur_state->vp2.x * dev_descrip.xndc_max;
4690 ndc_vp2.y = cur_state->vp2.y * dev_descrip.yndc_max;
4691
4692 /* x and y scale maps VDC to viewport in NDC (ISOTROPIC Mapping) */
4693 /* ...smallest scale magnitude, but keep the original sign */
4694 surf_state->xscale = (ndc_vp2.x - ndc_vp1.x) / (surf_state->vdc2.x - surf_state->vdc1.x);
4695 surf_state->yscale = (ndc_vp2.y - ndc_vp1.y) / (surf_state->vdc2.y - surf_state->vdc1.y);
4696
4697 if (fabs(surf_state->xscale) < fabs(surf_state->yscale)) {
4698 surf_state->yscale =
4699 (surf_state->yscale < 0) ? -1 * fabs(surf_state->xscale) : fabs(surf_state->xscale);
4700 }
4701 else {
4702 surf_state->xscale =
4703 (surf_state->xscale < 0) ? -1 * fabs(surf_state->yscale) : fabs(surf_state->yscale);
4704 }
4705
4706 /* x and y offset for VDC to NDC mapping */
4707 surf_state->xoffset = (ndc_vp1.x < ndc_vp2.x)
4708 ? ndc_vp1.x - surf_state->vdc1.x * surf_state->xscale
4709 : ndc_vp2.x - surf_state->vdc2.x * surf_state->xscale;
4710
4711 surf_state->yoffset = (ndc_vp1.y < ndc_vp2.y)
4712 ? ndc_vp1.y - surf_state->vdc1.y * surf_state->yscale
4713 : ndc_vp2.y - surf_state->vdc2.y * surf_state->yscale;
4714
4715 /* effective viewport */
4716 /* - mode is FRACTION OF DRAWING SURFACE */
4717 surf_state->eff_vp1.x = cur_state->vp1.x;
4718 surf_state->eff_vp1.y = cur_state->vp1.y;
4719 surf_state->eff_vp2.x =
4720 (surf_state->vdc2.x * surf_state->xscale + surf_state->xoffset) / dev_descrip.xndc_max;
4721 surf_state->eff_vp2.y =
4722 (surf_state->vdc2.y * surf_state->yscale + surf_state->yoffset) / dev_descrip.yndc_max;
4723
4724 } /* end set_mapping */
4725
4726 /* set_clipping */
4727 /* Set up the clip region. */
4728 static void set_clipping(surf_statelist *my_cur_state)
4729 {
4730 point clip1, clip2; /* temp clip values */
4731 clip1.x = clip1.y = clip2.x = clip2.y = 0;
4732
4733 /* The clip region depends on clip indicator and drawing surface
4734 * clip indicator.
4735 */
4736 switch (my_cur_state->clip_indicator) {
4737 case CON:
4738
4739 /* VDC clipping is on */
4740 switch (my_cur_state->ds_clip_indicator) {
4741
4742 case CDCOFF: /* view surface clipping off */
4743
4744 /* map the effective clip rectangle to NDC */
4745 my_cur_state->clip_on = TRUE;
4746 clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset;
4747 clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset;
4748 clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset;
4749 clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset;
4750
4751 break; /* end case CDCOFF */
4752
4753 case CVPORT: /* clip at viewport */
4754
4755 /* map the effective clip rectangle to NDC */
4756 my_cur_state->clip_on = TRUE;
4757
4758 clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset;
4759 clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset;
4760 clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset;
4761 clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset;
4762
4763 break; /* end case CVPORT */
4764
4765 case CDCREC: /* clip at display surface */
4766
4767 /* map the effective clip rectangle to NDC and intersect it
4768 with the max NDC space */
4769 my_cur_state->clip_on = TRUE;
4770
4771 clip1.x = my_cur_state->eff_clip_rect1.x * my_cur_state->xscale + my_cur_state->xoffset;
4772 clip1.y = my_cur_state->eff_clip_rect1.y * my_cur_state->yscale + my_cur_state->yoffset;
4773 clip2.x = my_cur_state->eff_clip_rect2.x * my_cur_state->xscale + my_cur_state->xoffset;
4774 clip2.y = my_cur_state->eff_clip_rect2.y * my_cur_state->yscale + my_cur_state->yoffset;
4775
4776 clip1.x = max(min(clip1.x, clip2.x), 0.0);
4777 clip1.y = max(min(clip1.y, clip2.y), 0.0);
4778 clip2.x = min(max(clip1.x, clip2.x), dev_descrip.xndc_max);
4779 clip2.y = min(max(clip1.y, clip2.y), dev_descrip.yndc_max);
4780
4781 break; /* end case CDCREC */
4782
4783 default:
4784 /* illegal enumeration type - ignore function */
4785 break;
4786
4787 } /* end switch ds_clip_indicator */
4788
4789 break; /* end case CON */
4790
4791 case COFF:
4792
4793 /* VDC clipping is off */
4794 switch (my_cur_state->ds_clip_indicator) {
4795
4796 case CDCOFF: /* display surface clipping off */
4797
4798 /* no clip */
4799 my_cur_state->clip_on = FALSE;
4800 break; /* end case CDCOFF */
4801
4802 case CVPORT: /* clip at viewport */
4803
4804 /* clip at NDC effective viewport */
4805 my_cur_state->clip_on = TRUE;
4806 clip1.x = my_cur_state->eff_vp1.x * dev_descrip.xndc_max;
4807 clip1.y = my_cur_state->eff_vp1.y * dev_descrip.yndc_max;
4808 clip2.x = my_cur_state->eff_vp2.x * dev_descrip.xndc_max;
4809 clip2.y = my_cur_state->eff_vp2.y * dev_descrip.yndc_max;
4810 break; /* end case CVPORT */
4811
4812 case CDCREC: /* clip at display surface */
4813
4814 /* clip at max NDC space */
4815 my_cur_state->clip_on = TRUE;
4816 clip1.x = 0.0;
4817 clip1.y = 0.0;
4818 clip2.x = dev_descrip.xndc_max;
4819 clip2.y = dev_descrip.yndc_max;
4820 break; /* end case CDCREC */
4821
4822 default:
4823 /* illegal enumeration type - ignore function */
4824 break;
4825
4826 } /* end switch ds_clip_indicator */
4827
4828 break; /* end case COFF */
4829
4830 default:
4831 /* illegal enumeration type - ignore function */
4832 break;
4833
4834 } /* end switch clip_indicator */
4835
4836 /* set clipmin and clipmax such that clipmin is the minimum corner of
4837 * the clipping window, and clipmax is the maximum. This is done
4838 * so that the clipping algorithms work correctly with mirroring.
4839 */
4840 if (my_cur_state->clip_on) {
4841 my_cur_state->clipmin.x = min(clip1.x, clip2.x);
4842 my_cur_state->clipmax.x = max(clip1.x, clip2.x);
4843 my_cur_state->clipmin.y = min(clip1.y, clip2.y);
4844 my_cur_state->clipmax.y = max(clip1.y, clip2.y);
4845 }
4846 } /* end set_clipping */
4847
4848 /* set_foreground_color */
4849 /* Set the SVDI foreground color */
4850 static void set_foreground_color(surf_statelist *surf_state, int *colors)
4851 {
4852 int zero = 0;
4853 int one = 1;
4854
4855 /* if color selection mode is in error, ignore function */
4856 if (surf_state->csm == -1) {
4857 return;
4858 }
4859
4860 /* indexed or direct color? */
4861 /* --vector SVDI only does indexed color */
4862 if (surf_state->csm == CINDEX || dev_descrip.svdi_type == 0) {
4863
4864 /* does foreground need to be updated? */
4865 if (colors[0] != cur_state->vdi_attrib.fg_color) {
4866
4867 /* color index mappings:
4868 * if set index 0 --> set bg_index
4869 * if set index 1 --> set fg_index
4870 * if set bg_index --> set 0
4871 * if set fg_index --> set 1
4872 */
4873 if (colors[0] == 0) {
4874 vdstfc(&cur_state->bg_index);
4875 }
4876 else if (colors[0] == 1) {
4877 vdstfc(&cur_state->fg_index);
4878 }
4879 else if (colors[0] == cur_state->bg_index) {
4880 vdstfc(&zero);
4881 }
4882 else if (colors[0] == cur_state->fg_index) {
4883 vdstfc(&one);
4884 }
4885 else {
4886 vdstfc(&colors[0]);
4887 }
4888
4889 /* update att_array */
4890 cur_state->vdi_attrib.fg_color = colors[0];
4891
4892 /* flag (direct) that foreground color has changed */
4893 /* do i need to do this? */
4894 cur_state->vdi_attrib.fg_rgb[0] = -1.0;
4895 cur_state->vdi_attrib.fg_rgb[1] = -1.0;
4896 cur_state->vdi_attrib.fg_rgb[2] = -1.0;
4897 } /* end does foreground... */
4898 } /* end indexed color */
4899
4900 else /* direct color */
4901
4902 /* does foreground need to be updated? */
4903 /* -- i need to check this out - might need to store as int */
4904 if (colors[0] != (int)(cur_state->vdi_attrib.fg_rgb[0] * 255.0f) ||
4905 colors[1] != (int)(cur_state->vdi_attrib.fg_rgb[1] * 255.0f) ||
4906 colors[2] != (int)(cur_state->vdi_attrib.fg_rgb[2] * 255.0f)) {
4907
4908 /* update att_array */
4909 cur_state->vdi_attrib.fg_rgb[0] = (float)colors[0] / 255.0f;
4910 cur_state->vdi_attrib.fg_rgb[1] = (float)colors[1] / 255.0f;
4911 cur_state->vdi_attrib.fg_rgb[2] = (float)colors[2] / 255.0f;
4912
4913 /* set new foreground color */
4914 vdfrgb(&cur_state->vdi_attrib.fg_rgb[0], &cur_state->vdi_attrib.fg_rgb[1],
4915 &cur_state->vdi_attrib.fg_rgb[2]);
4916
4917 /* flag (indexed) that foreground color has changed */
4918 /* do i need to do this? */
4919 cur_state->vdi_attrib.fg_color = -1;
4920 } /* end does foreground... */
4921
4922 } /* end set_foreground_color */
4923
4924 /* set_background_color */
4925 /* Set the SVDI background color */
4926 static void set_background_color(surf_statelist *surf_state, int *colors)
4927 {
4928 int i = 0; /* loop index */
4929 int index = 0; /* color index */
4930 float dr, dg, db, dmin, dist; /* for finding the closet index */
4931 int one = 1;
4932 float epsilon = .001;
4933
4934 /* does background need to be updated */
4935 /* --background color is saved in att_array, even for vector */
4936 if (colors[0] != (int)(cur_state->vdi_attrib.bg_rgb[0] * 255.0f) ||
4937 colors[1] != (int)(cur_state->vdi_attrib.bg_rgb[1] * 255.0f) ||
4938 colors[2] != (int)(cur_state->vdi_attrib.bg_rgb[2] * 255.0f)) {
4939
4940 /* store new values in att_array */
4941 cur_state->vdi_attrib.bg_rgb[0] = (float)colors[0] / 255.0f;
4942 cur_state->vdi_attrib.bg_rgb[1] = (float)colors[1] / 255.0f;
4943 cur_state->vdi_attrib.bg_rgb[2] = (float)colors[2] / 255.0f;
4944
4945 /* set the cgi state color table - index 0 */
4946 cur_state->color_table[0].r = colors[0];
4947 cur_state->color_table[0].g = colors[1];
4948 cur_state->color_table[0].b = colors[2];
4949
4950 /* has the SVDI color table ever been set */
4951 if (!surf_state->color_set) { /* has never been set */
4952
4953 /* find out if default SVDI table contains this color */
4954 if (dev_descrip.svdi_type == 1) { /* raster SVDI */
4955
4956 vdiqci(&cur_state->vdi_attrib.bg_rgb[0], &cur_state->vdi_attrib.bg_rgb[1],
4957 &cur_state->vdi_attrib.bg_rgb[2], &i);
4958
4959 /* does it match */
4960 dr = cur_state->vdi_attrib.bg_rgb[0] - dev_descrip.color_array[i][0];
4961 dg = cur_state->vdi_attrib.bg_rgb[1] - dev_descrip.color_array[i][1];
4962 db = cur_state->vdi_attrib.bg_rgb[2] - dev_descrip.color_array[i][2];
4963 dmin = dr * dr + dg * dg + db * db;
4964 } /* end raster SVDI */
4965
4966 else { /* vector SVDI */
4967
4968 for (i = 0; i < 8; i++) {
4969 dr = cur_state->vdi_attrib.bg_rgb[0] - dev_descrip.color_array[i][0];
4970 dg = cur_state->vdi_attrib.bg_rgb[1] - dev_descrip.color_array[i][1];
4971 db = cur_state->vdi_attrib.bg_rgb[2] - dev_descrip.color_array[i][2];
4972 dist = dr * dr + dg * dg + db * db;
4973
4974 if (i == 0 || dist < dmin) {
4975 dmin = dist;
4976 index = i;
4977 }
4978 } /* end for i */
4979 } /* end vector SVDI */
4980
4981 /* is it close enough? */
4982 if (dmin <= epsilon) {
4983 cur_state->bg_index = index;
4984 }
4985
4986 else { /* not close enough, set SVDI color table */
4987
4988 cur_state->bg_index = 0;
4989 vdstco(&one, &dev_descrip.index_array[cur_state->bg_index], &cur_state->vdi_attrib.bg_rgb,
4990 &dev_descrip.col_mode);
4991 cur_state->color_set = TRUE; /* flag that CT has been set */
4992 } /* end else not close enough */
4993
4994 } /* end has never been set */
4995
4996 else { /* color table has been set */
4997
4998 /* set SVDI color table */
4999 vdstco(&one, &dev_descrip.index_array[cur_state->bg_index], &cur_state->vdi_attrib.bg_rgb,
5000 &dev_descrip.col_mode);
5001
5002 } /* end else has been set */
5003
5004 /* set the SVDI background color */
5005 if (dev_descrip.svdi_type == 1) { /* raster SVDI */
5006 vdbrgb(&cur_state->vdi_attrib.bg_rgb[0], &cur_state->vdi_attrib.bg_rgb[1],
5007 &cur_state->vdi_attrib.bg_rgb[2]);
5008 }
5009 else { /* vector SVDI */
5010
5011 /* once the ct has been set, bg_index never changes */
5012 /* if( !cur_state->color_set ) */
5013 vdstbc(&cur_state->bg_index);
5014 }
5015
5016 } /* end does background need to be updated */
5017 } /* end set_background_color */
5018
5019 /* report_error */
5020 /* Stuff the error info into the error queue */
5021 static void report_error(surf_statelist *surf_state, int e_class, int e_num, int f_id)
5022 {
5023 int err_slot; /* slot in the queue to put the error */
5024
5025 /* is error reporting on for this class? */
5026 if (surf_state->err_flag[e_class - 1] == CEHON) {
5027
5028 /* figure out where the next slot is */
5029 err_slot = surf_state->err_head_ptr + surf_state->err_count;
5030 if (err_slot >= ERROR_LIST_SIZE) {
5031 err_slot = err_slot - ERROR_LIST_SIZE;
5032 }
5033
5034 /* store errors if there is room in the queue */
5035 if (surf_state->err_count < ERROR_LIST_SIZE) {
5036 surf_state->err_queue[err_slot].err_class = e_class;
5037 surf_state->err_queue[err_slot].err_num = e_num;
5038 surf_state->err_queue[err_slot].func_id = f_id;
5039 surf_state->err_count++;
5040 } /* end if room in the queue */
5041
5042 else { /* not enuff room in the queue */
5043
5044 /* if the most recent error is ERROR REPORTS LOST, increase count
5045 of errors lost by one (count is stored in func_id) */
5046 if (surf_state->err_queue[err_slot - 1].err_class == -1 &&
5047 surf_state->err_queue[err_slot - 1].err_num == 0) {
5048 surf_state->err_queue[err_slot - 1].func_id++;
5049 }
5050 else { /* create an ERROR REPORTS LOST error */
5051 /* The format for an ERROR REPORTS LOST has not yet
5052 * been defined. For now, use error class -1, error
5053 * number 0, and the count in function id.
5054 * (as defined in SRCP document)
5055 */
5056 surf_state->err_queue[err_slot - 1].err_class = -1;
5057 surf_state->err_queue[err_slot - 1].err_num = 0;
5058 surf_state->err_queue[err_slot - 1].func_id = 2;
5059 } /* end else create */
5060 } /* end not enuff room in the queue */
5061
5062 } /* end if error reporting is on */
5063 } /* end report_error */
5064
5065 /* gettoken */
5066 /* Return one token from data record....written by Pat MaGee, LANL */
5067 static void gettoken(int *index_p, int *numrecs_p, char *data_p, int max_chars, char *outtoken_p)
5068 /* in: 1st char of whitespace before token */
5069 /* out: 1st char past token */
5070 /* in: number of data records */
5071 /* in: 80 character records */
5072 /* in: max # of chars to put into outtoken */
5073 /* out: where to put output token */
5074 {
5075 char c; /* char from data record */
5076 int num_chars; /* # chars put into outtoken so far */
5077 int workstate; /* 0=whitespace,1=nonwhite,2=endofstring */
5078
5079 num_chars = 0;
5080
5081 workstate = 0;
5082 if (*index_p >= (*numrecs_p * 80)) {
5083 workstate = 2;
5084 }
5085
5086 while (workstate == 0) { /* while scanning whitespace */
5087 c = data_p[*index_p];
5088 if ((c == ' ') || (c == '\t') || (c == '\r')) {
5089 /* c is whitespace, keep scanning */
5090 ++(*index_p);
5091 if (*index_p >= *numrecs_p * 80) {
5092 workstate = 2;
5093 } /* end if off end of data */
5094 }
5095 else {
5096 /* c is not whitespace, is start of token */
5097 workstate = 1;
5098 } /* end if c is whitespace */
5099 } /* end while skipping whitespace */
5100
5101 while (workstate == 1) { /* while in token */
5102 c = data_p[*index_p];
5103 if (num_chars >= max_chars) {
5104 workstate = 3;
5105 }
5106 if ((c == ' ') || (c == '\t') || (c == '\r')) {
5107 workstate = 0;
5108 }
5109 else { /* c is not whitespace, output and keep scanning */
5110 outtoken_p[num_chars] = c;
5111 ++num_chars;
5112 ++(*index_p);
5113 if (*index_p >= *numrecs_p * 80) {
5114 workstate = 2;
5115 } /* end if off end of data */
5116 } /* end if c is whitespace */
5117
5118 } /* end while putting chars into outtoken */
5119
5120 outtoken_p[num_chars] = 0;
5121
5122 } /* end gettoken */
5123
5124 /* poly_clip */
5125 /* Clip a polygon. Based on Sutherland - Hodgman algorithm
5126 * Returns the new polygon vertices, and the new vertex count.
5127 * One day, I need to make this more efficient by moving everything
5128 * inline.
5129 */
5130 static int poly_clip(point *cmin, point *cmax, float *vx, float *vy, int vlen, float *xout,
5131 float *yout, int *lenout)
5132 {
5133 point s, p, t;
5134 int i, j, bnd, curlen;
5135 float xtemp[MAX_POLYGON];
5136 float ytemp[MAX_POLYGON];
5137
5138 /* make sure there is something to clip */
5139 if (vlen <= 0) {
5140 return (FALSE);
5141 }
5142
5143 for (bnd = 0; bnd < 4; bnd++) { /* loop through all boundaries */
5144
5145 /* start with last vertex */
5146 if (bnd == 0) { /* 1st time through use original vertex list */
5147 curlen = vlen;
5148 *lenout = 0;
5149 s.x = vx[curlen - 1];
5150 s.y = vy[curlen - 1];
5151 }
5152 else { /* after 1st time through, use new vertex list */
5153 curlen = *lenout;
5154 *lenout = 0;
5155 if (curlen > 0) {
5156 s.x = xout[curlen - 1];
5157 s.y = yout[curlen - 1];
5158 }
5159 }
5160
5161 for (i = 0; i < curlen; i++) { /* loop through all vertices */
5162
5163 if (bnd == 0) {
5164 p.x = vx[i];
5165 p.y = vy[i];
5166 }
5167 else {
5168 p.x = xout[i];
5169 p.y = yout[i];
5170 }
5171
5172 /* is vertex p 'inside' current boundary */
5173 if (inside_bnd(&p, cmin, cmax, bnd)) {
5174
5175 /* is vertex s 'inside' current boundary */
5176 if (inside_bnd(&s, cmin, cmax, bnd)) {
5177
5178 /* both p and s are inside, add p to vertex list */
5179 xtemp[*lenout] = p.x;
5180 ytemp[(*lenout)++] = p.y;
5181 } /* end s is inside */
5182
5183 else { /* p is inside, s is outside, intersect */
5184
5185 t = intersect_bnd(&s, &p, cmin, cmax, bnd);
5186
5187 /* add t and p to the vertex list */
5188 xtemp[*lenout] = t.x;
5189 ytemp[(*lenout)++] = t.y;
5190 xtemp[*lenout] = p.x;
5191 ytemp[(*lenout)++] = p.y;
5192 } /* end else intersect */
5193
5194 } /* end if p is inside */
5195
5196 else { /* p is outside, is s inside */
5197
5198 if (inside_bnd(&s, cmin, cmax, bnd)) {
5199
5200 /* p is outside, s is inside, intersect */
5201 t = intersect_bnd(&s, &p, cmin, cmax, bnd);
5202
5203 /* add t to the vertex list */
5204 xtemp[*lenout] = t.x;
5205 ytemp[(*lenout)++] = t.y;
5206 } /* end intersect */
5207 } /* end else p outside, s inside */
5208
5209 s.x = p.x;
5210 s.y = p.y;
5211 } /* end for i */
5212
5213 for (j = 0; j < *lenout; j++) {
5214 xout[j] = xtemp[j];
5215 yout[j] = ytemp[j];
5216 } /* end for j */
5217
5218 } /* end for bnd */
5219
5220 if (*lenout <= 0) {
5221 return (FALSE);
5222 }
5223 return (TRUE);
5224 } /* end poly_clip */
5225
5226 /* inside_bnd */
5227 /* Used by poly_clip and returns true if the vertex is within the
5228 * boundary. ( where the boundaries are numbered 1-4,corresponding to
5229 * top, right, bottom, left )
5230 */
5231 static int inside_bnd(point *v, point *bmin, point *bmax, int bound_num)
5232 {
5233 /* this routine assumes a rectangular boundary */
5234 switch (bound_num) {
5235 case 0: return (v->y <= bmax->y); /* top */
5236 case 1: return (v->x <= bmax->x); /* right */
5237 case 2: return (v->y >= bmin->y); /* bottom */
5238 case 3: return (v->x >= bmin->x); /* left */
5239 default: return (FALSE);
5240 } /* end switch */
5241 } /* end inside_bnd */
5242
5243 /* intersect_bnd */
5244 /* Used by poly_clip. Returns the the intersection point of a polygon
5245 * edge with a clip boundary. The clip boundary is coded 1-4, corresponding
5246 * to top, right, bottom, and left boundary edges, respectsively.
5247 */
5248 static point intersect_bnd(point *p1, point *p2, point *bmin, point *bmax, int bound_num)
5249 {
5250 point temp;
5251 temp.x = temp.y = 0;
5252
5253 switch (bound_num) {
5254 case 0: /* top */
5255 temp.x = p1->x + (p2->x - p1->x) * (bmax->y - p1->y) / (p2->y - p1->y);
5256 temp.y = bmax->y;
5257 break;
5258
5259 case 1: /* right */
5260 temp.y = p1->y + (p2->y - p1->y) * (bmax->x - p1->x) / (p2->x - p1->x);
5261 temp.x = bmax->x;
5262 break;
5263
5264 case 2: /* bottom */
5265 temp.x = p1->x + (p2->x - p1->x) * (bmin->y - p1->y) / (p2->y - p1->y);
5266 temp.y = bmin->y;
5267 break;
5268
5269 case 3: /* left */
5270 temp.y = p1->y + (p2->y - p1->y) * (bmin->y - p1->x) / (p2->x - p1->x);
5271 temp.x = bmin->x;
5272 break;
5273
5274 default:
5275 /* error check ? */
5276 break;
5277
5278 } /* end switch */
5279 return (temp);
5280 } /* end intersect_bnd */
5281
5282 /*-------------------------------------------------------------*/
5283 /* >> CDR ROUTINES */
5284 /*-------------------------------------------------------------*/
5285
5286 /* cur_state is global - points to current statelist */
5287 /*
5288 Open file for sequential access. FORTRAN unit number is ignored.
5289 File descriptor which is returned from open is stored in current
5290 statelist
5291 */
5292 void cdrofs(int *ifilcd)
5293 {
5294 int errnum, errsev;
5295 char symbol[1024];
5296 int qdc_index;
5297 float value;
5298 char *devid;
5299 char *env;
5300 static int file_cnt = 1;
5301
5302 /* if user hasn't named the file, build a default */
5303 if (!cur_state->filename[0]) { /* filename is blank */
5304 /* get the SVDI device code */
5305 qdc_index = 23;
5306 vdiqdc(&qdc_index, &value);
5307 devid = get_devid_char(value);
5308 if (devid != NULL) {
5309 snprintf(cur_state->filename, 100, "cgi%s%d", devid, file_cnt++);
5310 }
5311 else {
5312 snprintf(cur_state->filename, 100, "cgiout%d", file_cnt++);
5313 }
5314 }
5315
5316 /* copy filename to symbol */
5317 copy_string(symbol, cur_state->filename, 1024);
5318
5319 /* check the environment to see if a file name has been assigned */
5320 env = getenv(symbol);
5321 if (env != 0 && strlen(env) < 1024) {
5322 snprintf(symbol, 1024, "%s", env);
5323 }
5324
5325 /* open the file - if it doesn't exist, create it with mode 664 */
5326 /* -- open returns a file descriptor which is stored in the statelist */
5327 /* -- O_TRUNC ??? read/writing??? */
5328 if ((cur_state->file_d = open(symbol, (O_CREAT | O_TRUNC | O_RDWR), 0664)) == -1) {
5329 errnum = 722;
5330 errsev = 10;
5331 char err[50];
5332 snprintf(err, 50, "SVDI ERROR NUMBER %d SEVERITY CODE %d", errnum, errsev);
5333 perror(err);
5334 }
5335 }
5336
5337 /* this routine is here only for compatibility with SVDI drivers */
5338 void cdrof3(int *ifilcd, int *idum) { cdrofs(ifilcd); }
5339
5340 /* this routine is here only for compatibility with SVDI drivers */
5341 void cdroff(int *ifilcd, int *idum1, int *idum2, int *idum3) { cdrofs(ifilcd); }
5342
5343 /*
5344 Try to read LENGTH words from the file. Return the actual number
5345 of words read. FORTRAN unit number is ignored, file descriptor is
5346 gotten from the current statelist
5347 */
5348 void cdrrfs(int *ifilcd, int *length, char *buffer, int *istat)
5349 {
5350
5351 /* if the file hasn't been opened, open it */
5352 if (cur_state->file_d == -1) {
5353 cdrofs(ifilcd);
5354 }
5355
5356 /* read the data as a byte stream */
5357 if ((*istat = read(cur_state->file_d, buffer, (*length * cdrcom.KCPW))) != -1) {
5358 *istat = *istat / cdrcom.KCPW;
5359 }
5360 }
5361
5362 /*
5363 Write LENGTH words from BUFFER to the file. FORTRAN unit number is
5364 ignored, file descriptor is gotten from the current state list
5365 */
5366 void cdrwfs(int *ifilcd, int *length, char *buffer, int *istat)
5367 {
5368
5369 /* if the file hasn't been opened, open it */
5370 if (cur_state->file_d == 0) {
5371 cdrofs(ifilcd);
5372 }
5373
5374 /* write out the data as a byte stream. */
5375 if ((*istat = write(cur_state->file_d, buffer, (*length * cdrcom.KCPW))) == -1) {
5376 *istat = 1;
5377 }
5378 else {
5379 *istat = 0;
5380 }
5381 }
5382
5383 /*
5384 Close file sequential. FORTRAN unit number is ignore and file
5385 descriptor is gotten from current state
5386 */
5387 void cdrcfs(int *ifilcd, int *eof)
5388 {
5389 int istat;
5390 char buf[4];
5391 char err[50];
5392
5393 /* if eof = 1 then write eof on file */
5394 if (*eof == 1) {
5395 *buf = EOF;
5396 if ((istat = write(cur_state->file_d, buf, 4)) == -1) {
5397 snprintf(err, 50, "%s", "CDRCFS error");
5398 perror(err);
5399 }
5400 }
5401
5402 /* close the file */
5403 close(cur_state->file_d);
5404 }
5405
5406 /* open routine for the Abekas */
5407 void cdroab(int *ifilcd, int *frame)
5408 {
5409 char ic[5];
5410 int i, inbr;
5411
5412 /* form the file name from the frame number */
5413 inbr = *frame;
5414 for (i = 3; i >= 0; i--) {
5415 ic[i] = inbr % 10 + '0';
5416 inbr = inbr / 10;
5417 }
5418 ic[4] = '\0';
5419
5420 /* set the file name in the state list */
5421 snprintf(cur_state->filename, 100, "%s.RGB", ic);
5422
5423 cdrofs(ifilcd);
5424 }