[BACK]Return to init_disp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / talk

Annotation of src/usr.bin/talk/init_disp.c, Revision 1.2

1.1       deraadt     1: /*     $NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $        */
                      2:
                      3: /*
                      4:  * Copyright (c) 1983, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Berkeley and its contributors.
                     19:  * 4. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
                     36: #ifndef lint
                     37: #if 0
                     38: static char sccsid[] = "@(#)init_disp.c        8.2 (Berkeley) 2/16/94";
                     39: #endif
                     40: static char rcsid[] = "$NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $";
                     41: #endif /* not lint */
                     42:
                     43: /*
                     44:  * Initialization code for the display package,
                     45:  * as well as the signal handling routines.
                     46:  */
                     47:
                     48: #include <sys/ioctl.h>
                     49: #include <sys/ioctl_compat.h>
                     50:
                     51: #include <termios.h>
                     52: #include <signal.h>
                     53: #include <err.h>
                     54: #include "talk.h"
                     55:
                     56: /*
                     57:  * Set up curses, catch the appropriate signals,
                     58:  * and build the various windows.
                     59:  */
                     60: init_display()
                     61: {
                     62:        void sig_sent();
                     63:        struct sigvec sigv;
                     64:
                     65:        if (initscr() == NULL)
                     66:                errx(1, "Terminal type unset or lacking necessary features.");
                     67:        (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
                     68:        sigv.sv_mask |= sigmask(SIGALRM);
                     69:        (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
                     70:        curses_initialized = 1;
                     71:        clear();
                     72:        refresh();
                     73:        noecho();
                     74:        crmode();
                     75:        signal(SIGINT, sig_sent);
                     76:        signal(SIGPIPE, sig_sent);
                     77:        /* curses takes care of ^Z */
                     78:        my_win.x_nlines = LINES / 2;
                     79:        my_win.x_ncols = COLS;
                     80:        my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
                     81:        scrollok(my_win.x_win, FALSE);
                     82:        wclear(my_win.x_win);
                     83:
                     84:        his_win.x_nlines = LINES / 2 - 1;
                     85:        his_win.x_ncols = COLS;
                     86:        his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
                     87:            my_win.x_nlines+1, 0);
                     88:        scrollok(his_win.x_win, FALSE);
                     89:        wclear(his_win.x_win);
                     90:
                     91:        line_win = newwin(1, COLS, my_win.x_nlines, 0);
1.2     ! tholo      92: #ifdef NCURSES_VERSION
        !            93:        whline(line_win, '-', COLS);
        !            94: #else
1.1       deraadt    95:        box(line_win, '-', '-');
1.2     ! tholo      96: #endif
1.1       deraadt    97:        wrefresh(line_win);
                     98:        /* let them know we are working on it */
                     99:        current_state = "No connection yet";
                    100: }
                    101:
                    102: /*
                    103:  * Trade edit characters with the other talk. By agreement
                    104:  * the first three characters each talk transmits after
                    105:  * connection are the three edit characters.
                    106:  */
                    107: set_edit_chars()
                    108: {
                    109:        char buf[3];
                    110:        int cc;
                    111:        struct termios tty;
                    112:
                    113:        tcgetattr(0, &tty);
                    114:        my_win.cerase = tty.c_cc[VERASE];
                    115:        my_win.kill = tty.c_cc[VKILL];
                    116:        if (tty.c_cc[VWERASE] == (unsigned char) -1)
                    117:                my_win.werase = '\027';  /* control W */
                    118:        else
                    119:                my_win.werase = tty.c_cc[VWERASE];
                    120:        buf[0] = my_win.cerase;
                    121:        buf[1] = my_win.kill;
                    122:        buf[2] = my_win.werase;
                    123:        cc = write(sockt, buf, sizeof(buf));
                    124:        if (cc != sizeof(buf) )
                    125:                p_error("Lost the connection");
                    126:        cc = read(sockt, buf, sizeof(buf));
                    127:        if (cc != sizeof(buf) )
                    128:                p_error("Lost the connection");
                    129:        his_win.cerase = buf[0];
                    130:        his_win.kill = buf[1];
                    131:        his_win.werase = buf[2];
                    132: }
                    133:
                    134: void
                    135: sig_sent()
                    136: {
                    137:
                    138:        message("Connection closing. Exiting");
                    139:        quit();
                    140: }
                    141:
                    142: /*
                    143:  * All done talking...hang up the phone and reset terminal thingy's
                    144:  */
                    145: quit()
                    146: {
                    147:
                    148:        if (curses_initialized) {
                    149:                wmove(his_win.x_win, his_win.x_nlines-1, 0);
                    150:                wclrtoeol(his_win.x_win);
                    151:                wrefresh(his_win.x_win);
                    152:                endwin();
                    153:        }
                    154:        if (invitation_waiting)
                    155:                send_delete();
                    156:        exit(0);
                    157: }