aboutsummaryrefslogtreecommitdiff
path: root/local.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-11-08 10:39:52 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-11-08 10:39:52 +0000
commitf92243caa05a93e7def0f78c8de0880fd9b35d49 (patch)
tree1c3d45dd46624b5c607c0f9f7cfcfdbdd679efad /local.c
parent35591ecd4eccb96bb1c34909f3f463b09f1db7db (diff)
downloadrtmux-f92243caa05a93e7def0f78c8de0880fd9b35d49.tar.gz
rtmux-f92243caa05a93e7def0f78c8de0880fd9b35d49.tar.bz2
rtmux-f92243caa05a93e7def0f78c8de0880fd9b35d49.zip
Check for required term capabilities on start.
Diffstat (limited to 'local.c')
-rw-r--r--local.c82
1 files changed, 75 insertions, 7 deletions
diff --git a/local.c b/local.c
index c7c2e90d..62abab55 100644
--- a/local.c
+++ b/local.c
@@ -1,4 +1,4 @@
-/* $Id: local.c,v 1.17 2007-10-31 14:26:26 nicm Exp $ */
+/* $Id: local.c,v 1.18 2007-11-08 10:39:52 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -213,10 +213,32 @@ u_char local_colr;
int
local_init(struct buffer **in, struct buffer **out)
{
- char *tty;
- int mode;
- struct termios tio;
- struct local_key *lk;
+ char *tty;
+ int mode, error;
+ struct termios tio;
+ struct local_key *lk;
+ u_int i, j;
+ static const char *const reqd[] = {
+ "carriage_return",
+ "change_scroll_region",
+ "clear_screen",
+ "clr_bol",
+ "clr_eol",
+ "cursor_address",
+ "cursor_down",
+ "enter_ca_mode",
+ "exit_ca_mode",
+ "parm_dch",
+ "parm_delete_line",
+ "parm_down_cursor",
+ "parm_ich",
+ "parm_insert_line",
+ "parm_left_cursor",
+ "parm_right_cursor",
+ "parm_up_cursor",
+ "scroll_reverse",
+ NULL
+ };
if ((tty = ttyname(STDOUT_FILENO)) == NULL)
fatal("ttyname failed");
@@ -227,11 +249,57 @@ local_init(struct buffer **in, struct buffer **out)
if (fcntl(local_fd, F_SETFL, mode|O_NONBLOCK) == -1)
fatal("fcntl failed");
+ if (setupterm(NULL, STDOUT_FILENO, &error) != OK) {
+ switch (error) {
+ case 1:
+ log_warnx("hardcopy terminal cannot be used");
+ return (-1);
+ case 0:
+ log_warnx("terminal type not found or unsuitable");
+ return (-1);
+ case -1:
+ log_warnx("couldn't find terminfo database");
+ return (-1);
+ }
+ }
+ for (i = 0; reqd[i] != NULL; i++) {
+ error = 0;
+
+ for (j = 0; strfnames[j] != NULL; j++) {
+ if (strcmp(strfnames[j], reqd[i]) == 0) {
+ if (strcodes[j] == NULL)
+ error = -1;
+ break;
+ }
+ }
+ if (error != -1) {
+ for (j = 0; numfnames[j] != NULL; j++) {
+ if (strcmp(numfnames[j], reqd[i]) == 0) {
+ if (numcodes[j] == NULL)
+ error = -1;
+ break;
+ }
+ }
+ }
+ if (error != -1) {
+ for (j = 0; boolfnames[j] != NULL; j++) {
+ if (strcmp(boolfnames[j], reqd[i]) == 0) {
+ if (boolcodes[j] == NULL)
+ error = -1;
+ break;
+ }
+ }
+ }
+
+ if (error == -1) {
+ log_warnx("required capability missing: %s", reqd[i]);
+ return (-1);
+ }
+ }
+
*in = local_in = buffer_create(BUFSIZ);
*out = local_out = buffer_create(BUFSIZ);
- setupterm(NULL, STDOUT_FILENO, NULL);
-
if (tcgetattr(local_fd, &local_tio) != 0)
fatal("tcgetattr failed");
memset(&tio, 0, sizeof tio);