Debian Codegraph @

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

raw
1 /*
2 * Copyright(C) 1999-2022 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 /* mdcgi - multiple simultaneous devices routines for cgi */
9 #include "mdcgi.h"
10 #include "stdtyp.h"
11 #include <stdio.h> // for fprintf, stderr, NULL
12 /******************************************************************************/
13 /* */
14 /* Global variables */
15 /* */
16 /******************************************************************************/
17
18 /* these are shared with sdcgi.c, and are defined there */
19
20 extern device_struct devices[MAX_DEVICES]; /* list of currently active */
21 extern anything *in_params[MAX_IN_PARAMS]; /* params sent to driver */
22 extern short num_devices; /* how many items in devices*/
23 extern anything *sol_surf; /* current solicitation surface, */
24
25 /* these aren't shared with anybody */
26 static int num_oldest = 0; /* # surfs in oldest_surfs */
27 static anything *oldest_surfs[MAX_SURFACES]; /* states of oldest surfaces */
28
29 /******************************************************************************/
30 /* */
31 /* Added functions to allow for multiple simultaneous devices */
32 /* */
33 /******************************************************************************/
34
35 /******************************************************************************/
36 /* */
37 /* xcoon - turn output on for a cgi display surface. */
38 /* Note: it is not an error to turn output on for a surface which is */
39 /* already on. */
40 /* Note: it is an error to turn output on for a surface which is not */
41 /* initialized. */
42 /* */
43 /******************************************************************************/
44 #if defined(ADDC_)
45 void xcoon_(anything **surface_id) /* which surface to turn output on for*/
46 #else
47 void xcoon(anything **surface_id) /* which surface to turn output on for*/
48 #endif
49 {
50 /* does surface_id point to a valid surface? */
51 /* if not, do error action */
52 /* find out which device this surface is on */
53 /* rearrange the surface list for that device */
54
55 /* search active devices for this surface */
56 short dev_found = -1;
57 short surf_found = 0; /* which active_surface was found */
58 for (short dev = 0; (dev < num_devices) && (dev_found == -1); ++dev) {
59 for (short surf = 0; surf < devices[dev].num_active_surfaces; ++surf) {
60 if (*surface_id == devices[dev].statelist[surf]) {
61 dev_found = dev;
62 surf_found = surf;
63 break;
64 } /* end if found on list */
65 } /* end for */
66 } /* end for all devices */
67
68 /* does surface_id point to a valid surface? */
69 if (dev_found < 0) {
70 fprintf(stderr, "xcoon: surface id not a valid surface\n");
71 return;
72 } /* end if surface not found */
73
74 /* if surface was off */
75 if (surf_found >= devices[dev_found].num_on_surfaces) {
76 ++devices[dev_found].num_on_surfaces;
77 /* swap target surface with first off surface if there is one */
78 if (devices[dev_found].num_on_surfaces != devices[dev_found].num_active_surfaces) {
79 anything *temp = devices[dev_found].statelist[surf_found];
80 devices[dev_found].statelist[surf_found] =
81 devices[dev_found].statelist[devices[dev_found].num_on_surfaces - 1];
82 devices[dev_found].statelist[devices[dev_found].num_on_surfaces - 1] = temp;
83 } /* end if there is an off surface */
84 } /* end if surface was off */
85 } /* end xcoon */
86
87 /******************************************************************************/
88 /* */
89 /* xcact - initialize and activate a cgi display surface */
90 /* */
91 /******************************************************************************/
92 #if defined(ADDC_)
93 void xcact_(void (*device_fn)(anything **, int, anything **), anything **p_surface_id)
94 #else
95 void xcact(void (*device_fn)(anything **, int, anything **), anything **p_surface_id)
96 #endif
97 {
98 /* is device already initialized? */
99 short which_device = -1;
100 for (short i = 0; i < num_devices; ++i) {
101 if (device_fn == devices[i].device_fn) {
102 which_device = i;
103 break;
104 } /* end if */
105 } /* end for */
106
107 if (which_device < 0) { /* if device not initialized */
108 if (num_devices >= MAX_DEVICES) { /* if no room */
109 fprintf(stderr, "xcact: can't activate: too many initialized devices\n");
110 *p_surface_id = NULL;
111 return;
112 } /* end if no room for device */
113 } /* end if device not initialized */
114
115 /* call the device driver with ACTIVATE, so it can allocate a state list */
116 short arg1 = ACTIVATE_FN;
117 in_params[0] = (anything *)&arg1;
118 anything *temp_surface[1]; /* for calling driver */
119 (*device_fn)(in_params, 1, temp_surface);
120
121 if (temp_surface[0] == NULL) { /* error */
122 fprintf(stderr, "xcact: can't activate surface: driver error\n");
123 *p_surface_id = NULL;
124 return;
125 } /* end if error on activate */
126
127 if (which_device < 0) { /* if device not initialized */
128 /* then initialize it */
129 which_device = num_devices;
130 ++num_devices;
131 devices[which_device].num_active_surfaces = 0;
132 devices[which_device].num_on_surfaces = 0;
133 devices[which_device].device_fn = device_fn;
134 } /* end if */
135
136 /* add new surface to device */
137 short which_surface = devices[which_device].num_active_surfaces;
138 ++devices[which_device].num_active_surfaces;
139 devices[which_device].statelist[which_surface] = temp_surface[0];
140
141 /* if new surface is the oldest surface, make it the solicitation surface */
142 if (num_oldest == 0) {
143 sol_surf = temp_surface[0];
144 }
145
146 /* put this surface as newest surf on oldest_surfs list */
147 oldest_surfs[num_oldest] = temp_surface[0];
148 ++num_oldest;
149
150 /* return id of new surface */
151 *p_surface_id = temp_surface[0];
152
153 } /* end xcact */
154
155 /******************************************************************************/
156 /* */
157 /* xcooff - turn output off for a display surface */
158 /* Note: it is not an error to turn off a surface which is */
159 /* already off. */
160 /* Note: it is an error to turn off a surface which is not active. */
161 /* */
162 /******************************************************************************/
163
164 /******************************************************************************/
165 /* */
166 /* xcdact - deactivate a cgi display surface */
167 /* Note: it is an error to deactivate a surface which is not active. */
168 /* */
169 /******************************************************************************/
170
171 /******************************************************************************/
172 /* */
173 /* xcsol - set solicitation surface */
174 /* */
175 /******************************************************************************/
176 #if defined(ADDC_)
177 void xcsol_(anything **surface_id)
178 #else
179 void xcsol(anything **surface_id)
180 #endif
181 {
182 /* does surface_id point to a valid surface? */
183 /* if not, do error action */
184 /* set the solicitation surface to surface_id */
185 /* search devices for this surface */
186 short dev_found = -1;
187 for (short dev = 0; (dev < num_devices) && (dev_found == -1); ++dev) {
188 for (short surf = 0; surf < devices[dev].num_active_surfaces; ++surf) {
189 if (*surface_id == devices[dev].statelist[surf]) {
190 dev_found = dev;
191 break;
192 } /* end if found on list */
193 } /* end for */
194 } /* end for all devices */
195
196 /* does surface_id point to a valid surface? */
197 if (dev_found < 0) {
198 fprintf(stderr, "xcsol: surface id not a valid surface\n");
199 return;
200 } /* end if surface not found */
201
202 sol_surf = *surface_id;
203
204 } /* end xcsol */