Annotation of 43BSDReno/usr.bin/talk/init_disp.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)init_disp.c        5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: /*
        !            25:  * Initialization code for the display package,
        !            26:  * as well as the signal handling routines.
        !            27:  */
        !            28: 
        !            29: #include "talk.h"
        !            30: #include <signal.h>
        !            31: 
        !            32: /* 
        !            33:  * Set up curses, catch the appropriate signals,
        !            34:  * and build the various windows.
        !            35:  */
        !            36: init_display()
        !            37: {
        !            38:        void sig_sent();
        !            39:        struct sigvec sigv;
        !            40: 
        !            41:        initscr();
        !            42:        (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
        !            43:        sigv.sv_mask |= sigmask(SIGALRM);
        !            44:        (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
        !            45:        curses_initialized = 1;
        !            46:        clear();
        !            47:        refresh();
        !            48:        noecho();
        !            49:        crmode();
        !            50:        signal(SIGINT, sig_sent);
        !            51:        signal(SIGPIPE, sig_sent);
        !            52:        /* curses takes care of ^Z */
        !            53:        my_win.x_nlines = LINES / 2;
        !            54:        my_win.x_ncols = COLS;
        !            55:        my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
        !            56:        scrollok(my_win.x_win, FALSE);
        !            57:        wclear(my_win.x_win);
        !            58: 
        !            59:        his_win.x_nlines = LINES / 2 - 1;
        !            60:        his_win.x_ncols = COLS;
        !            61:        his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
        !            62:            my_win.x_nlines+1, 0);
        !            63:        scrollok(his_win.x_win, FALSE);
        !            64:        wclear(his_win.x_win);
        !            65: 
        !            66:        line_win = newwin(1, COLS, my_win.x_nlines, 0);
        !            67:        box(line_win, '-', '-');
        !            68:        wrefresh(line_win);
        !            69:        /* let them know we are working on it */
        !            70:        current_state = "No connection yet";
        !            71: }
        !            72: 
        !            73: /*
        !            74:  * Trade edit characters with the other talk. By agreement
        !            75:  * the first three characters each talk transmits after
        !            76:  * connection are the three edit characters.
        !            77:  */
        !            78: set_edit_chars()
        !            79: {
        !            80:        char buf[3];
        !            81:        int cc;
        !            82:        struct sgttyb tty;
        !            83:        struct ltchars ltc;
        !            84:        
        !            85:        ioctl(0, TIOCGETP, &tty);
        !            86:        ioctl(0, TIOCGLTC, (struct sgttyb *)&ltc);
        !            87:        my_win.cerase = tty.sg_erase;
        !            88:        my_win.kill = tty.sg_kill;
        !            89:        if (ltc.t_werasc == (char) -1)
        !            90:                my_win.werase = '\027';  /* control W */
        !            91:        else
        !            92:                my_win.werase = ltc.t_werasc;
        !            93:        buf[0] = my_win.cerase;
        !            94:        buf[1] = my_win.kill;
        !            95:        buf[2] = my_win.werase;
        !            96:        cc = write(sockt, buf, sizeof(buf));
        !            97:        if (cc != sizeof(buf) )
        !            98:                p_error("Lost the connection");
        !            99:        cc = read(sockt, buf, sizeof(buf));
        !           100:        if (cc != sizeof(buf) )
        !           101:                p_error("Lost the connection");
        !           102:        his_win.cerase = buf[0];
        !           103:        his_win.kill = buf[1];
        !           104:        his_win.werase = buf[2];
        !           105: }
        !           106: 
        !           107: void
        !           108: sig_sent()
        !           109: {
        !           110: 
        !           111:        message("Connection closing. Exiting");
        !           112:        quit();
        !           113: }
        !           114: 
        !           115: /*
        !           116:  * All done talking...hang up the phone and reset terminal thingy's
        !           117:  */
        !           118: quit()
        !           119: {
        !           120: 
        !           121:        if (curses_initialized) {
        !           122:                wmove(his_win.x_win, his_win.x_nlines-1, 0);
        !           123:                wclrtoeol(his_win.x_win);
        !           124:                wrefresh(his_win.x_win);
        !           125:                endwin();
        !           126:        }
        !           127:        if (invitation_waiting)
        !           128:                send_delete();
        !           129:        exit(0);
        !           130: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.