| 1 |
|
| 2 |
|
| 3 |
#include <curspriv.h> |
| 4 |
|
| 5 |
RCSID("$Id: insch.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $") |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#include <string.h> |
| 62 |
|
| 63 |
int winsch(WINDOW *win, chtype ch) |
| 64 |
{ |
| 65 |
int x, y; |
| 66 |
chtype attr; |
| 67 |
bool xlat; |
| 68 |
|
| 69 |
PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n", |
| 70 |
win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES)); |
| 71 |
|
| 72 |
if (!win) |
| 73 |
return ERR; |
| 74 |
|
| 75 |
x = win->_curx; |
| 76 |
y = win->_cury; |
| 77 |
|
| 78 |
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) |
| 79 |
return ERR; |
| 80 |
|
| 81 |
xlat = !SP->raw_out && !(ch & A_ALTCHARSET); |
| 82 |
attr = ch & A_ATTRIBUTES; |
| 83 |
ch &= A_CHARTEXT; |
| 84 |
|
| 85 |
if (xlat && (ch < ' ' || ch == 0x7f)) |
| 86 |
{ |
| 87 |
int x2; |
| 88 |
|
| 89 |
switch (ch) |
| 90 |
{ |
| 91 |
case '\t': |
| 92 |
for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++) |
| 93 |
{ |
| 94 |
if (winsch(win, attr | ' ') == ERR) |
| 95 |
return ERR; |
| 96 |
} |
| 97 |
return OK; |
| 98 |
|
| 99 |
case '\n': |
| 100 |
wclrtoeol(win); |
| 101 |
break; |
| 102 |
|
| 103 |
case 0x7f: |
| 104 |
if (winsch(win, attr | '?') == ERR) |
| 105 |
return ERR; |
| 106 |
|
| 107 |
return winsch(win, attr | '^'); |
| 108 |
|
| 109 |
default: |
| 110 |
|
| 111 |
|
| 112 |
if (winsch(win, attr | (ch + '@')) == ERR) |
| 113 |
return ERR; |
| 114 |
|
| 115 |
return winsch(win, attr | '^'); |
| 116 |
} |
| 117 |
} |
| 118 |
else |
| 119 |
{ |
| 120 |
int maxx; |
| 121 |
chtype *temp; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
if (!(attr & A_COLOR)) |
| 131 |
attr |= win->_attrs; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
if (!(attr & A_COLOR)) |
| 139 |
attr |= win->_bkgd & A_ATTRIBUTES; |
| 140 |
else |
| 141 |
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR); |
| 142 |
|
| 143 |
if (ch == ' ') |
| 144 |
ch = win->_bkgd & A_CHARTEXT; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
ch |= attr; |
| 149 |
|
| 150 |
maxx = win->_maxx; |
| 151 |
temp = &win->_y[y][x]; |
| 152 |
|
| 153 |
memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype)); |
| 154 |
|
| 155 |
win->_lastch[y] = maxx - 1; |
| 156 |
|
| 157 |
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x)) |
| 158 |
win->_firstch[y] = x; |
| 159 |
|
| 160 |
*temp = ch; |
| 161 |
} |
| 162 |
|
| 163 |
PDC_sync(win); |
| 164 |
|
| 165 |
return OK; |
| 166 |
} |
| 167 |
|
| 168 |
int insch(chtype ch) |
| 169 |
{ |
| 170 |
PDC_LOG(("insch() - called\n")); |
| 171 |
|
| 172 |
return winsch(stdscr, ch); |
| 173 |
} |
| 174 |
|
| 175 |
int mvinsch(int y, int x, chtype ch) |
| 176 |
{ |
| 177 |
PDC_LOG(("mvinsch() - called\n")); |
| 178 |
|
| 179 |
if (move(y, x) == ERR) |
| 180 |
return ERR; |
| 181 |
|
| 182 |
return winsch(stdscr, ch); |
| 183 |
} |
| 184 |
|
| 185 |
int mvwinsch(WINDOW *win, int y, int x, chtype ch) |
| 186 |
{ |
| 187 |
PDC_LOG(("mvwinsch() - called\n")); |
| 188 |
|
| 189 |
if (wmove(win, y, x) == ERR) |
| 190 |
return ERR; |
| 191 |
|
| 192 |
return winsch(win, ch); |
| 193 |
} |
| 194 |
|
| 195 |
int winsrawch(WINDOW *win, chtype ch) |
| 196 |
{ |
| 197 |
PDC_LOG(("winsrawch() - called: win=%p ch=%x " |
| 198 |
"(char=%c attr=0x%x)\n", win, ch, |
| 199 |
ch & A_CHARTEXT, ch & A_ATTRIBUTES)); |
| 200 |
|
| 201 |
if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f) |
| 202 |
ch |= A_ALTCHARSET; |
| 203 |
|
| 204 |
return winsch(win, ch); |
| 205 |
} |
| 206 |
|
| 207 |
int insrawch(chtype ch) |
| 208 |
{ |
| 209 |
PDC_LOG(("insrawch() - called\n")); |
| 210 |
|
| 211 |
return winsrawch(stdscr, ch); |
| 212 |
} |
| 213 |
|
| 214 |
int mvinsrawch(int y, int x, chtype ch) |
| 215 |
{ |
| 216 |
PDC_LOG(("mvinsrawch() - called\n")); |
| 217 |
|
| 218 |
if (move(y, x) == ERR) |
| 219 |
return ERR; |
| 220 |
|
| 221 |
return winsrawch(stdscr, ch); |
| 222 |
} |
| 223 |
|
| 224 |
int mvwinsrawch(WINDOW *win, int y, int x, chtype ch) |
| 225 |
{ |
| 226 |
PDC_LOG(("mvwinsrawch() - called\n")); |
| 227 |
|
| 228 |
if (wmove(win, y, x) == ERR) |
| 229 |
return ERR; |
| 230 |
|
| 231 |
return winsrawch(win, ch); |
| 232 |
} |
| 233 |
|
| 234 |
#ifdef PDC_WIDE |
| 235 |
int wins_wch(WINDOW *win, const cchar_t *wch) |
| 236 |
{ |
| 237 |
PDC_LOG(("wins_wch() - called\n")); |
| 238 |
|
| 239 |
return wch ? winsch(win, *wch) : ERR; |
| 240 |
} |
| 241 |
|
| 242 |
int ins_wch(const cchar_t *wch) |
| 243 |
{ |
| 244 |
PDC_LOG(("ins_wch() - called\n")); |
| 245 |
|
| 246 |
return wins_wch(stdscr, wch); |
| 247 |
} |
| 248 |
|
| 249 |
int mvins_wch(int y, int x, const cchar_t *wch) |
| 250 |
{ |
| 251 |
PDC_LOG(("mvins_wch() - called\n")); |
| 252 |
|
| 253 |
if (move(y, x) == ERR) |
| 254 |
return ERR; |
| 255 |
|
| 256 |
return wins_wch(stdscr, wch); |
| 257 |
} |
| 258 |
|
| 259 |
int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch) |
| 260 |
{ |
| 261 |
PDC_LOG(("mvwins_wch() - called\n")); |
| 262 |
|
| 263 |
if (wmove(win, y, x) == ERR) |
| 264 |
return ERR; |
| 265 |
|
| 266 |
return wins_wch(win, wch); |
| 267 |
} |
| 268 |
#endif |