aboutsummaryrefslogtreecommitdiff
path: root/third-party/patches/libtermkey-Add-support-for-Windows.patch
blob: b839e94d0589dfebd894d3c1adbd129ac3b42133 (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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From fbe91a958816d85fa93665eb8f7a7a8e05eb9650 Mon Sep 17 00:00:00 2001
From: Rui Abreu Ferreira <raf-ep@gmx.com>
Date: Tue, 5 Apr 2016 00:12:41 +0100
Subject: [PATCH] Add support for Windows

Ported termkey for windows.

- The TERMKEY_FLAG_NOTERMIOS is ignore in Windows, since there is no termios.
- The termkey_waitkey() function is not implemented in windows, since there
  is no poll() alternative.
- The CMake recipe only supports unibilium, not curses.
---
 driver-ti.c        |  8 +++++++-
 termkey-internal.h | 11 ++++++++++-
 termkey.c          | 22 ++++++++++++++++++----
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/driver-ti.c b/driver-ti.c
index e673ab7..f5f8052 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -17,7 +17,9 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
+#ifndef _WIN32
+# include <unistd.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -338,8 +340,10 @@ static int start_driver(TermKey *tk, void *info)
   if(fstat(tk->fd, &statbuf) == -1)
     return 0;
 
+#ifndef _WIN32
   if(S_ISFIFO(statbuf.st_mode))
     return 1;
+#endif
 
   // Can't call putp or tputs because they suck and don't give us fd control
   len = strlen(start_string);
@@ -367,8 +371,10 @@ static int stop_driver(TermKey *tk, void *info)
   if(fstat(tk->fd, &statbuf) == -1)
     return 0;
 
+#ifndef _WIN32
   if(S_ISFIFO(statbuf.st_mode))
     return 1;
+#endif
 
   /* The terminfo database will contain keys in application cursor key mode.
    * We may need to enable that mode
diff --git a/termkey-internal.h b/termkey-internal.h
index 52829b3..b796729 100644
--- a/termkey-internal.h
+++ b/termkey-internal.h
@@ -4,7 +4,14 @@
 #include "termkey.h"
 
 #include <stdint.h>
-#include <termios.h>
+#ifndef _WIN32
+# include <termios.h>
+#endif
+
+#ifdef _MSC_VER
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
 
 struct TermKeyDriver
 {
@@ -41,8 +48,10 @@ struct TermKey {
   size_t hightide; /* Position beyond buffstart at which peekkey() should next start
                     * normally 0, but see also termkey_interpret_csi */
 
+#ifndef _WIN32
   struct termios restore_termios;
   char restore_termios_valid;
+#endif
 
   TermKey_Terminfo_Getstr_Hook *ti_getstr_hook;
   void *ti_getstr_hook_data;
diff --git a/termkey.c b/termkey.c
index 2f01f3a..145b99f 100644
--- a/termkey.c
+++ b/termkey.c
@@ -3,14 +3,20 @@
 
 #include <ctype.h>
 #include <errno.h>
-#include <poll.h>
-#include <unistd.h>
+#ifndef _WIN32
+# include <poll.h>
+# include <unistd.h>
+# include <strings.h>
+#endif
 #include <string.h>
-#include <strings.h>
 
 #include <stdio.h>
 
-#define strcaseeq(a,b) (strcasecmp(a,b) == 0)
+#ifdef _MSC_VER
+# define strcaseeq(a,b) (_stricmp(a,b) == 0)
+#else
+# define strcaseeq(a,b) (strcasecmp(a,b) == 0)
+#endif
 
 void termkey_check_version(int major, int minor)
 {
@@ -282,7 +288,9 @@ static TermKey *termkey_alloc(void)
   tk->buffsize  = 256; /* bytes */
   tk->hightide  = 0;
 
+#ifndef _WIN32
   tk->restore_termios_valid = 0;
+#endif
 
   tk->ti_getstr_hook = NULL;
   tk->ti_getstr_hook_data = NULL;
@@ -483,6 +491,7 @@ int termkey_start(TermKey *tk)
   if(tk->is_started)
     return 1;
 
+#ifndef _WIN32
   if(tk->fd != -1 && !(tk->flags & TERMKEY_FLAG_NOTERMIOS)) {
     struct termios termios;
     if(tcgetattr(tk->fd, &termios) == 0) {
@@ -517,6 +526,7 @@ int termkey_start(TermKey *tk)
       tcsetattr(tk->fd, TCSANOW, &termios);
     }
   }
+#endif
 
   struct TermKeyDriverNode *p;
   for(p = tk->drivers; p; p = p->next)
@@ -542,8 +552,10 @@ int termkey_stop(TermKey *tk)
     if(p->driver->stop_driver)
       (*p->driver->stop_driver)(tk, p->info);
 
+#ifndef _WIN32
   if(tk->restore_termios_valid)
     tcsetattr(tk->fd, TCSANOW, &tk->restore_termios);
+#endif
 
   tk->is_started = 0;
 
@@ -1046,6 +1058,7 @@ TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key)
   return ret;
 }
 
+#ifndef _WIN32
 TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key)
 {
   if(tk->fd == -1) {
@@ -1105,6 +1118,7 @@ retry:
 
   /* UNREACHABLE */
 }
+#endif
 
 TermKeyResult termkey_advisereadable(TermKey *tk)
 {
-- 
2.16.1.windows.4