]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_addstr.c
ncurses 4.1
[ncurses.git] / ncurses / lib_addstr.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23 **      lib_addstr.c
24 *
25 **      The routines waddnstr(), waddchnstr().
26 **
27 */
28
29 #include <curses.priv.h>
30
31 MODULE_ID("$Id: lib_addstr.c,v 1.11 1997/03/08 21:38:52 tom Exp $")
32
33 int
34 waddnstr(WINDOW *win, const char *const astr, int n)
35 {
36 unsigned const char *str = (unsigned const char *)astr;
37 int code = ERR;
38
39         T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n));
40         T(("... current %s", _traceattr(win->_attrs)));
41
42         if (str != 0) {
43
44                 TR(TRACE_VIRTPUT, ("str is not null"));
45                 code = OK;
46                 if (n < 0)
47                         n = (int)strlen(astr);
48
49                 while((n-- > 0) && (*str != '\0')) {
50                         TR(TRACE_VIRTPUT, ("*str = %#x", *str));
51                         if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) {
52                                 code = ERR;
53                                 break;
54                         }
55                 }
56         }
57         _nc_synchook(win);
58         TR(TRACE_VIRTPUT, ("waddnstr returns %d", code));
59         returnCode(code);
60 }
61
62 int
63 waddchnstr(WINDOW *win, const chtype *const astr, int n)
64 {
65 short oy = win->_cury;
66 short ox = win->_curx;
67 const chtype *str = (const chtype *)astr;
68 int code = OK;
69
70         T((T_CALLED("waddchnstr(%p,%p,%d)"), win, str, n));
71
72         if (n < 0) {
73                 n = 0;
74                 while (*str++ != 0)
75                         n++;
76                 str = (const chtype *)astr;
77         }
78
79         while(n-- > 0) {
80                 if (_nc_waddch_nosync(win, *str++) == ERR) {
81                         code = ERR;
82                         break;
83                 }
84         }
85
86         win->_curx = ox;
87         win->_cury = oy;
88         _nc_synchook(win);
89         returnCode(code);
90 }