]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_insstr.c
ncurses 4.1
[ncurses.git] / ncurses / lib_insstr.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
24 /*
25 **      lib_insstr.c
26 **
27 **      The routine winsnstr().
28 **
29 */
30
31 #include <curses.priv.h>
32 #include <ctype.h>
33
34 MODULE_ID("$Id: lib_insstr.c,v 1.9 1997/02/15 16:09:53 tom Exp $")
35
36 int winsnstr(WINDOW *win, const char *str, int n)
37 {
38 short   oy = win->_cury;
39 short   ox = win->_curx;
40 const char *cp;
41
42         T((T_CALLED("winsstr(%p,%s,%d)"), win, _nc_visbuf(str), n));
43
44         for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
45                 if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b')
46                         _nc_waddch_nosync(win, (chtype)(*cp));
47                 else if (is7bits(*cp) && iscntrl(*cp)) {
48                         winsch(win, ' ' + (chtype)(*cp));
49                         winsch(win, '^');
50                         win->_curx += 2;
51                 } else {
52                         winsch(win, (chtype)(*cp));
53                         win->_curx++;
54                 }
55                 if (win->_curx > win->_maxx)
56                         win->_curx = win->_maxx;
57         }
58
59         win->_curx = ox;
60         win->_cury = oy;
61         _nc_synchook(win);
62         returnCode(OK);
63 }