aboutsummaryrefslogtreecommitdiff
path: root/term.c
diff options
context:
space:
mode:
Diffstat (limited to 'term.c')
-rw-r--r--term.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/term.c b/term.c
index dfbe30ef0d5a..6eafd9f6010d 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.32 2001/01/23 15:55:31 jdolecek Exp $ */
+/* $NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -36,12 +32,12 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#include "config.h"
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: term.c,v 1.32 2001/01/23 15:55:31 jdolecek Exp $");
+__RCSID("$NetBSD: term.c,v 1.40 2004/05/22 23:21:28 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -50,13 +46,24 @@ __RCSID("$NetBSD: term.c,v 1.32 2001/01/23 15:55:31 jdolecek Exp $");
* We have to declare a static variable here, since the
* termcap putchar routine does not take an argument!
*/
-#include "sys.h"
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+#ifdef HAVE_TERMCAP_H
#include <termcap.h>
+#endif
+#ifdef HAVE_CURSES_H
+#include <curses.h>
+#endif
+#ifdef HAVE_NCURSES_H
+#include <ncurses.h>
+#endif
+/* Solaris's term.h does horrid things. */
+#if (defined(HAVE_TERM_H) && !defined(SUNOS))
+#include <term.h>
+#endif
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -261,7 +268,7 @@ private void term_setflags(EditLine *);
private int term_rebuffer_display(EditLine *);
private void term_free_display(EditLine *);
private int term_alloc_display(EditLine *);
-private void term_alloc(EditLine *, const struct termcapstr *, char *);
+private void term_alloc(EditLine *, const struct termcapstr *, const char *);
private void term_init_arrow(EditLine *);
private void term_reset_arrow(EditLine *);
@@ -341,11 +348,11 @@ term_init(EditLine *el)
return (-1);
(void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
term_outfile = el->el_outfile;
- if (term_set(el, NULL) == -1)
- return (-1);
+ (void) term_set(el, NULL);
term_init_arrow(el);
return (0);
}
+
/* term_end():
* Clean up the terminal stuff
*/
@@ -362,6 +369,8 @@ term_end(EditLine *el)
el->el_term.t_str = NULL;
el_free((ptr_t) el->el_term.t_val);
el->el_term.t_val = NULL;
+ el_free((ptr_t) el->el_term.t_fkey);
+ el->el_term.t_fkey = NULL;
term_free_display(el);
}
@@ -370,7 +379,7 @@ term_end(EditLine *el)
* Maintain a string pool for termcap strings
*/
private void
-term_alloc(EditLine *el, const struct termcapstr *t, char *cap)
+term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
{
char termbuf[TC_BUFSIZE];
int tlen, clen;
@@ -638,7 +647,8 @@ mc_again:
* from col 0
*/
if (EL_CAN_TAB ?
- (-del > (((unsigned int) where >> 3) +
+ ((unsigned int)-del >
+ (((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
term__putc('\r'); /* do a CR */
@@ -658,7 +668,7 @@ mc_again:
* Overstrike num characters
*/
protected void
-term_overwrite(EditLine *el, char *cp, int n)
+term_overwrite(EditLine *el, const char *cp, int n)
{
if (n <= 0)
return; /* catch bugs */
@@ -866,12 +876,18 @@ term_clear_to_bottom(EditLine *el)
}
#endif
+protected void
+term_get(EditLine *el, const char **term)
+{
+ *term = el->el_term.t_name;
+}
+
/* term_set():
* Read in the terminal capabilities from the requested terminal
*/
protected int
-term_set(EditLine *el, char *term)
+term_set(EditLine *el, const char *term)
{
int i;
char buf[TC_BUFSIZE];
@@ -927,8 +943,11 @@ term_set(EditLine *el, char *term)
/* Get the size */
Val(T_co) = tgetnum("co");
Val(T_li) = tgetnum("li");
- for (t = tstr; t->name != NULL; t++)
- term_alloc(el, t, tgetstr(t->name, &area));
+ for (t = tstr; t->name != NULL; t++) {
+ /* XXX: some systems tgetstr needs non const */
+ term_alloc(el, t, tgetstr(strchr(t->name, *t->name),
+ &area));
+ }
}
if (Val(T_co) < 2)
@@ -947,6 +966,7 @@ term_set(EditLine *el, char *term)
return (-1);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
term_bind_arrow(el);
+ el->el_term.t_name = term;
return (i <= 0 ? -1 : 0);
}
@@ -1102,7 +1122,7 @@ term_reset_arrow(EditLine *el)
* Set an arrow key binding
*/
protected int
-term_set_arrow(EditLine *el, char *name, key_value_t *fun, int type)
+term_set_arrow(EditLine *el, const char *name, key_value_t *fun, int type)
{
fkey_t *arrow = el->el_term.t_fkey;
int i;
@@ -1121,7 +1141,7 @@ term_set_arrow(EditLine *el, char *name, key_value_t *fun, int type)
* Clear an arrow key binding
*/
protected int
-term_clear_arrow(EditLine *el, char *name)
+term_clear_arrow(EditLine *el, const char *name)
{
fkey_t *arrow = el->el_term.t_fkey;
int i;
@@ -1139,7 +1159,7 @@ term_clear_arrow(EditLine *el, char *name)
* Print the arrow key bindings
*/
protected void
-term_print_arrow(EditLine *el, char *name)
+term_print_arrow(EditLine *el, const char *name)
{
int i;
fkey_t *arrow = el->el_term.t_fkey;
@@ -1236,7 +1256,8 @@ term__flush(void)
*/
protected int
/*ARGSUSED*/
-term_telltc(EditLine *el, int argc, char **argv)
+term_telltc(EditLine *el, int argc __attribute__((__unused__)),
+ const char **argv __attribute__((__unused__)))
{
const struct termcapstr *t;
char **ts;
@@ -1271,11 +1292,12 @@ term_telltc(EditLine *el, int argc, char **argv)
*/
protected int
/*ARGSUSED*/
-term_settc(EditLine *el, int argc, char **argv)
+term_settc(EditLine *el, int argc __attribute__((__unused__)),
+ const char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
- char *what, *how;
+ const char *what, *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
@@ -1347,7 +1369,8 @@ term_settc(EditLine *el, int argc, char **argv)
*/
protected int
/*ARGSUSED*/
-term_echotc(EditLine *el, int argc, char **argv)
+term_echotc(EditLine *el, int argc __attribute__((__unused__)),
+ const char **argv)
{
char *cap, *scap, *ep;
int arg_need, arg_cols, arg_rows;
@@ -1406,7 +1429,7 @@ term_echotc(EditLine *el, int argc, char **argv)
}
(void) fprintf(el->el_outfile, fmtd, 0);
#else
- (void) fprintf(el->el_outfile, fmtd, el->el_tty.t_speed);
+ (void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
#endif
return (0);
} else if (strcmp(*argv, "rows") == 0 || strcmp(*argv, "lines") == 0) {
@@ -1425,8 +1448,10 @@ term_echotc(EditLine *el, int argc, char **argv)
scap = el->el_term.t_str[t - tstr];
break;
}
- if (t->name == NULL)
- scap = tgetstr(*argv, &area);
+ if (t->name == NULL) {
+ /* XXX: some systems tgetstr needs non const */
+ scap = tgetstr(strchr(*argv, **argv), &area);
+ }
if (!scap || scap[0] == '\0') {
if (!silent)
(void) fprintf(el->el_errfile,