void tickon(void) { #ifdef HAVE_SETITIMER struct itimerval val; val.it_interval.tv_sec = 0; val.it_interval.tv_usec = 0; if (auto_scroll) { int tim = auto_trig_time - mnow(); if (tim < 0) tim = 1; tim *= 1000; val.it_value.tv_sec = 0; val.it_value.tv_usec = tim; } else { val.it_value.tv_sec = 1; val.it_value.tv_usec = 0; } ticked = 0; joe_set_signal(SIGALRM, dotick); setitimer(ITIMER_REAL,&val,NULL); #else ticked = 0; joe_set_signal(SIGALRM, dotick); alarm(1); #endif }
/* Restore signals for exiting */ void signrm(void) { if (!ttysig) return; ttysig = 0; joe_set_signal(SIGABRT, SIG_DFL); joe_set_signal(SIGHUP, SIG_DFL); joe_set_signal(SIGTERM, SIG_DFL); joe_set_signal(SIGINT, SIG_DFL); joe_set_signal(SIGPIPE, SIG_DFL); }
/* Set signals for JOE */ void sigjoe(void) { if (ttysig) return; ttysig = 1; joe_set_signal(SIGHUP, ttsig); joe_set_signal(SIGTERM, ttsig); joe_set_signal(SIGABRT, ttsig); joe_set_signal(SIGINT, SIG_IGN); joe_set_signal(SIGPIPE, SIG_IGN); }
/* Open terminal */ void ttopnn(void) { int x; struct termios newterm; if (!open_terminal_handles()) { fprintf(stderr, (char *)joe_gettext(_("Couldn\'t open /dev/tty\n"))); exit(1); } joe_set_signal(SIGWINCH, winchd); if (ttymode) return; ttymode = 1; fflush(termout); tcgetattr(fileno(termin), &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; tcsetattr(fileno(termin), TCSADRAIN, &newterm); }
void tickon(void) { struct itimerval val; struct timeval now; gettimeofday(&now, NULL); val.it_interval.tv_sec = 0; val.it_interval.tv_usec = 0; if (auto_scroll) { time_t now = mnow(); time_t tim = (now > auto_trig_time) ? 1 : auto_trig_time - now; tim *= 1000; val.it_value.tv_sec = 0; val.it_value.tv_usec = tim; } else { val.it_value.tv_sec = 60 - (now.tv_sec % 60); val.it_value.tv_usec = 1000000 - now.tv_usec; } ticked = 0; joe_set_signal(SIGALRM, dotick); setitimer(ITIMER_REAL,&val,NULL); }
int ttflsh(void) { /* Flush output */ if (obufp) { unsigned long usec = obufp * upc; /* No. usecs this write should take */ #ifdef HAVE_SETITIMER if (usec >= 50000 && baud < 9600) { struct itimerval a, b; a.it_value.tv_sec = usec / 1000000; a.it_value.tv_usec = usec % 1000000; a.it_interval.tv_usec = 0; a.it_interval.tv_sec = 0; alarm(0); joe_set_signal(SIGALRM, dosig); yep = 0; maskit(); setitimer(ITIMER_REAL, &a, &b); joe_write(fileno(termout), obuf, obufp); while (!yep) pauseit(); unmaskit(); } else joe_write(fileno(termout), obuf, obufp); #else joe_write(fileno(termout), obuf, obufp); #ifdef FIORDCHK if (baud < 9600 && usec / 1000) nap(usec / 1000); #endif #endif obufp = 0; } /* Ack previous packet */ if (ackkbd != -1 && acceptch != NO_MORE_DATA && !have) { unsigned char c = 0; if (pack.who && pack.who->func) joe_write(pack.who->ackfd, &c, 1); else joe_write(ackkbd, &c, 1); acceptch = NO_MORE_DATA; } /* Check for typeahead or next packet */ if (!have && !leave) { if (ackkbd != -1) { fcntl(mpxfd, F_SETFL, O_NDELAY); if (read(mpxfd, &pack, sizeof(struct packet) - 1024) > 0) { fcntl(mpxfd, F_SETFL, 0); joe_read(mpxfd, pack.data, pack.size); have = 1; acceptch = pack.ch; } else fcntl(mpxfd, F_SETFL, 0); } else { /* Set terminal input to non-blocking */ fcntl(fileno(termin), F_SETFL, O_NDELAY); /* Try to read */ if (read(fileno(termin), &havec, 1) == 1) have = 1; /* Set terminal back to blocking */ fcntl(fileno(termin), F_SETFL, 0); } } return 0; }
void ttopnn(void) { int x, bbaud; #ifdef HAVE_POSIX_TERMIOS struct termios newterm; #else #ifdef HAVE_SYSV_TERMIO struct termio newterm; #else struct sgttyb arg; struct tchars targ; struct ltchars ltarg; #endif #endif if (!termin) { if (idleout ? (!(termin = stdin) || !(termout = stdout)) : (!(termin = fopen("/dev/tty", "r")) || !(termout = fopen("/dev/tty", "w")))) { fprintf(stderr, (char *)joe_gettext(_("Couldn\'t open /dev/tty\n"))); exit(1); } else { #ifdef SIGWINCH joe_set_signal(SIGWINCH, winchd); #endif } } if (ttymode) return; ttymode = 1; fflush(termout); #ifdef HAVE_POSIX_TERMIOS tcgetattr(fileno(termin), &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; tcsetattr(fileno(termin), TCSADRAIN, &newterm); bbaud = cfgetospeed(&newterm); #else #ifdef HAVE_SYSV_TERMIO joe_ioctl(fileno(termin), TCGETA, &oldterm); newterm = oldterm; newterm.c_lflag = 0; if (noxon) newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR | IXON | IXOFF); else newterm.c_iflag &= ~(ICRNL | IGNCR | INLCR); newterm.c_oflag = 0; newterm.c_cc[VMIN] = 1; newterm.c_cc[VTIME] = 0; joe_ioctl(fileno(termin), TCSETAW, &newterm); bbaud = (newterm.c_cflag & CBAUD); #else joe_ioctl(fileno(termin), TIOCGETP, &arg); joe_ioctl(fileno(termin), TIOCGETC, &targ); joe_ioctl(fileno(termin), TIOCGLTC, <arg); oarg = arg; otarg = targ; oltarg = ltarg; arg.sg_flags = ((arg.sg_flags & ~(ECHO | CRMOD | XTABS | ALLDELAY | TILDE)) | CBREAK); if (noxon) { targ.t_startc = -1; targ.t_stopc = -1; } targ.t_intrc = -1; targ.t_quitc = -1; targ.t_eofc = -1; targ.t_brkc = -1; ltarg.t_suspc = -1; ltarg.t_dsuspc = -1; ltarg.t_rprntc = -1; ltarg.t_flushc = -1; ltarg.t_werasc = -1; ltarg.t_lnextc = -1; joe_ioctl(fileno(termin), TIOCSETN, &arg); joe_ioctl(fileno(termin), TIOCSETC, &targ); joe_ioctl(fileno(termin), TIOCSLTC, <arg); bbaud = arg.sg_ospeed; #endif #endif baud = 9600; upc = 0; for (x = 0; x != 30; x += 2) if (bbaud == speeds[x]) { baud = speeds[x + 1]; break; } if (Baud) baud = Baud; upc = DIVIDEND / baud; if (obuf) joe_free(obuf); if (!(TIMES * upc)) obufsiz = 4096; else { obufsiz = 1000000 / (TIMES * upc); if (obufsiz > 4096) obufsiz = 4096; } if (!obufsiz) obufsiz = 1; obuf = (unsigned char *) joe_malloc(obufsiz); }