Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.bin / tn3270 / api / apilib.c
blob7f9a6b196eb2ee655a2d25ce3c843c2de62ac896
1 /* $NetBSD: apilib.c,v 1.6 2002/06/13 23:41:16 wiz Exp $ */
3 /*-
4 * Copyright (c) 1988 The Regents of the University of California.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #if defined(__RCSID) && !defined(lint)
34 #if 0
35 static char sccsid[] = "@(#)apilib.c 4.2 (Berkeley) 4/26/91";
36 #else
37 __RCSID("$NetBSD: apilib.c,v 1.6 2002/06/13 23:41:16 wiz Exp $");
38 #endif
39 #endif /* not lint */
41 #include "../ctlr/api.h"
43 #include "apilib.h"
45 int
46 api_sup_errno = 0, /* Supervisor error number */
47 api_sup_fcn_id = 0, /* Supervisor function id (0x12) */
48 api_fcn_errno = 0, /* Function error number */
49 api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */
51 static int
52 gate_sessmgr = 0,
53 gate_keyboard = 0,
54 gate_copy = 0,
55 gate_oiam = 0;
58 /* apilib.c */
59 static int api_issue_regs(int, int , int , int , int , int , char *, int,
60 union REGS *, struct SREGS *);
61 static int api_issue(int, int , int , int , int , int , char *, int);
64 * Issue an API request, with reg structures supplied by the caller.
66 * Only certain routines need this (supervisor services come to mind).
69 static int
70 api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, regs, sregs)
71 int ah, al, bh, bl, cx, dx;
72 char *parms;
73 int length;
74 union REGS *regs;
75 struct SREGS *sregs;
77 char far *ourseg = parms;
79 regs->h.ah = ah;
80 regs->h.al = al;
81 regs->h.bh = bh;
82 regs->h.bl = bl;
83 regs->x.cx = cx;
84 regs->x.dx = dx;
85 sregs->es = FP_SEG(ourseg);
86 regs->x.di = FP_OFF(ourseg);
88 #if defined(MSDOS)
89 int86x(API_INTERRUPT_NUMBER, regs, regs, sregs);
90 #endif /* defined(MSDOS) */
91 #if defined(unix)
92 api_exch_api(regs, sregs, parms, length);
93 #endif /* defined(unix) */
95 if (regs->h.cl != 0) {
96 api_sup_errno = regs->h.cl;
97 return -1;
98 } else {
99 return 0;
105 * Issue an API request without requiring caller to supply
106 * registers. Most routines use this.
109 static int
110 api_issue(ah, al, bh, bl, cx, dx, parms, length)
118 char *parms;
119 int length; /* Length of parms */
121 union REGS regs;
122 struct SREGS sregs;
124 return api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, &regs, &sregs);
128 * Supervisor Services
132 api_name_resolve(name)
133 char *name;
135 NameResolveParms parms;
136 int i;
137 union REGS regs;
138 struct SREGS sregs;
140 for (i = 0; i < sizeof parms.gate_name; i++) {
141 if (*name) {
142 parms.gate_name[i] = *name++;
143 } else {
144 parms.gate_name[i] = ' ';
148 if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, (char *) &parms,
149 sizeof parms, &regs, &sregs) == -1) {
150 return -1;
151 } else {
152 return regs.x.dx;
156 #if defined(unix)
158 * Block until the oia or ps is modified.
162 api_ps_or_oia_modified()
164 union REGS regs;
165 struct SREGS sregs;
167 if (api_issue_regs(PS_OR_OIA_MODIFIED, 0, 0, 0, 0, 0, (char *) 0,
168 0, &regs, &sregs) == -1) {
169 return -1;
170 } else {
171 return 0;
174 #endif /* defined(unix) */
177 * Session Information Services
181 api_query_session_id(parms)
182 QuerySessionIdParms *parms;
184 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0,
185 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
186 api_fcn_errno = 0;
187 api_fcn_fcn_id = 0;
188 return -1;
189 } else if (parms->rc == 0) {
190 return 0;
191 } else {
192 api_fcn_errno = parms->rc;
193 api_fcn_fcn_id = parms->function_id;
194 return -1;
200 api_query_session_parameters(parms)
201 QuerySessionParametersParms *parms;
203 if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0,
204 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
205 api_fcn_errno = 0;
206 api_fcn_fcn_id = 0;
207 return -1;
208 } else if (parms->rc == 0) {
209 return 0;
210 } else {
211 api_fcn_errno = parms->rc;
212 api_fcn_fcn_id = parms->function_id;
213 return -1;
218 api_query_session_cursor(parms)
219 QuerySessionCursorParms *parms;
221 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff,
222 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
223 api_fcn_errno = 0;
224 api_fcn_fcn_id = 0;
225 return -1;
226 } else if (parms->rc == 0) {
227 return 0;
228 } else {
229 api_fcn_errno = parms->rc;
230 api_fcn_fcn_id = parms->function_id;
231 return -1;
236 * Keyboard Services
240 api_connect_to_keyboard(parms)
241 ConnectToKeyboardParms *parms;
243 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0,
244 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
245 api_fcn_errno = 0;
246 api_fcn_fcn_id = 0;
247 return -1;
248 } else if (parms->rc == 0) {
249 return 0;
250 } else {
251 api_fcn_errno = parms->rc;
252 api_fcn_fcn_id = parms->function_id;
253 return -1;
259 api_disconnect_from_keyboard(parms)
260 DisconnectFromKeyboardParms *parms;
262 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0,
263 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
264 api_fcn_errno = 0;
265 api_fcn_fcn_id = 0;
266 return -1;
267 } else if (parms->rc == 0) {
268 return 0;
269 } else {
270 api_fcn_errno = parms->rc;
271 api_fcn_fcn_id = parms->function_id;
272 return -1;
278 api_write_keystroke(parms)
279 WriteKeystrokeParms *parms;
281 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0,
282 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
283 api_fcn_errno = 0;
284 api_fcn_fcn_id = 0;
285 return -1;
286 } else if (parms->rc == 0) {
287 return 0;
288 } else {
289 api_fcn_errno = parms->rc;
290 api_fcn_fcn_id = parms->function_id;
291 return -1;
297 api_disable_input(parms)
298 DisableInputParms *parms;
300 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0,
301 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
302 api_fcn_errno = 0;
303 api_fcn_fcn_id = 0;
304 return -1;
305 } else if (parms->rc == 0) {
306 return 0;
307 } else {
308 api_fcn_errno = parms->rc;
309 api_fcn_fcn_id = parms->function_id;
310 return -1;
315 api_enable_input(parms)
316 EnableInputParms *parms;
318 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0,
319 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
320 api_fcn_errno = 0;
321 api_fcn_fcn_id = 0;
322 return -1;
323 } else if (parms->rc == 0) {
324 return 0;
325 } else {
326 api_fcn_errno = parms->rc;
327 api_fcn_fcn_id = parms->function_id;
328 return -1;
333 * Copy Services
337 api_copy_string(parms)
338 CopyStringParms *parms;
340 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff,
341 gate_copy, (char *)parms, sizeof *parms) == -1) {
342 api_fcn_errno = 0;
343 api_fcn_fcn_id = 0;
344 return -1;
345 } else if (parms->rc == 0) {
346 return 0;
347 } else {
348 api_fcn_errno = parms->rc;
349 api_fcn_fcn_id = parms->function_id;
350 return -1;
355 * Operator Information Area Services
359 api_read_oia_group(parms)
360 ReadOiaGroupParms *parms;
362 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff,
363 gate_oiam, (char *)parms, sizeof *parms) == -1) {
364 api_fcn_errno = 0;
365 api_fcn_fcn_id = 0;
366 return -1;
367 } else if (parms->rc == 0) {
368 return 0;
369 } else {
370 api_fcn_errno = parms->rc;
371 api_fcn_fcn_id = parms->function_id;
372 return -1;
377 * The "we are done" routine. This gets called last.
381 api_finish()
383 #if defined(unix)
384 if (api_close_api() == -1) {
385 return -1;
386 } else {
387 return 0;
389 #else
390 return 0;
391 #endif /* defined(unix) */
396 * The initialization routine. Be sure to call this first.
400 api_init()
402 #if defined(MSDOS)
403 union REGS regs;
404 struct SREGS sregs;
406 regs.h.ah = 0x35;
407 regs.h.al = API_INTERRUPT_NUMBER;
408 intdosx(&regs, &regs, &sregs);
410 if ((regs.x.bx == 0) && (sregs.es == 0)) {
411 return 0; /* Interrupt not being handled */
413 #endif /* defined(MSDOS) */
414 #if defined(unix)
415 if (api_open_api((char *)0) == -1) {
416 return 0;
418 #endif /* defined(unix) */
420 gate_sessmgr = api_name_resolve("SESSMGR");
421 gate_keyboard = api_name_resolve("KEYBOARD");
422 gate_copy = api_name_resolve("COPY");
423 gate_oiam = api_name_resolve("OIAM");
425 if ((gate_sessmgr == gate_keyboard) ||
426 (gate_sessmgr == gate_copy) ||
427 (gate_sessmgr == gate_oiam) ||
428 (gate_keyboard == gate_copy) ||
429 (gate_keyboard == gate_oiam) ||
430 (gate_copy == gate_oiam)) {
431 return 0; /* Interrupt doesn't seem correct */
433 return 1;