summaryrefslogtreecommitdiffstats
path: root/lib/libmytinfo/tgoto.c
blob: 1bc735b1f18aa4005183833ab0d65bfde091d189 (plain)
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
/*
 * tgoto.c
 *
 * By Ross Ridge
 * Public Domain
 * 92/02/01 07:30:33
 *
 * A few kludged attempts to worry outputing ^D's and NL's...
 * My advice is to get a decent terminal.
 *
 */

#include "defs.h"
#include <term.h>

#ifdef USE_SCCS_IDS
static const char SCCSid[] = "@(#) mytinfo tgoto.c 3.2 92/02/01 public domain, By Ross Ridge";
#endif

#ifdef USE_LITOUT_KLUDGE

/*
 * This kludge works by telling tputs to switch the tty driver to
 * "literal output" when printing the string so we don't have worry
 * about newlines and EOTs. The problem is that ioctls used to
 * switch modes might flush buffers and cause other problems.
 */


char *
tgoto(str, x, y)
char *str;
int x,y; {
	register char *sp;

	static char buf[MAX_LINE] = {'\\', '@'};

	sp = str = tparm(str, y, x);

	while (*sp != '\0') {
		if (*sp == '\004' || *sp == '\n') {
			strncpy(buf + 2, str, MAX_LINE - 2);
			buf[MAX_LINE - 2] = '\0';
			return buf;
		}
		sp++;
	}
	return sp;
}
#else

#ifdef USE_UPBC_KLUDGE

#ifdef USE_EXTERN_UPBC
extern char *BC, *UP;
#else
#define BC	cursor_left
#define UP	cursor_right
#endif

#ifdef __GNUC__
__inline__
#endif
static int
checkit(s)
register char *s; {
	while(*s != '\0') {
		if (*s == '\004' || *s == '\n')
			return 1;
		s++;
	}
	return 0;
}

/*
 * Major kludge, basically we just change the parmeters until we get
 * a string that doesn't contain a newline or EOT.
 */

char *
tgoto(str, x, y)
char *str;
int x,y; {
	static char buf[MAX_LINE];
	register char *orig, *s;
	int l;

	orig = tparm(str, y, x);

	if (!checkit(orig))
		return orig;

	s = tparm(str, y + 1, x);

	if (!checkit(s)) {
		if (BC == NULL)
			return s;
		l = strlen(s);
		strncpy(buf, s, MAX_LINE - 1);
		if (l < MAX_LINE - 1)
			strncpy(buf + l, BC, MAX_LINE - 1 - l);
		return s;
	}

	s = tparm(str, y, x + 1);

	if (!checkit(s)) {
		if (UP == NULL)
			return s;
		l = strlen(s);
		strncpy(buf, s, MAX_LINE - 1);
		if (l < MAX_LINE - 1)
			strncpy(buf + l, UP, MAX_LINE - 1 - l);
		return s;
	}

	s = tparm(str, y + 1, x + 1);

	if (!checkit(s)) {
		if (UP == NULL || BC == NULL)
			return s;
		l = strlen(s);
		strncpy(buf, s, MAX_LINE - 1);
		if (l < MAX_LINE - 1)
			strncpy(buf + l, UP, MAX_LINE - 1 - l);
		l += strlen(UP);
		if (l < MAX_LINE - 1)
			strncpy(buf + l, BC, MAX_LINE - 1 - l);
		return s;
	}

	return orig;
}

#else

/* the simple tgoto, don't worry about any of this newline/EOT crap */

char *
tgoto(str, x, y)
char *str;
int x,y; {
	return tparm(str, y, x);
}

#endif

#endif
OpenPOWER on IntegriCloud