1 /* Public Domain Curses */
5 RCSID("$Id: insch.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
13 int winsch(WINDOW *win, chtype ch);
14 int mvinsch(int y, int x, chtype ch);
15 int mvwinsch(WINDOW *win, int y, int x, chtype ch);
17 int insrawch(chtype ch);
18 int winsrawch(WINDOW *win, chtype ch);
19 int mvinsrawch(int y, int x, chtype ch);
20 int mvwinsrawch(WINDOW *win, int y, int x, chtype ch);
22 int ins_wch(const cchar_t *wch);
23 int wins_wch(WINDOW *win, const cchar_t *wch);
24 int mvins_wch(int y, int x, const cchar_t *wch);
25 int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch);
28 The insch() functions insert a chtype into the window at the
29 current or specified cursor position. The cursor is NOT
30 advanced. A newline is equivalent to clrtoeol(); tabs are
31 expanded; other control characters are converted as with
34 The ins_wch() functions are the wide-character
35 equivalents, taking cchar_t pointers rather than chtypes.
37 Video attributes can be combined with a character by ORing
38 them into the parameter. Text, including attributes, can be
39 copied from one place to another using inch() and insch().
41 insrawch() etc. are PDCurses-specific wrappers for insch() etc.
42 that disable the translation of control characters.
45 All functions return OK on success and ERR on error.
47 Portability X/Open BSD SYS V
59 **man-end****************************************************************/
63 int winsch(WINDOW
*win
, chtype ch
)
69 PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
70 win
, ch
, ch
& A_CHARTEXT
, ch
& A_ATTRIBUTES
));
78 if (y
> win
->_maxy
|| x
> win
->_maxx
|| y
< 0 || x
< 0)
81 xlat
= !SP
->raw_out
&& !(ch
& A_ALTCHARSET
);
82 attr
= ch
& A_ATTRIBUTES
;
85 if (xlat
&& (ch
< ' ' || ch
== 0x7f))
92 for (x2
= ((x
/ TABSIZE
) + 1) * TABSIZE
; x
< x2
; x
++)
94 if (winsch(win
, attr
| ' ') == ERR
)
104 if (winsch(win
, attr
| '?') == ERR
)
107 return winsch(win
, attr
| '^');
110 /* handle control chars */
112 if (winsch(win
, attr
| (ch
+ '@')) == ERR
)
115 return winsch(win
, attr
| '^');
123 /* If the incoming character doesn't have its own attribute,
124 then use the current attributes for the window. If it has
125 attributes but not a color component, OR the attributes to
126 the current attributes for the window. If it has a color
127 component, use the attributes solely from the incoming
130 if (!(attr
& A_COLOR
))
133 /* wrs (4/10/93): Apply the same sort of logic for the window
134 background, in that it only takes precedence if other color
135 attributes are not there and that the background character
136 will only print if the printing character is blank. */
138 if (!(attr
& A_COLOR
))
139 attr
|= win
->_bkgd
& A_ATTRIBUTES
;
141 attr
|= win
->_bkgd
& (A_ATTRIBUTES
^ A_COLOR
);
144 ch
= win
->_bkgd
& A_CHARTEXT
;
146 /* Add the attribute back into the character. */
151 temp
= &win
->_y
[y
][x
];
153 memmove(temp
+ 1, temp
, (maxx
- x
- 1) * sizeof(chtype
));
155 win
->_lastch
[y
] = maxx
- 1;
157 if ((win
->_firstch
[y
] == _NO_CHANGE
) || (win
->_firstch
[y
] > x
))
158 win
->_firstch
[y
] = x
;
170 PDC_LOG(("insch() - called\n"));
172 return winsch(stdscr
, ch
);
175 int mvinsch(int y
, int x
, chtype ch
)
177 PDC_LOG(("mvinsch() - called\n"));
179 if (move(y
, x
) == ERR
)
182 return winsch(stdscr
, ch
);
185 int mvwinsch(WINDOW
*win
, int y
, int x
, chtype ch
)
187 PDC_LOG(("mvwinsch() - called\n"));
189 if (wmove(win
, y
, x
) == ERR
)
192 return winsch(win
, ch
);
195 int winsrawch(WINDOW
*win
, chtype ch
)
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
));
201 if ((ch
& A_CHARTEXT
) < ' ' || (ch
& A_CHARTEXT
) == 0x7f)
204 return winsch(win
, ch
);
207 int insrawch(chtype ch
)
209 PDC_LOG(("insrawch() - called\n"));
211 return winsrawch(stdscr
, ch
);
214 int mvinsrawch(int y
, int x
, chtype ch
)
216 PDC_LOG(("mvinsrawch() - called\n"));
218 if (move(y
, x
) == ERR
)
221 return winsrawch(stdscr
, ch
);
224 int mvwinsrawch(WINDOW
*win
, int y
, int x
, chtype ch
)
226 PDC_LOG(("mvwinsrawch() - called\n"));
228 if (wmove(win
, y
, x
) == ERR
)
231 return winsrawch(win
, ch
);
235 int wins_wch(WINDOW
*win
, const cchar_t
*wch
)
237 PDC_LOG(("wins_wch() - called\n"));
239 return wch
? winsch(win
, *wch
) : ERR
;
242 int ins_wch(const cchar_t
*wch
)
244 PDC_LOG(("ins_wch() - called\n"));
246 return wins_wch(stdscr
, wch
);
249 int mvins_wch(int y
, int x
, const cchar_t
*wch
)
251 PDC_LOG(("mvins_wch() - called\n"));
253 if (move(y
, x
) == ERR
)
256 return wins_wch(stdscr
, wch
);
259 int mvwins_wch(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
)
261 PDC_LOG(("mvwins_wch() - called\n"));
263 if (wmove(win
, y
, x
) == ERR
)
266 return wins_wch(win
, wch
);