| 1 |
|
| 2 |
|
| 3 |
#include <curspriv.h> |
| 4 |
|
| 5 |
RCSID("$Id: insstr.c,v 1.46 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 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#include <string.h> |
| 67 |
|
| 68 |
int winsnstr(WINDOW *win, const char *str, int n) |
| 69 |
{ |
| 70 |
#ifdef PDC_WIDE |
| 71 |
wchar_t wstr[513], *p; |
| 72 |
int i; |
| 73 |
#endif |
| 74 |
int len; |
| 75 |
|
| 76 |
PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n)); |
| 77 |
|
| 78 |
if (!win || !str) |
| 79 |
return ERR; |
| 80 |
|
| 81 |
len = strlen(str); |
| 82 |
|
| 83 |
if (n < 0 || n < len) |
| 84 |
n = len; |
| 85 |
|
| 86 |
#ifdef PDC_WIDE |
| 87 |
if (n > 512) |
| 88 |
n = 512; |
| 89 |
|
| 90 |
p = wstr; |
| 91 |
i = 0; |
| 92 |
|
| 93 |
while (str[i] && i < n) |
| 94 |
{ |
| 95 |
int retval = PDC_mbtowc(p, str + i, n - i); |
| 96 |
|
| 97 |
if (retval <= 0) |
| 98 |
break; |
| 99 |
p++; |
| 100 |
i += retval; |
| 101 |
} |
| 102 |
|
| 103 |
while (p > wstr) |
| 104 |
if (winsch(win, *--p) == ERR) |
| 105 |
#else |
| 106 |
while (n) |
| 107 |
if (winsch(win, (unsigned char)(str[--n])) == ERR) |
| 108 |
#endif |
| 109 |
return ERR; |
| 110 |
|
| 111 |
return OK; |
| 112 |
} |
| 113 |
|
| 114 |
int insstr(const char *str) |
| 115 |
{ |
| 116 |
PDC_LOG(("insstr() - called: string=\"%s\"\n", str)); |
| 117 |
|
| 118 |
return winsnstr(stdscr, str, -1); |
| 119 |
} |
| 120 |
|
| 121 |
int winsstr(WINDOW *win, const char *str) |
| 122 |
{ |
| 123 |
PDC_LOG(("winsstr() - called: string=\"%s\"\n", str)); |
| 124 |
|
| 125 |
return winsnstr(win, str, -1); |
| 126 |
} |
| 127 |
|
| 128 |
int mvinsstr(int y, int x, const char *str) |
| 129 |
{ |
| 130 |
PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y, x, str)); |
| 131 |
|
| 132 |
if (move(y, x) == ERR) |
| 133 |
return ERR; |
| 134 |
|
| 135 |
return winsnstr(stdscr, str, -1); |
| 136 |
} |
| 137 |
|
| 138 |
int mvwinsstr(WINDOW *win, int y, int x, const char *str) |
| 139 |
{ |
| 140 |
PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str)); |
| 141 |
|
| 142 |
if (wmove(win, y, x) == ERR) |
| 143 |
return ERR; |
| 144 |
|
| 145 |
return winsnstr(win, str, -1); |
| 146 |
} |
| 147 |
|
| 148 |
int insnstr(const char *str, int n) |
| 149 |
{ |
| 150 |
PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str, n)); |
| 151 |
|
| 152 |
return winsnstr(stdscr, str, n); |
| 153 |
} |
| 154 |
|
| 155 |
int mvinsnstr(int y, int x, const char *str, int n) |
| 156 |
{ |
| 157 |
PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n", |
| 158 |
y, x, str, n)); |
| 159 |
|
| 160 |
if (move(y, x) == ERR) |
| 161 |
return ERR; |
| 162 |
|
| 163 |
return winsnstr(stdscr, str, n); |
| 164 |
} |
| 165 |
|
| 166 |
int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n) |
| 167 |
{ |
| 168 |
PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n", |
| 169 |
y, x, str, n)); |
| 170 |
|
| 171 |
if (wmove(win, y, x) == ERR) |
| 172 |
return ERR; |
| 173 |
|
| 174 |
return winsnstr(win, str, n); |
| 175 |
} |
| 176 |
|
| 177 |
#ifdef PDC_WIDE |
| 178 |
int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n) |
| 179 |
{ |
| 180 |
const wchar_t *p; |
| 181 |
int len; |
| 182 |
|
| 183 |
PDC_LOG(("wins_nwstr() - called\n")); |
| 184 |
|
| 185 |
if (!win || !wstr) |
| 186 |
return ERR; |
| 187 |
|
| 188 |
for (len = 0, p = wstr; *p; p++) |
| 189 |
len++; |
| 190 |
|
| 191 |
if (n < 0 || n < len) |
| 192 |
n = len; |
| 193 |
|
| 194 |
while (n) |
| 195 |
if (winsch(win, wstr[--n]) == ERR) |
| 196 |
return ERR; |
| 197 |
|
| 198 |
return OK; |
| 199 |
} |
| 200 |
|
| 201 |
int ins_wstr(const wchar_t *wstr) |
| 202 |
{ |
| 203 |
PDC_LOG(("ins_wstr() - called\n")); |
| 204 |
|
| 205 |
return wins_nwstr(stdscr, wstr, -1); |
| 206 |
} |
| 207 |
|
| 208 |
int wins_wstr(WINDOW *win, const wchar_t *wstr) |
| 209 |
{ |
| 210 |
PDC_LOG(("wins_wstr() - called\n")); |
| 211 |
|
| 212 |
return wins_nwstr(win, wstr, -1); |
| 213 |
} |
| 214 |
|
| 215 |
int mvins_wstr(int y, int x, const wchar_t *wstr) |
| 216 |
{ |
| 217 |
PDC_LOG(("mvins_wstr() - called\n")); |
| 218 |
|
| 219 |
if (move(y, x) == ERR) |
| 220 |
return ERR; |
| 221 |
|
| 222 |
return wins_nwstr(stdscr, wstr, -1); |
| 223 |
} |
| 224 |
|
| 225 |
int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr) |
| 226 |
{ |
| 227 |
PDC_LOG(("mvwinsstr() - called\n")); |
| 228 |
|
| 229 |
if (wmove(win, y, x) == ERR) |
| 230 |
return ERR; |
| 231 |
|
| 232 |
return wins_nwstr(win, wstr, -1); |
| 233 |
} |
| 234 |
|
| 235 |
int ins_nwstr(const wchar_t *wstr, int n) |
| 236 |
{ |
| 237 |
PDC_LOG(("ins_nwstr() - called\n")); |
| 238 |
|
| 239 |
return wins_nwstr(stdscr, wstr, n); |
| 240 |
} |
| 241 |
|
| 242 |
int mvins_nwstr(int y, int x, const wchar_t *wstr, int n) |
| 243 |
{ |
| 244 |
PDC_LOG(("mvinsnstr() - called\n")); |
| 245 |
|
| 246 |
if (move(y, x) == ERR) |
| 247 |
return ERR; |
| 248 |
|
| 249 |
return wins_nwstr(stdscr, wstr, n); |
| 250 |
} |
| 251 |
|
| 252 |
int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n) |
| 253 |
{ |
| 254 |
PDC_LOG(("mvwinsnstr() - called\n")); |
| 255 |
|
| 256 |
if (wmove(win, y, x) == ERR) |
| 257 |
return ERR; |
| 258 |
|
| 259 |
return wins_nwstr(win, wstr, n); |
| 260 |
} |
| 261 |
#endif |