File: dumbterm.c

package info (click to toggle)
vile 9.4-s1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 10,448 kB
  • ctags: 7,909
  • sloc: ansic: 85,708; lex: 7,137; sh: 2,992; perl: 2,926; cpp: 2,869; makefile: 750; awk: 271
file content (152 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*	Dumb terminal driver, for I/O before we get into screen mode.
 *
 * $Header: /usr/build/vile/vile/RCS/dumbterm.c,v 1.18 2004/06/09 01:08:56 tom Exp $
 *
 */

#include	"estruct.h"
#include	"edef.h"

#define NPAUSE	10		/* # times thru update to pause */

static int this_col;
static int last_col;

static void
flush_blanks(void)
{
    if (last_col > 0) {
	while (last_col++ < this_col)
	    (void) putchar(' ');
	last_col = 0;
    }
    term.flush();
}

static void
dumb_kopen(void)
{
}

static void
dumb_kclose(void)
{
}

static int
dumb_getc(void)
{
    flush_blanks();
    return getchar();
}

static OUTC_DCL
dumb_putc(OUTC_ARGS)
{
    if (isSpace(c)) {
	if (last_col == 0)
	    last_col = this_col;
    } else {
	flush_blanks();
	(void) putchar(c);
    }
    this_col++;
    OUTC_RET c;
}

static int
dumb_typahead(void)
{
    return TRUE;
}

static void
dumb_flush(void)
{
    (void) fflush(stdout);
}

/*ARGSUSED*/
static void
dumb_move(int row GCC_UNUSED, int col)
{
    if (last_col == 0)
	last_col = this_col;
    if (col == 0) {
	putchar('\r');
	if (last_col != 0)
	    putchar('\n');
    } else if (last_col > col) {
	while (last_col-- > col)
	    putchar('\b');
    } else if (last_col < col) {
	while (last_col++ < col)
	    putchar(' ');
    }
    last_col = 0;
    this_col = col;
}

static void
dumb_eeol(void)
{
}

static void
dumb_eeop(void)
{
}

/*ARGSUSED*/
static int
dumb_cres(			/* change screen resolution */
	     const char *res GCC_UNUSED)
{
    return (FALSE);
}

/* ARGSUSED */
static void
dumb_rev(UINT state GCC_UNUSED)
{
}

static void
dumb_beep(void)
{
    putchar(BEL);
}

TERM dumb_term =
{
    1,
    1,
    80,
    80,
    NPAUSE,
    0,				/* use this to put us into raw mode */
    0,				/* ...and this, just in case we exit */
    dumb_kopen,
    dumb_kclose,
    dumb_getc,
    dumb_putc,
    dumb_typahead,
    dumb_flush,
    dumb_move,
    dumb_eeol,
    dumb_eeop,
    dumb_beep,
    dumb_rev,
    dumb_cres,
    nullterm_setfore,
    nullterm_setback,
    nullterm_setpal,
    nullterm_setccol,
    nullterm_scroll,
    nullterm_pflush,
    nullterm_icursor,
    nullterm_settitle,
    nullterm_watchfd,
    nullterm_unwatchfd,
    nullterm_cursorvis,
};