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