drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / pdcurses / addstr.c
blobca19fd02937885c51a65dcc5a3fb3d4eb1f6103b
1 /* Public Domain Curses */
3 #include <curspriv.h>
5 RCSID("$Id: addstr.c,v 1.44 2008/07/13 16:08:17 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: addstr
11 Synopsis:
12 int addstr(const char *str);
13 int addnstr(const char *str, int n);
14 int waddstr(WINDOW *win, const char *str);
15 int waddnstr(WINDOW *win, const char *str, int n);
16 int mvaddstr(int y, int x, const char *str);
17 int mvaddnstr(int y, int x, const char *str, int n);
18 int mvwaddstr(WINDOW *win, int y, int x, const char *str);
19 int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
21 int addwstr(const wchar_t *wstr);
22 int addnwstr(const wchar_t *wstr, int n);
23 int waddwstr(WINDOW *win, const wchar_t *wstr);
24 int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
25 int mvaddwstr(int y, int x, const wchar_t *wstr);
26 int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
27 int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
28 int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
30 Description:
31 These routines write all the characters of the null-terminated
32 string str or wide-character string wstr to the given window.
33 The functionality is similar to calling waddch() once for each
34 character in the string; except that, when PDCurses is built
35 with wide-character support enabled, the narrow-character
36 functions treat the string as a multibyte string in the current
37 locale, and convert it. The routines with n as the last
38 argument write at most n characters; if n is negative, then the
39 entire string will be added.
41 Return Value:
42 All functions return OK or ERR.
44 Portability X/Open BSD SYS V
45 addstr Y Y Y
46 waddstr Y Y Y
47 mvaddstr Y Y Y
48 mvwaddstr Y Y Y
49 addnstr Y - 4.0
50 waddnstr Y - 4.0
51 mvaddnstr Y - 4.0
52 mvwaddnstr Y - 4.0
53 addwstr Y
54 waddwstr Y
55 mvaddwstr Y
56 mvwaddwstr Y
57 addnwstr Y
58 waddnwstr Y
59 mvaddnwstr Y
60 mvwaddnwstr Y
62 **man-end****************************************************************/
64 int waddnstr(WINDOW *win, const char *str, int n)
66 int i = 0;
68 PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));
70 if (!win || !str)
71 return ERR;
73 while (str[i] && (i < n || n < 0))
75 #ifdef PDC_WIDE
76 wchar_t wch;
77 int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);
79 if (retval <= 0)
80 return OK;
82 i += retval;
83 #else
84 chtype wch = (unsigned char)(str[i++]);
85 #endif
86 if (waddch(win, wch) == ERR)
87 return ERR;
90 return OK;
93 int addstr(const char *str)
95 PDC_LOG(("addstr() - called: string=\"%s\"\n", str));
97 return waddnstr(stdscr, str, -1);
100 int addnstr(const char *str, int n)
102 PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));
104 return waddnstr(stdscr, str, n);
107 int waddstr(WINDOW *win, const char *str)
109 PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));
111 return waddnstr(win, str, -1);
114 int mvaddstr(int y, int x, const char *str)
116 PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
118 if (move(y, x) == ERR)
119 return ERR;
121 return waddnstr(stdscr, str, -1);
124 int mvaddnstr(int y, int x, const char *str, int n)
126 PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
127 y, x, str, n));
129 if (move(y, x) == ERR)
130 return ERR;
132 return waddnstr(stdscr, str, n);
135 int mvwaddstr(WINDOW *win, int y, int x, const char *str)
137 PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));
139 if (wmove(win, y, x) == ERR)
140 return ERR;
142 return waddnstr(win, str, -1);
145 int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
147 PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
148 y, x, str, n));
150 if (wmove(win, y, x) == ERR)
151 return ERR;
153 return waddnstr(win, str, n);
156 #ifdef PDC_WIDE
157 int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
159 int i = 0;
161 PDC_LOG(("waddnwstr() - called\n"));
163 if (!win || !wstr)
164 return ERR;
166 while (wstr[i] && (i < n || n < 0))
168 chtype wch = wstr[i++];
170 if (waddch(win, wch) == ERR)
171 return ERR;
174 return OK;
177 int addwstr(const wchar_t *wstr)
179 PDC_LOG(("addwstr() - called\n"));
181 return waddnwstr(stdscr, wstr, -1);
184 int addnwstr(const wchar_t *wstr, int n)
186 PDC_LOG(("addnwstr() - called\n"));
188 return waddnwstr(stdscr, wstr, n);
191 int waddwstr(WINDOW *win, const wchar_t *wstr)
193 PDC_LOG(("waddwstr() - called\n"));
195 return waddnwstr(win, wstr, -1);
198 int mvaddwstr(int y, int x, const wchar_t *wstr)
200 PDC_LOG(("mvaddstr() - called\n"));
202 if (move(y, x) == ERR)
203 return ERR;
205 return waddnwstr(stdscr, wstr, -1);
208 int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
210 PDC_LOG(("mvaddnstr() - called\n"));
212 if (move(y, x) == ERR)
213 return ERR;
215 return waddnwstr(stdscr, wstr, n);
218 int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
220 PDC_LOG(("mvwaddstr() - called\n"));
222 if (wmove(win, y, x) == ERR)
223 return ERR;
225 return waddnwstr(win, wstr, -1);
228 int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
230 PDC_LOG(("mvwaddnstr() - called\n"));
232 if (wmove(win, y, x) == ERR)
233 return ERR;
235 return waddnwstr(win, wstr, n);
237 #endif