home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-B.05 / NETKIT-B / NetKit-B-0.05 / talk / init_disp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  4.4 KB  |  152 lines

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