patch 8.0.0769: build problems with terminal on MS-Windows

Problem:    Build problems with terminal on MS-Windows using MSVC.
Solution:   Remove stdbool.h dependency. Only use ScreenLinesUC when it was
            allocated. Fix typos. (Ken Takata)
diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt
index 4fc119c..73bcf99 100644
--- a/runtime/doc/terminal.txt
+++ b/runtime/doc/terminal.txt
@@ -1,4 +1,4 @@
-*terminal.txt*	For Vim version 8.0.  Last change: 2017 Jul 19
+*terminal.txt*	For Vim version 8.0.  Last change: 2017 Jul 24
 
 
 		  VIM REFERENCE MANUAL	  by Bram Moolenaar
@@ -47,8 +47,9 @@
 (TODO: scrolling when the terminal is larger than the window)
 
 Syntax ~
-						*:ter* *:terminal*
-:terminal[!] [command]	Open a new terminal window.
+
+:ter[minal][!] [command]			*:ter* *:terminal*
+			Open a new terminal window.
 
 			If [command] is provided run it as a job and connect
 			the input and output to the terminal.
@@ -79,7 +80,7 @@
    The minimal size is 2 screen lines with 10 cells.
 
 2. The 'termsize' option is "rows*cols", where "rows" is the minimal number of
-   screen rows and "cols" is the minial number of cells.
+   screen rows and "cols" is the minimal number of cells.
 
 3. The 'termsize' option is "rowsXcols" (where the x is upper or lower case).
    The terminal size is fixed to the specified number of screen lines and
@@ -101,9 +102,20 @@
 
 MS-Windows ~
 
-On MS-Windows a hidden console is used to run the command in.  This should
-work well for all kind of commands.  Obviously, they must be commands that run
-in a terminal, not open their own window.
+On MS-Windows winpty is used to make it possible to run all kind of commands.
+Obviously, they must be commands that run in a terminal, not open their own
+window.
+
+You need the following two files from winpty:
+
+    winpty.dll
+    winpty-agent.exe
+
+You can download them from the following page:
+
+    https://github.com/rprichard/winpty
+
+Just put the files somewhere in your PATH.
 
 ==============================================================================
 2. Remote testing					*terminal-testing*
diff --git a/src/INSTALLpc.txt b/src/INSTALLpc.txt
index b875b77..762fdb6 100644
--- a/src/INSTALLpc.txt
+++ b/src/INSTALLpc.txt
@@ -706,20 +706,17 @@
 13. Building with Terminal support
 ==================================
 
-Vim with Terminal support can be built with either MSVC, or MinGW or Cygwin.
+Vim with Terminal support can be built with either MSVC, MinGW or Cygwin.
 This uses the included libvterm and winpty.  No extra header files or
-libraries are needed for building.
+libraries are needed for building.  Just set TERMINAL to yes.
 
-Running Vim with terminal support requires the following two winpty files:
+E.g. When using MSVC:
 
-    winpty.dll
-    winpty-agent.dll
+    nmake -f Make_mvc.mak TERMINAL=yes
 
-You can download them from the following page:
+Or when using MinGW (as one line):
 
-    https://github.com/rprichard/winpty
-
-Just put the DLL files somewhere in your PATH.
+    mingw32-make -f Make_mingw.mak TERMINAL=yes
 
 
 14. Windows 3.1x
diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak
index 0f6a492..a7bf3b9 100644
--- a/src/Make_cyg_ming.mak
+++ b/src/Make_cyg_ming.mak
@@ -73,6 +73,7 @@
 else
 CHANNEL=$(GUI)
 endif
+# Set to yes to enable terminal support.
 TERMINAL=no
 
 
diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak
index 99dcb29..d51d976 100644
--- a/src/Make_mvc.mak
+++ b/src/Make_mvc.mak
@@ -356,6 +356,9 @@
 !if "$(TERMINAL)" == "yes"
 TERMINAL_OBJ   = $(OBJDIR)/terminal.obj
 TERMINAL_DEFS  = -DFEAT_TERMINAL
+!if $(MSVC_MAJOR) <= 11
+TERMINAL_DEFS = $(TERMINAL_DEFS) /I if_perl_msvc
+!endif
 TERMINAL_SRC   = terminal.c
 VTERM_LIB      = libvterm/vterm.lib
 !endif
@@ -1154,7 +1157,7 @@
 
 $(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \
 		$(LUA_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) $(TCL_OBJ) \
-		$(CSCOPE_OBJ) $(TERMINAL_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) \
+		$(CSCOPE_OBJ) $(TERMINAL_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) $(VTERM_LIB) \
 		version.c version.h
 	$(CC) $(CFLAGS) version.c
 	$(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) \
@@ -1549,7 +1552,7 @@
 
 libvterm/vterm.lib :
 	cd libvterm
-	$(MAKE) /NOLOGO -f Makefile.msc
+	$(MAKE) /NOLOGO -f Makefile.msc "MSVC_MAJOR=$(MSVC_MAJOR)"
 	cd ..
 
 # vim: set noet sw=8 ts=8 sts=0 wm=0 tw=0:
diff --git a/src/libvterm/Makefile.msc b/src/libvterm/Makefile.msc
index 18280d2..c2313ba 100644
--- a/src/libvterm/Makefile.msc
+++ b/src/libvterm/Makefile.msc
@@ -1,3 +1,5 @@
+CFLAGS = /DINLINE= /Iinclude
+
 OBJS = \
 	src\encoding.c \
 	src\keyboard.c \
@@ -24,7 +26,10 @@
 
 
 .c.obj :
-	cl /DINLINE= /Iinclude /Fo$@ /c $<
+	cl $(CFLAGS) /Fo$@ /c $<
 
 vterm.lib : $(OBJS)
 	lib /OUT:$@ $(OBJS)
+
+clean:
+	del $(OBJS) vterm.lib
diff --git a/src/libvterm/bin/vterm-ctrl.c b/src/libvterm/bin/vterm-ctrl.c
index 14e35cd..2568ee6 100644
--- a/src/libvterm/bin/vterm-ctrl.c
+++ b/src/libvterm/bin/vterm-ctrl.c
@@ -1,10 +1,11 @@
 #define _XOPEN_SOURCE 500  /* strdup */
 
-#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #define streq(a,b) (strcmp(a,b)==0)
+#define TRUE 1
+#define FALSE 0
 
 #include <termios.h>
 
@@ -60,13 +61,14 @@
   NULL
 };
 
