Commit | Line | Data |
---|---|---|
8b28dacd KA |
1 | # include "curses.ext" |
2 | ||
3 | /* | |
4 | * This routine adds the character to the current position | |
5 | * | |
6 | * %G% (Berkeley) @(#)addch.c 1.1 | |
7 | */ | |
8 | waddch(win, c) | |
9 | reg WINDOW *win; | |
10 | char c; | |
11 | { | |
12 | reg int x, y; | |
13 | ||
14 | x = win->_curx; | |
15 | y = win->_cury; | |
16 | # ifdef FULLDEBUG | |
17 | fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x); | |
18 | # endif | |
19 | if (y >= win->_maxy || x >= win->_maxx || y < 0 || x < 0) | |
20 | return ERR; | |
21 | switch (c) { | |
22 | case '\t': | |
23 | { | |
24 | reg int newx; | |
25 | ||
26 | --x; | |
27 | for (newx = x + (8 - (x & 07)) + 1; x <= newx; x++) | |
28 | if (waddch(win, ' ') == ERR) | |
29 | return ERR; | |
30 | return OK; | |
31 | } | |
32 | default: | |
33 | # ifdef FULLDEBUG | |
34 | fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); | |
35 | # endif | |
36 | if (win->_flags & _STANDOUT) | |
37 | c |= _STANDOUT; | |
38 | if (win->_y[y][x] != c) { | |
39 | if (win->_firstch[y] == _NOCHANGE) | |
40 | win->_firstch[y] = win->_lastch[y] = x; | |
41 | else if (x < win->_firstch[y]) | |
42 | win->_firstch[y] = x; | |
43 | else if (x > win->_lastch[y]) | |
44 | win->_lastch[y] = x; | |
45 | } | |
46 | win->_y[y][x++] = c; | |
47 | if (x >= win->_maxx) { | |
48 | newline: | |
49 | x = 0; | |
50 | nonewline: | |
51 | if (++y + 1 == win->_maxy) | |
52 | if (win->_scroll) { | |
53 | wrefresh(win); | |
54 | scroll(win); | |
55 | --y; | |
56 | } | |
57 | else | |
58 | return ERR; | |
59 | } | |
60 | # ifdef FULLDEBUG | |
61 | fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); | |
62 | # endif | |
63 | break; | |
64 | case '\n': | |
65 | wclrtoeol(win); | |
66 | if (NONL) | |
67 | goto nonewline; | |
68 | else | |
69 | goto newline; | |
70 | case '\r': | |
71 | x = 0; | |
72 | break; | |
73 | case '\b': | |
74 | if (--x < 0) | |
75 | x = 0; | |
76 | break; | |
77 | } | |
78 | win->_curx = x; | |
79 | win->_cury = y; | |
80 | return OK; | |
81 | } |