00001 
00002 
00003 
00004 
00005 
00006 
00007 static char *rcsid="@(#)$Id$";
00008 #include <ctype.h>
00009 #include <sys/termios.h>
00010 #ifndef Darwin
00011 #include <termio.h>
00012 #endif
00013 
00014 
00015 #undef MAX
00016 #undef MIN
00017 #undef VMIN
00018 #undef VMAX
00019 #include "eus.h"
00020 
00021 extern int errno;
00022 
00023 static int getfd(x)
00024 pointer x;
00025 { if (isint(x)) return(intval(x));
00026   else if (isflt(x)) error(E_NOINT);
00027   else if (pisiostream(x)) x=x->c.iostream.in;
00028   else if (!pisfilestream(x)) error(E_STREAM);
00029   return(intval(x->c.fstream.fd));}
00030 
00031 static pointer getbuf(n,x,bufsize)
00032 int n,bufsize;
00033 pointer x;
00034 { if (n<=1) x=makebuffer(bufsize);
00035   else if (!isstring(x)) error(E_NOSTRING);
00036   else if (strlength(x)<bufsize) error(E_VECINDEX);
00037   return(x);}
00038 
00039 static pointer ioctl_struct(n,argv,ctlcode,bufsize)
00040 int n,bufsize;
00041 pointer argv[];
00042 { int fd,stat;
00043   pointer buf;
00044   if (n==0 || n>2) error(E_MISMATCHARG);
00045   fd=getfd(argv[0]);
00046   buf=getbuf(n,argv[1],bufsize);
00047   stat=ioctl(fd,ctlcode,buf->c.str.chars);
00048   if (stat<0) return(makeint( (-errno)));
00049   else return(buf);}
00050 
00051 static pointer ioctl_int(n,argv,ctlcode)
00052 int n;
00053 pointer argv[];
00054 { int fd,stat,intarg;
00055   pointer buf;
00056   ckarg(2);
00057   fd=getfd(argv[0]);
00058   intarg=ckintval(argv[1]);
00059   stat=ioctl(fd,ctlcode, &intarg);
00060   if (stat<0) return(makeint(-errno));
00061   else return(makeint(intarg));}
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 #if !Darwin
00173 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00174 
00175 pointer IOCTL_TCGETS(ctx,n,argv)
00176 register context *ctx;
00177 int n;
00178 pointer argv[];
00179 { return(ioctl_struct(n,argv,TCGETS,sizeof(struct termios)));}
00180 
00181 pointer IOCTL_TCSETS(ctx,n,argv)
00182 register context *ctx;
00183 int n;
00184 pointer argv[];
00185 { return(ioctl_struct(n,argv,TCSETS,sizeof(struct termios)));}
00186 
00187 pointer IOCTL_TCSETSW(ctx,n,argv)
00188 register context *ctx;
00189 int n;
00190 pointer argv[];
00191 { return(ioctl_struct(n,argv,TCSETSW,sizeof(struct termios)));}
00192 
00193 pointer IOCTL_TCSETSF(ctx,n,argv)
00194 register context *ctx;
00195 int n;
00196 pointer argv[];
00197 { return(ioctl_struct(n,argv,TCSETSF,sizeof(struct termios)));}
00198 #endif
00199 
00200 pointer IOCTL_TCGETA(ctx,n,argv)
00201 register context *ctx;
00202 int n;
00203 pointer argv[];
00204 { return(ioctl_struct(n,argv,TCGETA,sizeof(struct termio)));}
00205 
00206 pointer IOCTL_TCSETA(ctx,n,argv)
00207 register context *ctx;
00208 int n;
00209 pointer argv[];
00210 { return(ioctl_struct(n,argv,TCSETA,sizeof(struct termio)));}
00211 
00212 pointer IOCTL_TCSETAF(ctx,n,argv)
00213 register context *ctx;
00214 int n;
00215 pointer argv[];
00216 { return(ioctl_struct(n,argv,TCSETAF,sizeof(struct termio)));}
00217 
00218 pointer IOCTL_TCSETAW(n,argv)
00219 int n;
00220 pointer argv[];
00221 { return(ioctl_struct(n,argv,TCSETAW,sizeof(struct termio)));}
00222 #endif
00223 
00224 pointer TCGETATTR(ctx,n,argv)
00225 register context *ctx;
00226 int n;
00227 pointer argv[];
00228 { int stat;
00229   pointer buf;
00230   ckarg2(1,2);
00231   buf=getbuf(n,argv[1],sizeof(struct termios));
00232   stat=tcgetattr(getfd(argv[0]),(struct termios *)buf->c.str.chars);
00233   if (stat<0) return(makeint(-errno)); else return(buf);}
00234 
00235 pointer TCSETATTR(ctx,n,argv)
00236 register context *ctx;
00237 int n;
00238 pointer argv[];
00239 { int stat,optact=0;
00240   pointer buf;
00241   ckarg2(1,3);
00242   buf=getbuf(n,argv[2],sizeof(struct termios));
00243   if (n>=2) optact=ckintval(argv[1]);
00244   stat=tcsetattr(getfd(argv[0]),optact,(struct termios *)buf->c.str.chars);
00245   if (stat<0) return(makeint(-errno)); else return(buf);}
00246 
00247 void eusioctl(ctx,mod)
00248 register context *ctx;
00249 register pointer mod;
00250 {
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 #if !Darwin
00275 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00276   defunpkg(ctx,"TCGETS",mod,IOCTL_TCGETS,unixpkg);
00277   defunpkg(ctx,"TCSETS",mod,IOCTL_TCSETS,unixpkg);
00278   defunpkg(ctx,"TCSETSW",mod,IOCTL_TCSETSW,unixpkg);
00279   defunpkg(ctx,"TCSETSF",mod,IOCTL_TCSETSF,unixpkg);
00280 #endif
00281   defunpkg(ctx,"TCGETA",mod,IOCTL_TCGETA,unixpkg);
00282   defunpkg(ctx,"TCSETA",mod,IOCTL_TCSETA,unixpkg);
00283   defunpkg(ctx,"TCSETAW",mod,IOCTL_TCSETAW,unixpkg);
00284   defunpkg(ctx,"TCSETAF",mod,IOCTL_TCSETAF,unixpkg);
00285 #endif
00286   defunpkg(ctx,"TCGETATTR",mod,TCGETATTR,unixpkg);
00287   defunpkg(ctx,"TCSETATTR",mod,TCSETATTR,unixpkg);
00288 
00289   }