summaryrefslogtreecommitdiff
path: root/news/nget/files/patch-termstuff.cc
blob: a47ae652366432ba62cc6002cbdc55e731dd095d (plain) (blame)
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
--- termstuff.cc	2004-05-29 16:00:07.000000000 -0700
+++ termstuff.cc	2008-03-02 23:38:19.000000000 -0800
@@ -23,7 +23,15 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#ifdef HAVE_WORKING_TERMSTUFF
+#ifdef HAVE_NETBSD_CURSES
+#include <termcap.h>
+static struct tinfo *info;
+static char *clr_bol;
+static void my_putchar(char c, void *d) { putchar((int)c); }
+#elif HAVE_NEW_CURSES
+#include <term.h>
+#elif HAVE_OLD_CURSES
+#include <curses.h>
 #include <term.h>
 #endif
 
@@ -32,15 +40,22 @@
 //Fake clr_bol function incase we can't use termcap.  Assumes that we will be
 //writing another line of near the same length after clearing, thus we don't
 //really need to clear the whole line, only the end of it.
-void generic_clr_bol(void) {
+static void generic_clr_bol(void) {
 	printf("\b\b\b\b    ");
 }
 
-voidfunc *clr_bol_func = generic_clr_bol;
+static voidfunc *clr_bol_func = generic_clr_bol;
 
-#ifdef HAVE_WORKING_TERMSTUFF
-void tputs_clr_bol(void) {
-	if (tputs(clr_bol, 1, putchar)<0) {
+#if defined(HAVE_NETBSD_CURSES) || defined(HAVE_NEW_CURSES) || defined(HAVE_OLD_CURSES)
+static void tputs_clr_bol(void) {
+# ifdef HAVE_NETBSD_CURSES
+	if (t_puts(info, clr_bol, 1, my_putchar, NULL)<0)
+# elif HAVE_NEW_CURSES
+	if (tputs(clr_bol, 1, putchar)<0)
+# elif HAVE_OLD_CURSES
+	if (putp(clr_bol)<0)
+# endif 
+	{
 		generic_clr_bol();
 		PDEBUG(DEBUG_MIN, "tputs_clr_bol: error");
 	}
@@ -48,18 +63,38 @@
 #endif
 
 void init_term_stuff(void) {
-#ifdef HAVE_WORKING_TERMSTUFF
+#if defined(HAVE_NETBSD_CURSES) || defined(HAVE_NEW_CURSES) || defined(HAVE_OLD_CURSES)
+# ifdef HAVE_NEW_CURSES
 	char tbuf[1024];
+# elif HAVE_OLD_CURSES
+	int err;
+# endif
 	char *term = getenv("TERM");
 	if (!term){
 		PDEBUG(DEBUG_MIN, "init_term_stuff: TERM env not set");
 		return;
 	}
-	if (tgetent(tbuf, term) != 1){
+# ifdef HAVE_NETBSD_CURSES
+	if (t_getent(&info, term) != 1) {
+		PDEBUG(DEBUG_MIN, "init_term_stuff: t_getent failure");
+		return;
+	}
+	if (!(clr_bol = t_agetstr(info, "ce"))) {
+		PDEBUG(DEBUG_MIN, "init_term_stuff: t_agetstr failure");
+		return;
+	}
+# elif HAVE_NEW_CURSES
+	if (tgetent(tbuf, term) != 1) {
 		PDEBUG(DEBUG_MIN, "init_term_stuff: tgetent failure");
-//		err(2, "tgetent failure");
 		return;
 	}
+# else /* HAVE_OLD_CURSES */
+       setupterm(term, 1, &err);
+       if (err != 1) {
+		PDEBUG(DEBUG_MIN, "init_term_stuff: setupterm failure");
+		return;
+	}
+# endif
 	clr_bol_func = tputs_clr_bol;
 	PDEBUG(DEBUG_MIN, "init_term_stuff: using tputs_clr_bol");
 #else