File:  [gforth] / gforth / wordlibs / unixlib.pri
Revision 1.2: download - view: text, annotated - select for diffs
Mon May 17 13:20:03 1999 UTC (22 years, 2 months ago) by jwilke
Branches: MAIN
CVS tags: v0-7-0, v0-6-2, v0-6-1, v0-6-0, v0-5-0, HEAD
Updated

    1: alarm	u --	unixlib
    2: alarm(u);
    3: 
    4: timeusec	-- u_usec u_sec	unixlib
    5: struct timeval tv;
    6: struct timezone zone1;
    7:  gettimeofday(&tv,&zone1);
    8: u_usec=tv.tv_usec;
    9: u_sec=tv.tv_sec;
   10: 
   11: time	-- u1	unixlib
   12: u1=(long) time(NULL);
   13: 
   14: \ Serial Interface
   15: 
   16: setttyspeed	u u2 -- wior	unixlib
   17: struct termios tm;
   18: int BT[]={
   19:   0,B0,50,B50,75,B75,110,B110,134,B134,150,B150,200,B200,300,B300,
   20:   600,B600,1200,B1200,1800,B1800,2400,B2400,4800,B4800,9600,B9600,19200,B19200,38400,B38400,
   21: #ifdef B57600
   22:   57600,B57600,
   23: #endif
   24: #ifdef B115200
   25:   115200,B115200,
   26: #endif
   27: #ifdef B230400
   28:   230400,B230400,
   29: #endif
   30:   1};
   31: speed_t br;
   32: int i;
   33: i=0; br=0;
   34: while (BT[i]!=1)
   35: { if (BT[i]==u)
   36:   { br=BT[i+1];
   37:     break;
   38:   }
   39:   i=i+2;
   40: }
   41: if (BT[i]!=1)
   42: { tcgetattr(u2,&tm);
   43:   cfsetispeed(&tm, br);
   44:   cfsetospeed(&tm, br);
   45:   tcsetattr(u2,TCSANOW,&tm);
   46:   wior=0;
   47: } else
   48: { wior=-1;
   49: }
   50: 
   51: setttyraw	u -- wior	unixlib
   52: struct termios tm;
   53: tcgetattr(u,&tm);
   54: /* cfmakeraw(&tm); !!!!???? worked with linux, but nut on solaris */
   55: tcsetattr(u,TCSANOW,&tm);
   56: wior=0;
   57: 
   58: ttytostd	c_addr1 u1 -- wior	unixlib
   59: int i;
   60: wior=0;
   61: close(0);
   62: close(1);
   63: close(2);
   64: i=open(cstr(c_addr1,u1,0),O_RDWR|O_NOCTTY);
   65: if ((i==-1) || (i!=0))
   66: {	wior=-1;
   67: } else
   68: {	i= dup(0);
   69: 	i= dup(0);
   70: 	i=open("/dev/tty",O_RDWR);
   71: 	if (i>=0) {
   72: 	  ioctl(i,TIOCNOTTY,0);
   73: 	  (void) close(i);
   74: 	}
   75: }
   76: 
   77: uopen	c_addr u uflags umode -- w2 wior	file
   78: w2 = open(tilde_cstr(c_addr, u, 1), uflags , (mode_t) umode);
   79: if (w2 == -1) {
   80:   wior = -37;
   81: } else {
   82:   wior = 0;
   83: }
   84: 
   85: uread	c_addr u u1 -- u3 wior	new
   86: wior=0;
   87: if ((u3 = read(u1, c_addr, u))==-1) 
   88: {	if (errno==EWOULDBLOCK) u3=0;
   89: 	else wior=-37;
   90: } else
   91: { 	if (u3==0) wior=-39;
   92: }
   93: 
   94: uwrite	c_addr u u1 -- u3 wior	new
   95: wior=0;
   96: if ((u3 = write(u1, c_addr, u))==-1)
   97: {	if (errno==EAGAIN) u3=0;
   98: 	else wior=-37;
   99: }
  100: 
  101: uclose	u -- wior	new
  102: wior=0;
  103: if (close(u)) wior=-37;
  104: 
  105: nonblock	u1 -- wior	new
  106: fcntl(u1,F_SETFL,O_NONBLOCK);
  107: wior=0;
  108: 
  109: get_cconst	c_addr u -- u1 wior	new
  110: static char CONST_NAMES[][32]={
  111: "O_RDONLY",
  112: "O_WRONLY",
  113: "O_RDWR",
  114: ""};
  115: static unsigned int CONST_VALUES[]={
  116: O_RDONLY,
  117: O_WRONLY,
  118: O_RDWR}; 
  119: int i=0;
  120: int contd=1;
  121: u1=0;
  122: wior=-1;
  123: while (CONST_NAMES[i] && contd) {
  124: 	if (strcmp(CONST_NAMES[i],cstr(c_addr,u,1))==0) {
  125: 		contd=0; u1=CONST_VALUES[i]; wior=0;} ;
  126: 	i++;
  127: }
  128: 
  129: fork	-- u	new
  130: u=fork();
  131: 
  132: wait	a_addr -- u	new	I_wait
  133: u=wait((int *) a_addr);
  134: 
  135: waitpid	u a_addr u2 -- u3	new	I_waitpid
  136: u3=waitpid((pid_t) u,(int *) a_addr,u2);
  137: 
  138: execv	c_addr1 u1 c_addr2 --	new
  139: char *s1=cstr(c_addr1, u1, 0);
  140: execv(s1, (void *) c_addr2); 
  141: 
  142: errno	-- u	new
  143: u=errno;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>