Debian Codegraph @

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