| 1 |
|
| 2 |
|
| 3 |
#include <curspriv.h> |
| 4 |
|
| 5 |
RCSID("$Id: addstr.c,v 1.44 2008/07/13 16:08:17 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 |
|
| 62 |
|
| 63 |
|
| 64 |
int waddnstr(WINDOW *win, const char *str, int n) |
| 65 |
{ |
| 66 |
int i = 0; |
| 67 |
|
| 68 |
PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n)); |
| 69 |
|
| 70 |
if (!win || !str) |
| 71 |
return ERR; |
| 72 |
|
| 73 |
while (str[i] && (i < n || n < 0)) |
| 74 |
{ |
| 75 |
#ifdef PDC_WIDE |
| 76 |
wchar_t wch; |
| 77 |
int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6); |
| 78 |
|
| 79 |
if (retval <= 0) |
| 80 |
return OK; |
| 81 |
|
| 82 |
i += retval; |
| 83 |
#else |
| 84 |
chtype wch = (unsigned char)(str[i++]); |
| 85 |
#endif |
| 86 |
if (waddch(win, wch) == ERR) |
| 87 |
return ERR; |
| 88 |
} |
| 89 |
|
| 90 |
return OK; |
| 91 |
} |
| 92 |
|
| 93 |
int addstr(const char *str) |
| 94 |
{ |
| 95 |
PDC_LOG(("addstr() - called: string=\"%s\"\n", str)); |
| 96 |
|
| 97 |
return waddnstr(stdscr, str, -1); |
| 98 |
} |
| 99 |
|
| 100 |
int addnstr(const char *str, int n) |
| 101 |
{ |
| 102 |
PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n)); |
| 103 |
|
| 104 |
return waddnstr(stdscr, str, n); |
| 105 |
} |
| 106 |
|
| 107 |
int waddstr(WINDOW *win, const char *str) |
| 108 |
{ |
| 109 |
PDC_LOG(("waddstr() - called: string=\"%s\"\n", str)); |
| 110 |
|
| 111 |
return waddnstr(win, str, -1); |
| 112 |
} |
| 113 |
|
| 114 |
int mvaddstr(int y, int x, const char *str) |
| 115 |
{ |
| 116 |
PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); |
| 117 |
|
| 118 |
if (move(y, x) == ERR) |
| 119 |
return ERR; |
| 120 |
|
| 121 |
return waddnstr(stdscr, str, -1); |
| 122 |
} |
| 123 |
|
| 124 |
int mvaddnstr(int y, int x, const char *str, int n) |
| 125 |
{ |
| 126 |
PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n", |
| 127 |
y, x, str, n)); |
| 128 |
|
| 129 |
if (move(y, x) == ERR) |
| 130 |
return ERR; |
| 131 |
|
| 132 |
return waddnstr(stdscr, str, n); |
| 133 |
} |
| 134 |
|
| 135 |
int mvwaddstr(WINDOW *win, int y, int x, const char *str) |
| 136 |
{ |
| 137 |
PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str)); |
| 138 |
|
| 139 |
if (wmove(win, y, x) == ERR) |
| 140 |
return ERR; |
| 141 |
|
| 142 |
return waddnstr(win, str, -1); |
| 143 |
} |
| 144 |
|
| 145 |
int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n) |
| 146 |
{ |
| 147 |
PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n", |
| 148 |
y, x, str, n)); |
| 149 |
|
| 150 |
if (wmove(win, y, x) == ERR) |
| 151 |
return ERR; |
| 152 |
|
| 153 |
return waddnstr(win, str, n); |
| 154 |
} |
| 155 |
|
| 156 |
#ifdef PDC_WIDE |
| 157 |
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n) |
| 158 |
{ |
| 159 |
int i = 0; |
| 160 |
|
| 161 |
PDC_LOG(("waddnwstr() - called\n")); |
| 162 |
|
| 163 |
if (!win || !wstr) |
| 164 |
return ERR; |
| 165 |
|
| 166 |
while (wstr[i] && (i < n || n < 0)) |
| 167 |
{ |
| 168 |
chtype wch = wstr[i++]; |
| 169 |
|
| 170 |
if (waddch(win, wch) == ERR) |
| 171 |
return ERR; |
| 172 |
} |
| 173 |
|
| 174 |
return OK; |
| 175 |
} |
| 176 |
|
| 177 |
int addwstr(const wchar_t *wstr) |
| 178 |
{ |
| 179 |
PDC_LOG(("addwstr() - called\n")); |
| 180 |
|
| 181 |
return waddnwstr(stdscr, wstr, -1); |
| 182 |
} |
| 183 |
|
| 184 |
int addnwstr(const wchar_t *wstr, int n) |
| 185 |
{ |
| 186 |
PDC_LOG(("addnwstr() - called\n")); |
| 187 |
|
| 188 |
return waddnwstr(stdscr, wstr, n); |
| 189 |
} |
| 190 |
|
| 191 |
int waddwstr(WINDOW *win, const wchar_t *wstr) |
| 192 |
{ |
| 193 |
PDC_LOG(("waddwstr() - called\n")); |
| 194 |
|
| 195 |
return waddnwstr(win, wstr, -1); |
| 196 |
} |
| 197 |
|
| 198 |
int mvaddwstr(int y, int x, const wchar_t *wstr) |
| 199 |
{ |
| 200 |
PDC_LOG(("mvaddstr() - called\n")); |
| 201 |
|
| 202 |
if (move(y, x) == ERR) |
| 203 |
return ERR; |
| 204 |
|
| 205 |
return waddnwstr(stdscr, wstr, -1); |
| 206 |
} |
| 207 |
|
| 208 |
int mvaddnwstr(int y, int x, const wchar_t *wstr, int n) |
| 209 |
{ |
| 210 |
PDC_LOG(("mvaddnstr() - called\n")); |
| 211 |
|
| 212 |
if (move(y, x) == ERR) |
| 213 |
return ERR; |
| 214 |
|
| 215 |
return waddnwstr(stdscr, wstr, n); |
| 216 |
} |
| 217 |
|
| 218 |
int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr) |
| 219 |
{ |
| 220 |
PDC_LOG(("mvwaddstr() - called\n")); |
| 221 |
|
| 222 |
if (wmove(win, y, x) == ERR) |
| 223 |
return ERR; |
| 224 |
|
| 225 |
return waddnwstr(win, wstr, -1); |
| 226 |
} |
| 227 |
|
| 228 |
int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) |
| 229 |
{ |
| 230 |
PDC_LOG(("mvwaddnstr() - called\n")); |
| 231 |
|
| 232 |
if (wmove(win, y, x) == ERR) |
| 233 |
return ERR; |
| 234 |
|
| 235 |
return waddnwstr(win, wstr, n); |
| 236 |
} |
| 237 |
#endif |