11590Srgrimes/* 21590Srgrimes * Copyright (c) 1983, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 3087710Smarkm#include <sys/cdefs.h> 3187710Smarkm 3287710Smarkm__FBSDID("$FreeBSD$"); 3387710Smarkm 341590Srgrimes#ifndef lint 3587710Smarkmstatic const char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; 3632503Scharnier#endif 371590Srgrimes 381590Srgrimes/* 391590Srgrimes * The window 'manager', initializes curses and handles the actual 401590Srgrimes * displaying of text 411590Srgrimes */ 422929Sache#include <ctype.h> 43200418Sdelphij#include <unistd.h> 441590Srgrimes 4587710Smarkm#include "talk.h" 4687710Smarkm 471590Srgrimesxwin_t my_win; 481590Srgrimesxwin_t his_win; 491590SrgrimesWINDOW *line_win; 501590Srgrimes 511590Srgrimesint curses_initialized = 0; 521590Srgrimes 531590Srgrimes/* 541590Srgrimes * max HAS to be a function, it is called with 55108533Sschweikh * an argument of the form --foo at least once. 561590Srgrimes */ 5714443Sjoergint 58178642Sdelphijmax(int a, int b) 591590Srgrimes{ 601590Srgrimes 611590Srgrimes return (a > b ? a : b); 621590Srgrimes} 631590Srgrimes 641590Srgrimes/* 651590Srgrimes * Display some text on somebody's window, processing some control 661590Srgrimes * characters while we are at it. 671590Srgrimes */ 6814443Sjoergvoid 69178642Sdelphijdisplay(xwin_t *win, char *text, int size) 701590Srgrimes{ 7187710Smarkm int i; 721590Srgrimes char cch; 731590Srgrimes 741590Srgrimes for (i = 0; i < size; i++) { 752929Sache if (*text == '\n' || *text == '\r') { 762929Sache waddch(win->x_win, '\n'); 772929Sache getyx(win->x_win, win->x_line, win->x_col); 781590Srgrimes text++; 791590Srgrimes continue; 801590Srgrimes } 8199965Sluigi if (*text == 004 && win == &my_win) { 8299965Sluigi /* control-D clears the screen */ 8399965Sluigi werase(my_win.x_win); 8499965Sluigi getyx(my_win.x_win, my_win.x_line, my_win.x_col); 8599965Sluigi wrefresh(my_win.x_win); 8699965Sluigi werase(his_win.x_win); 8799965Sluigi getyx(his_win.x_win, his_win.x_line, his_win.x_col); 8899965Sluigi wrefresh(his_win.x_win); 8999965Sluigi text++; 9099965Sluigi continue; 9199965Sluigi } 92117238Sluigi 931590Srgrimes /* erase character */ 942929Sache if ( *text == win->cerase 952929Sache || *text == 010 /* BS */ 962929Sache || *text == 0177 /* DEL */ 972929Sache ) { 981590Srgrimes wmove(win->x_win, win->x_line, max(--win->x_col, 0)); 991590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1001590Srgrimes waddch(win->x_win, ' '); 1011590Srgrimes wmove(win->x_win, win->x_line, win->x_col); 1021590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1031590Srgrimes text++; 1041590Srgrimes continue; 1051590Srgrimes } 1061590Srgrimes /* 1071590Srgrimes * On word erase search backwards until we find 1081590Srgrimes * the beginning of a word or the beginning of 1091590Srgrimes * the line. 1101590Srgrimes */ 1112929Sache if ( *text == win->werase 1122929Sache || *text == 027 /* ^W */ 1132929Sache ) { 11487710Smarkm int endcol, xcol, ii, c; 1151590Srgrimes 1161590Srgrimes endcol = win->x_col; 1171590Srgrimes xcol = endcol - 1; 1181590Srgrimes while (xcol >= 0) { 1191590Srgrimes c = readwin(win->x_win, win->x_line, xcol); 1201590Srgrimes if (c != ' ') 1211590Srgrimes break; 1221590Srgrimes xcol--; 1231590Srgrimes } 1241590Srgrimes while (xcol >= 0) { 1251590Srgrimes c = readwin(win->x_win, win->x_line, xcol); 1261590Srgrimes if (c == ' ') 1271590Srgrimes break; 1281590Srgrimes xcol--; 1291590Srgrimes } 1301590Srgrimes wmove(win->x_win, win->x_line, xcol + 1); 13187710Smarkm for (ii = xcol + 1; ii < endcol; ii++) 1321590Srgrimes waddch(win->x_win, ' '); 1331590Srgrimes wmove(win->x_win, win->x_line, xcol + 1); 1341590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1351590Srgrimes text++; 1361590Srgrimes continue; 1371590Srgrimes } 1381590Srgrimes /* line kill */ 1392929Sache if ( *text == win->kill 1402929Sache || *text == 025 /* ^U */ 1412929Sache ) { 1421590Srgrimes wmove(win->x_win, win->x_line, 0); 1431590Srgrimes wclrtoeol(win->x_win); 1441590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1451590Srgrimes text++; 1461590Srgrimes continue; 1471590Srgrimes } 1481590Srgrimes if (*text == '\f') { 1491590Srgrimes if (win == &my_win) 1501590Srgrimes wrefresh(curscr); 1511590Srgrimes text++; 1521590Srgrimes continue; 1531590Srgrimes } 1542929Sache if (*text == '\7') { 15517676Speter write(STDOUT_FILENO, text, 1); 1562929Sache text++; 1572929Sache continue; 1581590Srgrimes } 15915022Sache if (!isprint((unsigned char)*text) && *text != '\t') { 1601590Srgrimes waddch(win->x_win, '^'); 1611590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1621590Srgrimes cch = (*text & 63) + 64; 1631590Srgrimes waddch(win->x_win, cch); 1641590Srgrimes } else 16515022Sache waddch(win->x_win, (unsigned char)*text); 1661590Srgrimes getyx(win->x_win, win->x_line, win->x_col); 1671590Srgrimes text++; 1681590Srgrimes } 1691590Srgrimes wrefresh(win->x_win); 1701590Srgrimes} 1711590Srgrimes 1721590Srgrimes/* 1731590Srgrimes * Read the character at the indicated position in win 1741590Srgrimes */ 17514443Sjoergint 176178642Sdelphijreadwin(WINDOW *win, int line, int col) 1771590Srgrimes{ 1781590Srgrimes int oldline, oldcol; 17987710Smarkm int c; 1801590Srgrimes 1811590Srgrimes getyx(win, oldline, oldcol); 1821590Srgrimes wmove(win, line, col); 1831590Srgrimes c = winch(win); 1841590Srgrimes wmove(win, oldline, oldcol); 1851590Srgrimes return (c); 1861590Srgrimes} 187