ncurses 4.1
[ncurses.git] / ncurses / lib_instr.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 **      lib_instr.c
25 **
26 **      The routine winnstr().
27 **
28 */
29
30 #include <curses.priv.h>
31
32 MODULE_ID("$Id: lib_instr.c,v 1.6 1997/05/03 10:51:07 juergen Exp $")
33
34 int winnstr(WINDOW *win, char *str, int n)
35 {
36         int     i, row, col;
37
38         T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n));
39
40         getyx(win, row, col);
41
42         if (n < 0)
43                 n = win->_maxx - win->_curx + 1;
44
45         for (i = 0; i < n;) {
46                 str[i++] = TextOf(win->_line[row].text[col]);
47                 if (++col > win->_maxx) {
48                         col = 0;
49                         if (++row > win->_maxy)
50                                 break;
51                 }
52         }
53         str[i] = '\0';  /* SVr4 does not seem to count the null */
54
55         returnCode(i);
56 }