Uninitialized vector entry?
[minix3.git] / lib / curses / waddch.c
blob780b26b21011897f9b3c0089521977aeea00d379
1 #include <curses.h>
2 #include "curspriv.h"
4 /****************************************************************/
5 /* Newline() does line advance and returns the new cursor line. */
6 /* If error, return -1. */
7 /****************************************************************/
9 _PROTOTYPE( static short newline, (WINDOW *win, int lin));
11 static short newline(win, lin)
12 WINDOW *win;
13 int lin;
15 if (++lin > win->_regbottom) {
16 lin--;
17 if (win->_scroll)
18 scroll(win);
19 else
20 return(-1);
21 } /* if */
22 return(lin);
23 } /* newline */
25 /****************************************************************/
26 /* Waddch() inserts character 'c' at the current cursor posi- */
27 /* Tion in window 'win', and takes any actions as dictated by */
28 /* The character. */
29 /****************************************************************/
31 int waddch(win, c)
32 WINDOW *win;
33 int c;
35 int x = win->_curx;
36 int y = win->_cury;
37 int newx;
38 int ch = c;
39 int ts = win->_tabsize;
41 ch &= (A_ALTCHARSET | 0xff);
42 if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) return(ERR);
43 switch (ch) {
44 case '\t':
45 for (newx = ((x / ts) + 1) * ts; x < newx; x++) {
46 if (waddch(win, ' ') == ERR) return(ERR);
47 if (win->_curx == 0) /* if tab to next line */
48 return(OK); /* exit the loop */
50 return(OK);
52 case '\n':
53 if (NONL) x = 0;
54 if ((y = newline(win, y)) < 0) return (ERR);
55 break;
57 case '\r': x = 0; break;
59 case '\b':
60 if (--x < 0) /* no back over left margin */
61 x = 0;
62 break;
64 case 0x7f:
66 if (waddch(win, '^') == ERR) return(ERR);
67 return(waddch(win, '?'));
70 default:
71 if (ch < ' ') { /* handle control chars */
72 if (waddch(win, '^') == ERR) return(ERR);
73 return(waddch(win, c + '@'));
75 ch |= (win->_attrs & ATR_MSK);
76 if (win->_line[y][x] != ch) { /* only if data change */
77 if (win->_minchng[y] == _NO_CHANGE)
78 win->_minchng[y] = win->_maxchng[y] = x;
79 else if (x < win->_minchng[y])
80 win->_minchng[y] = x;
81 else if (x > win->_maxchng[y])
82 win->_maxchng[y] = x;
83 } /* if */
84 win->_line[y][x++] = ch;
85 if (x > win->_maxx) { /* wrap around test */
86 x = 0;
87 if ((y = newline(win, y)) < 0) return(ERR);
89 break;
91 } /* switch */
92 win->_curx = x;
93 win->_cury = y;
94 return(OK);