static void mpxresume(void) { int fds[2]; pipe(fds); acceptch = NO_MORE_DATA; have = 0; if (!(kbdpid = fork())) { close(fds[1]); do { unsigned char c; int sta; pack.who = 0; sta = joe_read(fileno(termin), &c, 1); if (sta == 0) pack.ch = NO_MORE_DATA; else pack.ch = c; pack.size = 0; joe_write(mpxsfd, &pack, sizeof(struct packet) - 1024); } while (joe_read(fds[0], &pack, 1) == 1); _exit(0); } close(fds[0]); ackkbd = fds[1]; }
int ttflsh(void) { /* Flush output */ if (obufp) { joe_write(fileno(termout), obuf, obufp); 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; }
int ttshell(unsigned char *cmd) { int x, omode = ttymode; int stat= -1; unsigned char *s = (unsigned char *)getenv("SHELL"); if (!s) { s = USTR "/bin/sh"; /* return; */ } ttclsn(); #ifdef HAVE_FORK if ((x = fork()) != 0) { #else if ((x = vfork()) != 0) { /* For AMIGA only */ #endif if (x != -1) wait(&stat); if (omode) ttopnn(); return stat; } else { signrm(); if (cmd) execl((char *)s, (char *)s, "-c", cmd, NULL); else { fprintf(stderr, (char *)joe_gettext(_("You are at the command shell. Type 'exit' to return\n"))); execl((char *)s, (char *)s, NULL); } _exit(0); return 0; } } /* Create keyboard task */ static void mpxresume(void) { int fds[2]; pipe(fds); acceptch = NO_MORE_DATA; have = 0; if (!(kbdpid = fork())) { close(fds[1]); do { unsigned char c; int sta; pack.who = 0; sta = joe_read(fileno(termin), &c, 1); if (sta == 0) pack.ch = NO_MORE_DATA; else pack.ch = c; pack.size = 0; joe_write(mpxsfd, &pack, sizeof(struct packet) - 1024); } while (joe_read(fds[0], &pack, 1) == 1); _exit(0); } close(fds[0]); ackkbd = fds[1]; }
int ttgetc(void) { int stat; long new_time; int flg; tickon(); loop: flg = 0; /* Status line clock */ new_time = time(NULL); if (new_time != last_time) { last_time = new_time; dostaupd = 1; ticked = 1; } /* Autoscroller */ if (auto_scroll && mnow() >= auto_trig_time) { do_auto_scroll(); ticked = 1; flg = 1; } ttflsh(); while (winched) { winched = 0; edupd(1); ttflsh(); } if (ticked) { edupd(flg); ttflsh(); tickon(); } if (ackkbd != -1) { if (!have) { /* Wait for input */ stat = read(mpxfd, &pack, sizeof(struct packet) - 1024); if (pack.size && stat > 0) { joe_read(mpxfd, pack.data, pack.size); } else if (stat < 1) { if (winched || ticked) goto loop; else ttsig(0); } acceptch = pack.ch; } have = 0; if (pack.who) { /* Got bknd input */ if (acceptch != NO_MORE_DATA) { if (pack.who->func) { pack.who->func(pack.who->object, pack.data, pack.size); edupd(1); } } else mpxdied(pack.who); goto loop; } else { if (acceptch != NO_MORE_DATA) { tickoff(); return acceptch; } else { tickoff(); ttsig(0); return 0; } } } if (have) { have = 0; } else { if (read(fileno(termin), &havec, 1) < 1) { if (winched || ticked) goto loop; else ttsig(0); } } tickoff(); return havec; }
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; }