1 /* Public Domain Curses */
5 RCSID("$Id: insstr.c,v 1.46 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
12 int insstr(const char *str);
13 int insnstr(const char *str, int n);
14 int winsstr(WINDOW *win, const char *str);
15 int winsnstr(WINDOW *win, const char *str, int n);
16 int mvinsstr(int y, int x, const char *str);
17 int mvinsnstr(int y, int x, const char *str, int n);
18 int mvwinsstr(WINDOW *win, int y, int x, const char *str);
19 int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n);
21 int ins_wstr(const wchar_t *wstr);
22 int ins_nwstr(const wchar_t *wstr, int n);
23 int wins_wstr(WINDOW *win, const wchar_t *wstr);
24 int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n);
25 int mvins_wstr(int y, int x, const wchar_t *wstr);
26 int mvins_nwstr(int y, int x, const wchar_t *wstr, int n);
27 int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr);
28 int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
31 The insstr() functions insert a character string into a window
32 at the current cursor position, by repeatedly calling winsch().
33 When PDCurses is built with wide-character support enabled, the
34 narrow-character functions treat the string as a multibyte
35 string in the current locale, and convert it first. All
36 characters to the right of the cursor are moved to the right,
37 with the possibility of the rightmost characters on the line
38 being lost. The cursor position does not change (after moving
39 to y, x, if specified). The routines with n as the last
40 argument insert at most n characters; if n is negative, then the
41 entire string is inserted.
44 All functions return OK on success and ERR on error.
46 Portability X/Open BSD SYS V
64 **man-end****************************************************************/
68 int winsnstr(WINDOW
*win
, const char *str
, int n
)
71 wchar_t wstr
[513], *p
;
76 PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str
, n
));
93 while (str
[i
] && i
< n
)
95 int retval
= PDC_mbtowc(p
, str
+ i
, n
- i
);
104 if (winsch(win
, *--p
) == ERR
)
107 if (winsch(win
, (unsigned char)(str
[--n
])) == ERR
)
114 int insstr(const char *str
)
116 PDC_LOG(("insstr() - called: string=\"%s\"\n", str
));
118 return winsnstr(stdscr
, str
, -1);
121 int winsstr(WINDOW
*win
, const char *str
)
123 PDC_LOG(("winsstr() - called: string=\"%s\"\n", str
));
125 return winsnstr(win
, str
, -1);
128 int mvinsstr(int y
, int x
, const char *str
)
130 PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y
, x
, str
));
132 if (move(y
, x
) == ERR
)
135 return winsnstr(stdscr
, str
, -1);
138 int mvwinsstr(WINDOW
*win
, int y
, int x
, const char *str
)
140 PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str
));
142 if (wmove(win
, y
, x
) == ERR
)
145 return winsnstr(win
, str
, -1);
148 int insnstr(const char *str
, int n
)
150 PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str
, n
));
152 return winsnstr(stdscr
, str
, n
);
155 int mvinsnstr(int y
, int x
, const char *str
, int n
)
157 PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
160 if (move(y
, x
) == ERR
)
163 return winsnstr(stdscr
, str
, n
);
166 int mvwinsnstr(WINDOW
*win
, int y
, int x
, const char *str
, int n
)
168 PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
171 if (wmove(win
, y
, x
) == ERR
)
174 return winsnstr(win
, str
, n
);
178 int wins_nwstr(WINDOW
*win
, const wchar_t *wstr
, int n
)
183 PDC_LOG(("wins_nwstr() - called\n"));
188 for (len
= 0, p
= wstr
; *p
; p
++)
191 if (n
< 0 || n
< len
)
195 if (winsch(win
, wstr
[--n
]) == ERR
)
201 int ins_wstr(const wchar_t *wstr
)
203 PDC_LOG(("ins_wstr() - called\n"));
205 return wins_nwstr(stdscr
, wstr
, -1);
208 int wins_wstr(WINDOW
*win
, const wchar_t *wstr
)
210 PDC_LOG(("wins_wstr() - called\n"));
212 return wins_nwstr(win
, wstr
, -1);
215 int mvins_wstr(int y
, int x
, const wchar_t *wstr
)
217 PDC_LOG(("mvins_wstr() - called\n"));
219 if (move(y
, x
) == ERR
)
222 return wins_nwstr(stdscr
, wstr
, -1);
225 int mvwins_wstr(WINDOW
*win
, int y
, int x
, const wchar_t *wstr
)
227 PDC_LOG(("mvwinsstr() - called\n"));
229 if (wmove(win
, y
, x
) == ERR
)
232 return wins_nwstr(win
, wstr
, -1);
235 int ins_nwstr(const wchar_t *wstr
, int n
)
237 PDC_LOG(("ins_nwstr() - called\n"));
239 return wins_nwstr(stdscr
, wstr
, n
);
242 int mvins_nwstr(int y
, int x
, const wchar_t *wstr
, int n
)
244 PDC_LOG(("mvinsnstr() - called\n"));
246 if (move(y
, x
) == ERR
)
249 return wins_nwstr(stdscr
, wstr
, n
);
252 int mvwins_nwstr(WINDOW
*win
, int y
, int x
, const wchar_t *wstr
, int n
)
254 PDC_LOG(("mvwinsnstr() - called\n"));
256 if (wmove(win
, y
, x
) == ERR
)
259 return wins_nwstr(win
, wstr
, n
);