1 /* Public Domain Curses */
5 RCSID("$Id: addstr.c,v 1.44 2008/07/13 16:08:17 wmcbrine Exp $")
7 /*man-start**************************************************************
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);
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.
42 All functions return OK or ERR.
44 Portability X/Open BSD SYS V
62 **man-end****************************************************************/
64 int waddnstr(WINDOW
*win
, const char *str
, int n
)
68 PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str
, n
));
73 while (str
[i
] && (i
< n
|| n
< 0))
77 int retval
= PDC_mbtowc(&wch
, str
+ i
, n
>= 0 ? n
- i
: 6);
84 chtype wch
= (unsigned char)(str
[i
++]);
86 if (waddch(win
, wch
) == ERR
)
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
)
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",
129 if (move(y
, x
) == 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
)
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",
150 if (wmove(win
, y
, x
) == ERR
)
153 return waddnstr(win
, str
, n
);
157 int waddnwstr(WINDOW
*win
, const wchar_t *wstr
, int n
)
161 PDC_LOG(("waddnwstr() - called\n"));
166 while (wstr
[i
] && (i
< n
|| n
< 0))
168 chtype wch
= wstr
[i
++];
170 if (waddch(win
, wch
) == ERR
)
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
)
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
)
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
)
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
)
235 return waddnwstr(win
, wstr
, n
);