-static bool seticanon(bool icanon, bool echo)
+static int seticanon(int icanon, int echo)
 {
   struct termios termios;
+  int ret;
 
   tcgetattr(0, &termios);
 
-  bool ret = (termios.c_lflag & ICANON);
+  ret = (termios.c_lflag & ICANON);
 
   if(icanon) termios.c_lflag |=  ICANON;
   else       termios.c_lflag &= ~ICANON;
@@ -84,16 +86,16 @@
   int c;
 
   /* await CSI - 8bit or 2byte 7bit form */
-  bool in_esc = false;
+  int in_esc = FALSE;
   while((c = getchar())) {
     if(c == c1)
       break;
     if(in_esc && c == (char)(c1 - 0x40))
       break;
     if(!in_esc && c == 0x1b)
-      in_esc = true;
+      in_esc = TRUE;
     else
-      in_esc = false;
+      in_esc = FALSE;
   }
 }
 
@@ -121,7 +123,7 @@
 static char *read_dcs()
 {
   unsigned char dcs[32];
-  bool in_esc = false;
+  int in_esc = FALSE;
   int i;
 
   await_c1(0x90);
@@ -133,10 +135,10 @@
     if(in_esc && c == 0x5c)
       break;
     if(!in_esc && c == 0x1b)
-      in_esc = true;
+      in_esc = TRUE;
     else {
       dcs[i++] = c;
-      in_esc = false;
+      in_esc = FALSE;
     }
   }
   dcs[++i] = 0;
@@ -158,7 +160,7 @@
   exit(exitcode);
 }
 
-static bool query_dec_mode(int mode)
+static int query_dec_mode(int mode)
 {
   char *s = NULL;
 
@@ -189,12 +191,12 @@
     free(s);
 
     if(reply_value == 1 || reply_value == 3)
-      return true;
+      return TRUE;
     if(reply_value == 2 || reply_value == 4)
-      return false;
+      return FALSE;
 
     printf("Unrecognised reply to DECRQM: %d\n", reply_value);
-    return false;
+    return FALSE;
   } while(1);
 }
 
@@ -247,11 +249,11 @@
   } while(1);
 }
 
-bool wasicanon;
+int wasicanon;
 
 void restoreicanon(void)
 {
-  seticanon(wasicanon, true);
+  seticanon(wasicanon, TRUE);
 }
 
 int main(int argc, char *argv[])
@@ -261,7 +263,7 @@
   if(argc == 1)
     usage(0);
 
-  wasicanon = seticanon(false, false);
+  wasicanon = seticanon(FALSE, FALSE);
   atexit(restoreicanon);
 
   while(argi < argc) {
diff --git a/src/terminal.c b/src/terminal.c
index ef3c3c2..93715d5 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -25,7 +25,7 @@
  * the terminal emulator.
  *
  * If the terminal window has keyboard focus, typed keys are converted to the
- * terminal encoding and writting to the job over a channel.
+ * terminal encoding and writing to the job over a channel.
  *
  * If the job produces output, it is written to the terminal emulator.  The
  * terminal emulator invokes callbacks when its screen content changes.  The
@@ -731,7 +731,7 @@
     else if (red == 128)
     {
 	if (green == 128 && blue == 128)
-	    return 9; /* high intensity bladk */
+	    return 9; /* high intensity black */
     }
     else if (red == 255)
     {
@@ -894,7 +894,10 @@
 		if (c == NUL)
 		{
 		    ScreenLines[off] = ' ';
-		    ScreenLinesUC[off] = NUL;
+#if defined(FEAT_MBYTE)
+		    if (enc_utf8)
+			ScreenLinesUC[off] = NUL;
+#endif
 		}
 		else
 		{
@@ -907,7 +910,8 @@
 		    else
 		    {
 			ScreenLines[off] = c;
-			ScreenLinesUC[off] = NUL;
+			if (enc_utf8)
+			    ScreenLinesUC[off] = NUL;
 		    }
 #else
 		    ScreenLines[off] = c;
@@ -920,7 +924,10 @@
 		if (cell.width == 2)
 		{
 		    ScreenLines[off] = NUL;
-		    ScreenLinesUC[off] = NUL;
+#if defined(FEAT_MBYTE)
+		    if (enc_utf8)
+			ScreenLinesUC[off] = NUL;
+#endif
 		    ++pos.col;
 		    ++off;
 		}
@@ -1025,9 +1032,9 @@
 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul
 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull
 
-void* (*winpty_config_new)(int, void*);
+void* (*winpty_config_new)(UINT64, void*);
 void* (*winpty_open)(void*, void*);
-void* (*winpty_spawn_config_new)(int, void*, LPCWSTR, void*, void*, void*);
+void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*);
 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*);
 void (*winpty_config_set_initial_size)(void*, int, int);
 LPCWSTR (*winpty_conin_name)(void*);
diff --git a/src/version.c b/src/version.c
index 894fa45..2c0a53b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    769,
+/**/
     768,
 /**/
     767,