drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / insstr.c
bloba731eaf436f376df50c4358f87a692a4f937f1b3
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: insstr.c,v 1.46 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: insstr
11 Synopsis:
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);
30 Description:
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.
43 Return Value:
44 All functions return OK on success and ERR on error.
46 Portability X/Open BSD SYS V
47 insstr Y - 4.0
48 winsstr Y - 4.0
49 mvinsstr Y - 4.0
50 mvwinsstr Y - 4.0
51 insnstr Y - 4.0
52 winsnstr Y - 4.0
53 mvinsnstr Y - 4.0
54 mvwinsnstr Y - 4.0
55 ins_wstr Y
56 wins_wstr Y
57 mvins_wstr Y
58 mvwins_wstr Y
59 ins_nwstr Y
60 wins_nwstr Y
61 mvins_nwstr Y
62 mvwins_nwstr Y
64 **man-end****************************************************************/
66 #include <string.h>
68 int winsnstr(WINDOW *win, const char *str, int n)
70 #ifdef PDC_WIDE
71 wchar_t wstr[513], *p;
72 int i;
73 #endif
74 int len;
76 PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n));
78 if (!win || !str)
79 return ERR;
81 len = strlen(str);
83 if (n < 0 || n < len)
84 n = len;
86 #ifdef PDC_WIDE
87 if (n > 512)
88 n = 512;
90 p = wstr;
91 i = 0;
93 while (str[i] && i < n)
95 int retval = PDC_mbtowc(p, str + i, n - i);
97 if (retval <= 0)
98 break;
99 p++;
100 i += retval;
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;
111 return OK;
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)
133 return 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)
143 return 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",
158 y, x, str, n));
160 if (move(y, x) == ERR)
161 return 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",
169 y, x, str, n));
171 if (wmove(win, y, x) == ERR)
172 return ERR;
174 return winsnstr(win, str, n);
177 #ifdef PDC_WIDE
178 int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
180 const wchar_t *p;
181 int len;
183 PDC_LOG(("wins_nwstr() - called\n"));
185 if (!win || !wstr)
186 return ERR;
188 for (len = 0, p = wstr; *p; p++)
189 len++;
191 if (n < 0 || n < len)
192 n = len;
194 while (n)
195 if (winsch(win, wstr[--n]) == ERR)
196 return ERR;
198 return OK;
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)
220 return 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)
230 return 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)
247 return 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)
257 return ERR;
259 return wins_nwstr(win, wstr, n);
261 #endif