Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
7
met:
8
9
- Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
12
- Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in
14
the documentation and/or other materials provided with the
15
distribution.
16
17
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
18
names of its contributors may be used to endorse or promote products
19
derived from this software without specific prior written permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
#include "openaxiom-c-macros.h"
35
36
/*
37
Here is some code taken from Nick Simicich. It takes an escape sequence
38
from the child, and if I am actually talking to an HFT device, it
39
translates that escape sequence into an ioctl call.
40
*/
41
42
43
#if 0
44
45
#include "edible.h"
46
#include "sys/devinfo.h"
47
#include <sys/ioctl.h>
48
49
typedef union {
50
struct hfintro *hf;
51
struct hfctlreq *re;
52
char *c;
53
} Argument;
54
55
emuhft(Argument arg, int tty, int ptc, int len)
56
{
57
/* What does it do? */
58
/* 1. There are a number of ioctl's associated with the HFT terminal. */
59
/* 2. When an HFT terminal is being emulated over a PTY, the */
60
/* IOCTL cannot be executed directly on the server end of the PTY. */
61
/* 3. A system defined structure is set up such that the program */
62
/* at the end of the PTY can issue the ioctl as an escape */
63
/* sequence and get its response as an escape sequence. */
64
/* 4. This is badly broken, even stupid. If the protocol is */
65
/* defined, and everyone is supposed to use it, then the HFT */
66
/* should react directly to it. But No.... */
67
/* 5. Furthermore, our terminal itself might be a pty. In that */
68
/* case, we have to transmit the data just as we got it to the */
69
/* other PTY, instead of executing the IOCTL. */
70
71
static union {
72
struct hfintro hfi;
73
struct hfctlack ackn;
74
char charvector[1024]; /* Spacer to make sure that response can be
75
* moved here */
76
} aa;
77
78
extern int errno;
79
80
#ifdef DEBUG
81
dstream(arg.c, stderr, NULL, "From emuhft (input)");
82
#endif
83
84
if (len > 1000) {
85
fprintf(stderr, "Unreasonable value for len %d\n", len);
86
return -1;
87
}
88
89
if (ioctl(tty, IOCTYPE, 0) != (DD_PSEU << 8)) { /* is it a pty ? */
90
switch (arg.re->hf_request) {
91
case HFQUERY:{
92
struct hfquery hfqur;
93
int i;
94
95
hfqur.hf_resplen = iiret(arg.re->hf_rsp_len);
96
if (hfqur.hf_resplen > 0) {
97
hfqur.hf_resp = aa.charvector + sizeof aa.ackn;
98
if (hfqur.hf_resplen > (sizeof aa.charvector - sizeof
99
aa.ackn)) {
100
errno = ENOMEM;
101
perror("Can't store HFQUERY response");
102
return -1;
103
}
104
}
105
else
106
hfqur.hf_resp = NULL;
107
108
hfqur.hf_cmd = arg.c + 3 + ciret(arg.hf->hf_len);
109
hfqur.hf_cmdlen = iiret(arg.re->hf_arg_len);
110
i = ioctl(tty, HFQUERY, &hfqur); /* The meat of the
111
* matter */
112
aa.hfi.hf_esc = HFINTROESC;
113
aa.hfi.hf_lbr = HFINTROLBR;
114
aa.hfi.hf_ex = HFINTROEX;
115
icmove(sizeof aa.ackn - 3, aa.hfi.hf_len);
116
aa.hfi.hf_typehi = HFCTLACKCH;
117
aa.hfi.hf_typelo = HFCTLACKCL;
118
if (i == -1)
119
aa.ackn.hf_retcode = errno;
120
else
121
aa.ackn.hf_retcode = 0;
122
aa.ackn.hf_sublen = arg.re->hf_sublen;
123
aa.ackn.hf_subtype = arg.re->hf_subtype;
124
aa.ackn.hf_request = iiret(arg.re->hf_request);
125
aa.ackn.hf_arg_len = hfqur.hf_resplen;
126
if (-1 == write(ptc, aa.charvector, (sizeof aa.ackn) +
127
hfqur.hf_resplen)) {
128
perror("write of HFQUERY acknowledgement failed");
129
return (-1);
130
}
131
#ifdef DEBUG
132
dstream(aa.charvector, stderr, NULL, "From emuhft (hfquery ack)");
133
#endif
134
break;
135
}
136
case HFSKBD:{
137
struct hfbuf hfkey;
138
int i;
139
140
hfkey.hf_bufp = arg.c + 3 + ciret(arg.hf->hf_len);
141
hfkey.hf_buflen = iiret(arg.re->hf_arg_len);
142
i = ioctl(tty, HFSKBD, &hfkey); /* The meat of the matter */
143
aa.hfi.hf_esc = HFINTROESC;
144
aa.hfi.hf_lbr = HFINTROLBR;
145
aa.hfi.hf_ex = HFINTROEX;
146
icmove(sizeof aa.ackn - 3, aa.hfi.hf_len);
147
aa.hfi.hf_typehi = HFCTLACKCH;
148
aa.hfi.hf_typelo = HFCTLACKCL;
149
if (i == -1)
150
aa.ackn.hf_retcode = errno;
151
else
152
aa.ackn.hf_retcode = 0;
153
aa.ackn.hf_sublen = arg.re->hf_sublen;
154
aa.ackn.hf_subtype = arg.re->hf_subtype;
155
aa.ackn.hf_request = iiret(arg.re->hf_request);
156
aa.ackn.hf_arg_len = 0;
157
if (-1 == write(ptc, aa.charvector, sizeof aa.ackn)) {
158
perror("write of HFSKEY acknowledgement failed");
159
return (-1);
160
}
161
#ifdef DEBUG
162
dstream(aa.charvector, stderr, NULL, "From emuhft (HFSKEY ack)");
163
#endif
164
break;
165
}
166
default:{
167
aa.hfi.hf_esc = HFINTROESC;
168
aa.hfi.hf_lbr = HFINTROLBR;
169
aa.hfi.hf_ex = HFINTROEX;
170
icmove(sizeof aa.ackn - 3, aa.hfi.hf_len);
171
aa.hfi.hf_typehi = HFCTLACKCH;
172
aa.hfi.hf_typelo = HFCTLACKCL;
173
aa.ackn.hf_retcode = EINVAL;
174
aa.ackn.hf_sublen = arg.re->hf_sublen;
175
aa.ackn.hf_subtype = arg.re->hf_subtype;
176
aa.ackn.hf_request = iiret(arg.re->hf_request);
177
aa.ackn.hf_arg_len = 0;
178
if (-1 == write(ptc, aa.charvector, sizeof aa.ackn)) {
179
perror("write of default acknowledgement failed");
180
return (-1);
181
}
182
#ifdef DEBUG
183
dstream(aa.charvector, stderr, NULL, "From emuhft (default ack)");
184
#endif
185
186
break;
187
}
188
}
189
}
190
else {
191
/* Well, if we get here, we are a pseudo-device ourselves. So */
192
/* we will just send on the request that we got. we are in a */
193
/* unique situation. We believe that both ptc and tty are as */
194
/* transparent as we can get them, so we don't have to worry. */
195
/* We will just write the request to the tty, which we */
196
/* believe is a pty, and sooner or later, the ack will come */
197
/* back. */
198
if (-1 == write(tty, arg.c, len)) {
199
perror("write of control sequence to pty failed");
200
fprintf(stderr, "tty = %d, len = %d\n", tty, len);
201
return (-1);
202
}
203
#ifdef DEBUG
204
dstream(arg.c, stderr, NULL, "From emuhft (on pty transfer)");
205
fprintf(stderr, "tty = %d, len = %d\r\n", tty, len);
206
fflush(stderr);
207
#endif
208
209
}
210
return 0;
211
}
212
213
214
215
#endif
216
217
static int _ThatsAll_(int x)
218
{
219
return x;
220
}
221
222