source: trunk/minix/lib/curses/waddch.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.2 KB
Line 
1#include <curses.h>
2#include "curspriv.h"
3
4/****************************************************************/
5/* Newline() does line advance and returns the new cursor line. */
6/* If error, return -1. */
7/****************************************************************/
8
9_PROTOTYPE( static short newline, (WINDOW *win, int lin));
10
11static short newline(win, lin)
12WINDOW *win;
13int lin;
14{
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 */
24
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/****************************************************************/
30
31int waddch(win, c)
32WINDOW *win;
33int c;
34{
35 int x = win->_curx;
36 int y = win->_cury;
37 int newx;
38 int ch = c;
39 int ts = win->_tabsize;
40
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 */
49 }
50 return(OK);
51
52 case '\n':
53 if (NONL) x = 0;
54 if ((y = newline(win, y)) < 0) return (ERR);
55 break;
56
57 case '\r': x = 0; break;
58
59 case '\b':
60 if (--x < 0) /* no back over left margin */
61 x = 0;
62 break;
63
64 case 0x7f:
65 {
66 if (waddch(win, '^') == ERR) return(ERR);
67 return(waddch(win, '?'));
68 }
69
70 default:
71 if (ch < ' ') { /* handle control chars */
72 if (waddch(win, '^') == ERR) return(ERR);
73 return(waddch(win, c + '@'));
74 }
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);
88 }
89 break;
90
91 } /* switch */
92 win->_curx = x;
93 win->_cury = y;
94 return(OK);
95}
Note: See TracBrowser for help on using the repository browser.