|
|
1.1 ! root 1: /* $Header: init_disp.c,v 1.2 85/01/09 13:04:54 rcs Exp $ */ ! 2: ! 3: /* ! 4: * init_disp contains the initialization code for the display package, ! 5: * as well as the signal handling routines ! 6: */ ! 7: ! 8: #include "talk.h" ! 9: #include <signal.h> ! 10: ! 11: /* ! 12: * Changes: ! 13: * . add function to verify that the terminal is cursor addressable. ! 14: * . add function to handle QUIT signal. ! 15: * ! 16: */ ! 17: /* ! 18: * set up curses, catch the appropriate signals, and build the ! 19: * various windows ! 20: */ ! 21: ! 22: init_display() ! 23: { ! 24: void sig_sent(); ! 25: ! 26: checkcrt(); /* check if terminal is cursor addressable */ ! 27: initscr(); ! 28: curses_initialized = 1; ! 29: ! 30: clear(); ! 31: refresh(); ! 32: ! 33: noecho(); ! 34: crmode(); ! 35: ! 36: signal(SIGINT, sig_sent); ! 37: signal(SIGQUIT, sig_sent); ! 38: signal(SIGPIPE, sig_sent); ! 39: ! 40: /* curses takes care of ^Z */ ! 41: ! 42: my_win.x_nlines = LINES / 2; ! 43: my_win.x_ncols = COLS; ! 44: my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0); ! 45: scrollok(my_win.x_win, FALSE); ! 46: wclear(my_win.x_win); ! 47: ! 48: his_win.x_nlines = LINES / 2 - 1; ! 49: his_win.x_ncols = COLS; ! 50: his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols, ! 51: my_win.x_nlines+1, 0); ! 52: scrollok(his_win.x_win, FALSE); ! 53: wclear(his_win.x_win); ! 54: ! 55: line_win = newwin(1, COLS, my_win.x_nlines, 0); ! 56: box(line_win, '-', '-'); ! 57: wrefresh(line_win); ! 58: ! 59: /* let them know we are working on it */ ! 60: ! 61: current_state = "No connection yet"; ! 62: } ! 63: ! 64: /* trade edit characters with the other talk. By agreement ! 65: * the first three characters each talk transmits after ! 66: * connection are the three edit characters ! 67: */ ! 68: ! 69: set_edit_chars() ! 70: { ! 71: char buf[3]; ! 72: int cc; ! 73: struct sgttyb tty; ! 74: struct ltchars ltc; ! 75: ! 76: gtty(0, &tty); ! 77: ! 78: ioctl(0, TIOCGLTC, (struct sgttyb *) <c); ! 79: ! 80: my_win.cerase = tty.sg_erase; ! 81: my_win.kill = tty.sg_kill; ! 82: ! 83: if (ltc.t_werasc == (char) -1) { ! 84: my_win.werase = '\027'; /* control W */ ! 85: } else { ! 86: my_win.werase = ltc.t_werasc; ! 87: } ! 88: ! 89: buf[0] = my_win.cerase; ! 90: buf[1] = my_win.kill; ! 91: buf[2] = my_win.werase; ! 92: ! 93: cc = write(sockt, buf, sizeof(buf)); ! 94: ! 95: if (cc != sizeof(buf) ) { ! 96: p_error("Lost the connection"); ! 97: } ! 98: ! 99: cc = read(sockt, buf, sizeof(buf)); ! 100: ! 101: if (cc != sizeof(buf) ) { ! 102: p_error("Lost the connection"); ! 103: } ! 104: ! 105: his_win.cerase = buf[0]; ! 106: his_win.kill = buf[1]; ! 107: his_win.werase = buf[2]; ! 108: } ! 109: ! 110: void sig_sent() ! 111: { ! 112: message("Connection closing. Exiting"); ! 113: quit(); ! 114: } ! 115: ! 116: /* ! 117: * All done talking...hang up the phone and reset terminal thingy's ! 118: */ ! 119: ! 120: quit() ! 121: { ! 122: if (curses_initialized) { ! 123: wmove(his_win.x_win, his_win.x_nlines-1, 0); ! 124: wclrtoeol(his_win.x_win); ! 125: wrefresh(his_win.x_win); ! 126: endwin(); ! 127: } ! 128: ! 129: if (invitation_waiting) { ! 130: send_delete(); ! 131: } ! 132: ! 133: exit(0); ! 134: } ! 135: /*------------------------------------------------------------ ! 136: checkcrt ! 137: verify if the terminal is cursor addressable ! 138: ----------------------------------------------------------*/ ! 139: char *CM; ! 140: char *getenv(); ! 141: char *tgetstr(); ! 142: checkcrt(){ ! 143: char *termname; ! 144: char *x; ! 145: char *y; ! 146: char cm[1024]; ! 147: char buf[1024]; ! 148: ! 149: if ((termname = getenv("TERM")) == (char *)0) { ! 150: printf("talk:terminal type not defined.\n"); ! 151: exit(2); ! 152: } ! 153: switch (tgetent(buf, termname)) { ! 154: case -1: ! 155: printf("talk:cannot open termcap file.\n"); ! 156: exit(3); ! 157: case 0: ! 158: printf("talk:terminal type not defined in termcap file.\n"); ! 159: exit(4); ! 160: } ! 161: ! 162: x = cm; ! 163: CM = tgetstr("cm",&x); ! 164: if (!CM || *CM==0) { ! 165: printf("talk: terminal must have addressable cursor.\n"); ! 166: exit(5); ! 167: } ! 168: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.