aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2012-12-14 14:24:39 +1000
committerSteve Bennett <steveb@workware.net.au>2012-12-14 14:30:03 +1000
commitc75d1adc81d7fd1b9427aec8823859b881c34468 (patch)
tree383759474a44a20c2b30fe4b9de8502d18952d08
parentfe63bcdba4b63372a0aa18e1444cfdbc8621a881 (diff)
downloadjimtcl-c75d1adc81d7fd1b9427aec8823859b881c34468.zip
jimtcl-c75d1adc81d7fd1b9427aec8823859b881c34468.tar.gz
jimtcl-c75d1adc81d7fd1b9427aec8823859b881c34468.tar.bz2
Update linenoise.c to match recent github
From git://github.com/msteveb/linenoise.git Allow tab-completion only at the end of line Replace magic number 9 with '\t' in linenoisePrompt() Fix several warnings from gcc. Fix first-chance exceptions in Windows - WriteConsoleOutputCharacter() didn't have its final parameter set Add MSVC support - Test for _WIN32 to check for building for Windows.
-rw-r--r--linenoise.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/linenoise.c b/linenoise.c
index 281828b..a35ea12 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -102,18 +102,28 @@
* This support based in part on work by Jon Griffiths.
*/
-#ifdef __MINGW32__
+#ifdef _WIN32 /* Windows platform, either MinGW or Visual Studio (MSVC) */
#include <windows.h>
#include <fcntl.h>
#define USE_WINCONSOLE
+#ifdef __MINGW32__
+#define HAVE_UNISTD_H
+#else
+/* Microsoft headers don't like old POSIX names */
+#define strdup _strdup
+#define snprintf _snprintf
+#endif
#else
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#define USE_TERMIOS
+#define HAVE_UNISTD_H
#endif
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
@@ -121,7 +131,6 @@
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
-#include <unistd.h>
#include "linenoise.h"
@@ -522,7 +531,7 @@ static void clearScreen(struct current *current)
static void cursorToLeft(struct current *current)
{
- COORD pos = { 0, current->y };
+ COORD pos = { 0, (SHORT)current->y };
DWORD n;
FillConsoleOutputAttribute(current->outh,
@@ -532,15 +541,17 @@ static void cursorToLeft(struct current *current)
static int outputChars(struct current *current, const char *buf, int len)
{
- COORD pos = { current->x, current->y };
- WriteConsoleOutputCharacter(current->outh, buf, len, pos, 0);
+ COORD pos = { (SHORT)current->x, (SHORT)current->y };
+ DWORD n;
+
+ WriteConsoleOutputCharacter(current->outh, buf, len, pos, &n);
current->x += len;
return 0;
}
static void outputControlChar(struct current *current, char ch)
{
- COORD pos = { current->x, current->y };
+ COORD pos = { (SHORT)current->x, (SHORT)current->y };
DWORD n;
FillConsoleOutputAttribute(current->outh, BACKGROUND_INTENSITY, 2, pos, &n);
@@ -550,7 +561,7 @@ static void outputControlChar(struct current *current, char ch)
static void eraseEol(struct current *current)
{
- COORD pos = { current->x, current->y };
+ COORD pos = { (SHORT)current->x, (SHORT)current->y };
DWORD n;
FillConsoleOutputCharacter(current->outh, ' ', current->cols - current->x, pos, &n);
@@ -558,7 +569,7 @@ static void eraseEol(struct current *current)
static void setCursorPos(struct current *current, int x)
{
- COORD pos = { x, current->y };
+ COORD pos = { (SHORT)x, (SHORT)current->y };
SetConsoleCursorPosition(current->outh, pos);
current->x = x;
@@ -949,7 +960,7 @@ static int linenoisePrompt(struct current *current) {
/* Only autocomplete when the callback is set. It returns < 0 when
* there was an error reading from fd. Otherwise it will return the
* character that should be handled next. */
- if (c == 9 && completionCallback != NULL) {
+ if (c == '\t' && current->pos == current->chars && completionCallback != NULL) {
c = completeLine(current);
/* Return on errors */
if (c < 0) return current->len;