|
|
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 the above copyright notice and this paragraph are ! 7: * duplicated in all such forms and that any documentation, ! 8: * advertising materials, and other materials related to such ! 9: * distribution and use acknowledge that the software was developed ! 10: * by the University of California, Berkeley. The name of the ! 11: * University may not be used to endorse or promote products derived ! 12: * from this software without specific prior written permission. ! 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 16: */ ! 17: ! 18: #ifndef lint ! 19: static char sccsid[] = "@(#)display.c 5.3 (Berkeley) 6/29/88"; ! 20: #endif /* not lint */ ! 21: ! 22: /* ! 23: * The window 'manager', initializes curses and handles the actual ! 24: * displaying of text ! 25: */ ! 26: #include "talk.h" ! 27: ! 28: xwin_t my_win; ! 29: xwin_t his_win; ! 30: WINDOW *line_win; ! 31: ! 32: int curses_initialized = 0; ! 33: ! 34: /* ! 35: * max HAS to be a function, it is called with ! 36: * a argument of the form --foo at least once. ! 37: */ ! 38: max(a,b) ! 39: int a, b; ! 40: { ! 41: ! 42: return (a > b ? a : b); ! 43: } ! 44: ! 45: /* ! 46: * Display some text on somebody's window, processing some control ! 47: * characters while we are at it. ! 48: */ ! 49: display(win, text, size) ! 50: register xwin_t *win; ! 51: register char *text; ! 52: int size; ! 53: { ! 54: register int i; ! 55: char cch; ! 56: ! 57: for (i = 0; i < size; i++) { ! 58: if (*text == '\n') { ! 59: xscroll(win, 0); ! 60: text++; ! 61: continue; ! 62: } ! 63: /* erase character */ ! 64: if (*text == win->cerase) { ! 65: wmove(win->x_win, win->x_line, max(--win->x_col, 0)); ! 66: getyx(win->x_win, win->x_line, win->x_col); ! 67: waddch(win->x_win, ' '); ! 68: wmove(win->x_win, win->x_line, win->x_col); ! 69: getyx(win->x_win, win->x_line, win->x_col); ! 70: text++; ! 71: continue; ! 72: } ! 73: /* ! 74: * On word erase search backwards until we find ! 75: * the beginning of a word or the beginning of ! 76: * the line. ! 77: */ ! 78: if (*text == win->werase) { ! 79: int endcol, xcol, i, c; ! 80: ! 81: endcol = win->x_col; ! 82: xcol = endcol - 1; ! 83: while (xcol >= 0) { ! 84: c = readwin(win->x_win, win->x_line, xcol); ! 85: if (c != ' ') ! 86: break; ! 87: xcol--; ! 88: } ! 89: while (xcol >= 0) { ! 90: c = readwin(win->x_win, win->x_line, xcol); ! 91: if (c == ' ') ! 92: break; ! 93: xcol--; ! 94: } ! 95: wmove(win->x_win, win->x_line, xcol + 1); ! 96: for (i = xcol + 1; i < endcol; i++) ! 97: waddch(win->x_win, ' '); ! 98: wmove(win->x_win, win->x_line, xcol + 1); ! 99: getyx(win->x_win, win->x_line, win->x_col); ! 100: continue; ! 101: } ! 102: /* line kill */ ! 103: if (*text == win->kill) { ! 104: wmove(win->x_win, win->x_line, 0); ! 105: wclrtoeol(win->x_win); ! 106: getyx(win->x_win, win->x_line, win->x_col); ! 107: text++; ! 108: continue; ! 109: } ! 110: if (*text == '\f') { ! 111: if (win == &my_win) ! 112: wrefresh(curscr); ! 113: text++; ! 114: continue; ! 115: } ! 116: if (win->x_col == COLS-1) { ! 117: /* check for wraparound */ ! 118: xscroll(win, 0); ! 119: } ! 120: if (*text < ' ' && *text != '\t') { ! 121: waddch(win->x_win, '^'); ! 122: getyx(win->x_win, win->x_line, win->x_col); ! 123: if (win->x_col == COLS-1) /* check for wraparound */ ! 124: xscroll(win, 0); ! 125: cch = (*text & 63) + 64; ! 126: waddch(win->x_win, cch); ! 127: } else ! 128: waddch(win->x_win, *text); ! 129: getyx(win->x_win, win->x_line, win->x_col); ! 130: text++; ! 131: } ! 132: wrefresh(win->x_win); ! 133: } ! 134: ! 135: /* ! 136: * Read the character at the indicated position in win ! 137: */ ! 138: readwin(win, line, col) ! 139: WINDOW *win; ! 140: { ! 141: int oldline, oldcol; ! 142: register int c; ! 143: ! 144: getyx(win, oldline, oldcol); ! 145: wmove(win, line, col); ! 146: c = winch(win); ! 147: wmove(win, oldline, oldcol); ! 148: return (c); ! 149: } ! 150: ! 151: /* ! 152: * Scroll a window, blanking out the line following the current line ! 153: * so that the current position is obvious ! 154: */ ! 155: xscroll(win, flag) ! 156: register xwin_t *win; ! 157: int flag; ! 158: { ! 159: ! 160: if (flag == -1) { ! 161: wmove(win->x_win, 0, 0); ! 162: win->x_line = 0; ! 163: win->x_col = 0; ! 164: return; ! 165: } ! 166: win->x_line = (win->x_line + 1) % win->x_nlines; ! 167: win->x_col = 0; ! 168: wmove(win->x_win, win->x_line, win->x_col); ! 169: wclrtoeol(win->x_win); ! 170: wmove(win->x_win, (win->x_line + 1) % win->x_nlines, win->x_col); ! 171: wclrtoeol(win->x_win); ! 172: wmove(win->x_win, win->x_line, win->x_col); ! 173: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.