Commit | Line | Data |
---|---|---|
6e1c93d0 DF |
1 | /* |
2 | * Copyright (c) 1980 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[] = "@(#)addch.c 5.1 (Berkeley) %G%"; | |
9 | #endif not lint | |
10 | ||
8b28dacd KA |
11 | # include "curses.ext" |
12 | ||
13 | /* | |
14 | * This routine adds the character to the current position | |
15 | * | |
8b28dacd KA |
16 | */ |
17 | waddch(win, c) | |
18 | reg WINDOW *win; | |
19 | char c; | |
20 | { | |
21 | reg int x, y; | |
60d72089 | 22 | reg WINDOW *wp; |
84d35f99 | 23 | reg int newx; |
8b28dacd KA |
24 | |
25 | x = win->_curx; | |
26 | y = win->_cury; | |
27 | # ifdef FULLDEBUG | |
28 | fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x); | |
29 | # endif | |
8b28dacd KA |
30 | switch (c) { |
31 | case '\t': | |
b7b377b8 | 32 | for (newx = x + (8 - (x & 07)); x < newx; x++) |
8b28dacd KA |
33 | if (waddch(win, ' ') == ERR) |
34 | return ERR; | |
35 | return OK; | |
60d72089 | 36 | |
8b28dacd KA |
37 | default: |
38 | # ifdef FULLDEBUG | |
39 | fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); | |
40 | # endif | |
41 | if (win->_flags & _STANDOUT) | |
42 | c |= _STANDOUT; | |
84d35f99 | 43 | set_ch(win, y, x, c); |
8b28dacd KA |
44 | win->_y[y][x++] = c; |
45 | if (x >= win->_maxx) { | |
8b28dacd | 46 | x = 0; |
4ce7bc0f KA |
47 | newline: |
48 | if (++y >= win->_maxy) | |
8b28dacd | 49 | if (win->_scroll) { |
8b28dacd KA |
50 | scroll(win); |
51 | --y; | |
52 | } | |
53 | else | |
54 | return ERR; | |
55 | } | |
56 | # ifdef FULLDEBUG | |
57 | fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]); | |
58 | # endif | |
59 | break; | |
60 | case '\n': | |
61 | wclrtoeol(win); | |
4ce7bc0f KA |
62 | if (!NONL) |
63 | x = 0; | |
64 | goto newline; | |
8b28dacd KA |
65 | case '\r': |
66 | x = 0; | |
67 | break; | |
68 | case '\b': | |
69 | if (--x < 0) | |
70 | x = 0; | |
71 | break; | |
72 | } | |
73 | win->_curx = x; | |
74 | win->_cury = y; | |
75 | return OK; | |
76 | } | |
60d72089 KA |
77 | |
78 | /* | |
79 | * set_ch: | |
80 | * Set the first and last change flags for this window. | |
81 | */ | |
82 | static | |
84d35f99 | 83 | set_ch(win, y, x, ch) |
60d72089 | 84 | reg WINDOW *win; |
9fcd8c35 | 85 | int y, x; |
84d35f99 JB |
86 | { |
87 | # ifdef FULLDEBUG | |
88 | fprintf(outf, "SET_CH(%0.2o, %d, %d)\n", win, y, x); | |
89 | # endif | |
60d72089 | 90 | if (win->_y[y][x] != ch) { |
84d35f99 | 91 | x += win->_ch_off; |
60d72089 | 92 | if (win->_firstch[y] == _NOCHANGE) |
84d35f99 | 93 | win->_firstch[y] = win->_lastch[y] = x; |
60d72089 | 94 | else if (x < win->_firstch[y]) |
84d35f99 | 95 | win->_firstch[y] = x; |
60d72089 | 96 | else if (x > win->_lastch[y]) |
84d35f99 JB |
97 | win->_lastch[y] = x; |
98 | # ifdef FULLDEBUG | |
99 | fprintf(outf, "SET_CH: change gives f/l: %d/%d [%d/%d]\n", | |
100 | win->_firstch[y], win->_lastch[y], | |
101 | win->_firstch[y] - win->_ch_off, | |
102 | win->_lastch[y] - win->_ch_off); | |
103 | # endif | |
60d72089 KA |
104 | } |
105 | } |