- DEMUX_DECL; /* OS-dependent data needed by DEMUX... macros */
- char buf[500]; /* FIXME, what is "500" here? */
- int i, n;
- unsigned char stop_exit;
- unsigned char stop_code;
- TTY_STRUCT tty;
- long ip_value, fp_value, sp_value; /* Reg values from stop */
-
-
- WSETEXIT( (*status), 0 );
-
- /* OPERATE IN PASSTHROUGH MODE UNTIL NINDY SENDS A DLE CHARACTER */
-
- /* Save current tty attributes, set up signals to restore them.
- */
- ioctl( 0, TIOCGETP, &orig_tty );
- old_ctrlc = signal( SIGINT, cleanup );
-#ifdef SIGTSTP
- old_ctrlz = signal( SIGTSTP, cleanup );
-#endif
-
- /* Pass input from keyboard to NINDY as it arrives.
- * NINDY will interpret <CR> and perform echo.
- */
- tty = orig_tty;
- TTY_NINDYTERM( tty );
- ioctl( 0, TIOCSETN, &tty );
-
- while ( 1 ){
- /* Go to sleep until there's something for us on either
- * the remote port or stdin.
- */
-
- DEMUX_WAIT( nindy_fd );
-
- /* Pass input through to correct place */
+ fd_set fds;
+ char buf[500]; /* FIXME, what is "500" here? */
+ int i, n;
+ unsigned char stop_exit;
+ unsigned char stop_code;
+ struct clean_up_tty_args tty_args;
+ struct cleanup *old_cleanups;
+ long ip_value, fp_value, sp_value; /* Reg values from stop */
+
+ WSETEXIT( (*status), 0 );
+
+ /* OPERATE IN PASSTHROUGH MODE UNTIL NINDY SENDS A DLE CHARACTER */
+
+ /* Save current tty attributes, and restore them when done. */
+ tty_args.serial = SERIAL_FDOPEN (0);
+ tty_args.state = SERIAL_GET_TTY_STATE (tty_args.serial);
+ old_cleanups = make_cleanup (clean_up_tty, &tty_args);
+
+ /* Pass input from keyboard to NINDY as it arrives. NINDY will interpret
+ <CR> and perform echo. */
+ /* This used to set CBREAK and clear ECHO and CRMOD. I hope this is close
+ enough. */
+ SERIAL_RAW (tty_args.serial);
+
+ while (1)
+ {
+ /* Wait for input on either the remote port or stdin. */
+ FD_ZERO (&fds);
+ FD_SET (0, &fds);
+ FD_SET (nindy_serial->fd, &fds);
+ if (select (nindy_serial->fd + 1, &fds, 0, 0, 0) <= 0)
+ continue;
+
+ /* Pass input through to correct place */
+ if (FD_ISSET (0, &fds))
+ {
+ /* Input on stdin */
+ n = read (0, buf, sizeof (buf));
+ if (n)
+ {
+ SERIAL_WRITE (nindy_serial, buf, n );
+ }
+ }