diff options
Diffstat (limited to '')
-rw-r--r-- | scripts/kconfig/libcurses/overlay.c | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/overlay.c b/scripts/kconfig/libcurses/overlay.c new file mode 100644 index 000000000..75a93d83c --- /dev/null +++ b/scripts/kconfig/libcurses/overlay.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* PDCurses */ | ||
2 | |||
3 | #include "curspriv.h" | ||
4 | |||
5 | /*man-start************************************************************** | ||
6 | |||
7 | overlay | ||
8 | ------- | ||
9 | |||
10 | ### Synopsis | ||
11 | |||
12 | int overlay(const WINDOW *src_w, WINDOW *dst_w) | ||
13 | int overwrite(const WINDOW *src_w, WINDOW *dst_w) | ||
14 | int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, | ||
15 | int src_tc, int dst_tr, int dst_tc, int dst_br, | ||
16 | int dst_bc, int _overlay) | ||
17 | |||
18 | ### Description | ||
19 | |||
20 | overlay() and overwrite() copy all the text from src_w into dst_w. | ||
21 | The windows need not be the same size. Those characters in the source | ||
22 | window that intersect with the destination window are copied, so that | ||
23 | the characters appear in the same physical position on the screen. | ||
24 | The difference between the two functions is that overlay() is non- | ||
25 | destructive (blanks are not copied) while overwrite() is destructive | ||
26 | (blanks are copied). | ||
27 | |||
28 | copywin() is similar, but doesn't require that the two windows | ||
29 | overlap. The arguments src_tc and src_tr specify the top left corner | ||
30 | of the region to be copied. dst_tc, dst_tr, dst_br, and dst_bc | ||
31 | specify the region within the destination window to copy to. The | ||
32 | argument "overlay", if TRUE, indicates that the copy is done non- | ||
33 | destructively (as in overlay()); blanks in the source window are not | ||
34 | copied to the destination window. When overlay is FALSE, blanks are | ||
35 | copied. | ||
36 | |||
37 | ### Return Value | ||
38 | |||
39 | All functions return OK on success and ERR on error. | ||
40 | |||
41 | ### Portability | ||
42 | |||
43 | Function | X/Open | ncurses | NetBSD | ||
44 | :---------------------|:------:|:-------:|:------: | ||
45 | overlay | Y | Y | Y | ||
46 | overwrite | Y | Y | Y | ||
47 | copywin | Y | Y | Y | ||
48 | |||
49 | **man-end****************************************************************/ | ||
50 | |||
51 | /* Thanks to Andreas Otte <venn@@uni-paderborn.de> for the | ||
52 | corrected overlay()/overwrite() behavior. */ | ||
53 | |||
54 | static int _copy_win(const WINDOW *src_w, WINDOW *dst_w, int src_tr, | ||
55 | int src_tc, int src_br, int src_bc, int dst_tr, | ||
56 | int dst_tc, bool _overlay) | ||
57 | { | ||
58 | int col, line, y1, fc, *minchng, *maxchng; | ||
59 | chtype *w1ptr, *w2ptr; | ||
60 | |||
61 | int lc = 0; | ||
62 | int xdiff = src_bc - src_tc; | ||
63 | int ydiff = src_br - src_tr; | ||
64 | |||
65 | if (!src_w || !dst_w) | ||
66 | return ERR; | ||
67 | |||
68 | minchng = dst_w->_firstch; | ||
69 | maxchng = dst_w->_lastch; | ||
70 | |||
71 | for (y1 = 0; y1 < dst_tr; y1++) | ||
72 | { | ||
73 | minchng++; | ||
74 | maxchng++; | ||
75 | } | ||
76 | |||
77 | for (line = 0; line < ydiff; line++) | ||
78 | { | ||
79 | w1ptr = src_w->_y[line + src_tr] + src_tc; | ||
80 | w2ptr = dst_w->_y[line + dst_tr] + dst_tc; | ||
81 | |||
82 | fc = _NO_CHANGE; | ||
83 | |||
84 | for (col = 0; col < xdiff; col++) | ||
85 | { | ||
86 | if ((*w1ptr) != (*w2ptr) && | ||
87 | !((*w1ptr & A_CHARTEXT) == ' ' && _overlay)) | ||
88 | { | ||
89 | *w2ptr = *w1ptr; | ||
90 | |||
91 | if (fc == _NO_CHANGE) | ||
92 | fc = col + dst_tc; | ||
93 | |||
94 | lc = col + dst_tc; | ||
95 | } | ||
96 | |||
97 | w1ptr++; | ||
98 | w2ptr++; | ||
99 | } | ||
100 | |||
101 | if (*minchng == _NO_CHANGE) | ||
102 | { | ||
103 | *minchng = fc; | ||
104 | *maxchng = lc; | ||
105 | } | ||
106 | else if (fc != _NO_CHANGE) | ||
107 | { | ||
108 | if (fc < *minchng) | ||
109 | *minchng = fc; | ||
110 | if (lc > *maxchng) | ||
111 | *maxchng = lc; | ||
112 | } | ||
113 | |||
114 | minchng++; | ||
115 | maxchng++; | ||
116 | } | ||
117 | |||
118 | return OK; | ||
119 | } | ||
120 | |||
121 | int _copy_overlap(const WINDOW *src_w, WINDOW *dst_w, bool overlay) | ||
122 | { | ||
123 | int first_line, first_col, last_line, last_col; | ||
124 | int src_start_x, src_start_y, dst_start_x, dst_start_y; | ||
125 | int xdiff, ydiff; | ||
126 | |||
127 | if (!src_w || !dst_w) | ||
128 | return ERR; | ||
129 | |||
130 | first_col = max(dst_w->_begx, src_w->_begx); | ||
131 | first_line = max(dst_w->_begy, src_w->_begy); | ||
132 | |||
133 | last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx); | ||
134 | last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy); | ||
135 | |||
136 | /* determine the overlapping region of the two windows in real | ||
137 | coordinates */ | ||
138 | |||
139 | /* if no overlapping region, do nothing */ | ||
140 | |||
141 | if ((last_col < first_col) || (last_line < first_line)) | ||
142 | return OK; | ||
143 | |||
144 | /* size of overlapping region */ | ||
145 | |||
146 | xdiff = last_col - first_col; | ||
147 | ydiff = last_line - first_line; | ||
148 | |||
149 | if (src_w->_begx <= dst_w->_begx) | ||
150 | { | ||
151 | src_start_x = dst_w->_begx - src_w->_begx; | ||
152 | dst_start_x = 0; | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | dst_start_x = src_w->_begx - dst_w->_begx; | ||
157 | src_start_x = 0; | ||
158 | } | ||
159 | |||
160 | if (src_w->_begy <= dst_w->_begy) | ||
161 | { | ||
162 | src_start_y = dst_w->_begy - src_w->_begy; | ||
163 | dst_start_y = 0; | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | dst_start_y = src_w->_begy - dst_w->_begy; | ||
168 | src_start_y = 0; | ||
169 | } | ||
170 | |||
171 | return _copy_win(src_w, dst_w, src_start_y, src_start_x, | ||
172 | src_start_y + ydiff, src_start_x + xdiff, | ||
173 | dst_start_y, dst_start_x, overlay); | ||
174 | } | ||
175 | |||
176 | int overlay(const WINDOW *src_w, WINDOW *dst_w) | ||
177 | { | ||
178 | PDC_LOG(("overlay() - called\n")); | ||
179 | |||
180 | return _copy_overlap(src_w, dst_w, TRUE); | ||
181 | } | ||
182 | |||
183 | int overwrite(const WINDOW *src_w, WINDOW *dst_w) | ||
184 | { | ||
185 | PDC_LOG(("overwrite() - called\n")); | ||
186 | |||
187 | return _copy_overlap(src_w, dst_w, FALSE); | ||
188 | } | ||
189 | |||
190 | int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, int src_tc, | ||
191 | int dst_tr, int dst_tc, int dst_br, int dst_bc, int _overlay) | ||
192 | { | ||
193 | int src_end_x, src_end_y; | ||
194 | int src_rows, src_cols, dst_rows, dst_cols; | ||
195 | int min_rows, min_cols; | ||
196 | |||
197 | PDC_LOG(("copywin() - called\n")); | ||
198 | |||
199 | if (!src_w || !dst_w || dst_w == curscr || dst_br >= dst_w->_maxy | ||
200 | || dst_bc >= dst_w->_maxx || dst_tr < 0 || dst_tc < 0) | ||
201 | return ERR; | ||
202 | |||
203 | src_rows = src_w->_maxy - src_tr; | ||
204 | src_cols = src_w->_maxx - src_tc; | ||
205 | dst_rows = dst_br - dst_tr + 1; | ||
206 | dst_cols = dst_bc - dst_tc + 1; | ||
207 | |||
208 | min_rows = min(src_rows, dst_rows); | ||
209 | min_cols = min(src_cols, dst_cols); | ||
210 | |||
211 | src_end_y = src_tr + min_rows; | ||
212 | src_end_x = src_tc + min_cols; | ||
213 | |||
214 | return _copy_win(src_w, dst_w, src_tr, src_tc, src_end_y, src_end_x, | ||
215 | dst_tr, dst_tc, _overlay); | ||
216 | } | ||