Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* $Header: mview.c, 2009246515, , $ */
- /* jamie findlay */
- /* 2-13-97 */
- /* Joe Munson 5-10-97 Add buffering to all reads and writes for performance */
- /* Joe Munson 5-12-97 CTRL-W use to toggle to the next windows and CTRL-N */
- /* opened a new one. Now, CTRL-W is used as a handshake to */
- /* communicate with the applications. When CTRL-W is noticed, */
- /* it is sent on to the active view, and mview begins scanning */
- /* every character for a response from the application in the */
- /* (CTRL-V,CTRL-V,WINDOW #) format. */
- /* Joe Munson 9-9-97 Add ioctl switching to allow a windows to have a ksh */
- /* or a DBC program. ( -a option ) */
- /* compile: cc -O -o mview mview.c */
- static char Ident[] = "@(#)$Revision: 2009246515$ $Date: $";
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <signal.h>
- #include <errno.h>
- #include <unistd.h>
- #include <termio.h>
- #include <stropts.h>
- #include <poll.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <curses.h>
- #include <term.h>
- #ifdef __STDC__
- #include <wait.h>
- #endif
- #ifndef STDIN_FILENO
- #define STDIN_FILENO (fileno(stdin))
- #endif
- #ifndef STDOUT_FILENO
- #define STDOUT_FILENO (fileno(stdout))
- #endif
- #ifndef FD_CLOEXEC
- #define FD_CLOEXEC 1
- #endif
- #if !defined(_PID_T) & !defined(_SYS_TYPES_H) & (!defined(_H_TYPES) | !defined(_POSIX_SOURCE)) & !defined(P_MYPID)
- typedef int pid_t;
- #endif
- #define VIEWMAX 16
- #define IOBUF 2048
- #define FLAGS_TTYIN 0x00000001
- #define FLAGS_TTYOUT 0x00000002
- #define FLAGS_TTYSAME 0x00000004
- #define FLAGS_IOCTL 0x00000008
- #define FLAGS_SIGNAL 0x00000010
- #define FLAGS_REFRESH 0x00000020
- #define FLAGS_QUIT 0x00000040
- #define FLAGS_NEWVIEW 0x00000080
- #define FLAGS_IOCTLCHG 0x00000100
- typedef struct {
- pid_t pid;
- int input;
- int output;
- char refresh;
- char vilable;
- char ioctltype;
- } VIEWINFO;
- static int flags;
- static char *shell[] = {
- "-@",
- "ksh",
- NULL
- };
- static pid_t childpid;
- static VIEWINFO viewinfo[VIEWMAX];
- static int viewcnt;
- static int viewactive = 0;
- static struct pollfd pollttys[VIEWMAX];
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- static struct sigaction oldhup;
- static struct sigaction oldint;
- static struct sigaction oldpipe;
- static struct sigaction oldchld;
- #ifdef SIGTSTP
- static struct sigaction oldtstp;
- #endif
- #else
- #ifdef __STDC__
- static void (*oldhup)(INT);
- static void (*oldint)(INT);
- static void (*oldpipe)(INT);
- static void (*oldchld)(INT);
- #ifdef SIGTSTP
- static void (*oldtstp)(INT);
- #endif
- #else
- static void (*oldhup)();
- static void (*oldint)();
- static void (*oldpipe)();
- static void (*oldchld)();
- #ifdef SIGTSTP
- static void (*oldtstp)();
- #endif
- #endif
- #endif
- static struct termio terminshell, termindbc, terminold;
- static struct termio termoutshell, termoutdbc, termoutold;
- static char dbc_pstation[80];
- static char dbcvol_ram[80];
- #ifdef __STDC__
- static void initialize(void);
- static void flushtowrite(int, char *, int *);
- static void cleanup(void);
- static char **getcommand(void);
- static int startview(char **, char *);
- static void checkviews(void);
- static void sigevent(int);
- #else
- static void initialize();
- static void flushtowrite();
- static void cleanup();
- static char **getcommand();
- static int startview();
- static void checkviews();
- static void sigevent();
- #endif
- #define VIEW_CHG_IN 0x17 /* CTRL-W */ /* mview change view */
- #define VIEW_CHG_OUT 0x17 /* CTRL-V */ /* command change view */
- #define VIEW_ACK 0x16 /* CTRL-V */ /* acknowledgement from commmand */
- #define VIEW_REF 0x0C /* CTRL-L */ /* refresh to command */
- #define VIEW_BREAK 0x03 /* CTRL-C */ /* mview send break to command */
- /* different commands need different ioctl settings */
- #define IOCTL_NULL 0
- #define IOCTL_DBC 1
- #define IOCTL_SHELL 2
- int ASKCMD;
- int main(argc, argv)
- int argc;
- char *argv[];
- {
- int i1, i2, i3, iosize, towritesize, prevview;
- char c1, **cmd, io[IOBUF];
- char towrite[IOBUF];
- prevview = 0;
- initialize();
- ASKCMD=0;
- if (argc > 1)
- if (argv[1][0] == '-' && argv[1][1] == 'a') {
- cmd = &argv[2];
- ASKCMD=1;
- }
- else
- cmd = &argv[1];
- else
- cmd = shell;
- c1 = '1';
- if (startview(cmd,&c1) == -1) {
- fprintf(stderr, "Unable to execute '%s'\n", *cmd);
- cleanup();
- exit(1);
- }
- while (!(flags & FLAGS_QUIT)) {
- /* refresh active view */
- if (flags & FLAGS_REFRESH) {
- if (viewinfo[viewactive].refresh)
- write(viewinfo[viewactive].output, &viewinfo[viewactive].refresh, 1);
- flags &= ~FLAGS_REFRESH;
- }
- if (flags & FLAGS_IOCTLCHG) {
- ioctlswitch(viewinfo[viewactive].ioctltype);
- flags &= ~FLAGS_IOCTLCHG;
- }
- /* check for IO on each commands STDOUT & mview's STDIN */
- if (poll(pollttys, viewcnt, -1) > 0) {
- /* cycle through each view and check for STDIO */
- for (i1 = 0; i1 < viewcnt && !(flags & FLAGS_QUIT); i1++) {
- /* refresh active view */
- if (flags & FLAGS_REFRESH) {
- if (viewinfo[viewactive].refresh)
- write(viewinfo[viewactive].output, &viewinfo[viewactive].refresh, 1);
- flags &= ~FLAGS_REFRESH;
- }
- if (flags & FLAGS_IOCTLCHG) {
- ioctlswitch(viewinfo[viewactive].ioctltype);
- flags &= ~FLAGS_IOCTLCHG;
- }
- if (pollttys[i1].revents & POLLIN) {
- /* read command's STDOUT or mview's STDIN */
- iosize = read(pollttys[i1].fd, io, IOBUF);
- if (iosize < 1) continue;
- /* if it's mview's STDIN */
- if (!i1) {
- towritesize=0;
- /* check each character to mview's IO buffer. If it's not */
- /* special stick it in the array of chars "towrite" */
- for (i2 = 0; i2 < iosize; ++i2) {
- switch (io[i2]) {
- case VIEW_CHG_IN: /* ^W - change window */
- flushtowrite(viewinfo[viewactive].output,towrite, &towritesize);
- checkviews();
- /* write the CTRL-W to the active view */
- towrite[towritesize++] = VIEW_CHG_OUT;
- flushtowrite(viewinfo[viewactive].output,towrite, &towritesize);
- flags |= FLAGS_NEWVIEW;
- break;
- case VIEW_BREAK: /* ^C - interrupt */
- flushtowrite(viewinfo[viewactive].output,towrite, &towritesize);
- #ifdef P_PID
- sigsend(P_PID, viewinfo[viewactive].pid, SIGINT);
- #else
- kill(viewinfo[viewactive].pid, SIGINT);
- #endif
- break;
- case 27:
- flushtowrite(viewinfo[viewactive].output,towrite, &towritesize);
- usleep(10000);
- kill(childpid, SIGALRM);
- default:
- towrite[towritesize++] = io[i2];
- break;
- }
- flushtowrite(viewinfo[viewactive].output,towrite, &towritesize);
- }
- }
- else if (i1 == viewactive && (flags & FLAGS_NEWVIEW)){
- /* get the active view's response to determine */
- /* the new active view */
- towritesize=0;
- for (i2 = 0; i2 < iosize; ++i2) {
- if (io[i2] == VIEW_ACK && io[i2 + 1] == VIEW_ACK) {
- flushtowrite(STDOUT_FILENO, towrite, &towritesize);
- if (((i2 + 2) == iosize) || io[i2 + 2] < '1' || io[i2 + 2] > '9'){
- /* abort the view change if the char */
- /* wasn't read or char < 1 or > 9 */
- printf("abort 1: %d %d %d\n", io[i2], io[i2 + 1], io[i2 + 2]);
- flags &= ~FLAGS_NEWVIEW;
- break;
- }
- /* check for existing views to switch to */
- prevview = viewactive;
- viewactive = 0;
- for (i3 = 0; i3 < viewcnt; ++i3) {
- if (viewinfo[i3].vilable == io[i2 + 2]){
- viewactive = i3;
- flags |= FLAGS_REFRESH;
- if (viewinfo[i3].ioctltype != viewinfo[prevview].ioctltype){
- flags |= FLAGS_IOCTLCHG;
- }
- }
- }
- /* it must be a new one, create it */
- if (viewactive == 0){
- if (ASKCMD) cmd = getcommand();
- c1 = io[i2 + 2];
- if (cmd == NULL){
- flags |= FLAGS_REFRESH;
- viewactive=prevview;
- }
- else if (startview(cmd, &c1) == -1) {
- fprintf(stderr, "Unable to execute '%s'\n", *cmd);
- sleep(1);
- flags |= FLAGS_REFRESH;
- }
- }
- flags &= ~FLAGS_NEWVIEW;
- break;
- }
- else if (io[i2] == VIEW_ACK) {
- /* abort the view change if only one CTRL-W */
- printf("abort 2: %d %d %d\n", io[i2], io[i2 + 1], io[i2 + 2]);
- sleep(3);
- flags &= ~FLAGS_NEWVIEW;
- }
- else towrite[towritesize++] = io[i2];
- }
- flushtowrite(STDOUT_FILENO,towrite, &towritesize);
- }
- else if (i1 == viewactive) write(STDOUT_FILENO, io, iosize);
- }
- }
- }
- }
- cleanup();
- exit(0);
- return 0;
- }
- static void initialize()
- {
- char work[128];
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- struct sigaction act;
- #endif
- viewinfo[0].pid = getpid();
- viewinfo[0].input = STDIN_FILENO;
- viewinfo[0].output = STDOUT_FILENO;
- viewinfo[0].vilable = '0';
- viewinfo[0].ioctltype = IOCTL_NULL;
- pollttys[0].fd = STDIN_FILENO;
- pollttys[0].events = POLLIN;
- pollttys[0].revents = 0;
- viewcnt = 1;
- flags = 0;
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- act.sa_handler = sigevent;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- #ifdef SA_INTERRUPT
- act.sa_flags |= SA_INTERRUPT;
- #endif
- sigaction(SIGHUP, &act, &oldhup);
- sigaction(SIGINT, &act, &oldint);
- sigaction(SIGPIPE, &act, &oldpipe);
- sigaction(SIGCHLD, &act, &oldchld);
- #if 0
- #ifdef SIGTSTP
- act.sa_handler = SIG_IGN;
- sigaction(SIGTSTP, &act, &oldtstp);
- if (oldtstp.sa_handler == SIG_DFL) {
- act.sa_handler = sigevent;
- sigaction(SIGTSTP, &act, NULL);
- }
- #endif
- #endif
- #else
- oldhup = sigset(SIGHUP, sigevent);
- oldint = sigset(SIGINT, sigevent);
- oldpipe = sigset(SIGPIPE, sigevent);
- oldchld = sigset(SIGCHLD, sigevent);
- #if 0
- #ifdef SIGTSTP
- if ((oldtstp = sigset(SIGTSTP, SIG_IGN)) == SIG_DFL) sigset(SIGTSTP, sigevent);
- #endif
- #endif
- #endif
- flags |= FLAGS_SIGNAL;
- if (isatty(STDIN_FILENO)) flags |= FLAGS_TTYIN;
- if (isatty(STDOUT_FILENO)) flags |= FLAGS_TTYOUT;
- if ((flags & FLAGS_TTYIN) && (flags & FLAGS_TTYOUT)) {
- strcpy(work, (char *) ttyname(STDIN_FILENO));
- if (!strcmp(work, (char *) ttyname(STDOUT_FILENO)))
- flags |= FLAGS_TTYSAME;
- }
- /* prepare terminal attributes for shell and dbc */
- if (flags & FLAGS_TTYIN) {
- ioctl(STDIN_FILENO, TCGETA, &terminold);
- memcpy((char *) &terminshell, (char *) &terminold, sizeof(struct termio));
- memcpy((char *) &termindbc, (char *) &terminold, sizeof(struct termio));
- termindbc.c_iflag &= ~ICRNL;
- termindbc.c_iflag |= IGNBRK;
- termindbc.c_lflag = ISIG; /* enable signals, non-canonical, no echo, etc. */
- /* disable the intr character so it can be sent to the active view. */
- termindbc.c_cc[VINTR] = fpathconf(STDIN_FILENO, _PC_VDISABLE);
- terminshell.c_cc[VINTR] = fpathconf(STDIN_FILENO, _PC_VDISABLE);
- termindbc.c_cc[VMIN] = 1;
- termindbc.c_cc[VTIME] = 0;
- if (flags & FLAGS_TTYSAME) termindbc.c_oflag = 0;
- }
- if ((flags & FLAGS_TTYOUT) && !(flags & FLAGS_TTYSAME)) {
- ioctl(STDOUT_FILENO, TCGETA, &termoutold);
- memcpy((char *) &termoutdbc, (char *) &termoutold, sizeof(struct termio));
- memcpy((char *) &termoutshell, (char *) &termoutold, sizeof(struct termio));
- termoutdbc.c_oflag = 0; /* No output translation */
- }
- flags |= FLAGS_IOCTL;
- }
- static void cleanup()
- {
- int i1, i2, status;
- pid_t pid, dead;
- checkviews();
- /* kill all of the children */
- for (i1 = 1; i1 < viewcnt; i1++) {
- if ((pid = viewinfo[i1].pid) == -1) continue;
- #ifdef P_PID
- if (sigsend(P_PID, pid, SIGHUP) == -1) {
- if (sigsend(P_PID, pid, SIGHUP) == -1) continue;
- }
- #else
- if (kill(pid, SIGHUP) == -1) {
- if (kill(pid, SIGHUP) == -1) continue;
- }
- #endif
- #if 0
- #ifdef WNOHANG
- while (waitpid(pid, &status, 0) == -1) if (errno != EINTR) break;
- #else
- for ( ; ; ) {
- dead = wait(&status);
- if (dead == pid) break;
- if (dead == -1) {
- if (errno == EINTR) continue;
- break;
- }
- for (i2 = 1; i2 < viewcnt; i2++) {
- if (dead == viewinfo[i2].pid) {
- viewinfo[i2].pid = -1;
- break;
- }
- }
- }
- #endif
- #endif
- }
- if (flags & FLAGS_IOCTL) {
- if (flags & FLAGS_TTYIN) ioctl(STDIN_FILENO, TCSETAW, &terminold);
- if ((flags & FLAGS_TTYOUT) && !(flags & FLAGS_TTYSAME)) ioctl(STDOUT_FILENO, TCSETAW, &termoutold);
- }
- if (flags & FLAGS_SIGNAL) {
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- sigaction(SIGHUP, &oldhup, NULL);
- sigaction(SIGINT, &oldint, NULL);
- sigaction(SIGPIPE, &oldpipe, NULL);
- sigaction(SIGCHLD, &oldchld, NULL);
- #if 0
- #ifdef SIGTSTP
- sigaction(SIGINT, &oldtstp, NULL);
- #endif
- #endif
- #else
- sigset(SIGHUP, oldint);
- sigset(SIGINT, oldint);
- sigset(SIGPIPE, oldpipe);
- sigset(SIGCHLD, oldchld);
- #if 0
- #ifdef SIGTSTP
- sigset(SIGTSTP, oldtstp);
- #endif
- #endif
- #endif
- }
- flags = 0;
- }
- static char **getcommand()
- {
- static char *argv[50];
- static char args[256];
- int i1, i2, i3, i4, argc;
- char *ptr;
- ptr = "\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
- write(STDOUT_FILENO, ptr, strlen(ptr));
- ptr = "Enter Command to Execute: ";
- write(STDOUT_FILENO, ptr, strlen(ptr));
- for (i2 = 0; i2 < sizeof(args) - 1; i2++) {
- if (read(STDIN_FILENO, &args[i2], 1) == 1) {
- if (args[i2] == '\n' || args[i2] == '\r') {
- write(STDOUT_FILENO, "\r\n", 2);
- break;
- }
- if (args[i2] == '\b') {
- if (i2) {
- i2--;
- write(STDOUT_FILENO, "\b \b", 3);
- }
- }
- else write(STDOUT_FILENO, &args[i2], 1);
- }
- }
- args[i2] = 0;
- argc = 0;
- for (i1 = 0; i1 < i2; i1++) {
- if (isspace(args[i1])) continue;
- if (argc == sizeof(argv) / sizeof(*argv)) break;
- argv[argc++] = &args[i1];
- for (i3 = i1, i4 = FALSE; i1 < i2 && (!isspace(args[i1]) || i4); i1++) {
- if (args[i1] == '"') {
- i4 = !i4;
- continue;
- }
- if (args[i1] == '\\' && (args[i1 + 1] == '"' || args[i1 + 1] == '\\')) i1++;
- args[i3++] = args[i1];
- }
- args[i3] = 0;
- }
- if (!argc || !argv[0][0]) return(NULL);
- argv[argc] = NULL;
- return(argv);
- }
- static int startview(argv, vilable)
- char *argv[];
- char *vilable;
- {
- int fflags; /* needed for fcntl calls */
- int refresh, ioctltype, input[2], output[2];
- char c1, tmpdbc_pstation[80], tmpdbcvol_ram[80], tmpdbc_mview[80], tmpdbc_cfg[80], homedir[80];
- pid_t pid;
- refresh = VIEW_REF;
- if (argv[0][0] == '-') {
- c1 = toupper(argv[0][1]);
- if (c1 >= '@' && c1 <= '_') refresh = (char)(c1 - '@'); /* '@' turns it off */
- argv++;
- }
- if (argv[0] == NULL) return(-1);
- checkviews();
- if (viewcnt == VIEWMAX) return(-1);
- if (!strcmp(*argv,"DBC") || !strcmp(*argv,"dbc") || !strcmp(*argv,"EDIT") || !strcmp(*argv,"edit"))
- ioctltype=IOCTL_DBC;
- else
- ioctltype=IOCTL_SHELL;
- ioctlswitch(ioctltype);
- if (pipe(input) == -1) return(-1);
- if (pipe(output) == -1) {
- close(input[0]);
- close(input[1]);
- return(-1);
- }
- if ((pid = fork()) == (pid_t) -1) { /* fork failed */
- close(input[0]);
- close(input[1]);
- close(output[0]);
- close(output[1]);
- return(-1);
- }
- if (pid == (pid_t) 0) { /* child */
- /* reset signal to default */
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- sigaction(SIGHUP, &oldhup, NULL);
- sigaction(SIGINT, &oldint, NULL);
- sigaction(SIGPIPE, &oldpipe, NULL);
- sigaction(SIGCHLD, &oldchld, NULL);
- #if 0
- #ifdef SIGTSTP
- sigaction(SIGINT, &oldtstp, NULL);
- #endif
- #endif
- #else
- sigset(SIGHUP, oldint);
- sigset(SIGINT, oldint);
- sigset(SIGPIPE, oldpipe);
- sigset(SIGCHLD, oldchld);
- #if 0
- #ifdef SIGTSTP
- sigset(SIGTSTP, oldtstp);
- #endif
- #endif
- #endif
- /* for child, input and output are reversed. */
- /* close unneeded file descriptors */
- close(input[0]);
- close(output[1]);
- /* change descriptors to become stdin and stdout */
- if (output[0] != STDIN_FILENO) {
- if (dup2(output[0], STDIN_FILENO) == -1) goto error;
- close(output[0]);
- }
- if (input[1] != STDOUT_FILENO) {
- if (dup2(input[1], STDOUT_FILENO) == -1) goto error;
- close(input[1]);
- }
- /* create a unique DBC_PSTATION, and DBCVOL_RAM variable for
- * this command */
- sprintf(tmpdbc_pstation,"DBC_PSTATION=%s_s%c",dbc_pstation,*vilable);
- sprintf(tmpdbcvol_ram,"DBCVOL_RAM=%s/mview%c",dbcvol_ram,*vilable);
- sprintf(tmpdbc_mview,"DBC_MVIEW=%c",*vilable);
- sprintf(tmpdbc_cfg,"DBC_CFG=%s/mview%c/DBCDX.CFG",dbcvol_ram,*vilable);
- putenv(tmpdbc_pstation);
- putenv(tmpdbcvol_ram);
- putenv(tmpdbc_mview);
- putenv(tmpdbc_cfg);
- /* make each command start in it's own directory if it exists */
- sprintf(homedir,"%s/mview%c",dbcvol_ram,*vilable);
- chdir(homedir);
- system("cvtenv");
- execvp(argv[0], argv);
- error:
- _exit(1);
- }
- childpid = pid;
- /* close unneeded file descriptors */
- close(input[1]);
- close(output[0]);
- /* set pipe for reading/writing to close on exec */
- fcntl(input[0], F_SETFD, FD_CLOEXEC);
- fcntl(output[1], F_SETFD, FD_CLOEXEC);
- fflags = fcntl(input[0], F_GETFL, 0);
- fcntl(input[0], F_SETFL, fflags | O_NDELAY);
- viewinfo[viewcnt].pid = pid;
- viewinfo[viewcnt].input = input[0];
- viewinfo[viewcnt].output = output[1];
- viewinfo[viewcnt].refresh = refresh;
- viewinfo[viewcnt].vilable = *vilable;
- viewinfo[viewcnt].ioctltype = ioctltype;
- pollttys[viewcnt].fd = input[0];
- pollttys[viewcnt].events = POLLIN;
- pollttys[viewcnt].revents = 0;
- viewactive = viewcnt++;
- return(0);
- }
- static void checkviews()
- {
- int i1;
- #if 0
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- sigemptyset(&newmask);
- sigaddset(&newmask, SIGPIPE);
- sigprocmask(SIG_BLOCK, &newmask, &oldmask);
- #else
- sighold(SIGPIPE);
- #endif
- #endif
- for (i1 = 1; i1 < viewcnt; i1++) {
- #ifdef P_PID
- if (sigsend(P_PID, viewinfo[i1].pid, 0) != -1 || errno != ESRCH) continue;
- #else
- if (kill(viewinfo[i1].pid, 0) != -1 || errno != ESRCH) continue;
- #endif
- close(viewinfo[i1].input);
- close(viewinfo[i1].output);
- viewcnt--;
- memmove((char *) &viewinfo[i1], (char *) &viewinfo[i1 + 1], (viewcnt - i1) * sizeof(VIEWINFO));
- memmove((char *) &pollttys[i1], (char *) &pollttys[i1 + 1], (viewcnt - i1) * sizeof(struct pollfd));
- if (i1 == viewactive) flags &= ~FLAGS_NEWVIEW;
- if (viewactive > i1){
- viewactive--;
- }
- i1--;
- }
- if (viewactive >= viewcnt) viewactive = viewcnt - 1;
- #if 0
- #ifdef SIGPOLL
- #if defined(SA_RESTART) | defined(SA_INTERRUPT) | defined(SA_RESETHAND)
- sigprocmask(SIG_SETMASK, &oldmask, NULL);
- #else
- sigrelse(SIGPOLL);
- #endif
- #endif
- #endif
- }
- static void sigevent(sig)
- int sig;
- {
- int oldcnt;
- switch (sig) {
- case SIGCHLD:
- wait(NULL);
- case SIGPIPE:
- oldcnt = viewcnt;
- checkviews();
- if (viewcnt > 1) {
- if (oldcnt != viewcnt){
- flags |= FLAGS_REFRESH;
- flags |= FLAGS_IOCTLCHG;
- flags &= ~FLAGS_NEWVIEW;
- }
- break;
- }
- case SIGHUP:
- case SIGINT:
- flags |= FLAGS_QUIT;
- break;
- }
- }
- static void flushtowrite(outfd,writeout,writeoutsize)
- int outfd;
- char * writeout;
- int * writeoutsize;
- {
- if (*writeoutsize > 0){
- write(outfd, writeout, *writeoutsize);
- *writeoutsize = 0;
- }
- }
- ioctlswitch(ioctltp)
- int ioctltp;
- {
- if (flags & FLAGS_TTYIN) {
- if (ioctltp == IOCTL_DBC) {
- ioctl(STDIN_FILENO, TCSETAW, &termindbc);
- }
- else if (ioctltp == IOCTL_SHELL) {
- ioctl(STDIN_FILENO, TCSETAW, &terminshell);
- }
- }
- if ((flags & FLAGS_TTYOUT) && !(flags & FLAGS_TTYSAME)) {
- if (ioctltp == IOCTL_DBC)
- ioctl(STDOUT_FILENO, TCSETAW, &termoutdbc);
- else if (ioctltp == IOCTL_SHELL)
- ioctl(STDOUT_FILENO, TCSETAW, &termoutshell);
- }
- flags &= ~FLAGS_IOCTLCHG;
- }
Advertisement
Add Comment
Please, Sign In to add comment