1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)display.c	5.1 (Berkeley) 6/6/85";
   9: #endif not lint
  10: 
  11: /*
  12:  * The window 'manager', initializes curses and handles the actual
  13:  * displaying of text
  14:  */
  15: #include "talk.h"
  16: 
  17: xwin_t  my_win;
  18: xwin_t  his_win;
  19: WINDOW  *line_win;
  20: 
  21: int curses_initialized = 0;
  22: 
  23: /*
  24:  * max HAS to be a function, it is called with
  25:  * a argument of the form --foo at least once.
  26:  */
  27: max(a,b)
  28:     int a, b;
  29: {
  30: 
  31:     return (a > b ? a : b);
  32: }
  33: 
  34: /*
  35:  * Display some text on somebody's window, processing some control
  36:  * characters while we are at it.
  37:  */
  38: display(win, text, size)
  39:     register xwin_t *win;
  40:     register char *text;
  41:     int size;
  42: {
  43:     register int i;
  44:     char cch;
  45: 
  46:     for (i = 0; i < size; i++) {
  47:         if (*text == '\n') {
  48:             xscroll(win, 0);
  49:             text++;
  50:             continue;
  51:         }
  52:         /* erase character */
  53:         if (*text == win->cerase) {
  54:             wmove(win->x_win, win->x_line, max(--win->x_col, 0));
  55:             getyx(win->x_win, win->x_line, win->x_col);
  56:             waddch(win->x_win, ' ');
  57:             wmove(win->x_win, win->x_line, win->x_col);
  58:             getyx(win->x_win, win->x_line, win->x_col);
  59:             text++;
  60:             continue;
  61:         }
  62:         /*
  63: 		 * On word erase search backwards until we find
  64: 		 * the beginning of a word or the beginning of
  65: 		 * the line.
  66: 		 */
  67:         if (*text == win->werase) {
  68:             int endcol, xcol, i, c;
  69: 
  70:             endcol = win->x_col;
  71:             xcol = endcol - 1;
  72:             while (xcol >= 0) {
  73:                 c = readwin(win->x_win, win->x_line, xcol);
  74:                 if (c != ' ')
  75:                     break;
  76:                 xcol--;
  77:             }
  78:             while (xcol >= 0) {
  79:                 c = readwin(win->x_win, win->x_line, xcol);
  80:                 if (c == ' ')
  81:                     break;
  82:                 xcol--;
  83:             }
  84:             wmove(win->x_win, win->x_line, xcol + 1);
  85:             for (i = xcol + 1; i < endcol; i++)
  86:                 waddch(win->x_win, ' ');
  87:             wmove(win->x_win, win->x_line, xcol + 1);
  88:             getyx(win->x_win, win->x_line, win->x_col);
  89:             continue;
  90:         }
  91:         /* line kill */
  92:         if (*text == win->kill) {
  93:             wmove(win->x_win, win->x_line, 0);
  94:             wclrtoeol(win->x_win);
  95:             getyx(win->x_win, win->x_line, win->x_col);
  96:             text++;
  97:             continue;
  98:         }
  99:         if (*text == '\f') {
 100:             if (win == &my_win)
 101:                 wrefresh(curscr);
 102:             text++;
 103:             continue;
 104:         }
 105:         if (win->x_col == COLS-1) {
 106:             /* check for wraparound */
 107:             xscroll(win, 0);
 108:         }
 109:         if (*text < ' ' && *text != '\t') {
 110:             waddch(win->x_win, '^');
 111:             getyx(win->x_win, win->x_line, win->x_col);
 112:             if (win->x_col == COLS-1) /* check for wraparound */
 113:                 xscroll(win, 0);
 114:             cch = (*text & 63) + 64;
 115:             waddch(win->x_win, cch);
 116:         } else
 117:             waddch(win->x_win, *text);
 118:         getyx(win->x_win, win->x_line, win->x_col);
 119:         text++;
 120:     }
 121:     wrefresh(win->x_win);
 122: }
 123: 
 124: /*
 125:  * Read the character at the indicated position in win
 126:  */
 127: readwin(win, line, col)
 128:     WINDOW *win;
 129: {
 130:     int oldline, oldcol;
 131:     register int c;
 132: 
 133:     getyx(win, oldline, oldcol);
 134:     wmove(win, line, col);
 135:     c = winch(win);
 136:     wmove(win, oldline, oldcol);
 137:     return (c);
 138: }
 139: 
 140: /*
 141:  * Scroll a window, blanking out the line following the current line
 142:  * so that the current position is obvious
 143:  */
 144: xscroll(win, flag)
 145:     register xwin_t *win;
 146:     int flag;
 147: {
 148: 
 149:     if (flag == -1) {
 150:         wmove(win->x_win, 0, 0);
 151:         win->x_line = 0;
 152:         win->x_col = 0;
 153:         return;
 154:     }
 155:     win->x_line = (win->x_line + 1) % win->x_nlines;
 156:     win->x_col = 0;
 157:     wmove(win->x_win, win->x_line, win->x_col);
 158:     wclrtoeol(win->x_win);
 159:     wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col);
 160:     wclrtoeol(win->x_win);
 161:     wmove(win->x_win, win->x_line, win->x_col);
 162: }

Defined functions

display defined in line 38; used 2 times
max defined in line 27; used 1 times
  • in line 54
readwin defined in line 127; used 2 times
xscroll defined in line 144; used 3 times

Defined variables

curses_initialized defined in line 21; never used
his_win defined in line 18; never used
my_win defined in line 17; used 1 times
sccsid defined in line 8; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1078
Valid CSS Valid XHTML 1.0 Strict