aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-23 02:51:08 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-23 03:05:01 +0200
commitcac1f8373bb16aae02ffa80acf8640385bf94591 (patch)
treea510a7786de636529d45a4ac008f3d751d067350
parentc0cc27c55517f9c3db2370819fc6bc81b80f2eee (diff)
downloadtermo-cac1f8373bb16aae02ffa80acf8640385bf94591.tar.gz
termo-cac1f8373bb16aae02ffa80acf8640385bf94591.tar.xz
termo-cac1f8373bb16aae02ffa80acf8640385bf94591.zip
Less code duplication
-rw-r--r--driver-ti.c44
1 files changed, 13 insertions, 31 deletions
diff --git a/driver-ti.c b/driver-ti.c
index ee9104a..bb7ef6e 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -304,13 +304,9 @@ abort_free_ti:
}
static int
-start_driver (termkey_t *tk, void *info)
+write_string (termkey_t *tk, char *string)
{
- termkey_ti_t *ti = info;
- char *start_string = ti->start_string;
- size_t len;
-
- if (tk->fd == -1 || !isatty (tk->fd) || !start_string)
+ if (tk->fd == -1 || !isatty (tk->fd) || !string)
return 1;
/* The terminfo database will contain keys in application cursor key mode.
@@ -318,44 +314,30 @@ start_driver (termkey_t *tk, void *info)
*/
// Can't call putp or tputs because they suck and don't give us fd control
- len = strlen (start_string);
+ size_t len = strlen (string);
while (len)
{
- ssize_t written = write (tk->fd, start_string, len);
+ ssize_t written = write (tk->fd, string, len);
if (written == -1)
return 0;
- start_string += written;
+ string += written;
len -= written;
}
return 1;
}
-// XXX: this is the same as above only with a different string
static int
-stop_driver (termkey_t *tk, void *info)
+start_driver (termkey_t *tk, void *info)
{
termkey_ti_t *ti = info;
- char *stop_string = ti->stop_string;
- size_t len;
-
- if (tk->fd == -1 || !isatty (tk->fd) || !stop_string)
- return 1;
-
- /* The terminfo database will contain keys in application cursor key mode.
- * We may need to enable that mode
- */
+ return write_string (tk, ti->start_string);
+}
- // Can't call putp or tputs because they suck and don't give us fd control
- len = strlen (stop_string);
- while (len)
- {
- ssize_t written = write (tk->fd, stop_string, len);
- if (written == -1)
- return 0;
- stop_string += written;
- len -= written;
- }
- return 1;
+static int
+stop_driver (termkey_t *tk, void *info)
+{
+ termkey_ti_t *ti = info;
+ return write_string (tk, ti->stop_string);
}
static void