Add 'shell_active' global.
[unix-history] / usr / src / usr.bin / tn3270 / api / apilib.c
CommitLineData
28e559a0
GM
1#include "../api/api.h"
2
f81b28ad
GM
3#include "apilib.h"
4
5int
6 api_sup_errno = 0, /* Supervisor error number */
7 api_sup_fcn_id = 0, /* Supervisor function id (0x12) */
8 api_fcn_errno = 0, /* Function error number */
9 api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */
10
11static int
12 gate_sessmgr = 0,
13 gate_keyboard = 0,
14 gate_copy = 0,
15 gate_oiam = 0;
16
17/*
18 * Issue an API request, with reg structures supplied by the caller.
19 *
20 * Only certain routines need this (supervisor services come to mind).
21 */
22
23int
24api_issue_regs(ah, al, bh, bl, cx, dx, parms, regs, sregs)
25int ah, al, bh, bl, cx, dx;
26char *parms;
27union REGS *regs;
28struct SREGS *sregs;
29{
30 char far *ourseg = parms;
31
32 regs->h.ah = ah;
33 regs->h.al = al;
34 regs->h.bh = bh;
35 regs->h.bl = bl;
36 regs->x.cx = cx;
37 regs->x.dx = dx;
38 sregs->es = (int) FP_SEG(ourseg);
39 regs->x.di = (int) FP_OFF(ourseg);
40
41 int86x(API_INTERRUPT_NUMBER, regs, regs, sregs);
42 if (regs->h.cl != 0) {
43 api_sup_errno = regs->h.cl;
44 return -1;
45 } else {
46 return 0;
47 }
48}
49
50
51/*
52 * Issue an API request without requiring caller to supply
53 * registers. Most routines use this.
54 */
28e559a0
GM
55
56int
57api_issue(ah, al, bh, bl, cx, dx, parms)
58int
59 ah,
60 al,
61 bh,
62 bl,
63 cx,
64 dx;
65char *parms;
66{
67 union REGS regs;
68 struct SREGS sregs;
28e559a0 69
f81b28ad 70 return api_issue_regs(ah, al, bh, bl, cx, dx, parms, &regs, &sregs);
28e559a0 71}
f81b28ad
GM
72\f
73/*
74 * Supervisor Services
75 */
28e559a0
GM
76
77int
78api_name_resolve(name)
79char *name;
80{
81 NameResolveParms parms;
82 int i;
83 union REGS regs;
84 struct SREGS sregs;
28e559a0
GM
85
86 for (i = 0; i < sizeof parms.gate_name; i++) {
87 if (*name) {
88 parms.gate_name[i] = *name++;
89 } else {
90 parms.gate_name[i] = ' ';
91 }
92 }
93
f81b28ad
GM
94 if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, &parms, &regs, &sregs)
95 == -1) {
28e559a0
GM
96 return -1;
97 } else {
98 return regs.x.dx;
99 }
100}
f81b28ad
GM
101\f
102/*
103 * Session Information Services
104 */
105
106api_query_sesion_id(parms)
107QuerySessionIdParms *parms;
108{
109 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0,
110 gate_sessmgr, (char *)parms) == -1) {
111 api_fcn_errno = 0;
112 api_fcn_fcn_id = 0;
113 return -1;
114 } else if (parms->rc == 0) {
115 return 0;
116 } else {
117 api_fcn_errno = parms->rc;
118 api_fcn_fcn_id = parms->function_id;
119 return -1;
120 }
121}
122
123
124api_query_session_parms(parms)
125QuerySessionParametersParms *parms;
126{
127 if (api_issue(0x09, QUERY_SESSION_PARMS, 0x80, 0x20, 0,
128 gate_sessmgr, (char *)parms) == -1) {
129 api_fcn_errno = 0;
130 api_fcn_fcn_id = 0;
131 return -1;
132 } else if (parms->rc == 0) {
133 return 0;
134 } else {
135 api_fcn_errno = parms->rc;
136 api_fcn_fcn_id = parms->function_id;
137 return -1;
138 }
139}
140
141api_query_session_cursor(parms)
142QuerySessionCursorParms *parms;
143{
144 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0,
145 gate_sessmgr, (char *)parms) == -1) {
146 api_fcn_errno = 0;
147 api_fcn_fcn_id = 0;
148 return -1;
149 } else if (parms->rc == 0) {
150 return 0;
151 } else {
152 api_fcn_errno = parms->rc;
153 api_fcn_fcn_id = parms->function_id;
154 return -1;
155 }
156}
157\f
158/*
159 * Keyboard Services
160 */
161
162api_connect_to_keyboard(parms)
163ConnectToKeyboardParms *parms;
164{
165 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0,
166 gate_keyboard, (char *)parms) == -1) {
167 api_fcn_errno = 0;
168 api_fcn_fcn_id = 0;
169 return -1;
170 } else if (parms->rc == 0) {
171 return 0;
172 } else {
173 api_fcn_errno = parms->rc;
174 api_fcn_fcn_id = parms->function_id;
175 return -1;
176 }
177}
178
179
180api_disconnect_from_keyboard(parms)
181DisconnectFromKeyboardParms *parms;
182{
183 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0,
184 gate_keyboard, (char *)parms) == -1) {
185 api_fcn_errno = 0;
186 api_fcn_fcn_id = 0;
187 return -1;
188 } else if (parms->rc == 0) {
189 return 0;
190 } else {
191 api_fcn_errno = parms->rc;
192 api_fcn_fcn_id = parms->function_id;
193 return -1;
194 }
195}
196
197
198api_write_keystroke(parms)
199WriteKeystrokeParms *parms;
200{
201 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0,
202 gate_keyboard, (char *)parms) == -1) {
203 api_fcn_errno = 0;
204 api_fcn_fcn_id = 0;
205 return -1;
206 } else if (parms->rc == 0) {
207 return 0;
208 } else {
209 api_fcn_errno = parms->rc;
210 api_fcn_fcn_id = parms->function_id;
211 return -1;
212 }
213}
214
215
216api_disable_input(parms)
217DisableInputParms *parms;
218{
219 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0,
220 gate_keyboard, (char *)parms) == -1) {
221 api_fcn_errno = 0;
222 api_fcn_fcn_id = 0;
223 return -1;
224 } else if (parms->rc == 0) {
225 return 0;
226 } else {
227 api_fcn_errno = parms->rc;
228 api_fcn_fcn_id = parms->function_id;
229 return -1;
230 }
231}
232
233api_enable_input(parms)
234EnableInputParms *parms;
235{
236 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0,
237 gate_keyboard, (char *)parms) == -1) {
238 api_fcn_errno = 0;
239 api_fcn_fcn_id = 0;
240 return -1;
241 } else if (parms->rc == 0) {
242 return 0;
243 } else {
244 api_fcn_errno = parms->rc;
245 api_fcn_fcn_id = parms->function_id;
246 return -1;
247 }
248}
249\f
250/*
251 * Copy Services
252 */
253
254api_copy_string(parms)
255CopyStringParms *parms;
256{
257 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0,
258 gate_copy, (char *)parms) == -1) {
259 api_fcn_errno = 0;
260 api_fcn_fcn_id = 0;
261 return -1;
262 } else if (parms->rc == 0) {
263 return 0;
264 } else {
265 api_fcn_errno = parms->rc;
266 api_fcn_fcn_id = parms->function_id;
267 return -1;
268 }
269}
270
271/*
272 * Operator Information Area Services
273 */
274
275api_read_oia_group(parms)
276ReadOiaGroupParms *parms;
277{
278 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0,
279 gate_oiam, (char *)parms) == -1) {
280 api_fcn_errno = 0;
281 api_fcn_fcn_id = 0;
282 return -1;
283 } else if (parms->rc == 0) {
284 return 0;
285 } else {
286 api_fcn_errno = parms->rc;
287 api_fcn_fcn_id = parms->function_id;
288 return -1;
289 }
290}
291\f
292/*
293 * The initialization routine. Be sure to call this first.
294 */
295
296api_init()
297{
298 union REGS regs;
299 struct SREGS sregs;
300
301 regs.h.ah = 0x35;
302 regs.h.al = API_INTERRUPT_NUMBER;
303 intdosx(&regs, &regs, &sregs);
304
305 if ((regs.x.bx == 0) && (sregs.es == 0)) {
306 return 0; /* Interrupt not being handled */
307 }
308
309 gate_sessmgr = api_name_resolve("SESSMGR");
310 gate_keyboard = api_name_resolve("KEYBOARD");
311 gate_copy = api_name_resolve("COPY");
312 gate_oiam = api_name_resolve("OIAM");
313
314 if ((gate_sessmgr == gate_keyboard) ||
315 (gate_sessmgr == gate_copy) ||
316 (gate_sessmgr == gate_oiam) ||
317 (gate_keyboard == gate_copy) ||
318 (gate_keyboard == gate_oiam) ||
319 (gate_copy == gate_oiam)) {
320 return 0; /* Interrupt doesn't seem correct */
321 }
322 return 1;
323}