eusioctl.c
Go to the documentation of this file.
1 /****************************************************************/
2 /* ioctl.c
3 /* ioctl interface for euslisp
4 /* 1988Mar23
5 /* Copyright(c)1988 Toshihiro MATSUI, Electrotechnical Laboratory
6 /****************************************************************/
7 static char *rcsid="@(#)$Id$";
8 #include <ctype.h>
9 #include <sys/termios.h>
10 #ifndef Darwin
11 #include <termio.h>
12 #endif
13 /* #include <sgtty.h> */
14 
15 #undef MAX
16 #undef MIN
17 #undef VMIN
18 #undef VMAX
19 #include "eus.h"
20 
21 extern int errno;
22 
23 static int getfd(x)
24 pointer x;
25 { if (isint(x)) return(intval(x));
26  else if (isflt(x)) error(E_NOINT);
27  else if (pisiostream(x)) x=x->c.iostream.in;
28  else if (!pisfilestream(x)) error(E_STREAM);
29  return(intval(x->c.fstream.fd));}
30 
31 static pointer getbuf(n,x,bufsize)
32 int n,bufsize;
33 pointer x;
34 { if (n<=1) x=makebuffer(bufsize);
35  else if (!isstring(x)) error(E_NOSTRING);
36  else if (strlength(x)<bufsize) error(E_VECINDEX);
37  return(x);}
38 
39 static pointer ioctl_struct(n,argv,ctlcode,bufsize)
40 int n,bufsize;
41 unsigned long ctlcode;
42 pointer argv[];
43 { int fd,stat;
44  pointer buf;
45  if (n==0 || n>2) error(E_MISMATCHARG);
46  fd=getfd(argv[0]);
47  buf=getbuf(n,argv[1],bufsize);
48  stat=ioctl(fd,ctlcode,buf->c.str.chars);
49  if (stat<0) return(makeint( (-errno)));
50  else return(buf);}
51 
52 static pointer ioctl_int(n,argv,ctlcode)
53 int n;
54 unsigned long ctlcode;
55 pointer argv[];
56 { int fd,stat,intarg;
57  pointer buf;
58  ckarg(2);
59  fd=getfd(argv[0]);
60  intarg=ckintval(argv[1]);
61  stat=ioctl(fd,ctlcode, &intarg);
62  if (stat<0) return(makeint(-errno));
63  else return(makeint(intarg));}
64 
65 /******************************** obsolete interfaces
66 
67 pointer IOCTL_TIOCGETP(ctx,n,argv)
68 register context *ctx;
69 int n;
70 pointer argv[];
71 { return(ioctl_struct(n,argv,TIOCGETP,sizeof(struct sgttyb)));}
72 
73 pointer IOCTL_TIOCSETP(ctx,n,argv)
74 register context *ctx;
75 int n;
76 pointer argv[];
77 { ckarg(2);
78  return(ioctl_struct(n,argv,TIOCSETP,sizeof(struct sgttyb)));}
79 
80 pointer IOCTL_TIOCSETN(ctx,n,argv)
81 register context *ctx;
82 int n;
83 pointer argv[];
84 { ckarg(2);
85  return(ioctl_struct(n,argv,TIOCSETN,sizeof(struct sgttyb)));}
86 
87 pointer IOCTL_TIOCGETD(ctx,n,argv)
88 register context *ctx;
89 int n;
90 pointer argv[];
91 { return(ioctl_int(n,argv,TIOCGETD));}
92 
93 pointer IOCTL_TIOCSETD(ctx,n,argv)
94 register context *ctx;
95 int n;
96 pointer argv[];
97 { return(ioctl_int(n,argv,TIOCSETD));}
98 
99 pointer IOCTL_TIOCFLUSH(ctx,n,argv)
100 register context *ctx;
101 int n;
102 pointer argv[];
103 { return(ioctl_int(n,argv,TIOCFLUSH));}
104 
105 pointer IOCTL_TIOCGPGRP(ctx,n,argv)
106 register context *ctx;
107 int n;
108 pointer argv[];
109 { return(ioctl_int(n,argv,TIOCGPGRP));}
110 
111 pointer IOCTL_TIOCSPGRP(ctx,n,argv)
112 register context *ctx;
113 int n;
114 pointer argv[];
115 { return(ioctl_int(n,argv,TIOCSPGRP));}
116 
117 pointer IOCTL_TIOCOUTQ(ctx,n,argv)
118 register context *ctx;
119 int n;
120 pointer argv[];
121 { return(ioctl_int(n,argv,TIOCOUTQ));}
122 
123 pointer IOCTL_TIOCLBIS(ctx,n,argv)
124 register context *ctx;
125 int n;
126 pointer argv[];
127 { return(ioctl_int(n,argv,TIOCLBIS));}
128 
129 pointer IOCTL_TIOCLBIC(ctx,n,argv)
130 register context *ctx;
131 int n;
132 pointer argv[];
133 { return(ioctl_int(n,argv,TIOCLBIC));}
134 
135 pointer IOCTL_TIOCLSET(ctx,n,argv)
136 register context *ctx;
137 int n;
138 pointer argv[];
139 { return(ioctl_int(n,argv,TIOCLSET));}
140 
141 pointer IOCTL_TIOCLGET(ctx,n,argv)
142 register context *ctx;
143 int n;
144 pointer argv[];
145 { return(ioctl_int(n,argv,TIOCLGET));}
146 
147 
148 **********************************************/
149 
150 /****************************************
151 #if !Solaris2
152 pointer IOCTL_FIONREAD(ctx,n,argv)
153 register context *ctx;
154 int n;
155 pointer argv[];
156 { return(ioctl_int(n,argv,FIONREAD));}
157 
158 pointer IOCTL_TIOCGETC(ctx,n,argv)
159 register context *ctx;
160 int n;
161 pointer argv[];
162 { return(ioctl_struct(n,argv,TIOCGETC,sizeof(struct tchars)));}
163 
164 pointer IOCTL_TIOCSETC(ctx,n,argv)
165 register context *ctx;
166 int n;
167 pointer argv[];
168 { ckarg(2);
169  return(ioctl_struct(n,argv,TIOCSETC,sizeof(struct tchars)));}
170 #endif
171 ********************************************/
172 
173 
174 #if !Darwin
175 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
176 
178 register context *ctx;
179 int n;
180 pointer argv[];
181 { return(ioctl_struct(n,argv,TCGETS,sizeof(struct termios)));}
182 
184 register context *ctx;
185 int n;
186 pointer argv[];
187 { return(ioctl_struct(n,argv,TCSETS,sizeof(struct termios)));}
188 
190 register context *ctx;
191 int n;
192 pointer argv[];
193 { return(ioctl_struct(n,argv,TCSETSW,sizeof(struct termios)));}
194 
196 register context *ctx;
197 int n;
198 pointer argv[];
199 { return(ioctl_struct(n,argv,TCSETSF,sizeof(struct termios)));}
200 #endif
201 
203 register context *ctx;
204 int n;
205 pointer argv[];
206 { return(ioctl_struct(n,argv,TCGETA,sizeof(struct termio)));}
207 
209 register context *ctx;
210 int n;
211 pointer argv[];
212 { return(ioctl_struct(n,argv,TCSETA,sizeof(struct termio)));}
213 
215 register context *ctx;
216 int n;
217 pointer argv[];
218 { return(ioctl_struct(n,argv,TCSETAF,sizeof(struct termio)));}
219 
221 int n;
222 pointer argv[];
223 { return(ioctl_struct(n,argv,TCSETAW,sizeof(struct termio)));}
224 #endif
225 
226 pointer TCGETATTR(ctx,n,argv)
227 register context *ctx;
228 int n;
229 pointer argv[];
230 { int stat;
231  pointer buf;
232  ckarg2(1,2);
233  buf=getbuf(n,argv[1],sizeof(struct termios));
234  stat=tcgetattr(getfd(argv[0]),(struct termios *)buf->c.str.chars);
235  if (stat<0) return(makeint(-errno)); else return(buf);}
236 
237 pointer TCSETATTR(ctx,n,argv)
238 register context *ctx;
239 int n;
240 pointer argv[];
241 { int stat,optact=0;
242  pointer buf;
243  ckarg2(1,3);
244  buf=getbuf(n,argv[2],sizeof(struct termios));
245  if (n>=2) optact=ckintval(argv[1]);
246  stat=tcsetattr(getfd(argv[0]),optact,(struct termios *)buf->c.str.chars);
247  if (stat<0) return(makeint(-errno)); else return(buf);}
248 
249 void eusioctl(ctx,mod)
250 register context *ctx;
251 register pointer mod;
252 {
253 /*********************** obsolete
254  defunpkg(ctx,"TIOCGETP",mod,IOCTL_TIOCGETP,unixpkg);
255  defunpkg(ctx,"TIOCSETP",mod,IOCTL_TIOCSETP,unixpkg);
256  defunpkg(ctx,"TIOCSETN",mod,IOCTL_TIOCSETN,unixpkg);
257  defunpkg(ctx,"TIOCGETD",mod,IOCTL_TIOCGETD,unixpkg);
258  defunpkg(ctx,"TIOCFLUSH",mod,IOCTL_TIOCFLUSH,unixpkg);
259  defunpkg(ctx,"TIOCGPGRP",mod,IOCTL_TIOCGPGRP,unixpkg);
260  defunpkg(ctx,"TIOCSPGRP",mod,IOCTL_TIOCSPGRP,unixpkg);
261  defunpkg(ctx,"TIOCOUTQ",mod,IOCTL_TIOCOUTQ,unixpkg);
262  defunpkg(ctx,"TIOCLBIS",mod,IOCTL_TIOCLBIS,unixpkg);
263  defunpkg(ctx,"TIOCLBIC",mod,IOCTL_TIOCLBIC,unixpkg);
264  defunpkg(ctx,"TIOCLSET",mod,IOCTL_TIOCLSET,unixpkg);
265  defunpkg(ctx,"TIOCLGET",mod,IOCTL_TIOCLGET,unixpkg);
266 *************************************/
267 
268 /*********************************** obsolete
269 #if !Solaris2
270  defunpkg(ctx,"FIONREAD",mod,IOCTL_FIONREAD,unixpkg);
271  defunpkg(ctx,"TIOCGETC",mod,IOCTL_TIOCGETC,unixpkg);
272  defunpkg(ctx,"TIOCSETC",mod,IOCTL_TIOCSETC,unixpkg);
273 #endif
274 *********************************************/
275 
276 #if !Darwin
277 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
278  defunpkg(ctx,"TCGETS",mod,IOCTL_TCGETS,unixpkg);
279  defunpkg(ctx,"TCSETS",mod,IOCTL_TCSETS,unixpkg);
280  defunpkg(ctx,"TCSETSW",mod,IOCTL_TCSETSW,unixpkg);
281  defunpkg(ctx,"TCSETSF",mod,IOCTL_TCSETSF,unixpkg);
282 #endif
283  defunpkg(ctx,"TCGETA",mod,IOCTL_TCGETA,unixpkg);
284  defunpkg(ctx,"TCSETA",mod,IOCTL_TCSETA,unixpkg);
285  defunpkg(ctx,"TCSETAW",mod,IOCTL_TCSETAW,unixpkg);
286  defunpkg(ctx,"TCSETAF",mod,IOCTL_TCSETAF,unixpkg);
287 #endif
288  defunpkg(ctx,"TCGETATTR",mod,TCGETATTR,unixpkg);
289  defunpkg(ctx,"TCSETATTR",mod,TCSETATTR,unixpkg);
290 /* printf("eusioctl: TCGETS=%x\n", TCGETS); */
291  }
pointer TCSETATTR(context *ctx, int n, argv)
Definition: eusioctl.c:237
#define makeint(v)
Definition: sfttest.c:2
pointer IOCTL_TCSETSW(context *ctx, int n, argv)
Definition: eusioctl.c:189
Definition: eus.h:522
struct string str
Definition: eus.h:400
pointer unixpkg
Definition: eus.c:109
byte chars[1]
Definition: eus.h:210
pointer IOCTL_TCSETS(context *ctx, int n, argv)
Definition: eusioctl.c:183
GLfloat n[6][3]
Definition: cube.c:15
static pointer ioctl_int(int n, argv, unsigned long ctlcode)
Definition: eusioctl.c:52
pointer defunpkg(context *, char *, pointer, pointer(*)(), pointer)
Definition: makes.c:636
static pointer getbuf(int n, pointer x, int bufsize)
Definition: eusioctl.c:31
#define intval(p)
Definition: sfttest.c:1
pointer IOCTL_TCSETSF(context *ctx, int n, argv)
Definition: eusioctl.c:195
ckarg(2)
static char * rcsid
Definition: eusioctl.c:7
union cell::cellunion c
static int getfd(pointer x)
Definition: eusioctl.c:23
static pointer ioctl_struct(int n, argv, unsigned long ctlcode, int bufsize)
Definition: eusioctl.c:39
pointer IOCTL_TCGETA(context *ctx, int n, argv)
Definition: eusioctl.c:202
Definition: eus.h:379
pointer IOCTL_TCSETAF(context *ctx, int n, argv)
Definition: eusioctl.c:214
pointer makebuffer(int)
Definition: makes.c:140
void eusioctl(context *ctx, pointer mod)
Definition: eusioctl.c:249
pointer IOCTL_TCGETS(context *ctx, int n, argv)
Definition: eusioctl.c:177
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
Definition: eus.c:297
pointer IOCTL_TCSETAW(int n, argv)
Definition: eusioctl.c:220
int errno
Definition: eus.h:950
static char buf[CHAR_SIZE]
Definition: helpsub.c:23
pointer IOCTL_TCSETA(context *ctx, int n, argv)
Definition: eusioctl.c:208
pointer TCGETATTR(context *ctx, int n, argv)
Definition: eusioctl.c:226
Definition: eus.h:952


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54