Some linting of tn3270.
[unix-history] / usr / src / usr.bin / tn3270 / api / apilib.c
CommitLineData
992de934 1/*
f6e43951
KB
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
992de934 4 *
f6e43951
KB
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
992de934
GM
11 */
12
13#ifndef lint
f6e43951
KB
14static char sccsid[] = "@(#)apilib.c 3.2 (Berkeley) %G%";
15#endif /* not lint */
992de934 16
9c711786 17#include "../ctlr/api.h"
28e559a0 18
f81b28ad
GM
19#include "apilib.h"
20
21int
22 api_sup_errno = 0, /* Supervisor error number */
23 api_sup_fcn_id = 0, /* Supervisor function id (0x12) */
24 api_fcn_errno = 0, /* Function error number */
25 api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */
26
27static int
28 gate_sessmgr = 0,
29 gate_keyboard = 0,
30 gate_copy = 0,
31 gate_oiam = 0;
32
33/*
34 * Issue an API request, with reg structures supplied by the caller.
35 *
36 * Only certain routines need this (supervisor services come to mind).
37 */
38
cee740d6
GM
39static int
40api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, regs, sregs)
f81b28ad
GM
41int ah, al, bh, bl, cx, dx;
42char *parms;
cee740d6 43int length;
f81b28ad
GM
44union REGS *regs;
45struct SREGS *sregs;
46{
47 char far *ourseg = parms;
48
49 regs->h.ah = ah;
50 regs->h.al = al;
51 regs->h.bh = bh;
52 regs->h.bl = bl;
53 regs->x.cx = cx;
54 regs->x.dx = dx;
55 sregs->es = (int) FP_SEG(ourseg);
56 regs->x.di = (int) FP_OFF(ourseg);
57
cd746900 58#if defined(MSDOS)
f81b28ad 59 int86x(API_INTERRUPT_NUMBER, regs, regs, sregs);
cd746900
GM
60#endif /* defined(MSDOS) */
61#if defined(unix)
cee740d6 62 api_exch_api(regs, sregs, parms, length);
cd746900
GM
63#endif /* defined(unix) */
64
f81b28ad
GM
65 if (regs->h.cl != 0) {
66 api_sup_errno = regs->h.cl;
67 return -1;
68 } else {
69 return 0;
70 }
71}
72
73
74/*
75 * Issue an API request without requiring caller to supply
76 * registers. Most routines use this.
77 */
28e559a0 78
cee740d6
GM
79static int
80api_issue(ah, al, bh, bl, cx, dx, parms, length)
28e559a0
GM
81int
82 ah,
83 al,
84 bh,
85 bl,
86 cx,
87 dx;
88char *parms;
cee740d6 89int length; /* Length of parms */
28e559a0
GM
90{
91 union REGS regs;
92 struct SREGS sregs;
28e559a0 93
cee740d6 94 return api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, &regs, &sregs);
28e559a0 95}
f81b28ad
GM
96\f
97/*
98 * Supervisor Services
99 */
28e559a0
GM
100
101int
102api_name_resolve(name)
103char *name;
104{
105 NameResolveParms parms;
106 int i;
107 union REGS regs;
108 struct SREGS sregs;
28e559a0
GM
109
110 for (i = 0; i < sizeof parms.gate_name; i++) {
111 if (*name) {
112 parms.gate_name[i] = *name++;
113 } else {
114 parms.gate_name[i] = ' ';
115 }
116 }
117
cee740d6 118 if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, &parms, sizeof parms, &regs, &sregs)
f81b28ad 119 == -1) {
28e559a0
GM
120 return -1;
121 } else {
122 return regs.x.dx;
123 }
124}
7e20fa70
GM
125
126#if defined(unix)
127/*
128 * Block until the oia or ps is modified.
129 */
130
131int
132api_ps_or_oia_modified()
133{
134 union REGS regs;
135 struct SREGS sregs;
136
137 if (api_issue_regs(PS_OR_OIA_MODIFIED, 0, 0, 0, 0, 0, 0, 0, &regs, &sregs)
138 == -1) {
139 return -1;
140 } else {
141 return 0;
142 }
143}
144#endif /* defined(unix) */
f81b28ad
GM
145\f
146/*
147 * Session Information Services
148 */
149
e99f17a9 150api_query_session_id(parms)
f81b28ad
GM
151QuerySessionIdParms *parms;
152{
153 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0,
cee740d6 154 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
155 api_fcn_errno = 0;
156 api_fcn_fcn_id = 0;
157 return -1;
158 } else if (parms->rc == 0) {
159 return 0;
160 } else {
161 api_fcn_errno = parms->rc;
162 api_fcn_fcn_id = parms->function_id;
163 return -1;
164 }
165}
166
167
e99f17a9 168api_query_session_parameters(parms)
f81b28ad
GM
169QuerySessionParametersParms *parms;
170{
e99f17a9 171 if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0,
cee740d6 172 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
173 api_fcn_errno = 0;
174 api_fcn_fcn_id = 0;
175 return -1;
176 } else if (parms->rc == 0) {
177 return 0;
178 } else {
179 api_fcn_errno = parms->rc;
180 api_fcn_fcn_id = parms->function_id;
181 return -1;
182 }
183}
184
185api_query_session_cursor(parms)
186QuerySessionCursorParms *parms;
187{
e99f17a9 188 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff,
cee740d6 189 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
190 api_fcn_errno = 0;
191 api_fcn_fcn_id = 0;
192 return -1;
193 } else if (parms->rc == 0) {
194 return 0;
195 } else {
196 api_fcn_errno = parms->rc;
197 api_fcn_fcn_id = parms->function_id;
198 return -1;
199 }
200}
201\f
202/*
203 * Keyboard Services
204 */
205
206api_connect_to_keyboard(parms)
207ConnectToKeyboardParms *parms;
208{
209 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0,
cee740d6 210 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
211 api_fcn_errno = 0;
212 api_fcn_fcn_id = 0;
213 return -1;
214 } else if (parms->rc == 0) {
215 return 0;
216 } else {
217 api_fcn_errno = parms->rc;
218 api_fcn_fcn_id = parms->function_id;
219 return -1;
220 }
221}
222
223
224api_disconnect_from_keyboard(parms)
225DisconnectFromKeyboardParms *parms;
226{
227 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0,
cee740d6 228 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
229 api_fcn_errno = 0;
230 api_fcn_fcn_id = 0;
231 return -1;
232 } else if (parms->rc == 0) {
233 return 0;
234 } else {
235 api_fcn_errno = parms->rc;
236 api_fcn_fcn_id = parms->function_id;
237 return -1;
238 }
239}
240
241
242api_write_keystroke(parms)
243WriteKeystrokeParms *parms;
244{
245 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0,
cee740d6 246 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
247 api_fcn_errno = 0;
248 api_fcn_fcn_id = 0;
249 return -1;
250 } else if (parms->rc == 0) {
251 return 0;
252 } else {
253 api_fcn_errno = parms->rc;
254 api_fcn_fcn_id = parms->function_id;
255 return -1;
256 }
257}
258
259
260api_disable_input(parms)
261DisableInputParms *parms;
262{
263 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0,
cee740d6 264 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
265 api_fcn_errno = 0;
266 api_fcn_fcn_id = 0;
267 return -1;
268 } else if (parms->rc == 0) {
269 return 0;
270 } else {
271 api_fcn_errno = parms->rc;
272 api_fcn_fcn_id = parms->function_id;
273 return -1;
274 }
275}
276
277api_enable_input(parms)
278EnableInputParms *parms;
279{
280 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0,
cee740d6 281 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
282 api_fcn_errno = 0;
283 api_fcn_fcn_id = 0;
284 return -1;
285 } else if (parms->rc == 0) {
286 return 0;
287 } else {
288 api_fcn_errno = parms->rc;
289 api_fcn_fcn_id = parms->function_id;
290 return -1;
291 }
292}
293\f
294/*
295 * Copy Services
296 */
297
298api_copy_string(parms)
299CopyStringParms *parms;
300{
e99f17a9 301 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff,
cee740d6 302 gate_copy, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
303 api_fcn_errno = 0;
304 api_fcn_fcn_id = 0;
305 return -1;
306 } else if (parms->rc == 0) {
307 return 0;
308 } else {
309 api_fcn_errno = parms->rc;
310 api_fcn_fcn_id = parms->function_id;
311 return -1;
312 }
313}
314
315/*
316 * Operator Information Area Services
317 */
318
319api_read_oia_group(parms)
320ReadOiaGroupParms *parms;
321{
e99f17a9 322 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff,
cee740d6 323 gate_oiam, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
324 api_fcn_errno = 0;
325 api_fcn_fcn_id = 0;
326 return -1;
327 } else if (parms->rc == 0) {
328 return 0;
329 } else {
330 api_fcn_errno = parms->rc;
331 api_fcn_fcn_id = parms->function_id;
332 return -1;
333 }
334}
335\f
d024bcc4
GM
336/*
337 * The "we are done" routine. This gets called last.
338 */
339
340api_finish()
341{
342#if defined(unix)
343 if (api_close_api() == -1) {
344 return -1;
345 } else {
346 return 0;
347 }
348#endif /* defined(unix) */
349}
350
351
f81b28ad
GM
352/*
353 * The initialization routine. Be sure to call this first.
354 */
355
356api_init()
357{
358 union REGS regs;
359 struct SREGS sregs;
360
cd746900 361#if defined(MSDOS)
f81b28ad
GM
362 regs.h.ah = 0x35;
363 regs.h.al = API_INTERRUPT_NUMBER;
364 intdosx(&regs, &regs, &sregs);
365
366 if ((regs.x.bx == 0) && (sregs.es == 0)) {
367 return 0; /* Interrupt not being handled */
368 }
5751bea5 369#endif /* defined(MSDOS) */
cd746900
GM
370#if defined(unix)
371 if (api_open_api(0) == -1) {
372 return 0;
373 }
374#endif /* defined(unix) */
f81b28ad
GM
375
376 gate_sessmgr = api_name_resolve("SESSMGR");
377 gate_keyboard = api_name_resolve("KEYBOARD");
378 gate_copy = api_name_resolve("COPY");
379 gate_oiam = api_name_resolve("OIAM");
380
381 if ((gate_sessmgr == gate_keyboard) ||
382 (gate_sessmgr == gate_copy) ||
383 (gate_sessmgr == gate_oiam) ||
384 (gate_keyboard == gate_copy) ||
385 (gate_keyboard == gate_oiam) ||
386 (gate_copy == gate_oiam)) {
387 return 0; /* Interrupt doesn't seem correct */
388 }
389 return 1;
390}