Annotation of 42BSD/ucb/talk/init_disp.c, revision 1.1

1.1     ! root        1: /* $Header: init_disp.c 1.2 83/06/23 02:01:11 moore 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:  * set up curses, catch the appropriate signals, and build the
        !            13:  * various windows
        !            14:  */
        !            15: 
        !            16: init_display()
        !            17: {
        !            18:     void sig_sent();
        !            19: 
        !            20:     initscr();
        !            21:     curses_initialized = 1;
        !            22: 
        !            23:     clear();
        !            24:     refresh();
        !            25: 
        !            26:     noecho();
        !            27:     crmode();
        !            28: 
        !            29:     signal(SIGINT, sig_sent);
        !            30:     signal(SIGPIPE, sig_sent);
        !            31: 
        !            32:        /* curses takes care of ^Z */
        !            33: 
        !            34:     my_win.x_nlines = LINES / 2;
        !            35:     my_win.x_ncols = COLS;
        !            36:     my_win.x_win = newwin(my_win.x_nlines, my_win.x_ncols, 0, 0);
        !            37:     scrollok(my_win.x_win, FALSE);
        !            38:     wclear(my_win.x_win);
        !            39: 
        !            40:     his_win.x_nlines = LINES / 2 - 1;
        !            41:     his_win.x_ncols = COLS;
        !            42:     his_win.x_win = newwin(his_win.x_nlines, his_win.x_ncols,
        !            43:                                             my_win.x_nlines+1, 0);
        !            44:     scrollok(his_win.x_win, FALSE);
        !            45:     wclear(his_win.x_win);
        !            46: 
        !            47:     line_win = newwin(1, COLS, my_win.x_nlines, 0);
        !            48:     box(line_win, '-', '-');
        !            49:     wrefresh(line_win);
        !            50: 
        !            51:        /* let them know we are working on it */
        !            52: 
        !            53:     current_state = "No connection yet";
        !            54: }
        !            55: 
        !            56:     /* trade edit characters with the other talk. By agreement
        !            57:      * the first three characters each talk transmits after
        !            58:      * connection are the three edit characters
        !            59:      */
        !            60: 
        !            61: set_edit_chars()
        !            62: {
        !            63:     char buf[3];
        !            64:     int cc;
        !            65:     struct sgttyb tty;
        !            66:     struct ltchars ltc;
        !            67:     
        !            68:     gtty(0, &tty);
        !            69: 
        !            70:     ioctl(0, TIOCGLTC, (struct sgttyb *) &ltc);
        !            71:        
        !            72:     my_win.cerase = tty.sg_erase;
        !            73:     my_win.kill = tty.sg_kill;
        !            74: 
        !            75:     if (ltc.t_werasc == (char) -1) {
        !            76:        my_win.werase = '\027';  /* control W */
        !            77:     } else {
        !            78:        my_win.werase = ltc.t_werasc;
        !            79:     }
        !            80: 
        !            81:     buf[0] = my_win.cerase;
        !            82:     buf[1] = my_win.kill;
        !            83:     buf[2] = my_win.werase;
        !            84: 
        !            85:     cc = write(sockt, buf, sizeof(buf));
        !            86: 
        !            87:     if (cc != sizeof(buf) ) {
        !            88:        p_error("Lost the connection");
        !            89:     }
        !            90: 
        !            91:     cc = read(sockt, buf, sizeof(buf));
        !            92: 
        !            93:     if (cc != sizeof(buf) ) {
        !            94:        p_error("Lost the connection");
        !            95:     }
        !            96: 
        !            97:     his_win.cerase = buf[0];
        !            98:     his_win.kill = buf[1];
        !            99:     his_win.werase = buf[2];
        !           100: }
        !           101: 
        !           102: void sig_sent()
        !           103: {
        !           104:     message("Connection closing. Exiting");
        !           105:     quit();
        !           106: }
        !           107: 
        !           108: /*
        !           109:  * All done talking...hang up the phone and reset terminal thingy's
        !           110:  */
        !           111: 
        !           112: quit()
        !           113: {
        !           114:        if (curses_initialized) {
        !           115:            wmove(his_win.x_win, his_win.x_nlines-1, 0);
        !           116:            wclrtoeol(his_win.x_win);
        !           117:            wrefresh(his_win.x_win);
        !           118:            endwin();
        !           119:        }
        !           120: 
        !           121:        if (invitation_waiting) {
        !           122:            send_delete();
        !           123:        }
        !           124: 
        !           125:        exit(0);
        !           126: }

unix.superglobalmegacorp.com

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