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


euslisp
Author(s): Toshihiro Matsui
autogenerated on Mon Feb 28 2022 22:18:27