kern

view src/term.c @ 73:b4b7198986a6

fixed a potential null dereference when deleting a bug in the redblack tree
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Oct 2011 08:06:10 +0300
parents 06172322fb76
children
line source
1 #include <ctype.h>
2 #include "term.h"
3 #include "vid.h"
4 #include "intr.h"
6 static int bg, fg = LTGRAY;
7 static int cursor_x, cursor_y;
9 /* sets the active text color and returns previous value */
10 int set_text_color(int c)
11 {
12 int prev = fg;
14 if(c >= 0 && c < 16) {
15 fg = c;
16 }
17 return prev;
18 }
20 /* sets the active background color and returns the current value */
21 int set_back_color(int c)
22 {
23 int prev = bg;
25 if(c >= 0 && c < 16) {
26 bg = c;
27 }
28 return prev;
29 }
31 /* output a single character, handles formatting, cursor advancement
32 * and scrolling the screen when we reach the bottom.
33 */
34 int putchar(int c)
35 {
36 int istate = get_intr_state();
37 disable_intr();
39 switch(c) {
40 case '\n':
41 cursor_y++;
43 case '\r':
44 cursor_x = 0;
45 break;
47 case '\b':
48 cursor_x--;
49 set_char(' ', cursor_x, cursor_y, fg, bg);
50 break;
52 case '\t':
53 cursor_x = ((cursor_x >> 3) + 1) << 3;
54 break;
56 default:
57 if(isprint(c)) {
58 set_char(c, cursor_x, cursor_y, fg, bg);
59 if(++cursor_x >= WIDTH) {
60 cursor_x = 0;
61 cursor_y++;
62 }
63 }
64 }
66 if(cursor_y >= HEIGHT) {
67 scroll_scr();
68 cursor_y--;
69 }
71 set_cursor(cursor_x, cursor_y);
73 set_intr_state(istate);
74 return c;
75 }