To: vim_dev@googlegroups.com Subject: Patch 8.1.2393 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2393 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/os_amiga.c, src/os_beos.c, src/os_mac_conv.c, src/os_mswin.c, src/os_qnx.c, src/os_unix.c, src/os_vms.c, src/os_win32.c *** ../vim-8.1.2392/src/os_amiga.c 2019-10-26 21:33:11.330329105 +0200 --- src/os_amiga.c 2019-12-05 20:15:14.479454196 +0100 *************** *** 17,29 **** #include "version.h" #ifdef Window ! # undef Window /* Amiga has its own Window definition */ #endif ! #undef TRUE /* will be redefined by exec/types.h */ #undef FALSE ! /* cproto fails on missing include files, skip them */ #ifndef PROTO #ifndef LATTICE --- 17,29 ---- #include "version.h" #ifdef Window ! # undef Window // Amiga has its own Window definition #endif ! #undef TRUE // will be redefined by exec/types.h #undef FALSE ! // cproto fails on missing include files, skip them #ifndef PROTO #ifndef LATTICE *************** *** 33,53 **** # include #endif ! /* XXX These are included from os_amiga.h ! #include ! #include ! #include ! */ #include #include ! #include /* for 2.0 functions */ #include ! /* From version 4 of AmigaOS, several system structures must be allocated ! * and freed using system functions. "struct AnchorPath" is one. ! */ #ifdef __amigaos4__ # include # define free_fib(x) FreeDosObject(DOS_FIB, x) --- 33,51 ---- # include #endif ! // XXX These are included from os_amiga.h ! // #include ! // #include ! // #include #include #include ! #include // for 2.0 functions #include ! // From version 4 of AmigaOS, several system structures must be allocated ! // and freed using system functions. "struct AnchorPath" is one. #ifdef __amigaos4__ # include # define free_fib(x) FreeDosObject(DOS_FIB, x) *************** *** 59,65 **** # include #endif ! #endif /* PROTO */ /* * Set stack size to 1 MiB on NG systems. This should be enough even for --- 57,63 ---- # include #endif ! #endif // PROTO /* * Set stack size to 1 MiB on NG systems. This should be enough even for *************** *** 92,100 **** static BPTR raw_in = (BPTR)NULL; static BPTR raw_out = (BPTR)NULL; ! static int close_win = FALSE; /* set if Vim opened the window */ ! #ifndef __amigaos4__ /* Use autoopen for AmigaOS4 */ struct IntuitionBase *IntuitionBase = NULL; #endif #ifdef FEAT_ARP --- 90,98 ---- static BPTR raw_in = (BPTR)NULL; static BPTR raw_out = (BPTR)NULL; ! static int close_win = FALSE; // set if Vim opened the window ! #ifndef __amigaos4__ // Use autoopen for AmigaOS4 struct IntuitionBase *IntuitionBase = NULL; #endif #ifdef FEAT_ARP *************** *** 105,113 **** static char_u *oldwindowtitle = NULL; #ifdef FEAT_ARP ! int dos2 = FALSE; /* Amiga DOS 2.0x or higher */ #endif ! int size_set = FALSE; /* set to TRUE if window size was set */ #ifdef __GNUC__ static char version[] __attribute__((used)) = --- 103,111 ---- static char_u *oldwindowtitle = NULL; #ifdef FEAT_ARP ! int dos2 = FALSE; // Amiga DOS 2.0x or higher #endif ! int size_set = FALSE; // set to TRUE if window size was set #ifdef __GNUC__ static char version[] __attribute__((used)) = *************** *** 151,157 **** mch_inchar( char_u *buf, int maxlen, ! long time, /* milli seconds */ int tb_change_cnt) { int len; --- 149,155 ---- mch_inchar( char_u *buf, int maxlen, ! long time, // milli seconds int tb_change_cnt) { int len; *************** *** 160,172 **** if (time >= 0) { if (time == 0) ! utime = 100L; /* time = 0 causes problems in DOS 1.2 */ else ! utime = time * 1000L; /* convert from milli to micro secs */ ! if (WaitForChar(raw_in, utime) == 0) /* no character available */ return 0; } ! else /* time == -1 */ { /* * If there is no character available within 2 seconds (default) --- 158,170 ---- if (time >= 0) { if (time == 0) ! utime = 100L; // time = 0 causes problems in DOS 1.2 else ! utime = time * 1000L; // convert from milli to micro secs ! if (WaitForChar(raw_in, utime) == 0) // no character available return 0; } ! else // time == -1 { /* * If there is no character available within 2 seconds (default) *************** *** 186,197 **** } } ! for (;;) /* repeat until we got a character */ { len = Read(raw_in, (char *)buf, (long)maxlen / input_conv.vc_factor); if (len > 0) { ! /* Convert from 'termencoding' to 'encoding'. */ if (input_conv.vc_type != CONV_NONE) len = convert_input(buf, len, maxlen); return len; --- 184,195 ---- } } ! for (;;) // repeat until we got a character { len = Read(raw_in, (char *)buf, (long)maxlen / input_conv.vc_factor); if (len > 0) { ! // Convert from 'termencoding' to 'encoding'. if (input_conv.vc_type != CONV_NONE) len = convert_input(buf, len, maxlen); return len; *************** *** 228,241 **** void mch_delay(long msec, int ignoreinput) { ! #ifndef LATTICE /* SAS declares void Delay(ULONG) */ void Delay(long); #endif if (msec > 0) { if (ignoreinput) ! Delay(msec / 20L); /* Delay works with 20 msec intervals */ else WaitForChar(raw_in, msec * 1000L); } --- 226,239 ---- void mch_delay(long msec, int ignoreinput) { ! #ifndef LATTICE // SAS declares void Delay(ULONG) void Delay(long); #endif if (msec > 0) { if (ignoreinput) ! Delay(msec / 20L); // Delay works with 20 msec intervals else WaitForChar(raw_in, msec * 1000L); } *************** *** 260,266 **** static char intlibname[] = "intuition.library"; #ifdef AZTEC_C ! Enable_Abort = 0; /* disallow vim to be aborted */ #endif Columns = 80; Rows = 24; --- 258,264 ---- static char intlibname[] = "intuition.library"; #ifdef AZTEC_C ! Enable_Abort = 0; // disallow vim to be aborted #endif Columns = 80; Rows = 24; *************** *** 313,319 **** * For the -f option (foreground mode) we open our own window and disable :sh. * Otherwise the calling program would never know when editing is finished. */ ! #define BUF2SIZE 320 /* length of buffer for argument with complete path */ int mch_check_win(int argc, char **argv) --- 311,317 ---- * For the -f option (foreground mode) we open our own window and disable :sh. * Otherwise the calling program would never know when editing is finished. */ ! #define BUF2SIZE 320 // length of buffer for argument with complete path int mch_check_win(int argc, char **argv) *************** *** 342,361 **** #ifndef __amigaos4__ DosBase = OpenLibrary(DOS_LIBRARY, 37L); if (DosBase != NULL) ! /* if (((struct Library *)DOSBase)->lib_Version >= 37) */ { CloseLibrary(DosBase); # ifdef FEAT_ARP dos2 = TRUE; # endif } ! else /* without arp functions we NEED 2.0 */ { # ifndef FEAT_ARP mch_errmsg(_("Need Amigados version 2.04 or later\n")); exit(3); # else ! /* need arp functions for dos 1.x */ if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion))) { fprintf(stderr, _("Need %s version %ld\n"), ArpName, ArpVersion); --- 340,359 ---- #ifndef __amigaos4__ DosBase = OpenLibrary(DOS_LIBRARY, 37L); if (DosBase != NULL) ! // if (((struct Library *)DOSBase)->lib_Version >= 37) { CloseLibrary(DosBase); # ifdef FEAT_ARP dos2 = TRUE; # endif } ! else // without arp functions we NEED 2.0 { # ifndef FEAT_ARP mch_errmsg(_("Need Amigados version 2.04 or later\n")); exit(3); # else ! // need arp functions for dos 1.x if (!(ArpBase = (struct ArpBase *) OpenLibrary((UBYTE *)ArpName, ArpVersion))) { fprintf(stderr, _("Need %s version %ld\n"), ArpName, ArpVersion); *************** *** 363,369 **** } # endif } ! #endif /* __amigaos4__ */ /* * scan argv[] for the "-f" and "-d" arguments --- 361,367 ---- } # endif } ! #endif // __amigaos4__ /* * scan argv[] for the "-f" and "-d" arguments *************** *** 380,386 **** case 'd': if (i < argc - 1 #ifdef FEAT_DIFF ! /* require using "-dev", "-d" means diff mode */ && argv[i][2] == 'e' && argv[i][3] == 'v' #endif ) --- 378,384 ---- case 'd': if (i < argc - 1 #ifdef FEAT_DIFF ! // require using "-dev", "-d" means diff mode && argv[i][2] == 'e' && argv[i][3] == 'v' #endif ) *************** *** 419,425 **** (long)MODE_NEWFILE)) != (BPTR)NULL) break; } ! if (raw_in == (BPTR)NULL) /* all three failed */ { mch_errmsg(_(winerr)); goto exit; --- 417,423 ---- (long)MODE_NEWFILE)) != (BPTR)NULL) break; } ! if (raw_in == (BPTR)NULL) // all three failed { mch_errmsg(_(winerr)); goto exit; *************** *** 458,464 **** * Write the command into the file, put quotes around the arguments that * have a space in them. */ ! if (argc == 0) /* run from workbench */ ac = ((struct WBStartup *)argv)->sm_NumArgs; else ac = argc; --- 456,462 ---- * Write the command into the file, put quotes around the arguments that * have a space in them. */ ! if (argc == 0) // run from workbench ac = ((struct WBStartup *)argv)->sm_NumArgs; else ac = argc; *************** *** 471,481 **** if (argp->wa_Lock) (void)lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1)); #ifdef FEAT_ARP ! if (dos2) /* use 2.0 function */ #endif AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1)); #ifdef FEAT_ARP ! else /* use arp function */ TackOn((char *)buf2, argp->wa_Name); #endif av = (char *)buf2; --- 469,479 ---- if (argp->wa_Lock) (void)lock2name(argp->wa_Lock, buf2, (long)(BUF2SIZE - 1)); #ifdef FEAT_ARP ! if (dos2) // use 2.0 function #endif AddPart((UBYTE *)buf2, (UBYTE *)argp->wa_Name, (long)(BUF2SIZE - 1)); #ifdef FEAT_ARP ! else // use arp function TackOn((char *)buf2, argp->wa_Name); #endif av = (char *)buf2; *************** *** 483,489 **** else av = argv[i]; ! /* skip '-d' or "-dev" option */ if (av[0] == '-' && av[1] == 'd' #ifdef FEAT_DIFF && av[2] == 'e' && av[3] == 'v' --- 481,487 ---- else av = argv[i]; ! // skip '-d' or "-dev" option if (av[0] == '-' && av[1] == 'd' #ifdef FEAT_DIFF && av[2] == 'e' && av[3] == 'v' *************** *** 530,542 **** } #endif } ! if (i == 3) /* all three failed */ { DeleteFile((UBYTE *)buf1); mch_errmsg(_(winerr)); goto exit; } ! exitval = 0; /* The Execute succeeded: exit this program */ exit: #ifdef FEAT_ARP --- 528,540 ---- } #endif } ! if (i == 3) // all three failed { DeleteFile((UBYTE *)buf1); mch_errmsg(_(winerr)); goto exit; } ! exitval = 0; // The Execute succeeded: exit this program exit: #ifdef FEAT_ARP *************** *** 544,550 **** CloseLibrary((struct Library *) ArpBase); #endif exit(exitval); ! /* NOTREACHED */ return FAIL; } --- 542,548 ---- CloseLibrary((struct Library *) ArpBase); #endif exit(exitval); ! // NOTREACHED return FAIL; } *************** *** 563,573 **** * This will cause the file name to remain exactly the same * if the file system ignores, but preserves case. */ ! /*ARGSUSED*/ void fname_case( char_u *name, ! int len) /* buffer size, ignored here */ { struct FileInfoBlock *fib; size_t flen; --- 561,571 ---- * This will cause the file name to remain exactly the same * if the file system ignores, but preserves case. */ ! //ARGSUSED void fname_case( char_u *name, ! int len) // buffer size, ignored here { struct FileInfoBlock *fib; size_t flen; *************** *** 576,587 **** if (fib != NULL) { flen = STRLEN(name); ! /* TODO: Check if this fix applies to AmigaOS < 4 too.*/ #ifdef __amigaos4__ if (fib->fib_DirEntryType == ST_ROOT) strcat(fib->fib_FileName, ":"); #endif ! if (flen == strlen(fib->fib_FileName)) /* safety check */ mch_memmove(name, fib->fib_FileName, flen); free_fib(fib); } --- 574,585 ---- if (fib != NULL) { flen = STRLEN(name); ! // TODO: Check if this fix applies to AmigaOS < 4 too. #ifdef __amigaos4__ if (fib->fib_DirEntryType == ST_ROOT) strcat(fib->fib_FileName, ":"); #endif ! if (flen == strlen(fib->fib_FileName)) // safety check mch_memmove(name, fib->fib_FileName, flen); free_fib(fib); } *************** *** 598,604 **** BPTR flock; struct FileInfoBlock *fib; ! if (fname == NULL) /* safety check */ return NULL; #ifdef __amigaos4__ fib = AllocDosObject(DOS_FIB,0); --- 596,602 ---- BPTR flock; struct FileInfoBlock *fib; ! if (fname == NULL) // safety check return NULL; #ifdef __amigaos4__ fib = AllocDosObject(DOS_FIB,0); *************** *** 610,616 **** flock = Lock((UBYTE *)fname, (long)ACCESS_READ); if (flock == (BPTR)NULL || !Examine(flock, fib)) { ! free_fib(fib); /* in case of an error the memory is freed here */ fib = NULL; } if (flock) --- 608,614 ---- flock = Lock((UBYTE *)fname, (long)ACCESS_READ); if (flock == (BPTR)NULL || !Examine(flock, fib)) { ! free_fib(fib); // in case of an error the memory is freed here fib = NULL; } if (flock) *************** *** 703,711 **** mch_get_pid(void) { #ifdef __amigaos4__ ! /* This is as close to a pid as we can come. We could use CLI numbers also, ! * but then we would have two different types of process identifiers. ! */ return((long)FindTask(0)); #else return (long)0; --- 701,708 ---- mch_get_pid(void) { #ifdef __amigaos4__ ! // This is as close to a pid as we can come. We could use CLI numbers also, ! // but then we would have two different types of process identifiers. return((long)FindTask(0)); #else return (long)0; *************** *** 738,750 **** int retval = FAIL; int i; ! /* Lock the file. If it exists, we can get the exact name. */ if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0) { retval = lock2name(l, buf, (long)len - 1); UnLock(l); } ! else if (force || !mch_isFullName(fname)) /* not a full path yet */ { /* * If the file cannot be locked (doesn't exist), try to lock the --- 735,747 ---- int retval = FAIL; int i; ! // Lock the file. If it exists, we can get the exact name. if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0) { retval = lock2name(l, buf, (long)len - 1); UnLock(l); } ! else if (force || !mch_isFullName(fname)) // not a full path yet { /* * If the file cannot be locked (doesn't exist), try to lock the *************** *** 757,764 **** if (retval == OK) { i = STRLEN(buf); ! /* Concatenate the fname to the directory. Don't add a slash ! * if fname is empty, but do change "" to "/". */ if (i == 0 || *fname != NUL) { if (i < len - 1 && (i == 0 || buf[i - 1] != ':')) --- 754,761 ---- if (retval == OK) { i = STRLEN(buf); ! // Concatenate the fname to the directory. Don't add a slash ! // if fname is empty, but do change "" to "/". if (i == 0 || *fname != NUL) { if (i < len - 1 && (i == 0 || buf[i - 1] != ':')) *************** *** 769,775 **** } } if (*buf == 0 || *buf == ':') ! retval = FAIL; /* something failed; use the file name */ return retval; } --- 766,772 ---- } } if (*buf == 0 || *buf == ':') ! retval = FAIL; // something failed; use the file name return retval; } *************** *** 792,802 **** lock2name(BPTR lock, char_u *buf, long len) { #ifdef FEAT_ARP ! if (dos2) /* use 2.0 function */ #endif return ((int)NameFromLock(lock, (UBYTE *)buf, len) ? OK : FAIL); #ifdef FEAT_ARP ! else /* use arp function */ return ((int)PathName(lock, (char *)buf, (long)(len/32)) ? OK : FAIL); #endif } --- 789,799 ---- lock2name(BPTR lock, char_u *buf, long len) { #ifdef FEAT_ARP ! if (dos2) // use 2.0 function #endif return ((int)NameFromLock(lock, (UBYTE *)buf, len) ? OK : FAIL); #ifdef FEAT_ARP ! else // use arp function return ((int)PathName(lock, (char *)buf, (long)(len/32)) ? OK : FAIL); #endif } *************** *** 828,834 **** int mch_setperm(char_u *name, long perm) { ! perm &= ~FIBF_ARCHIVE; /* reset archived bit */ return (SetProtection((UBYTE *)name, (long)perm) ? OK : FAIL); } --- 825,831 ---- int mch_setperm(char_u *name, long perm) { ! perm &= ~FIBF_ARCHIVE; // reset archived bit return (SetProtection((UBYTE *)name, (long)perm) ? OK : FAIL); } *************** *** 838,844 **** void mch_hide(char_u *name) { ! /* can't hide a file */ } /* --- 835,841 ---- void mch_hide(char_u *name) { ! // can't hide a file } /* *************** *** 890,896 **** int mch_can_exe(char_u *name, char_u **path, int use_path) { ! /* TODO */ return -1; } --- 887,893 ---- int mch_can_exe(char_u *name, char_u **path, int use_path) { ! // TODO return -1; } *************** *** 903,909 **** int mch_nodetype(char_u *name) { ! /* TODO */ return NODE_NORMAL; } --- 900,906 ---- int mch_nodetype(char_u *name) { ! // TODO return NODE_NORMAL; } *************** *** 920,926 **** { exiting = TRUE; ! if (raw_in) /* put terminal in 'normal' mode */ { settmode(TMODE_COOK); stoptermcap(); --- 917,923 ---- { exiting = TRUE; ! if (raw_in) // put terminal in 'normal' mode { settmode(TMODE_COOK); stoptermcap(); *************** *** 930,947 **** { if (term_console) { ! win_resize_off(); /* window resize events de-activated */ if (size_set) ! OUT_STR("\233t\233u"); /* reset window size (CSI t CSI u) */ } out_flush(); } #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); /* restore window title */ #endif ! ml_close_all(TRUE); /* remove all memfiles */ #ifdef FEAT_ARP if (ArpBase) --- 927,944 ---- { if (term_console) { ! win_resize_off(); // window resize events de-activated if (size_set) ! OUT_STR("\233t\233u"); // reset window size (CSI t CSI u) } out_flush(); } #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); // restore window title #endif ! ml_close_all(TRUE); // remove all memfiles #ifdef FEAT_ARP if (ArpBase) *************** *** 950,956 **** if (close_win) Close(raw_in); if (r) ! printf(_("Vim exiting with %d\n"), r); /* somehow this makes :cq work!? */ exit(r); } --- 947,953 ---- if (close_win) Close(raw_in); if (r) ! printf(_("Vim exiting with %d\n"), r); // somehow this makes :cq work!? exit(r); } *************** *** 1027,1036 **** #endif struct InfoData *id=0; ! if (!term_console) /* not an amiga window */ goto out; ! /* insure longword alignment */ #ifdef __amigaos4__ if (!(id = AllocDosObject(DOS_INFODATA, 0))) goto out; --- 1024,1033 ---- #endif struct InfoData *id=0; ! if (!term_console) // not an amiga window goto out; ! // insure longword alignment #ifdef __amigaos4__ if (!(id = AllocDosObject(DOS_INFODATA, 0))) goto out; *************** *** 1044,1050 **** * is rarely needed, so we skip it now, unless we changed the size. */ if (size_set) ! OUT_STR("\233t\233u"); /* CSI t CSI u */ out_flush(); #ifdef __AROS__ --- 1041,1047 ---- * is rarely needed, so we skip it now, unless we changed the size. */ if (size_set) ! OUT_STR("\233t\233u"); // CSI t CSI u out_flush(); #ifdef __AROS__ *************** *** 1055,1062 **** || (wb_window = (struct Window *)id->id_VolumeNode) == NULL) #endif { ! /* it's not an amiga window, maybe aux device */ ! /* terminal type should be set */ term_console = FALSE; goto out; } --- 1052,1059 ---- || (wb_window = (struct Window *)id->id_VolumeNode) == NULL) #endif { ! // it's not an amiga window, maybe aux device ! // terminal type should be set term_console = FALSE; goto out; } *************** *** 1069,1078 **** } conUnit = (struct ConUnit *) ((struct IOStdReq *) id->id_InUse)->io_Unit; ! /* get window size */ Rows = conUnit->cu_YMax + 1; Columns = conUnit->cu_XMax + 1; ! if (Rows < 0 || Rows > 200) /* cannot be an amiga window */ { Columns = 80; Rows = 24; --- 1066,1075 ---- } conUnit = (struct ConUnit *) ((struct IOStdReq *) id->id_InUse)->io_Unit; ! // get window size Rows = conUnit->cu_YMax + 1; Columns = conUnit->cu_XMax + 1; ! if (Rows < 0 || Rows > 200) // cannot be an amiga window { Columns = 80; Rows = 24; *************** *** 1083,1089 **** return OK; out: #ifdef __amigaos4__ ! FreeDosObject(DOS_INFODATA, id); /* Safe to pass NULL */ #endif return FAIL; --- 1080,1086 ---- return OK; out: #ifdef __amigaos4__ ! FreeDosObject(DOS_INFODATA, id); // Safe to pass NULL #endif return FAIL; *************** *** 1114,1120 **** void mch_new_shellsize(void) { ! /* Nothing to do. */ } /* --- 1111,1117 ---- void mch_new_shellsize(void) { ! // Nothing to do. } /* *************** *** 1139,1146 **** */ #ifndef PROTO ! /* #include */ ! /* #include */ # include #endif --- 1136,1143 ---- */ #ifndef PROTO ! // #include ! // #include # include #endif *************** *** 1152,1160 **** static long dos_packet( ! struct MsgPort *pid, /* process identifier ... (handlers message port) */ ! long action, /* packet type ... (what you want handler to do) */ ! long arg) /* single argument */ { # ifdef FEAT_ARP struct MsgPort *replyport; --- 1149,1157 ---- static long dos_packet( ! struct MsgPort *pid, // process identifier ... (handlers message port) ! long action, // packet type ... (what you want handler to do) ! long arg) // single argument { # ifdef FEAT_ARP struct MsgPort *replyport; *************** *** 1163,1176 **** if (dos2) # endif ! return DoPkt(pid, action, arg, 0L, 0L, 0L, 0L); /* use 2.0 function */ # ifdef FEAT_ARP ! replyport = (struct MsgPort *) CreatePort(NULL, 0); /* use arp function */ if (!replyport) return (0); ! /* Allocate space for a packet, make it public and clear it */ packet = (struct StandardPacket *) AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR); if (!packet) { --- 1160,1173 ---- if (dos2) # endif ! return DoPkt(pid, action, arg, 0L, 0L, 0L, 0L); // use 2.0 function # ifdef FEAT_ARP ! replyport = (struct MsgPort *) CreatePort(NULL, 0); // use arp function if (!replyport) return (0); ! // Allocate space for a packet, make it public and clear it packet = (struct StandardPacket *) AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR); if (!packet) { *************** *** 1183,1189 **** packet->sp_Pkt.dp_Type = action; packet->sp_Pkt.dp_Arg1 = arg; ! PutMsg(pid, (struct Message *)packet); /* send packet */ WaitPort(replyport); GetMsg(replyport); --- 1180,1186 ---- packet->sp_Pkt.dp_Type = action; packet->sp_Pkt.dp_Arg1 = arg; ! PutMsg(pid, (struct Message *)packet); // send packet WaitPort(replyport); GetMsg(replyport); *************** *** 1196,1202 **** return (res1); # endif } ! #endif /* !defined(AZTEC_C) && !defined(__AROS__) */ /* * Call shell. --- 1193,1199 ---- return (res1); # endif } ! #endif // !defined(AZTEC_C) && !defined(__AROS__) /* * Call shell. *************** *** 1205,1211 **** int mch_call_shell( char_u *cmd, ! int options) /* SHELL_*, see vim.h */ { BPTR mydir; int x; --- 1202,1208 ---- int mch_call_shell( char_u *cmd, ! int options) // SHELL_*, see vim.h { BPTR mydir; int x; *************** *** 1219,1238 **** if (close_win) { ! /* if Vim opened a window: Executing a shell may cause crashes */ emsg(_("E360: Cannot execute shell with -f option")); return -1; } if (term_console) ! win_resize_off(); /* window resize events de-activated */ out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); /* set to normal mode */ ! mydir = Lock((UBYTE *)"", (long)ACCESS_READ); /* remember current dir */ ! #if !defined(AZTEC_C) /* not tested very much */ if (cmd == NULL) { # ifdef FEAT_ARP --- 1216,1235 ---- if (close_win) { ! // if Vim opened a window: Executing a shell may cause crashes emsg(_("E360: Cannot execute shell with -f option")); return -1; } if (term_console) ! win_resize_off(); // window resize events de-activated out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); // set to normal mode ! mydir = Lock((UBYTE *)"", (long)ACCESS_READ); // remember current dir ! #if !defined(AZTEC_C) // not tested very much if (cmd == NULL) { # ifdef FEAT_ARP *************** *** 1289,1295 **** retval = x; } } ! #else /* else part is for AZTEC_C */ if (p_st >= 4 || (p_st >= 2 && !(options & SHELL_FILTER))) use_execute = 1; else --- 1286,1292 ---- retval = x; } } ! #else // else part is for AZTEC_C if (p_st >= 4 || (p_st >= 2 && !(options & SHELL_FILTER))) use_execute = 1; else *************** *** 1300,1310 **** * separate shell name from argument */ shellcmd = vim_strsave(p_sh); ! if (shellcmd == NULL) /* out of memory, use Execute */ use_execute = 1; else { ! shellarg = skiptowhite(shellcmd); /* find start of arguments */ if (*shellarg != NUL) { *shellarg++ = NUL; --- 1297,1307 ---- * separate shell name from argument */ shellcmd = vim_strsave(p_sh); ! if (shellcmd == NULL) // out of memory, use Execute use_execute = 1; else { ! shellarg = skiptowhite(shellcmd); // find start of arguments if (*shellarg != NUL) { *shellarg++ = NUL; *************** *** 1392,1408 **** } } vim_free(shellcmd); ! #endif /* AZTEC_C */ ! if ((mydir = CurrentDir(mydir)) != 0) /* make sure we stay in the same directory */ UnLock(mydir); if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); /* set to raw mode */ #ifdef FEAT_TITLE resettitle(); #endif if (term_console) ! win_resize_on(); /* window resize events activated */ return retval; } --- 1389,1405 ---- } } vim_free(shellcmd); ! #endif // AZTEC_C ! if ((mydir = CurrentDir(mydir)) != 0) // make sure we stay in the same directory UnLock(mydir); if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); // set to raw mode #ifdef FEAT_TITLE resettitle(); #endif if (term_console) ! win_resize_on(); // window resize events activated return retval; } *************** *** 1418,1426 **** got_int = TRUE; } ! /* this routine causes manx to use this Chk_Abort() rather than its own */ ! /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */ ! /* is zero). Since we want to check for our own ^C's */ #ifdef _DCC #define Chk_Abort chkabort --- 1415,1423 ---- got_int = TRUE; } ! // this routine causes manx to use this Chk_Abort() rather than its own ! // otherwise it resets our ^C when doing any I/O (even when Enable_Abort ! // is zero). Since we want to check for our own ^C's #ifdef _DCC #define Chk_Abort chkabort *************** *** 1464,1470 **** mch_expandpath( garray_T *gap, char_u *pat, ! int flags) /* EW_* flags */ { struct AnchorPath *Anchor; LONG Result; --- 1461,1467 ---- mch_expandpath( garray_T *gap, char_u *pat, ! int flags) // EW_* flags { struct AnchorPath *Anchor; LONG Result; *************** *** 1481,1487 **** start_len = gap->ga_len; ! /* Get our AnchorBase */ #ifdef __amigaos4__ Anchor = AllocDosObject(DOS_ANCHORPATH, AnchorTags); #else --- 1478,1484 ---- start_len = gap->ga_len; ! // Get our AnchorBase #ifdef __amigaos4__ Anchor = AllocDosObject(DOS_ANCHORPATH, AnchorTags); #else *************** *** 1491,1501 **** return 0; #ifndef __amigaos4__ ! Anchor->ap_Strlen = ANCHOR_BUF_SIZE; /* ap_Length not supported anymore */ # ifdef APF_DODOT ! Anchor->ap_Flags = APF_DODOT | APF_DOWILD; /* allow '.' for current dir */ # else ! Anchor->ap_Flags = APF_DoDot | APF_DoWild; /* allow '.' for current dir */ # endif #endif --- 1488,1498 ---- return 0; #ifndef __amigaos4__ ! Anchor->ap_Strlen = ANCHOR_BUF_SIZE; // ap_Length not supported anymore # ifdef APF_DODOT ! Anchor->ap_Flags = APF_DODOT | APF_DOWILD; // allow '.' for current dir # else ! Anchor->ap_Flags = APF_DoDot | APF_DoWild; // allow '.' for current dir # endif #endif *************** *** 1503,1509 **** if (dos2) { #endif ! /* hack to replace '*' by '#?' */ starbuf = alloc(2 * STRLEN(pat) + 1); if (starbuf == NULL) goto Return; --- 1500,1506 ---- if (dos2) { #endif ! // hack to replace '*' by '#?' starbuf = alloc(2 * STRLEN(pat) + 1); if (starbuf == NULL) goto Return; *************** *** 1561,1567 **** qsort((void *)(((char_u **)gap->ga_data) + start_len), (size_t)matches, sizeof(char_u *), sortcmp); ! /* Free the wildcard stuff */ #ifdef FEAT_ARP if (dos2) #endif --- 1558,1564 ---- qsort((void *)(((char_u **)gap->ga_data) + start_len), (size_t)matches, sizeof(char_u *), sortcmp); ! // Free the wildcard stuff #ifdef FEAT_ARP if (dos2) #endif *************** *** 1638,1646 **** mch_getenv(char_u *var) { int len; ! UBYTE *buf; /* buffer to expand in */ ! char_u *retval; /* return value */ ! static char_u *alloced = NULL; /* allocated memory */ #ifdef FEAT_ARP if (!dos2) --- 1635,1643 ---- mch_getenv(char_u *var) { int len; ! UBYTE *buf; // buffer to expand in ! char_u *retval; // return value ! static char_u *alloced = NULL; // allocated memory #ifdef FEAT_ARP if (!dos2) *************** *** 1665,1671 **** vim_free(buf); } ! /* if $VIM is not defined, use "vim:" instead */ if (retval == NULL && STRCMP(var, "VIM") == 0) retval = (char_u *)"vim:"; --- 1662,1668 ---- vim_free(buf); } ! // if $VIM is not defined, use "vim:" instead if (retval == NULL && STRCMP(var, "VIM") == 0) retval = (char_u *)"vim:"; *************** *** 1675,1681 **** /* * Amiga version of setenv() with AmigaDOS 2.0 support. */ ! /* ARGSUSED */ int mch_setenv(char *var, char *value, int x) { --- 1672,1678 ---- /* * Amiga version of setenv() with AmigaDOS 2.0 support. */ ! // ARGSUSED int mch_setenv(char *var, char *value, int x) { *************** *** 1685,1690 **** #endif if (SetVar((UBYTE *)var, (UBYTE *)value, (LONG)-1, (ULONG)GVF_LOCAL_ONLY)) ! return 0; /* success */ ! return -1; /* failure */ } --- 1682,1687 ---- #endif if (SetVar((UBYTE *)var, (UBYTE *)value, (LONG)-1, (ULONG)GVF_LOCAL_ONLY)) ! return 0; // success ! return -1; // failure } *** ../vim-8.1.2392/src/os_beos.c 2016-08-29 22:42:20.000000000 +0200 --- src/os_beos.c 2019-12-05 20:15:31.295397906 +0100 *************** *** 21,27 **** #if USE_THREAD_FOR_INPUT_WITH_TIMEOUT ! #ifdef PROTO /* making prototypes on Unix */ #define sem_id int #define thread_id int #endif --- 21,27 ---- #if USE_THREAD_FOR_INPUT_WITH_TIMEOUT ! #ifdef PROTO // making prototypes on Unix #define sem_id int #define thread_id int #endif *************** *** 32,38 **** sem_id character_wanted; thread_id read_thread_id; ! #define TRY_ABORT 0 /* This code does not work so turn it off. */ #if TRY_ABORT static void --- 32,38 ---- sem_id character_wanted; thread_id read_thread_id; ! #define TRY_ABORT 0 // This code does not work so turn it off. #if TRY_ABORT static void *************** *** 89,95 **** bigtime_t tmo; if (nbits == 0) { ! /* select is purely being used for delay */ snooze(timeout->tv_sec * 1e6 + timeout->tv_usec); return 0; } --- 89,95 ---- bigtime_t tmo; if (nbits == 0) { ! // select is purely being used for delay snooze(timeout->tv_sec * 1e6 + timeout->tv_usec); return 0; } *************** *** 140,149 **** resume_thread(read_thread_id); } ! /* timeout == NULL means "indefinitely" */ if (timeout) { tmo = timeout->tv_sec * 1e6 + timeout->tv_usec; ! /* 0 means "don't wait, which is impossible to do exactly. */ if (tmo == 0) tmo = 1.0; } --- 140,149 ---- resume_thread(read_thread_id); } ! // timeout == NULL means "indefinitely" if (timeout) { tmo = timeout->tv_sec * 1e6 + timeout->tv_usec; ! // 0 means "don't wait, which is impossible to do exactly. if (tmo == 0) tmo = 1.0; } *** ../vim-8.1.2392/src/os_mac_conv.c 2019-05-28 23:08:12.072648675 +0200 --- src/os_mac_conv.c 2019-12-05 20:15:57.179311311 +0100 *************** *** 25,31 **** #if defined(MACOS_CONVERT) || defined(PROTO) # ifdef PROTO ! /* A few dummy types to be able to generate function prototypes. */ typedef int UniChar; typedef int *TECObjectRef; typedef int CFStringRef; --- 25,31 ---- #if defined(MACOS_CONVERT) || defined(PROTO) # ifdef PROTO ! // A few dummy types to be able to generate function prototypes. typedef int UniChar; typedef int *TECObjectRef; typedef int CFStringRef; *************** *** 34,42 **** static char_u *mac_utf16_to_utf8(UniChar *from, size_t fromLen, size_t *actualLen); static UniChar *mac_utf8_to_utf16(char_u *from, size_t fromLen, size_t *actualLen); ! /* Converter for composing decomposed HFS+ file paths */ static TECObjectRef gPathConverter; ! /* Converter used by mac_utf16_to_utf8 */ static TECObjectRef gUTF16ToUTF8Converter; /* --- 34,42 ---- static char_u *mac_utf16_to_utf8(UniChar *from, size_t fromLen, size_t *actualLen); static UniChar *mac_utf8_to_utf16(char_u *from, size_t fromLen, size_t *actualLen); ! // Converter for composing decomposed HFS+ file paths static TECObjectRef gPathConverter; ! // Converter used by mac_utf16_to_utf8 static TECObjectRef gUTF16ToUTF8Converter; /* *************** *** 79,87 **** if (cfstr == NULL) fprintf(stderr, "Encoding failed\n"); ! /* When conversion failed, try excluding bytes from the end, helps when ! * there is an incomplete byte sequence. Only do up to 6 bytes to avoid ! * looping a long time when there really is something unconvertible. */ while (cfstr == NULL && unconvlenp != NULL && len > 1 && *unconvlenp < 6) { --len; --- 79,87 ---- if (cfstr == NULL) fprintf(stderr, "Encoding failed\n"); ! // When conversion failed, try excluding bytes from the end, helps when ! // there is an incomplete byte sequence. Only do up to 6 bytes to avoid ! // looping a long time when there really is something unconvertible. while (cfstr == NULL && unconvlenp != NULL && len > 1 && *unconvlenp < 6) { --len; *************** *** 104,110 **** #if 0 CFRange convertRange = CFRangeMake(0, CFStringGetLength(cfstr)); ! /* Determine output buffer size */ CFStringGetBytes(cfstr, convertRange, to, NULL, FALSE, NULL, 0, (CFIndex *)&buflen); retval = (buflen > 0) ? alloc(buflen) : NULL; if (retval == NULL) { --- 104,110 ---- #if 0 CFRange convertRange = CFRangeMake(0, CFStringGetLength(cfstr)); ! // Determine output buffer size CFStringGetBytes(cfstr, convertRange, to, NULL, FALSE, NULL, 0, (CFIndex *)&buflen); retval = (buflen > 0) ? alloc(buflen) : NULL; if (retval == NULL) { *************** *** 127,134 **** } fprintf(stderr, "Trying char-by-char conversion...\n"); ! /* conversion failed for the whole string, but maybe it will work ! * for each character */ for (d = retval, in = 0, out = 0; in < len && out < buflen - 1;) { if (from == kCFStringEncodingUTF8) --- 127,134 ---- } fprintf(stderr, "Trying char-by-char conversion...\n"); ! // conversion failed for the whole string, but maybe it will work ! // for each character for (d = retval, in = 0, out = 0; in < len && out < buflen - 1;) { if (from == kCFStringEncodingUTF8) *************** *** 188,195 **** CFRange r; CFIndex len = *sizep; ! /* MacRoman is an 8-bit encoding, no need to move bytes to ! * conv_rest[]. */ cfstr = CFStringCreateWithBytes(NULL, ptr, len, kCFStringEncodingMacRoman, 0); /* --- 188,195 ---- CFRange r; CFIndex len = *sizep; ! // MacRoman is an 8-bit encoding, no need to move bytes to ! // conv_rest[]. cfstr = CFStringCreateWithBytes(NULL, ptr, len, kCFStringEncodingMacRoman, 0); /* *************** *** 203,210 **** r.length = CFStringGetLength(cfstr); if (r.length != CFStringGetBytes(cfstr, r, (enc_utf8) ? kCFStringEncodingUTF8 : kCFStringEncodingISOLatin1, ! 0, /* no lossy conversion */ ! 0, /* not external representation */ ptr + *sizep, real_size - *sizep, &len)) { CFRelease(cfstr); --- 203,210 ---- r.length = CFStringGetLength(cfstr); if (r.length != CFStringGetBytes(cfstr, r, (enc_utf8) ? kCFStringEncodingUTF8 : kCFStringEncodingISOLatin1, ! 0, // no lossy conversion ! 0, // not external representation ptr + *sizep, real_size - *sizep, &len)) { CFRelease(cfstr); *************** *** 256,264 **** r.length = CFStringGetLength(cfstr); if (r.length != CFStringGetBytes(cfstr, r, kCFStringEncodingMacRoman, ! 0, /* no lossy conversion */ ! 0, /* not external representation (since vim ! * handles this internally */ to, maxtolen, &l)) { CFRelease(cfstr); --- 256,264 ---- r.length = CFStringGetLength(cfstr); if (r.length != CFStringGetBytes(cfstr, r, kCFStringEncodingMacRoman, ! 0, // no lossy conversion ! 0, // not external representation (since vim ! // handles this internally to, maxtolen, &l)) { CFRelease(cfstr); *************** *** 296,303 **** if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding, utf8_canon_encoding) != noErr) { ! /* On pre-10.3, Unicode normalization is not available so ! * fall back to non-normalizing converter */ if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding, utf8_encoding) != noErr) gUTF16ToUTF8Converter = NULL; --- 296,303 ---- if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding, utf8_canon_encoding) != noErr) { ! // On pre-10.3, Unicode normalization is not available so ! // fall back to non-normalizing converter if (TECCreateConverter(&gUTF16ToUTF8Converter, utf16_encoding, utf8_encoding) != noErr) gUTF16ToUTF8Converter = NULL; *************** *** 334,363 **** size_t fromLen, size_t *actualLen) { ! /* Following code borrows somewhat from os_mswin.c */ vimconv_T conv; size_t utf8_len; char_u *utf8_str; char_u *result = NULL; ! /* Convert to utf-8 first, works better with iconv */ utf8_len = 0; utf8_str = mac_utf16_to_utf8(from, fromLen, &utf8_len); if (utf8_str) { ! /* We might be called before we have p_enc set up. */ conv.vc_type = CONV_NONE; ! /* If encoding (p_enc) is any unicode, it is actually in utf-8 (vim ! * internal unicode is always utf-8) so don't convert in such cases */ if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0) convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"macroman"); if (conv.vc_type == CONV_NONE) { ! /* p_enc is utf-8, so we're done. */ result = utf8_str; } else --- 334,363 ---- size_t fromLen, size_t *actualLen) { ! // Following code borrows somewhat from os_mswin.c vimconv_T conv; size_t utf8_len; char_u *utf8_str; char_u *result = NULL; ! // Convert to utf-8 first, works better with iconv utf8_len = 0; utf8_str = mac_utf16_to_utf8(from, fromLen, &utf8_len); if (utf8_str) { ! // We might be called before we have p_enc set up. conv.vc_type = CONV_NONE; ! // If encoding (p_enc) is any unicode, it is actually in utf-8 (vim ! // internal unicode is always utf-8) so don't convert in such cases if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0) convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"macroman"); if (conv.vc_type == CONV_NONE) { ! // p_enc is utf-8, so we're done. result = utf8_str; } else *************** *** 388,394 **** size_t fromLen, size_t *actualLen) { ! /* Following code borrows somewhat from os_mswin.c */ vimconv_T conv; size_t utf8_len; char_u *utf8_str; --- 388,394 ---- size_t fromLen, size_t *actualLen) { ! // Following code borrows somewhat from os_mswin.c vimconv_T conv; size_t utf8_len; char_u *utf8_str; *************** *** 397,405 **** do { ! /* Use MacRoman by default, we might be called before we have p_enc ! * set up. Convert to utf-8 first, works better with iconv(). Does ! * nothing if 'encoding' is "utf-8". */ conv.vc_type = CONV_NONE; if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0 && convert_setup(&conv, p_enc ? p_enc : (char_u *)"macroman", --- 397,405 ---- do { ! // Use MacRoman by default, we might be called before we have p_enc ! // set up. Convert to utf-8 first, works better with iconv(). Does ! // nothing if 'encoding' is "utf-8". conv.vc_type = CONV_NONE; if ((enc_canon_props(p_enc) & ENC_UNICODE) == 0 && convert_setup(&conv, p_enc ? p_enc : (char_u *)"macroman", *************** *** 583,586 **** } } } ! #endif /* MACOS_CONVERT */ --- 583,586 ---- } } } ! #endif // MACOS_CONVERT *** ../vim-8.1.2392/src/os_mswin.c 2019-12-01 18:58:07.610835613 +0100 --- src/os_mswin.c 2019-12-05 20:17:52.274926756 +0100 *************** *** 42,48 **** # include # endif ! #endif /* PROTO */ #ifdef __MINGW32__ # ifndef FROM_LEFT_1ST_BUTTON_PRESSED --- 42,48 ---- # include # endif ! #endif // PROTO #ifdef __MINGW32__ # ifndef FROM_LEFT_1ST_BUTTON_PRESSED *************** *** 122,129 **** typedef void VOID; #endif ! /* Record all output and all keyboard & mouse input */ ! /* #define MCH_WRITE_DUMP */ #ifdef MCH_WRITE_DUMP FILE* fdDump = NULL; --- 122,129 ---- typedef void VOID; #endif ! // Record all output and all keyboard & mouse input ! // #define MCH_WRITE_DUMP #ifdef MCH_WRITE_DUMP FILE* fdDump = NULL; *************** *** 136,150 **** #ifdef FEAT_GUI extern HWND s_hwnd; #else ! static HWND s_hwnd = 0; /* console window handle, set by GetConsoleHwnd() */ #endif #ifdef FEAT_JOB_CHANNEL ! int WSInitialized = FALSE; /* WinSock is initialized */ #endif ! /* Don't generate prototypes here, because some systems do have these ! * functions. */ #if defined(__GNUC__) && !defined(PROTO) # ifndef __MINGW32__ int _stricoll(char *a, char *b) --- 136,150 ---- #ifdef FEAT_GUI extern HWND s_hwnd; #else ! static HWND s_hwnd = 0; // console window handle, set by GetConsoleHwnd() #endif #ifdef FEAT_JOB_CHANNEL ! int WSInitialized = FALSE; // WinSock is initialized #endif ! // Don't generate prototypes here, because some systems do have these ! // functions. #if defined(__GNUC__) && !defined(PROTO) # ifndef __MINGW32__ int _stricoll(char *a, char *b) *************** *** 199,205 **** display_errors(); ! ml_close_all(TRUE); /* remove all memfiles */ # ifdef FEAT_OLE UninitOLE(); --- 199,205 ---- display_errors(); ! ml_close_all(TRUE); // remove all memfiles # ifdef FEAT_OLE UninitOLE(); *************** *** 225,231 **** exit(r); } ! #endif /* FEAT_GUI_MSWIN */ /* --- 225,231 ---- exit(r); } ! #endif // FEAT_GUI_MSWIN /* *************** *** 238,244 **** PlatformId(); ! /* Init the tables for toupper() and tolower() */ for (i = 0; i < 256; ++i) toupper_tab[i] = tolower_tab[i] = i; CharUpperBuff((LPSTR)toupper_tab, 256); --- 238,244 ---- PlatformId(); ! // Init the tables for toupper() and tolower() for (i = 0; i < 256; ++i) toupper_tab[i] = tolower_tab[i] = i; CharUpperBuff((LPSTR)toupper_tab, 256); *************** *** 256,262 **** # ifdef VIMDLL if (gui.in_use) # endif ! return TRUE; /* GUI always has a tty */ #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) if (isatty(read_cmd_fd)) --- 256,262 ---- # ifdef VIMDLL if (gui.in_use) # endif ! return TRUE; // GUI always has a tty #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) if (isatty(read_cmd_fd)) *************** *** 336,342 **** { return FALSE; } ! #endif /* FEAT_TITLE */ /* --- 336,342 ---- { return FALSE; } ! #endif // FEAT_TITLE /* *************** *** 387,403 **** int mch_isFullName(char_u *fname) { ! /* WinNT and later can use _MAX_PATH wide characters for a pathname, which ! * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is ! * UTF-8. */ char szName[_MAX_PATH * 3 + 1]; ! /* A name like "d:/foo" and "//server/share" is absolute */ if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))) return TRUE; ! /* A name that can't be made absolute probably isn't absolute. */ if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL) return FALSE; --- 387,403 ---- int mch_isFullName(char_u *fname) { ! // WinNT and later can use _MAX_PATH wide characters for a pathname, which ! // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is ! // UTF-8. char szName[_MAX_PATH * 3 + 1]; ! // A name like "d:/foo" and "//server/share" is absolute if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))) return TRUE; ! // A name that can't be made absolute probably isn't absolute. if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL) return FALSE; *************** *** 424,430 **** { size_t len = STRLEN(p); ! /* don't replace backslash in backtick quoted strings */ if (len > 2 && *(p + len - 1) == '`') return; } --- 424,430 ---- { size_t len = STRLEN(p); ! // don't replace backslash in backtick quoted strings if (len > 2 && *(p + len - 1) == '`') return; } *************** *** 437,443 **** } } ! /* Use 64-bit stat functions if available. */ #ifdef HAVE_STAT64 # undef stat # undef _stat --- 437,443 ---- } } ! // Use 64-bit stat functions if available. #ifdef HAVE_STAT64 # undef stat # undef _stat *************** *** 459,473 **** wstat_symlink_aware(const WCHAR *name, stat_T *stp) { #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) ! /* Work around for VC12 or earlier (and MinGW). _wstat() can't handle ! * symlinks properly. ! * VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves ! * status of a symlink itself. ! * VC10: _wstat() supports a symlink to a normal file, but it doesn't ! * support a symlink to a directory (always returns an error). ! * VC11 and VC12: _wstat() doesn't return an error for a symlink to a ! * directory, but it doesn't set S_IFDIR flag. ! * MinGW: Same as VC9. */ int n; BOOL is_symlink = FALSE; HANDLE hFind, h; --- 459,473 ---- wstat_symlink_aware(const WCHAR *name, stat_T *stp) { #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) ! // Work around for VC12 or earlier (and MinGW). _wstat() can't handle ! // symlinks properly. ! // VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves ! // status of a symlink itself. ! // VC10: _wstat() supports a symlink to a normal file, but it doesn't ! // support a symlink to a directory (always returns an error). ! // VC11 and VC12: _wstat() doesn't return an error for a symlink to a ! // directory, but it doesn't set S_IFDIR flag. ! // MinGW: Same as VC9. int n; BOOL is_symlink = FALSE; HANDLE hFind, h; *************** *** 513,521 **** int vim_stat(const char *name, stat_T *stp) { ! /* WinNT and later can use _MAX_PATH wide characters for a pathname, which ! * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is ! * UTF-8. */ char_u buf[_MAX_PATH * 3 + 1]; char_u *p; WCHAR *wp; --- 513,521 ---- int vim_stat(const char *name, stat_T *stp) { ! // WinNT and later can use _MAX_PATH wide characters for a pathname, which ! // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is ! // UTF-8. char_u buf[_MAX_PATH * 3 + 1]; char_u *p; WCHAR *wp; *************** *** 526,538 **** if (p > buf) MB_PTR_BACK(buf, p); ! /* Remove trailing '\\' except root path. */ if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') *p = NUL; if ((buf[0] == '\\' && buf[1] == '\\') || (buf[0] == '/' && buf[1] == '/')) { ! /* UNC root path must be followed by '\\'. */ p = vim_strpbrk(buf + 2, (char_u *)"\\/"); if (p != NULL) { --- 526,538 ---- if (p > buf) MB_PTR_BACK(buf, p); ! // Remove trailing '\\' except root path. if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') *p = NUL; if ((buf[0] == '\\' && buf[1] == '\\') || (buf[0] == '/' && buf[1] == '/')) { ! // UNC root path must be followed by '\\'. p = vim_strpbrk(buf + 2, (char_u *)"\\/"); if (p != NULL) { *************** *** 555,574 **** void mch_settmode(int tmode UNUSED) { ! /* nothing to do */ } int mch_get_shellsize(void) { ! /* never used */ return OK; } void mch_set_shellsize(void) { ! /* never used */ } /* --- 555,574 ---- void mch_settmode(int tmode UNUSED) { ! // nothing to do } int mch_get_shellsize(void) { ! // never used return OK; } void mch_set_shellsize(void) { ! // never used } /* *************** *** 577,583 **** void mch_new_shellsize(void) { ! /* never used */ } #endif --- 577,583 ---- void mch_new_shellsize(void) { ! // never used } #endif *************** *** 612,618 **** { if (error_ga.ga_data != NULL) { ! /* avoid putting up a message box with blanks only */ for (p = (char *)error_ga.ga_data; *p; ++p) if (!isspace(*p)) { --- 612,618 ---- { if (error_ga.ga_data != NULL) { ! // avoid putting up a message box with blanks only for (p = (char *)error_ga.ga_data; *p; ++p) if (!isspace(*p)) { *************** *** 686,692 **** WCHAR *p; int n; ! if (path[0] == NUL) /* just checking... */ return -1; if (p_verbose >= 5) --- 686,692 ---- WCHAR *p; int n; ! if (path[0] == NUL) // just checking... return -1; if (p_verbose >= 5) *************** *** 695,710 **** smsg("chdir(%s)", path); verbose_leave(); } ! if (isalpha(path[0]) && path[1] == ':') /* has a drive name */ { ! /* If we can change to the drive, skip that part of the path. If we ! * can't then the current directory may be invalid, try using chdir() ! * with the whole path. */ if (_chdrive(TOLOWER_ASC(path[0]) - 'a' + 1) == 0) path += 2; } ! if (*path == NUL) /* drive name only */ return 0; p = enc_to_utf16((char_u *)path, NULL); --- 695,710 ---- smsg("chdir(%s)", path); verbose_leave(); } ! if (isalpha(path[0]) && path[1] == ':') // has a drive name { ! // If we can change to the drive, skip that part of the path. If we ! // can't then the current directory may be invalid, try using chdir() ! // with the whole path. if (_chdrive(TOLOWER_ASC(path[0]) - 'a' + 1) == 0) path += 2; } ! if (*path == NUL) // drive name only return 0; p = enc_to_utf16((char_u *)path, NULL); *************** *** 724,730 **** int mch_char_avail(void) { ! /* never used */ return TRUE; } --- 724,730 ---- int mch_char_avail(void) { ! // never used return TRUE; } *************** *** 735,741 **** int mch_check_messages(void) { ! /* TODO: check for messages */ return TRUE; } # endif --- 735,741 ---- int mch_check_messages(void) { ! // TODO: check for messages return TRUE; } # endif *************** *** 778,797 **** size_t i; const char_u *p; ! /* get page size */ GetSystemInfo(&si); ! /* get memory information */ if (VirtualQuery(str, &mbi, sizeof(mbi))) { ! /* pre cast these (typing savers) */ long_u dwStr = (long_u)str; long_u dwBaseAddress = (long_u)mbi.BaseAddress; ! /* get start address of page that str is on */ long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize; ! /* get length from str to end of page */ long_u pageLength = si.dwPageSize - (dwStr - strPage); for (p = str; !IsBadReadPtr(p, (UINT)pageLength); --- 778,797 ---- size_t i; const char_u *p; ! // get page size GetSystemInfo(&si); ! // get memory information if (VirtualQuery(str, &mbi, sizeof(mbi))) { ! // pre cast these (typing savers) long_u dwStr = (long_u)str; long_u dwBaseAddress = (long_u)mbi.BaseAddress; ! // get start address of page that str is on long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize; ! // get length from str to end of page long_u pageLength = si.dwPageSize - (dwStr - strPage); for (p = str; !IsBadReadPtr(p, (UINT)pageLength); *************** *** 834,842 **** mch_libcall( char_u *libname, char_u *funcname, ! char_u *argstring, /* NULL when using a argint */ int argint, ! char_u **string_result,/* NULL when using number_result */ int *number_result) { HINSTANCE hinstLib; --- 834,842 ---- mch_libcall( char_u *libname, char_u *funcname, ! char_u *argstring, // NULL when using a argint int argint, ! char_u **string_result,// NULL when using number_result int *number_result) { HINSTANCE hinstLib; *************** *** 860,866 **** # endif if (argstring != NULL) { ! /* Call with string argument */ ProcAdd = (MYSTRPROCSTR)GetProcAddress(hinstLib, (LPCSTR)funcname); if ((fRunTimeLinkSuccess = (ProcAdd != NULL)) != 0) { --- 860,866 ---- # endif if (argstring != NULL) { ! // Call with string argument ProcAdd = (MYSTRPROCSTR)GetProcAddress(hinstLib, (LPCSTR)funcname); if ((fRunTimeLinkSuccess = (ProcAdd != NULL)) != 0) { *************** *** 872,878 **** } else { ! /* Call with number argument */ ProcAddI = (MYINTPROCSTR) GetProcAddress(hinstLib, (LPCSTR)funcname); if ((fRunTimeLinkSuccess = (ProcAddI != NULL)) != 0) { --- 872,878 ---- } else { ! // Call with number argument ProcAddI = (MYINTPROCSTR) GetProcAddress(hinstLib, (LPCSTR)funcname); if ((fRunTimeLinkSuccess = (ProcAddI != NULL)) != 0) { *************** *** 957,963 **** #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO) # ifdef FEAT_TITLE ! extern HWND g_hWnd; /* This is in os_win32.c. */ # endif /* --- 957,963 ---- #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO) # ifdef FEAT_TITLE ! extern HWND g_hWnd; // This is in os_win32.c. # endif /* *************** *** 968,979 **** static void GetConsoleHwnd(void) { ! /* Skip if it's already set. */ if (s_hwnd != 0) return; # ifdef FEAT_TITLE ! /* Window handle may have been found by init code (Windows NT only) */ if (g_hWnd != 0) { s_hwnd = g_hWnd; --- 968,979 ---- static void GetConsoleHwnd(void) { ! // Skip if it's already set. if (s_hwnd != 0) return; # ifdef FEAT_TITLE ! // Window handle may have been found by init code (Windows NT only) if (g_hWnd != 0) { s_hwnd = g_hWnd; *************** *** 1013,1021 **** #if (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) || defined(PROTO) ! /*================================================================= ! * Win32 printer stuff ! */ static HFONT prt_font_handles[2][2][2]; static PRINTDLGW prt_dlg; --- 1013,1020 ---- #if (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) || defined(PROTO) ! //================================================================= ! // Win32 printer stuff static HFONT prt_font_handles[2][2][2]; static PRINTDLGW prt_dlg; *************** *** 1031,1037 **** static int *bUserAbort = NULL; static char_u *prt_name = NULL; ! /* Defines which are also in vim.rc. */ # define IDC_BOX1 400 # define IDC_PRINTTEXT1 401 # define IDC_PRINTTEXT2 402 --- 1030,1036 ---- static int *bUserAbort = NULL; static char_u *prt_name = NULL; ! // Defines which are also in vim.rc. # define IDC_BOX1 400 # define IDC_PRINTTEXT1 401 # define IDC_PRINTTEXT2 402 *************** *** 1067,1073 **** return colorref; } ! /* Attempt to make this work for old and new compilers */ # if !defined(_WIN64) && (!defined(_MSC_VER) || _MSC_VER < 1300) # define PDP_RETVAL BOOL # else --- 1066,1072 ---- return colorref; } ! // Attempt to make this work for old and new compilers # if !defined(_WIN64) && (!defined(_MSC_VER) || _MSC_VER < 1300) # define PDP_RETVAL BOOL # else *************** *** 1100,1106 **** char buff[MAX_PATH]; int i; ! /* Translate the dialog texts */ hfont = CreateFontIndirect(&nm.lfMessageFont); for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) { --- 1099,1105 ---- char buff[MAX_PATH]; int i; ! // Translate the dialog texts hfont = CreateFontIndirect(&nm.lfMessageFont); for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) { *************** *** 1201,1211 **** 0, 0, // ignores size arguments SWP_NOSIZE); ! /* tackle the printdlg copiesctrl problem */ pPD = (PRINTDLGW *)lParam; pPD->nCopies = (WORD)pPD->lCustData; SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); ! /* Bring the window to top */ BringWindowToTop(GetParent(hDlg)); SetForegroundWindow(hDlg); } --- 1200,1210 ---- 0, 0, // ignores size arguments SWP_NOSIZE); ! // tackle the printdlg copiesctrl problem pPD = (PRINTDLGW *)lParam; pPD->nCopies = (WORD)pPD->lCustData; SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); ! // Bring the window to top BringWindowToTop(GetParent(hDlg)); SetForegroundWindow(hDlg); } *************** *** 1323,1329 **** prt_top_margin = to_device_units(OPT_PRINT_TOP, dpi, phyw, dvoff, 5); ! /* adjust top margin if there is a header */ prt_top_margin += prt_line_height * prt_header_height(); bottom_margin = vr - to_device_units(OPT_PRINT_BOT, dpi, phyw, --- 1322,1328 ---- prt_top_margin = to_device_units(OPT_PRINT_TOP, dpi, phyw, dvoff, 5); ! // adjust top margin if there is a header prt_top_margin += prt_line_height * prt_header_height(); bottom_margin = vr - to_device_units(OPT_PRINT_BOT, dpi, phyw, *************** *** 1356,1362 **** # ifdef VIMDLL if (!gui.in_use) # endif ! GetConsoleHwnd(); /* get value of s_hwnd */ # endif prt_dlg.hwndOwner = s_hwnd; prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; --- 1355,1361 ---- # ifdef VIMDLL if (!gui.in_use) # endif ! GetConsoleHwnd(); // get value of s_hwnd # endif prt_dlg.hwndOwner = s_hwnd; prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; *************** *** 1428,1442 **** return FALSE; } ! /* Not all printer drivers report the support of color (or grey) in the ! * same way. Let's set has_color if there appears to be some way to print ! * more than B&W. */ i = GetDeviceCaps(prt_dlg.hDC, NUMCOLORS); psettings->has_color = (GetDeviceCaps(prt_dlg.hDC, BITSPIXEL) > 1 || GetDeviceCaps(prt_dlg.hDC, PLANES) > 1 || i > 2 || i == -1); ! /* Ensure all font styles are baseline aligned */ SetTextAlign(prt_dlg.hDC, TA_BASELINE|TA_LEFT); /* --- 1427,1441 ---- return FALSE; } ! // Not all printer drivers report the support of color (or grey) in the ! // same way. Let's set has_color if there appears to be some way to print ! // more than B&W. i = GetDeviceCaps(prt_dlg.hDC, NUMCOLORS); psettings->has_color = (GetDeviceCaps(prt_dlg.hDC, BITSPIXEL) > 1 || GetDeviceCaps(prt_dlg.hDC, PLANES) > 1 || i > 2 || i == -1); ! // Ensure all font styles are baseline aligned SetTextAlign(prt_dlg.hDC, TA_BASELINE|TA_LEFT); /* *************** *** 1537,1544 **** { char_u *buf; ! /* I suspect FormatMessage() doesn't work for values returned by ! * CommDlgExtendedError(). What does? */ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, --- 1536,1543 ---- { char_u *buf; ! // I suspect FormatMessage() doesn't work for values returned by ! // CommDlgExtendedError(). What does? FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, *************** *** 1548,1554 **** LocalFree((LPVOID)(buf)); } else ! msg_clr_eos(); /* Maybe canceled */ mch_print_cleanup(); return FALSE; --- 1547,1553 ---- LocalFree((LPVOID)(buf)); } else ! msg_clr_eos(); // Maybe canceled mch_print_cleanup(); return FALSE; *************** *** 1582,1588 **** } # ifdef FEAT_GUI ! /* Give focus back to main window (when using MDI). */ # ifdef VIMDLL if (gui.in_use) # endif --- 1581,1587 ---- } # ifdef FEAT_GUI ! // Give focus back to main window (when using MDI). # ifdef VIMDLL if (gui.in_use) # endif *************** *** 1651,1657 **** GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); vim_free(wp); prt_pos_x += (sz.cx - prt_tm.tmOverhang); ! /* This is wrong when printing spaces for a TAB. */ if (p[len] != NUL) { wlen = mb_ptr2len(p + len); --- 1650,1656 ---- GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); vim_free(wp); prt_pos_x += (sz.cx - prt_tm.tmOverhang); ! // This is wrong when printing spaces for a TAB. if (p[len] != NUL) { wlen = mb_ptr2len(p + len); *************** *** 1694,1700 **** swap_me((COLORREF)fgcol))); } ! #endif /*FEAT_PRINTER && !FEAT_POSTSCRIPT*/ --- 1693,1699 ---- swap_me((COLORREF)fgcol))); } ! #endif // FEAT_PRINTER && !FEAT_POSTSCRIPT *************** *** 1830,1837 **** IShellLinkW *pslw = NULL; WIN32_FIND_DATAW ffdw; // we get those free of charge ! /* Check if the file name ends in ".lnk". Avoid calling ! * CoCreateInstance(), it's quite slow. */ if (fname == NULL) return rfname; len = (int)STRLEN(fname); --- 1829,1836 ---- IShellLinkW *pslw = NULL; WIN32_FIND_DATAW ffdw; // we get those free of charge ! // Check if the file name ends in ".lnk". Avoid calling ! // CoCreateInstance(), it's quite slow. if (fname == NULL) return rfname; len = (int)STRLEN(fname); *************** *** 1907,1913 **** void win32_set_foreground(void) { ! GetConsoleHwnd(); /* get value of s_hwnd */ if (s_hwnd != 0) SetForegroundWindow(s_hwnd); } --- 1906,1912 ---- void win32_set_foreground(void) { ! GetConsoleHwnd(); // get value of s_hwnd if (s_hwnd != 0) SetForegroundWindow(s_hwnd); } *************** *** 1920,1939 **** * Originally written by Paul Moore */ ! /* In order to handle inter-process messages, we need to have a window. But ! * the functions in this module can be called before the main GUI window is ! * created (and may also be called in the console version, where there is no ! * GUI window at all). ! * ! * So we create a hidden window, and arrange to destroy it on exit. ! */ ! HWND message_window = 0; /* window that's handling messages */ # define VIM_CLASSNAME "VIM_MESSAGES" # define VIM_CLASSNAME_LEN (sizeof(VIM_CLASSNAME) - 1) ! /* Communication is via WM_COPYDATA messages. The message type is send in ! * the dwData parameter. Types are defined here. */ # define COPYDATA_KEYS 0 # define COPYDATA_REPLY 1 # define COPYDATA_EXPR 10 --- 1919,1937 ---- * Originally written by Paul Moore */ ! // In order to handle inter-process messages, we need to have a window. But ! // the functions in this module can be called before the main GUI window is ! // created (and may also be called in the console version, where there is no ! // GUI window at all). ! // ! // So we create a hidden window, and arrange to destroy it on exit. ! HWND message_window = 0; // window that's handling messages # define VIM_CLASSNAME "VIM_MESSAGES" # define VIM_CLASSNAME_LEN (sizeof(VIM_CLASSNAME) - 1) ! // Communication is via WM_COPYDATA messages. The message type is send in ! // the dwData parameter. Types are defined here. # define COPYDATA_KEYS 0 # define COPYDATA_REPLY 1 # define COPYDATA_EXPR 10 *************** *** 1941,1954 **** # define COPYDATA_ERROR_RESULT 12 # define COPYDATA_ENCODING 20 ! /* This is a structure containing a server HWND and its name. */ struct server_id { HWND hwnd; char_u *name; }; ! /* Last received 'encoding' that the client uses. */ static char_u *client_enc = NULL; /* --- 1939,1952 ---- # define COPYDATA_ERROR_RESULT 12 # define COPYDATA_ENCODING 20 ! // This is a structure containing a server HWND and its name. struct server_id { HWND hwnd; char_u *name; }; ! // Last received 'encoding' that the client uses. static char_u *client_enc = NULL; /* *************** *** 1997,2023 **** { if (msg == WM_COPYDATA) { ! /* This is a message from another Vim. The dwData member of the ! * COPYDATASTRUCT determines the type of message: ! * COPYDATA_ENCODING: ! * The encoding that the client uses. Following messages will ! * use this encoding, convert if needed. ! * COPYDATA_KEYS: ! * A key sequence. We are a server, and a client wants these keys ! * adding to the input queue. ! * COPYDATA_REPLY: ! * A reply. We are a client, and a server has sent this message ! * in response to a request. (server2client()) ! * COPYDATA_EXPR: ! * An expression. We are a server, and a client wants us to ! * evaluate this expression. ! * COPYDATA_RESULT: ! * A reply. We are a client, and a server has sent this message ! * in response to a COPYDATA_EXPR. ! * COPYDATA_ERROR_RESULT: ! * A reply. We are a client, and a server has sent this message ! * in response to a COPYDATA_EXPR that failed to evaluate. ! */ COPYDATASTRUCT *data = (COPYDATASTRUCT*)lParam; HWND sender = (HWND)wParam; COPYDATASTRUCT reply; --- 1995,2020 ---- { if (msg == WM_COPYDATA) { ! // This is a message from another Vim. The dwData member of the ! // COPYDATASTRUCT determines the type of message: ! // COPYDATA_ENCODING: ! // The encoding that the client uses. Following messages will ! // use this encoding, convert if needed. ! // COPYDATA_KEYS: ! // A key sequence. We are a server, and a client wants these keys ! // adding to the input queue. ! // COPYDATA_REPLY: ! // A reply. We are a client, and a server has sent this message ! // in response to a request. (server2client()) ! // COPYDATA_EXPR: ! // An expression. We are a server, and a client wants us to ! // evaluate this expression. ! // COPYDATA_RESULT: ! // A reply. We are a client, and a server has sent this message ! // in response to a COPYDATA_EXPR. ! // COPYDATA_ERROR_RESULT: ! // A reply. We are a client, and a server has sent this message ! // in response to a COPYDATA_EXPR that failed to evaluate. COPYDATASTRUCT *data = (COPYDATASTRUCT*)lParam; HWND sender = (HWND)wParam; COPYDATASTRUCT reply; *************** *** 2029,2051 **** switch (data->dwData) { case COPYDATA_ENCODING: ! /* Remember the encoding that the client uses. */ vim_free(client_enc); client_enc = enc_canonize((char_u *)data->lpData); return 1; case COPYDATA_KEYS: ! /* Remember who sent this, for */ clientWindow = sender; ! /* Add the received keys to the input buffer. The loop waiting ! * for the user to do something should check the input buffer. */ str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); server_to_input_buf(str); vim_free(tofree); # ifdef FEAT_GUI ! /* Wake up the main GUI loop. */ # ifdef VIMDLL if (gui.in_use) # endif --- 2026,2048 ---- switch (data->dwData) { case COPYDATA_ENCODING: ! // Remember the encoding that the client uses. vim_free(client_enc); client_enc = enc_canonize((char_u *)data->lpData); return 1; case COPYDATA_KEYS: ! // Remember who sent this, for clientWindow = sender; ! // Add the received keys to the input buffer. The loop waiting ! // for the user to do something should check the input buffer. str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); server_to_input_buf(str); vim_free(tofree); # ifdef FEAT_GUI ! // Wake up the main GUI loop. # ifdef VIMDLL if (gui.in_use) # endif *************** *** 2055,2061 **** return 1; case COPYDATA_EXPR: ! /* Remember who sent this, for */ clientWindow = sender; str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); --- 2052,2058 ---- return 1; case COPYDATA_EXPR: ! // Remember who sent this, for clientWindow = sender; str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); *************** *** 2114,2126 **** else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) { ! /* When the message window is activated (brought to the foreground), ! * this actually applies to the text window. */ # if !defined(FEAT_GUI) || defined(VIMDLL) # ifdef VIMDLL if (!gui.in_use) # endif ! GetConsoleHwnd(); /* get value of s_hwnd */ # endif if (s_hwnd != 0) { --- 2111,2123 ---- else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) { ! // When the message window is activated (brought to the foreground), ! // this actually applies to the text window. # if !defined(FEAT_GUI) || defined(VIMDLL) # ifdef VIMDLL if (!gui.in_use) # endif ! GetConsoleHwnd(); // get value of s_hwnd # endif if (s_hwnd != 0) { *************** *** 2141,2152 **** { WNDCLASS wndclass; ! /* Clean up on exit */ atexit(CleanUpMessaging); ! /* Register a window class - we only really care ! * about the window procedure ! */ wndclass.style = 0; wndclass.lpfnWndProc = Messaging_WndProc; wndclass.cbClsExtra = 0; --- 2138,2148 ---- { WNDCLASS wndclass; ! // Clean up on exit atexit(CleanUpMessaging); ! // Register a window class - we only really care ! // about the window procedure wndclass.style = 0; wndclass.lpfnWndProc = Messaging_WndProc; wndclass.cbClsExtra = 0; *************** *** 2159,2167 **** wndclass.lpszClassName = VIM_CLASSNAME; RegisterClass(&wndclass); ! /* Create the message window. It will be hidden, so the details don't ! * matter. Don't use WS_OVERLAPPEDWINDOW, it will make a shortcut remove ! * focus from gvim. */ message_window = CreateWindow(VIM_CLASSNAME, "", WS_POPUPWINDOW | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, --- 2155,2163 ---- wndclass.lpszClassName = VIM_CLASSNAME; RegisterClass(&wndclass); ! // Create the message window. It will be hidden, so the details don't ! // matter. Don't use WS_OVERLAPPEDWINDOW, it will make a shortcut remove ! // focus from gvim. message_window = CreateWindow(VIM_CLASSNAME, "", WS_POPUPWINDOW | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, *************** *** 2169,2175 **** g_hinst, NULL); } ! /* Used by serverSendToVim() to find an alternate server name. */ static char_u *altname_buf_ptr = NULL; /* --- 2165,2171 ---- g_hinst, NULL); } ! // Used by serverSendToVim() to find an alternate server name. static char_u *altname_buf_ptr = NULL; /* *************** *** 2183,2194 **** int len; char buffer[VIM_CLASSNAME_LEN + 1]; ! /* Ignore windows which aren't Vim message windows */ len = GetClassName(hwnd, buffer, sizeof(buffer)); if (len != VIM_CLASSNAME_LEN || STRCMP(buffer, VIM_CLASSNAME) != 0) return 0; ! /* Get the title of the window */ return GetWindowText(hwnd, name, namelen); } --- 2179,2190 ---- int len; char buffer[VIM_CLASSNAME_LEN + 1]; ! // Ignore windows which aren't Vim message windows len = GetClassName(hwnd, buffer, sizeof(buffer)); if (len != VIM_CLASSNAME_LEN || STRCMP(buffer, VIM_CLASSNAME) != 0) return 0; ! // Get the title of the window return GetWindowText(hwnd, name, namelen); } *************** *** 2198,2224 **** struct server_id *id = (struct server_id *)lparam; char server[MAX_PATH]; ! /* Get the title of the window */ if (getVimServerName(hwnd, server, sizeof(server)) == 0) return TRUE; ! /* If this is the server we're looking for, return its HWND */ if (STRICMP(server, id->name) == 0) { id->hwnd = hwnd; return FALSE; } ! /* If we are looking for an alternate server, remember this name. */ if (altname_buf_ptr != NULL && STRNICMP(server, id->name, STRLEN(id->name)) == 0 && vim_isdigit(server[STRLEN(id->name)])) { STRCPY(altname_buf_ptr, server); ! altname_buf_ptr = NULL; /* don't use another name */ } ! /* Otherwise, keep looking */ return TRUE; } --- 2194,2220 ---- struct server_id *id = (struct server_id *)lparam; char server[MAX_PATH]; ! // Get the title of the window if (getVimServerName(hwnd, server, sizeof(server)) == 0) return TRUE; ! // If this is the server we're looking for, return its HWND if (STRICMP(server, id->name) == 0) { id->hwnd = hwnd; return FALSE; } ! // If we are looking for an alternate server, remember this name. if (altname_buf_ptr != NULL && STRNICMP(server, id->name, STRLEN(id->name)) == 0 && vim_isdigit(server[STRLEN(id->name)])) { STRCPY(altname_buf_ptr, server); ! altname_buf_ptr = NULL; // don't use another name } ! // Otherwise, keep looking return TRUE; } *************** *** 2228,2238 **** garray_T *ga = (garray_T *)lparam; char server[MAX_PATH]; ! /* Get the title of the window */ if (getVimServerName(hwnd, server, sizeof(server)) == 0) return TRUE; ! /* Add the name to the list */ ga_concat(ga, (char_u *)server); ga_concat(ga, (char_u *)"\n"); return TRUE; --- 2224,2234 ---- garray_T *ga = (garray_T *)lparam; char server[MAX_PATH]; ! // Get the title of the window if (getVimServerName(hwnd, server, sizeof(server)) == 0) return TRUE; ! // Add the name to the list ga_concat(ga, (char_u *)server); ga_concat(ga, (char_u *)"\n"); return TRUE; *************** *** 2262,2268 **** return EnumChildWindows(hwnd, enum_windows_child, lParam); } ! /* Enumerate all windows including children. */ static BOOL enum_windows(WNDENUMPROC lpEnumFunc, LPARAM lParam) { --- 2258,2266 ---- return EnumChildWindows(hwnd, enum_windows_child, lParam); } ! /* ! * Enumerate all windows including children. ! */ static BOOL enum_windows(WNDENUMPROC lpEnumFunc, LPARAM lParam) { *************** *** 2294,2300 **** int i = 0; char_u *p; ! /* Leave enough space for a 9-digit suffix to ensure uniqueness! */ ok_name = alloc(STRLEN(name) + 10); STRCPY(ok_name, name); --- 2292,2298 ---- int i = 0; char_u *p; ! // Leave enough space for a 9-digit suffix to ensure uniqueness! ok_name = alloc(STRLEN(name) + 10); STRCPY(ok_name, name); *************** *** 2302,2311 **** for (;;) { ! /* This is inefficient - we're doing an EnumWindows loop for each ! * possible name. It would be better to grab all names in one go, ! * and scan the list each time... ! */ hwnd = findServer(ok_name); if (hwnd == 0) break; --- 2300,2308 ---- for (;;) { ! // This is inefficient - we're doing an EnumWindows loop for each ! // possible name. It would be better to grab all names in one go, ! // and scan the list each time... hwnd = findServer(ok_name); if (hwnd == 0) break; *************** *** 2321,2337 **** vim_free(ok_name); else { ! /* Remember the name */ serverName = ok_name; # ifdef FEAT_TITLE ! need_maketitle = TRUE; /* update Vim window title later */ # endif ! /* Update the message window title */ SetWindowText(message_window, (LPCSTR)ok_name); # ifdef FEAT_EVAL ! /* Set the servername variable */ set_vim_var_string(VV_SEND_SERVER, serverName, -1); # endif } --- 2318,2334 ---- vim_free(ok_name); else { ! // Remember the name serverName = ok_name; # ifdef FEAT_TITLE ! need_maketitle = TRUE; // update Vim window title later # endif ! // Update the message window title SetWindowText(message_window, (LPCSTR)ok_name); # ifdef FEAT_EVAL ! // Set the servername variable set_vim_var_string(VV_SEND_SERVER, serverName, -1); # endif } *************** *** 2352,2368 **** int serverSendReply( ! char_u *name, /* Where to send. */ ! char_u *reply) /* What to send. */ { HWND target; COPYDATASTRUCT data; long_u n = 0; ! /* The "name" argument is a magic cookie obtained from expand(""). ! * It should be of the form 0xXXXXX - i.e. a C hex literal, which is the ! * value of the client's message window HWND. ! */ sscanf((char *)name, SCANF_HEX_LONG_U, &n); if (n == 0) return -1; --- 2349,2364 ---- int serverSendReply( ! char_u *name, // Where to send. ! char_u *reply) // What to send. { HWND target; COPYDATASTRUCT data; long_u n = 0; ! // The "name" argument is a magic cookie obtained from expand(""). ! // It should be of the form 0xXXXXX - i.e. a C hex literal, which is the ! // value of the client's message window HWND. sscanf((char *)name, SCANF_HEX_LONG_U, &n); if (n == 0) return -1; *************** *** 2385,2397 **** int serverSendToVim( ! char_u *name, /* Where to send. */ ! char_u *cmd, /* What to send. */ ! char_u **result, /* Result of eval'ed expression */ ! void *ptarget, /* HWND of server */ ! int asExpr, /* Expression or keys? */ ! int timeout, /* timeout in seconds or zero */ ! int silent) /* don't complain about no server */ { HWND target; COPYDATASTRUCT data; --- 2381,2393 ---- int serverSendToVim( ! char_u *name, // Where to send. ! char_u *cmd, // What to send. ! char_u **result, // Result of eval'ed expression ! void *ptarget, // HWND of server ! int asExpr, // Expression or keys? ! int timeout, // timeout in seconds or zero ! int silent) // don't complain about no server { HWND target; COPYDATASTRUCT data; *************** *** 2399,2417 **** int retcode = 0; char_u altname_buf[MAX_PATH]; ! /* Execute locally if no display or target is ourselves */ if (serverName != NULL && STRICMP(name, serverName) == 0) return sendToLocalVim(cmd, asExpr, result); ! /* If the server name does not end in a digit then we look for an ! * alternate name. e.g. when "name" is GVIM the we may find GVIM2. */ if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) altname_buf_ptr = altname_buf; altname_buf[0] = NUL; target = findServer(name); altname_buf_ptr = NULL; if (target == 0 && altname_buf[0] != NUL) ! /* Use another server name we found. */ target = findServer(altname_buf); if (target == 0) --- 2395,2413 ---- int retcode = 0; char_u altname_buf[MAX_PATH]; ! // Execute locally if no display or target is ourselves if (serverName != NULL && STRICMP(name, serverName) == 0) return sendToLocalVim(cmd, asExpr, result); ! // If the server name does not end in a digit then we look for an ! // alternate name. e.g. when "name" is GVIM the we may find GVIM2. if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) altname_buf_ptr = altname_buf; altname_buf[0] = NUL; target = findServer(name); altname_buf_ptr = NULL; if (target == 0 && altname_buf[0] != NUL) ! // Use another server name we found. target = findServer(altname_buf); if (target == 0) *************** *** 2439,2445 **** if (result == NULL) vim_free(retval); else ! *result = retval; /* Caller assumes responsibility for freeing */ return retcode; } --- 2435,2441 ---- if (result == NULL) vim_free(retval); else ! *result = retval; // Caller assumes responsibility for freeing return retcode; } *************** *** 2456,2474 **** SetForegroundWindow(target); } ! /* Replies from server need to be stored until the client picks them up via ! * remote_read(). So we maintain a list of server-id/reply pairs. ! * Note that there could be multiple replies from one server pending if the ! * client is slow picking them up. ! * We just store the replies in a simple list. When we remove an entry, we ! * move list entries down to fill the gap. ! * The server ID is simply the HWND. ! */ typedef struct { ! HWND server; /* server window */ ! char_u *reply; /* reply string */ ! int expr_result; /* 0 for REPLY, 1 for RESULT 2 for error */ } reply_T; static garray_T reply_list = {0, 0, sizeof(reply_T), 5, 0}; --- 2452,2469 ---- SetForegroundWindow(target); } ! // Replies from server need to be stored until the client picks them up via ! // remote_read(). So we maintain a list of server-id/reply pairs. ! // Note that there could be multiple replies from one server pending if the ! // client is slow picking them up. ! // We just store the replies in a simple list. When we remove an entry, we ! // move list entries down to fill the gap. ! // The server ID is simply the HWND. typedef struct { ! HWND server; // server window ! char_u *reply; // reply string ! int expr_result; // 0 for REPLY, 1 for RESULT 2 for error } reply_T; static garray_T reply_list = {0, 0, sizeof(reply_T), 5, 0}; *************** *** 2476,2482 **** # define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i)) # define REPLY_COUNT (reply_list.ga_len) ! /* Flag which is used to wait for a reply */ static int reply_received = 0; /* --- 2471,2477 ---- # define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i)) # define REPLY_COUNT (reply_list.ga_len) ! // Flag which is used to wait for a reply static int reply_received = 0; /* *************** *** 2520,2531 **** time_t start; time_t now; ! /* When waiting, loop until the message waiting for is received. */ time(&start); for (;;) { ! /* Reset this here, in case a message arrives while we are going ! * through the already received messages. */ reply_received = 0; for (i = 0; i < REPLY_COUNT; ++i) --- 2515,2526 ---- time_t start; time_t now; ! // When waiting, loop until the message waiting for is received. time(&start); for (;;) { ! // Reset this here, in case a message arrives while we are going ! // through the already received messages. reply_received = 0; for (i = 0; i < REPLY_COUNT; ++i) *************** *** 2534,2564 **** if (rep->server == server && ((rep->expr_result != 0) == (expr_res != NULL))) { ! /* Save the values we've found for later */ reply = rep->reply; if (expr_res != NULL) *expr_res = rep->expr_result == 1 ? 0 : -1; if (remove) { ! /* Move the rest of the list down to fill the gap */ mch_memmove(rep, rep + 1, (REPLY_COUNT - i - 1) * sizeof(reply_T)); --REPLY_COUNT; } ! /* Return the reply to the caller, who takes on responsibility ! * for freeing it if "remove" is TRUE. */ return reply; } } ! /* If we got here, we didn't find a reply. Return immediately if the ! * "wait" parameter isn't set. */ if (!wait) { ! /* Process pending messages once. Without this, looping on ! * remote_peek() would never get the reply. */ if (!did_process) { did_process = TRUE; --- 2529,2559 ---- if (rep->server == server && ((rep->expr_result != 0) == (expr_res != NULL))) { ! // Save the values we've found for later reply = rep->reply; if (expr_res != NULL) *expr_res = rep->expr_result == 1 ? 0 : -1; if (remove) { ! // Move the rest of the list down to fill the gap mch_memmove(rep, rep + 1, (REPLY_COUNT - i - 1) * sizeof(reply_T)); --REPLY_COUNT; } ! // Return the reply to the caller, who takes on responsibility ! // for freeing it if "remove" is TRUE. return reply; } } ! // If we got here, we didn't find a reply. Return immediately if the ! // "wait" parameter isn't set. if (!wait) { ! // Process pending messages once. Without this, looping on ! // remote_peek() would never get the reply. if (!did_process) { did_process = TRUE; *************** *** 2568,2593 **** break; } ! /* We need to wait for a reply. Enter a message loop until the ! * "reply_received" flag gets set. */ ! /* Loop until we receive a reply */ while (reply_received == 0) { # ifdef FEAT_TIMERS ! /* TODO: use the return value to decide how long to wait. */ check_due_timer(); # endif time(&now); if (timeout > 0 && (now - start) >= timeout) break; ! /* Wait for a SendMessage() call to us. This could be the reply ! * we are waiting for. Use a timeout of a second, to catch the ! * situation that the server died unexpectedly. */ MsgWaitForMultipleObjects(0, NULL, TRUE, 1000, QS_ALLINPUT); ! /* If the server has died, give up */ if (!IsWindow(server)) return NULL; --- 2563,2588 ---- break; } ! // We need to wait for a reply. Enter a message loop until the ! // "reply_received" flag gets set. ! // Loop until we receive a reply while (reply_received == 0) { # ifdef FEAT_TIMERS ! // TODO: use the return value to decide how long to wait. check_due_timer(); # endif time(&now); if (timeout > 0 && (now - start) >= timeout) break; ! // Wait for a SendMessage() call to us. This could be the reply ! // we are waiting for. Use a timeout of a second, to catch the ! // situation that the server died unexpectedly. MsgWaitForMultipleObjects(0, NULL, TRUE, 1000, QS_ALLINPUT); ! // If the server has died, give up if (!IsWindow(server)) return NULL; *************** *** 2613,2619 **** } } ! #endif /* FEAT_CLIENTSERVER */ #if defined(FEAT_GUI) || (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) \ || defined(PROTO) --- 2608,2614 ---- } } ! #endif // FEAT_CLIENTSERVER #if defined(FEAT_GUI) || (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) \ || defined(PROTO) *************** *** 2713,2719 **** -12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, ! L"Fixedsys" /* see _ReadVimIni */ }; // Initialise the "current height" to -12 (same as s_lfDefault) just --- 2708,2714 ---- -12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, ! L"Fixedsys" // see _ReadVimIni }; // Initialise the "current height" to -12 (same as s_lfDefault) just *************** *** 2722,2728 **** // (-12 equates to roughly 9pt). int current_font_height = -12; // also used in gui_w32.c ! /* Convert a string representing a point size into pixels. The string should * be a positive decimal number, with an optional decimal point (eg, "12", or * "10.5"). The pixel value is returned, and a pointer to the next unconverted * character is stored in *end. The flag "vertical" says whether this --- 2717,2724 ---- // (-12 equates to roughly 9pt). int current_font_height = -12; // also used in gui_w32.c ! /* ! * Convert a string representing a point size into pixels. The string should * be a positive decimal number, with an optional decimal point (eg, "12", or * "10.5"). The pixel value is returned, and a pointer to the next unconverted * character is stored in *end. The flag "vertical" says whether this *************** *** 2742,2748 **** { if (*str == L'.' && divisor == 0) { ! /* Start keeping a divisor, for later */ divisor = 1; } else --- 2738,2744 ---- { if (*str == L'.' && divisor == 0) { ! // Start keeping a divisor, for later divisor = 1; } else *************** *** 2786,2820 **** DWORD type UNUSED, LPARAM lparam) { ! /* Return value: ! * 0 = terminate now (monospace & ANSI) ! * 1 = continue, still no luck... ! * 2 = continue, but we have an acceptable LOGFONTW ! * (monospace, not ANSI) ! * We use these values, as EnumFontFamilies returns 1 if the ! * callback function is never called. So, we check the return as ! * 0 = perfect, 2 = OK, 1 = no good... ! * It's not pretty, but it works! ! */ LOGFONTW *lf = (LOGFONTW *)(lparam); # ifndef FEAT_PROPORTIONAL_FONTS ! /* Ignore non-monospace fonts without further ado */ if ((ntm->tmPitchAndFamily & 1) != 0) return 1; # endif ! /* Remember this LOGFONTW as a "possible" */ *lf = elf->elfLogFont; ! /* Terminate the scan as soon as we find an ANSI font */ if (lf->lfCharSet == ANSI_CHARSET || lf->lfCharSet == OEM_CHARSET || lf->lfCharSet == DEFAULT_CHARSET) return 0; ! /* Continue the scan - we have a non-ANSI font */ return 2; } --- 2782,2815 ---- DWORD type UNUSED, LPARAM lparam) { ! // Return value: ! // 0 = terminate now (monospace & ANSI) ! // 1 = continue, still no luck... ! // 2 = continue, but we have an acceptable LOGFONTW ! // (monospace, not ANSI) ! // We use these values, as EnumFontFamilies returns 1 if the ! // callback function is never called. So, we check the return as ! // 0 = perfect, 2 = OK, 1 = no good... ! // It's not pretty, but it works! LOGFONTW *lf = (LOGFONTW *)(lparam); # ifndef FEAT_PROPORTIONAL_FONTS ! // Ignore non-monospace fonts without further ado if ((ntm->tmPitchAndFamily & 1) != 0) return 1; # endif ! // Remember this LOGFONTW as a "possible" *lf = elf->elfLogFont; ! // Terminate the scan as soon as we find an ANSI font if (lf->lfCharSet == ANSI_CHARSET || lf->lfCharSet == OEM_CHARSET || lf->lfCharSet == DEFAULT_CHARSET) return 0; ! // Continue the scan - we have a non-ANSI font return 2; } *************** *** 2832,2845 **** ReleaseDC(hwnd, hdc); ! /* If we couldn't find a usable font, return failure */ if (n == 1) return FAIL; ! /* Tidy up the rest of the LOGFONTW structure. We set to a basic ! * font - get_logfont() sets bold, italic, etc based on the user's ! * input. ! */ lf->lfHeight = current_font_height; lf->lfWidth = 0; lf->lfItalic = FALSE; --- 2827,2839 ---- ReleaseDC(hwnd, hdc); ! // If we couldn't find a usable font, return failure if (n == 1) return FAIL; ! // Tidy up the rest of the LOGFONTW structure. We set to a basic ! // font - get_logfont() sets bold, italic, etc based on the user's ! // input. lf->lfHeight = current_font_height; lf->lfWidth = 0; lf->lfItalic = FALSE; *************** *** 2847,2853 **** lf->lfStrikeOut = FALSE; lf->lfWeight = FW_NORMAL; ! /* Return success */ return OK; } --- 2841,2847 ---- lf->lfStrikeOut = FALSE; lf->lfWeight = FW_NORMAL; ! // Return success return OK; } *************** *** 2897,2903 **** { # if defined(FEAT_GUI_MSWIN) CHOOSEFONTW cf; ! /* if name is "*", bring up std font dialog: */ vim_memset(&cf, 0, sizeof(cf)); cf.lStructSize = sizeof(cf); cf.hwndOwner = s_hwnd; --- 2891,2897 ---- { # if defined(FEAT_GUI_MSWIN) CHOOSEFONTW cf; ! // if name is "*", bring up std font dialog: vim_memset(&cf, 0, sizeof(cf)); cf.lStructSize = sizeof(cf); cf.hwndOwner = s_hwnd; *************** *** 2918,2930 **** for (p = wname; *p && *p != L':'; p++) { if (p - wname + 1 >= LF_FACESIZE) ! goto theend; /* Name too long */ lf->lfFaceName[p - wname] = *p; } if (p != wname) lf->lfFaceName[p - wname] = NUL; ! /* First set defaults */ lf->lfHeight = -12; lf->lfWidth = 0; lf->lfWeight = FW_NORMAL; --- 2912,2924 ---- for (p = wname; *p && *p != L':'; p++) { if (p - wname + 1 >= LF_FACESIZE) ! goto theend; // Name too long lf->lfFaceName[p - wname] = *p; } if (p != wname) lf->lfFaceName[p - wname] = NUL; ! // First set defaults lf->lfHeight = -12; lf->lfWidth = 0; lf->lfWeight = FW_NORMAL; *************** *** 2952,2958 **** while (*p == L':') p++; ! /* Set the values found after ':' */ while (*p) { switch (*p++) --- 2946,2952 ---- while (*p == L':') p++; ! // Set the values found after ':' while (*p) { switch (*p++) *************** *** 3029,3035 **** ret = OK; theend: ! /* ron: init lastlf */ if (ret == OK && printer_dc == NULL) { vim_free(lastlf); --- 3023,3029 ---- ret = OK; theend: ! // ron: init lastlf if (ret == OK && printer_dc == NULL) { vim_free(lastlf); *************** *** 3042,3048 **** return ret; } ! #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */ #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) /* --- 3036,3042 ---- return ret; } ! #endif // defined(FEAT_GUI) || defined(FEAT_PRINTER) #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) /* *** ../vim-8.1.2392/src/os_qnx.c 2019-06-14 21:36:51.014437500 +0200 --- src/os_qnx.c 2019-12-05 20:18:17.794841576 +0100 *************** *** 36,52 **** #define CLIP_TYPE_VIM "VIMTYPE" #define CLIP_TYPE_TEXT "TEXT" ! /* Turn on the clipboard for a console vim when photon is running */ void qnx_clip_init(void) { if (is_photon_available == TRUE && !gui.in_use) clip_init(TRUE); } ! /*****************************************************************************/ ! /* Clipboard */ ! /* No support for owning the clipboard */ int clip_mch_own_selection(Clipboard_T *cbd) { --- 36,52 ---- #define CLIP_TYPE_VIM "VIMTYPE" #define CLIP_TYPE_TEXT "TEXT" ! // Turn on the clipboard for a console vim when photon is running void qnx_clip_init(void) { if (is_photon_available == TRUE && !gui.in_use) clip_init(TRUE); } ! ///////////////////////////////////////////////////////////////////////////// ! // Clipboard ! // No support for owning the clipboard int clip_mch_own_selection(Clipboard_T *cbd) { *************** *** 69,81 **** cbdata = PhClipboardPasteStart(PhInputGroup(NULL)); if (cbdata != NULL) { ! /* Look for the vim specific clip first */ clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM); if (clip_header != NULL && clip_header->data != NULL) { switch(*(char *) clip_header->data) { ! default: /* fallthrough to line type */ case 'L': type = MLINE; break; case 'C': type = MCHAR; break; case 'B': type = MBLOCK; break; --- 69,81 ---- cbdata = PhClipboardPasteStart(PhInputGroup(NULL)); if (cbdata != NULL) { ! // Look for the vim specific clip first clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_VIM); if (clip_header != NULL && clip_header->data != NULL) { switch(*(char *) clip_header->data) { ! default: // fallthrough to line type case 'L': type = MLINE; break; case 'C': type = MCHAR; break; case 'B': type = MBLOCK; break; *************** *** 83,89 **** is_type_set = TRUE; } ! /* Try for just normal text */ clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT); if (clip_header != NULL) { --- 83,89 ---- is_type_set = TRUE; } ! // Try for just normal text clip_header = PhClipboardPasteType(cbdata, CLIP_TYPE_TEXT); if (clip_header != NULL) { *************** *** 109,115 **** char_u *text_clip, vim_clip[2], *str = NULL; PhClipHeader clip_header[2]; ! /* Prevent recursion from clip_get_selection() */ if (cbd->owned == TRUE) return; --- 109,115 ---- char_u *text_clip, vim_clip[2], *str = NULL; PhClipHeader clip_header[2]; ! // Prevent recursion from clip_get_selection() if (cbd->owned == TRUE) return; *************** *** 136,142 **** switch(type) { ! default: /* fallthrough to MLINE */ case MLINE: *vim_clip = 'L'; break; case MCHAR: *vim_clip = 'C'; break; case MBLOCK: *vim_clip = 'B'; break; --- 136,142 ---- switch(type) { ! default: // fallthrough to MLINE case MLINE: *vim_clip = 'L'; break; case MCHAR: *vim_clip = 'C'; break; case MBLOCK: *vim_clip = 'B'; break; *** ../vim-8.1.2392/src/os_unix.c 2019-11-30 22:38:11.913921804 +0100 --- src/os_unix.c 2019-12-05 20:24:07.325677593 +0100 *************** *** 24,30 **** # include "if_mzsch.h" #endif ! #include "os_unixx.h" /* unix includes for os_unix.c only */ #ifdef USE_XSMP # include --- 24,30 ---- # include "if_mzsch.h" #endif ! #include "os_unixx.h" // unix includes for os_unix.c only #ifdef USE_XSMP # include *************** *** 51,58 **** #ifdef __CYGWIN__ # ifndef MSWIN # include ! # include /* for cygwin_conv_to_posix_path() and/or ! * for cygwin_conv_path() */ # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD # define WIN32_LEAN_AND_MEAN # include --- 51,58 ---- #ifdef __CYGWIN__ # ifndef MSWIN # include ! # include // for cygwin_conv_to_posix_path() and/or ! // for cygwin_conv_path() # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD # define WIN32_LEAN_AND_MEAN # include *************** *** 63,73 **** #ifdef FEAT_MOUSE_GPM # include ! /* contains defines conflicting with "keymap.h", ! * I just copied relevant defines here. A cleaner solution would be to put gpm ! * code into separate file and include there linux/keyboard.h ! */ ! /* #include */ # define KG_SHIFT 0 # define KG_CTRL 2 # define KG_ALT 3 --- 63,72 ---- #ifdef FEAT_MOUSE_GPM # include ! // contains defines conflicting with "keymap.h", ! // I just copied relevant defines here. A cleaner solution would be to put gpm ! // code into separate file and include there linux/keyboard.h ! // #include # define KG_SHIFT 0 # define KG_CTRL 2 # define KG_ALT 3 *************** *** 96,102 **** * end of autoconf section. To be extended... */ ! /* Are the following #ifdefs still required? And why? Is that for X11? */ #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) # ifdef SIGWINCH --- 95,101 ---- * end of autoconf section. To be extended... */ ! // Are the following #ifdefs still required? And why? Is that for X11? #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) # ifdef SIGWINCH *************** *** 107,113 **** # endif #endif ! #if defined(SIGWINDOW) && !defined(SIGWINCH) /* hpux 9.01 has it */ # define SIGWINCH SIGWINDOW #endif --- 106,112 ---- # endif #endif ! #if defined(SIGWINDOW) && !defined(SIGWINCH) // hpux 9.01 has it # define SIGWINCH SIGWINDOW #endif *************** *** 157,163 **** #ifdef FEAT_XCLIPBOARD static int do_xterm_trace(void); ! # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ #endif static void handle_resize(void); --- 156,162 ---- #ifdef FEAT_XCLIPBOARD static int do_xterm_trace(void); ! # define XT_TRACE_DELAY 50 // delay for xterm tracing #endif static void handle_resize(void); *************** *** 175,181 **** && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) # define SET_SIG_ALARM static RETSIGTYPE sig_alarm SIGPROTOARG; ! /* volatile because it is used in signal handler sig_alarm(). */ static volatile sig_atomic_t sig_alarm_called; #endif static RETSIGTYPE deathtrap SIGPROTOARG; --- 174,180 ---- && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) # define SET_SIG_ALARM static RETSIGTYPE sig_alarm SIGPROTOARG; ! // volatile because it is used in signal handler sig_alarm(). static volatile sig_atomic_t sig_alarm_called; #endif static RETSIGTYPE deathtrap SIGPROTOARG; *************** *** 201,229 **** # define SIG_ERR ((RETSIGTYPE (*)())-1) #endif ! /* volatile because it is used in signal handler sig_winch(). */ static volatile sig_atomic_t do_resize = FALSE; static char_u *extra_shell_arg = NULL; static int show_shell_mess = TRUE; ! /* volatile because it is used in signal handler deathtrap(). */ ! static volatile sig_atomic_t deadly_signal = 0; /* The signal we caught */ ! /* volatile because it is used in signal handler deathtrap(). */ ! static volatile sig_atomic_t in_mch_delay = FALSE; /* sleeping in mch_delay() */ #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM) static int dont_check_job_ended = 0; #endif ! static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ #ifdef USE_XSMP typedef struct { ! SmcConn smcconn; /* The SM connection ID */ ! IceConn iceconn; /* The ICE connection ID */ ! char *clientid; /* The client ID for the current smc session */ ! Bool save_yourself; /* If we're in the middle of a save_yourself */ ! Bool shutdown; /* If we're in shutdown mode */ } xsmp_config_T; static xsmp_config_T xsmp; --- 200,228 ---- # define SIG_ERR ((RETSIGTYPE (*)())-1) #endif ! // volatile because it is used in signal handler sig_winch(). static volatile sig_atomic_t do_resize = FALSE; static char_u *extra_shell_arg = NULL; static int show_shell_mess = TRUE; ! // volatile because it is used in signal handler deathtrap(). ! static volatile sig_atomic_t deadly_signal = 0; // The signal we caught ! // volatile because it is used in signal handler deathtrap(). ! static volatile sig_atomic_t in_mch_delay = FALSE; // sleeping in mch_delay() #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM) static int dont_check_job_ended = 0; #endif ! static int curr_tmode = TMODE_COOK; // contains current terminal mode #ifdef USE_XSMP typedef struct { ! SmcConn smcconn; // The SM connection ID ! IceConn iceconn; // The ICE connection ID ! char *clientid; // The client ID for the current smc session ! Bool save_yourself; // If we're in the middle of a save_yourself ! Bool shutdown; // If we're in shutdown mode } xsmp_config_T; static xsmp_config_T xsmp; *************** *** 243,251 **** static struct signalinfo { ! int sig; /* Signal number, eg. SIGSEGV etc */ ! char *name; /* Signal name (not char_u!). */ ! char deadly; /* Catch as a deadly signal? */ } signal_info[] = { #ifdef SIGHUP --- 242,250 ---- static struct signalinfo { ! int sig; // Signal number, eg. SIGSEGV etc ! char *name; // Signal name (not char_u!). ! char deadly; // Catch as a deadly signal? } signal_info[] = { #ifdef SIGHUP *************** *** 273,286 **** {SIGBUS, "BUS", TRUE}, #endif #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) ! /* MzScheme uses SEGV in its garbage collector */ {SIGSEGV, "SEGV", TRUE}, #endif #ifdef SIGSYS {SIGSYS, "SYS", TRUE}, #endif #ifdef SIGALRM ! {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ #endif #ifdef SIGTERM {SIGTERM, "TERM", TRUE}, --- 272,285 ---- {SIGBUS, "BUS", TRUE}, #endif #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) ! // MzScheme uses SEGV in its garbage collector {SIGSEGV, "SEGV", TRUE}, #endif #ifdef SIGSYS {SIGSYS, "SYS", TRUE}, #endif #ifdef SIGALRM ! {SIGALRM, "ALRM", FALSE}, // Perl's alarm() can trigger it #endif #ifdef SIGTERM {SIGTERM, "TERM", TRUE}, *************** *** 289,296 **** {SIGVTALRM, "VTALRM", TRUE}, #endif #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) ! /* MzScheme uses SIGPROF for its own needs; On Linux with profiling ! * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ {SIGPROF, "PROF", TRUE}, #endif #ifdef SIGXCPU --- 288,295 ---- {SIGVTALRM, "VTALRM", TRUE}, #endif #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) ! // MzScheme uses SIGPROF for its own needs; On Linux with profiling ! // this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. {SIGPROF, "PROF", TRUE}, #endif #ifdef SIGXCPU *************** *** 303,309 **** {SIGUSR1, "USR1", TRUE}, #endif #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) ! /* Used for sysmouse handling */ {SIGUSR2, "USR2", TRUE}, #endif #ifdef SIGINT --- 302,308 ---- {SIGUSR1, "USR1", TRUE}, #endif #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) ! // Used for sysmouse handling {SIGUSR2, "USR2", TRUE}, #endif #ifdef SIGINT *************** *** 337,343 **** # endif } ! /* Why is NeXT excluded here (and not in os_unixx.h)? */ #if defined(ECHOE) && defined(ICANON) \ && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) \ && !defined(__NeXT__) --- 336,342 ---- # endif } ! // Why is NeXT excluded here (and not in os_unixx.h)? #if defined(ECHOE) && defined(ICANON) \ && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) \ && !defined(__NeXT__) *************** *** 351,357 **** mch_write(char_u *s, int len) { vim_ignored = (int)write(1, (char *)s, len); ! if (p_wd) /* Unix is too fast, slow down a bit more */ RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); } --- 350,356 ---- mch_write(char_u *s, int len) { vim_ignored = (int)write(1, (char *)s, len); ! if (p_wd) // Unix is too fast, slow down a bit more RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); } *************** *** 382,388 **** mch_inchar( char_u *buf, int maxlen, ! long wtime, /* don't use "time", MIPS cannot handle it */ int tb_change_cnt) { return inchar_loop(buf, maxlen, wtime, tb_change_cnt, --- 381,387 ---- mch_inchar( char_u *buf, int maxlen, ! long wtime, // don't use "time", MIPS cannot handle it int tb_change_cnt) { return inchar_loop(buf, maxlen, wtime, tb_change_cnt, *************** *** 439,449 **** mch_total_mem(int special UNUSED) { long_u mem = 0; ! long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ # ifdef MACOS_X { ! /* Mac (Darwin) way of getting the amount of RAM available */ mach_port_t host = mach_host_self(); kern_return_t kret; # ifdef HOST_VM_INFO64 --- 438,448 ---- mch_total_mem(int special UNUSED) { long_u mem = 0; ! long_u shiftright = 10; // how much to shift "mem" right for Kbyte # ifdef MACOS_X { ! // Mac (Darwin) way of getting the amount of RAM available mach_port_t host = mach_host_self(); kern_return_t kret; # ifdef HOST_VM_INFO64 *************** *** 460,466 **** (host_info_t)&vm_stat, &count); # endif if (kret == KERN_SUCCESS) ! /* get the amount of user memory by summing each usage */ mem = (long_u)(vm_stat.free_count + vm_stat.active_count + vm_stat.inactive_count # ifdef MAC_OS_X_VERSION_10_9 --- 459,465 ---- (host_info_t)&vm_stat, &count); # endif if (kret == KERN_SUCCESS) ! // get the amount of user memory by summing each usage mem = (long_u)(vm_stat.free_count + vm_stat.active_count + vm_stat.inactive_count # ifdef MAC_OS_X_VERSION_10_9 *************** *** 474,486 **** # ifdef HAVE_SYSCTL if (mem == 0) { ! /* BSD way of getting the amount of RAM available. */ int mib[2]; size_t len = sizeof(long_u); # ifdef HW_USERMEM64 long_u physmem; # else ! /* sysctl() may return 32 bit or 64 bit, accept both */ union { int_u u32; long_u u64; --- 473,485 ---- # ifdef HAVE_SYSCTL if (mem == 0) { ! // BSD way of getting the amount of RAM available. int mib[2]; size_t len = sizeof(long_u); # ifdef HW_USERMEM64 long_u physmem; # else ! // sysctl() may return 32 bit or 64 bit, accept both union { int_u u32; long_u u64; *************** *** 512,522 **** { struct sysinfo sinfo; ! /* Linux way of getting amount of RAM available */ if (sysinfo(&sinfo) == 0) { # ifdef HAVE_SYSINFO_MEM_UNIT ! /* avoid overflow as much as possible */ while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) { sinfo.mem_unit = sinfo.mem_unit >> 1; --- 511,521 ---- { struct sysinfo sinfo; ! // Linux way of getting amount of RAM available if (sysinfo(&sinfo) == 0) { # ifdef HAVE_SYSINFO_MEM_UNIT ! // avoid overflow as much as possible while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) { sinfo.mem_unit = sinfo.mem_unit >> 1; *************** *** 535,546 **** { long pagesize, pagecount; ! /* Solaris way of getting amount of RAM available */ pagesize = sysconf(_SC_PAGESIZE); pagecount = sysconf(_SC_PHYS_PAGES); if (pagesize > 0 && pagecount > 0) { ! /* avoid overflow as much as possible */ while (shiftright > 0 && (pagesize & 1) == 0) { pagesize = (long_u)pagesize >> 1; --- 534,545 ---- { long pagesize, pagecount; ! // Solaris way of getting amount of RAM available pagesize = sysconf(_SC_PAGESIZE); pagecount = sysconf(_SC_PHYS_PAGES); if (pagesize > 0 && pagecount > 0) { ! // avoid overflow as much as possible while (shiftright > 0 && (pagesize & 1) == 0) { pagesize = (long_u)pagesize >> 1; *************** *** 551,558 **** } # endif ! /* Return the minimum of the physical memory and the user limit, because ! * using more than the user limit may cause Vim to be terminated. */ # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) { struct rlimit rlp; --- 550,557 ---- } # endif ! // Return the minimum of the physical memory and the user limit, because ! // using more than the user limit may cause Vim to be terminated. # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) { struct rlimit rlp; *************** *** 582,595 **** { int old_tmode; #ifdef FEAT_MZSCHEME ! long total = msec; /* remember original value */ #endif if (ignoreinput) { ! /* Go to cooked mode without echo, to allow SIGINT interrupting us ! * here. But we don't want QUIT to kill us (CTRL-\ used in a ! * shell may produce SIGQUIT). */ in_mch_delay = TRUE; old_tmode = curr_tmode; if (curr_tmode == TMODE_RAW) --- 581,594 ---- { int old_tmode; #ifdef FEAT_MZSCHEME ! long total = msec; // remember original value #endif if (ignoreinput) { ! // Go to cooked mode without echo, to allow SIGINT interrupting us ! // here. But we don't want QUIT to kill us (CTRL-\ used in a ! // shell may produce SIGQUIT). in_mch_delay = TRUE; old_tmode = curr_tmode; if (curr_tmode == TMODE_RAW) *************** *** 603,609 **** #ifdef FEAT_MZSCHEME do { ! /* if total is large enough, wait by portions in p_mzq */ if (total > p_mzq) msec = p_mzq; else --- 602,608 ---- #ifdef FEAT_MZSCHEME do { ! // if total is large enough, wait by portions in p_mzq if (total > p_mzq) msec = p_mzq; else *************** *** 641,649 **** */ select(0, NULL, NULL, NULL, &tv); } ! # endif /* HAVE_SELECT */ ! # endif /* HAVE_NANOSLEEP */ ! #endif /* HAVE_USLEEP */ #ifdef FEAT_MZSCHEME } while (total > 0); --- 640,648 ---- */ select(0, NULL, NULL, NULL, &tv); } ! # endif // HAVE_SELECT ! # endif // HAVE_NANOSLEEP ! #endif // HAVE_USLEEP #ifdef FEAT_MZSCHEME } while (total > 0); *************** *** 702,709 **** int i; long lim; ! /* Set the stack limit to 15/16 of the allowable size. Skip this when the ! * limit doesn't fit in a long (rlim_cur might be "long long"). */ if (getrlimit(RLIMIT_STACK, &rlp) == 0 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) # ifdef RLIM_INFINITY --- 701,708 ---- int i; long lim; ! // Set the stack limit to 15/16 of the allowable size. Skip this when the ! // limit doesn't fit in a long (rlim_cur might be "long long"). if (getrlimit(RLIMIT_STACK, &rlp) == 0 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) # ifdef RLIM_INFINITY *************** *** 717,724 **** pthread_attr_t attr; size_t size; ! /* On FreeBSD the initial thread always has a fixed stack size, no ! * matter what the limits are set to. Normally it's 1 Mbyte. */ pthread_attr_init(&attr); if (pthread_attr_get_np(pthread_self(), &attr) == 0) { --- 716,723 ---- pthread_attr_t attr; size_t size; ! // On FreeBSD the initial thread always has a fixed stack size, no ! // matter what the limits are set to. Normally it's 1 Mbyte. pthread_attr_init(&attr); if (pthread_attr_get_np(pthread_self(), &attr) == 0) { *************** *** 733,746 **** { stack_limit = (char *)((long)&i - (lim / 16L * 15L)); if (stack_limit >= (char *)&i) ! /* overflow, set to 1/16 of current stack position */ stack_limit = (char *)((long)&i / 16L); } else { stack_limit = (char *)((long)&i + (lim / 16L * 15L)); if (stack_limit <= (char *)&i) ! stack_limit = NULL; /* overflow */ } } } --- 732,745 ---- { stack_limit = (char *)((long)&i - (lim / 16L * 15L)); if (stack_limit >= (char *)&i) ! // overflow, set to 1/16 of current stack position stack_limit = (char *)((long)&i / 16L); } else { stack_limit = (char *)((long)&i + (lim / 16L * 15L)); if (stack_limit <= (char *)&i) ! stack_limit = NULL; // overflow } } } *************** *** 775,787 **** */ #ifndef SIGSTKSZ ! # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ #endif # ifdef HAVE_SIGALTSTACK ! static stack_t sigstk; /* for sigaltstack() */ # else ! static struct sigstack sigstk; /* for sigstack() */ # endif static char *signal_stack; --- 774,786 ---- */ #ifndef SIGSTKSZ ! # define SIGSTKSZ 8000 // just a guess of how much stack is needed... #endif # ifdef HAVE_SIGALTSTACK ! static stack_t sigstk; // for sigaltstack() # else ! static struct sigstack sigstk; // for sigstack() # endif static char *signal_stack; *************** *** 820,826 **** static RETSIGTYPE sig_winch SIGDEFARG(sigarg) { ! /* this is not required on all systems, but it doesn't hurt anybody */ signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); do_resize = TRUE; SIGRETURN; --- 819,825 ---- static RETSIGTYPE sig_winch SIGDEFARG(sigarg) { ! // this is not required on all systems, but it doesn't hurt anybody signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); do_resize = TRUE; SIGRETURN; *************** *** 831,837 **** static RETSIGTYPE catch_sigint SIGDEFARG(sigarg) { ! /* this is not required on all systems, but it doesn't hurt anybody */ signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); got_int = TRUE; SIGRETURN; --- 830,836 ---- static RETSIGTYPE catch_sigint SIGDEFARG(sigarg) { ! // this is not required on all systems, but it doesn't hurt anybody signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); got_int = TRUE; SIGRETURN; *************** *** 842,848 **** static RETSIGTYPE catch_sigpwr SIGDEFARG(sigarg) { ! /* this is not required on all systems, but it doesn't hurt anybody */ signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); /* * I'm not sure we get the SIGPWR signal when the system is really going --- 841,847 ---- static RETSIGTYPE catch_sigpwr SIGDEFARG(sigarg) { ! // this is not required on all systems, but it doesn't hurt anybody signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); /* * I'm not sure we get the SIGPWR signal when the system is really going *************** *** 861,867 **** static RETSIGTYPE sig_alarm SIGDEFARG(sigarg) { ! /* doesn't do anything, just to break a system call */ sig_alarm_called = TRUE; SIGRETURN; } --- 860,866 ---- static RETSIGTYPE sig_alarm SIGDEFARG(sigarg) { ! // doesn't do anything, just to break a system call sig_alarm_called = TRUE; SIGRETURN; } *************** *** 944,952 **** static RETSIGTYPE deathtrap SIGDEFARG(sigarg) { ! static int entered = 0; /* count the number of times we got here. ! Note: when memory has been corrupted ! this may get an arbitrary value! */ #ifdef SIGHASARG int i; #endif --- 943,951 ---- static RETSIGTYPE deathtrap SIGDEFARG(sigarg) { ! static int entered = 0; // count the number of times we got here. ! // Note: when memory has been corrupted ! // this may get an arbitrary value! #ifdef SIGHASARG int i; #endif *************** *** 962,985 **** # if defined(SIGHASARG) lc_signal = sigarg; # endif ! lc_active = FALSE; /* don't jump again */ LONGJMP(lc_jump_env, 1); ! /* NOTREACHED */ } #endif #ifdef SIGHASARG # ifdef SIGQUIT ! /* While in mch_delay() we go to cooked mode to allow a CTRL-C to ! * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when ! * pressing CTRL-\, but we don't want Vim to exit then. */ if (in_mch_delay && sigarg == SIGQUIT) SIGRETURN; # endif ! /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return ! * here. This avoids that a non-reentrant function is interrupted, e.g., ! * free(). Calling free() again may then cause a crash. */ if (entered == 0 && (0 # ifdef SIGHUP --- 961,984 ---- # if defined(SIGHASARG) lc_signal = sigarg; # endif ! lc_active = FALSE; // don't jump again LONGJMP(lc_jump_env, 1); ! // NOTREACHED } #endif #ifdef SIGHASARG # ifdef SIGQUIT ! // While in mch_delay() we go to cooked mode to allow a CTRL-C to ! // interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when ! // pressing CTRL-\, but we don't want Vim to exit then. if (in_mch_delay && sigarg == SIGQUIT) SIGRETURN; # endif ! // When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return ! // here. This avoids that a non-reentrant function is interrupted, e.g., ! // free(). Calling free() again may then cause a crash. if (entered == 0 && (0 # ifdef SIGHUP *************** *** 1005,1033 **** SIGRETURN; #endif ! /* Remember how often we have been called. */ ++entered; ! /* Executing autocommands is likely to use more stack space than we have ! * available in the signal stack. */ block_autocmds(); #ifdef FEAT_EVAL ! /* Set the v:dying variable. */ set_vim_var_nr(VV_DYING, (long)entered); #endif v_dying = entered; #ifdef HAVE_STACK_LIMIT ! /* Since we are now using the signal stack, need to reset the stack ! * limit. Otherwise using a regexp will fail. */ get_stack_limit(); #endif #if 0 ! /* This is for opening gdb the moment Vim crashes. ! * You need to manually adjust the file name and Vim executable name. ! * Suggested by SungHyun Nam. */ { # define VI_GDB_FILE "/tmp/vimgdb" # define VIM_NAME "/usr/bin/vim" --- 1004,1032 ---- SIGRETURN; #endif ! // Remember how often we have been called. ++entered; ! // Executing autocommands is likely to use more stack space than we have ! // available in the signal stack. block_autocmds(); #ifdef FEAT_EVAL ! // Set the v:dying variable. set_vim_var_nr(VV_DYING, (long)entered); #endif v_dying = entered; #ifdef HAVE_STACK_LIMIT ! // Since we are now using the signal stack, need to reset the stack ! // limit. Otherwise using a regexp will fail. get_stack_limit(); #endif #if 0 ! // This is for opening gdb the moment Vim crashes. ! // You need to manually adjust the file name and Vim executable name. ! // Suggested by SungHyun Nam. { # define VI_GDB_FILE "/tmp/vimgdb" # define VIM_NAME "/usr/bin/vim" *************** *** 1048,1062 **** #endif #ifdef SIGHASARG ! /* try to find the name of this signal */ for (i = 0; signal_info[i].sig != -1; i++) if (sigarg == signal_info[i].sig) break; deadly_signal = sigarg; #endif ! full_screen = FALSE; /* don't write message to the GUI, it might be ! * part of the problem... */ /* * If something goes wrong after entering here, we may get here again. * When this happens, give a message and try to exit nicely (resetting the --- 1047,1061 ---- #endif #ifdef SIGHASARG ! // try to find the name of this signal for (i = 0; signal_info[i].sig != -1; i++) if (sigarg == signal_info[i].sig) break; deadly_signal = sigarg; #endif ! full_screen = FALSE; // don't write message to the GUI, it might be ! // part of the problem... /* * If something goes wrong after entering here, we may get here again. * When this happens, give a message and try to exit nicely (resetting the *************** *** 1068,1074 **** */ if (entered >= 3) { ! reset_signals(); /* don't catch any signals anymore */ may_core_dump(); if (entered >= 4) _exit(8); --- 1067,1073 ---- */ if (entered >= 3) { ! reset_signals(); // don't catch any signals anymore may_core_dump(); if (entered >= 4) _exit(8); *************** *** 1076,1088 **** } if (entered == 2) { ! /* No translation, it may call malloc(). */ OUT_STR("Vim: Double signal, exiting\n"); out_flush(); getout(1); } ! /* No translation, it may call malloc(). */ #ifdef SIGHASARG sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", signal_info[i].name); --- 1075,1087 ---- } if (entered == 2) { ! // No translation, it may call malloc(). OUT_STR("Vim: Double signal, exiting\n"); out_flush(); getout(1); } ! // No translation, it may call malloc(). #ifdef SIGHASARG sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", signal_info[i].name); *************** *** 1090,1100 **** sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); #endif ! /* Preserve files and exit. This sets the really_exiting flag to prevent ! * calling free(). */ preserve_exit(); ! /* NOTREACHED */ #ifdef NBDEBUG reset_signals(); --- 1089,1099 ---- sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); #endif ! // Preserve files and exit. This sets the really_exiting flag to prevent ! // calling free(). preserve_exit(); ! // NOTREACHED #ifdef NBDEBUG reset_signals(); *************** *** 1238,1250 **** void mch_suspend(void) { ! /* BeOS does have SIGTSTP, but it doesn't work. */ #if defined(SIGTSTP) && !defined(__BEOS__) in_mch_suspend = TRUE; ! out_flush(); /* needed to make cursor visible on some systems */ settmode(TMODE_COOK); ! out_flush(); /* needed to disable mouse on some systems */ # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) loose_clipboard(); --- 1237,1249 ---- void mch_suspend(void) { ! // BeOS does have SIGTSTP, but it doesn't work. #if defined(SIGTSTP) && !defined(__BEOS__) in_mch_suspend = TRUE; ! out_flush(); // needed to make cursor visible on some systems settmode(TMODE_COOK); ! out_flush(); // needed to disable mouse on some systems # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) loose_clipboard(); *************** *** 1253,1259 **** sigcont_received = FALSE; # endif ! kill(0, SIGTSTP); /* send ourselves a STOP signal */ # if defined(SIGCONT) /* --- 1252,1258 ---- sigcont_received = FALSE; # endif ! kill(0, SIGTSTP); // send ourselves a STOP signal # if defined(SIGCONT) /* *************** *** 1374,1380 **** { catch_signals(SIG_DFL, SIG_DFL); #if defined(SIGCONT) ! /* SIGCONT isn't in the list, because its default action is ignore */ signal(SIGCONT, SIG_DFL); #endif } --- 1373,1379 ---- { catch_signals(SIG_DFL, SIG_DFL); #if defined(SIGCONT) ! // SIGCONT isn't in the list, because its default action is ignore signal(SIGCONT, SIG_DFL); #endif } *************** *** 1392,1406 **** #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) struct sigaction sa; ! /* Setup to use the alternate stack for the signal function. */ sa.sa_handler = func_deadly; sigemptyset(&sa.sa_mask); # if defined(__linux__) && defined(_REENTRANT) ! /* On Linux, with glibc compiled for kernel 2.2, there is a bug in ! * thread handling in combination with using the alternate stack: ! * pthread library functions try to use the stack pointer to ! * identify the current thread, causing a SEGV signal, which ! * recursively calls deathtrap() and hangs. */ sa.sa_flags = 0; # else sa.sa_flags = SA_ONSTACK; --- 1391,1405 ---- #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) struct sigaction sa; ! // Setup to use the alternate stack for the signal function. sa.sa_handler = func_deadly; sigemptyset(&sa.sa_mask); # if defined(__linux__) && defined(_REENTRANT) ! // On Linux, with glibc compiled for kernel 2.2, there is a bug in ! // thread handling in combination with using the alternate stack: ! // pthread library functions try to use the stack pointer to ! // identify the current thread, causing a SEGV signal, which ! // recursively calls deathtrap() and hangs. sa.sa_flags = 0; # else sa.sa_flags = SA_ONSTACK; *************** *** 1410,1416 **** # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) struct sigvec sv; ! /* Setup to use the alternate stack for the signal function. */ sv.sv_handler = func_deadly; sv.sv_mask = 0; sv.sv_flags = SV_ONSTACK; --- 1409,1415 ---- # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) struct sigvec sv; ! // Setup to use the alternate stack for the signal function. sv.sv_handler = func_deadly; sv.sv_mask = 0; sv.sv_flags = SV_ONSTACK; *************** *** 1437,1443 **** sigaddset(&newset, signal_info[i].sig); # if defined(SIGCONT) ! /* SIGCONT isn't in the list, because its default action is ignore */ sigaddset(&newset, SIGCONT); # endif --- 1436,1442 ---- sigaddset(&newset, signal_info[i].sig); # if defined(SIGCONT) ! // SIGCONT isn't in the list, because its default action is ignore sigaddset(&newset, SIGCONT); # endif *************** *** 1480,1491 **** break; default: if (!blocked) ! return TRUE; /* exit! */ got_signal = sig; #ifdef SIGPWR if (sig != SIGPWR) #endif ! got_int = TRUE; /* break any loops */ break; } return FALSE; --- 1479,1490 ---- break; default: if (!blocked) ! return TRUE; // exit! got_signal = sig; #ifdef SIGPWR if (sig != SIGPWR) #endif ! got_int = TRUE; // break any loops break; } return FALSE; *************** *** 1545,1556 **** XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); STRCAT(IObuff, _("\nVim: Got X error\n")); ! /* We cannot print a message and continue, because no X calls are allowed ! * here (causes my system to hang). Silently continuing might be an ! * alternative... */ ! preserve_exit(); /* preserve files and exit */ ! return 0; /* NOTREACHED */ } /* --- 1544,1555 ---- XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); STRCAT(IObuff, _("\nVim: Got X error\n")); ! // We cannot print a message and continue, because no X calls are allowed ! // here (causes my system to hang). Silently continuing might be an ! // alternative... ! preserve_exit(); // preserve files and exit ! return 0; // NOTREACHED } /* *************** *** 1603,1612 **** static int x_IOerror_check(Display *dpy UNUSED) { ! /* This function should not return, it causes exit(). Longjump instead. */ LONGJMP(lc_jump_env, 1); # if defined(VMS) || defined(__CYGWIN__) ! return 0; /* avoid the compiler complains about missing return value */ # endif } # endif --- 1602,1611 ---- static int x_IOerror_check(Display *dpy UNUSED) { ! // This function should not return, it causes exit(). Longjump instead. LONGJMP(lc_jump_env, 1); # if defined(VMS) || defined(__CYGWIN__) ! return 0; // avoid the compiler complains about missing return value # endif } # endif *************** *** 1625,1634 **** x11_display = NULL; xterm_Shell = (Widget)0; ! /* This function should not return, it causes exit(). Longjump instead. */ LONGJMP(x_jump_env, 1); # if defined(VMS) || defined(__CYGWIN__) ! return 0; /* avoid the compiler complains about missing return value */ # endif } --- 1624,1633 ---- x11_display = NULL; xterm_Shell = (Widget)0; ! // This function should not return, it causes exit(). Longjump instead. LONGJMP(x_jump_env, 1); # if defined(VMS) || defined(__CYGWIN__) ! return 0; // avoid the compiler complains about missing return value # endif } *************** *** 1646,1657 **** --xterm_dpy_retry_count; # ifndef LESSTIF_VERSION ! /* This has been reported to avoid Vim getting stuck. */ if (app_context != (XtAppContext)NULL) { XtDestroyApplicationContext(app_context); app_context = (XtAppContext)NULL; ! x11_display = NULL; /* freed by XtDestroyApplicationContext() */ } # endif --- 1645,1656 ---- --xterm_dpy_retry_count; # ifndef LESSTIF_VERSION ! // This has been reported to avoid Vim getting stuck. if (app_context != (XtAppContext)NULL) { XtDestroyApplicationContext(app_context); app_context = (XtAppContext)NULL; ! x11_display = NULL; // freed by XtDestroyApplicationContext() } # endif *************** *** 1723,1738 **** { char *winid; static int result = -1; ! #define XD_NONE 0 /* x11_display not set here */ ! #define XD_HERE 1 /* x11_display opened here */ ! #define XD_GUI 2 /* x11_display used from gui.dpy */ ! #define XD_XTERM 3 /* x11_display used from xterm_dpy */ static int x11_display_from = XD_NONE; static int did_set_error_handler = FALSE; if (!did_set_error_handler) { ! /* X just exits if it finds an error otherwise! */ (void)XSetErrorHandler(x_error_handler); did_set_error_handler = TRUE; } --- 1722,1737 ---- { char *winid; static int result = -1; ! #define XD_NONE 0 // x11_display not set here ! #define XD_HERE 1 // x11_display opened here ! #define XD_GUI 2 // x11_display used from gui.dpy ! #define XD_XTERM 3 // x11_display used from xterm_dpy static int x11_display_from = XD_NONE; static int did_set_error_handler = FALSE; if (!did_set_error_handler) { ! // X just exits if it finds an error otherwise! (void)XSetErrorHandler(x_error_handler); did_set_error_handler = TRUE; } *************** *** 1759,1772 **** } else if (x11_display_from == XD_GUI) { ! /* GUI must have stopped somehow, clear x11_display */ x11_window = 0; x11_display = NULL; x11_display_from = XD_NONE; } #endif ! /* When started with the "-X" argument, don't try connecting. */ if (!x_connect_to_server()) return FAIL; --- 1758,1771 ---- } else if (x11_display_from == XD_GUI) { ! // GUI must have stopped somehow, clear x11_display x11_window = 0; x11_display = NULL; x11_display_from = XD_NONE; } #endif ! // When started with the "-X" argument, don't try connecting. if (!x_connect_to_server()) return FAIL; *************** *** 1786,1793 **** if (xterm_dpy != NULL && x11_window != 0) { ! /* We may have checked it already, but Gnome terminal can move us to ! * another window, so we need to check every time. */ if (x11_display_from != XD_XTERM) { /* --- 1785,1792 ---- if (xterm_dpy != NULL && x11_window != 0) { ! // We may have checked it already, but Gnome terminal can move us to ! // another window, so we need to check every time. if (x11_display_from != XD_XTERM) { /* *************** *** 1801,1807 **** } if (test_x11_window(x11_display) == FAIL) { ! /* probably bad $WINDOWID */ x11_window = 0; x11_display = NULL; x11_display_from = XD_NONE; --- 1800,1806 ---- } if (test_x11_window(x11_display) == FAIL) { ! // probably bad $WINDOWID x11_window = 0; x11_display = NULL; x11_display_from = XD_NONE; *************** *** 1814,1821 **** if (x11_window == 0 || x11_display == NULL) result = -1; ! if (result != -1) /* Have already been here and set this */ ! return result; /* Don't do all these X calls again */ if (x11_window != 0 && x11_display == NULL) { --- 1813,1820 ---- if (x11_window == 0 || x11_display == NULL) result = -1; ! if (result != -1) // Have already been here and set this ! return result; // Don't do all these X calls again if (x11_window != 0 && x11_display == NULL) { *************** *** 1859,1865 **** # endif if (test_x11_window(x11_display) == FAIL) { ! /* Maybe window id is bad */ x11_window = 0; XCloseDisplay(x11_display); x11_display = NULL; --- 1858,1864 ---- # endif if (test_x11_window(x11_display) == FAIL) { ! // Maybe window id is bad x11_window = 0; XCloseDisplay(x11_display); x11_display = NULL; *************** *** 1897,1903 **** retval = get_x11_thing(FALSE, test_only); ! /* could not get old icon, use terminal name */ if (oldicon == NULL && !test_only) { if (STRNCMP(T_NAME, "builtin_", 8) == 0) --- 1896,1902 ---- retval = get_x11_thing(FALSE, test_only); ! // could not get old icon, use terminal name if (oldicon == NULL && !test_only) { if (STRNCMP(T_NAME, "builtin_", 8) == 0) *************** *** 1911,1917 **** static int get_x11_thing( ! int get_title, /* get title string */ int test_only) { XTextProperty text_prop; --- 1910,1916 ---- static int get_x11_thing( ! int get_title, // get title string int test_only) { XTextProperty text_prop; *************** *** 1920,1926 **** if (get_x11_windis() == OK) { ! /* Get window/icon name if any */ if (get_title) status = XGetWMName(x11_display, x11_window, &text_prop); else --- 1919,1925 ---- if (get_x11_windis() == OK) { ! // Get window/icon name if any if (get_title) status = XGetWMName(x11_display, x11_window, &text_prop); else *************** *** 1932,1940 **** * keep traversing up the tree until a window with a title/icon is * found. */ ! /* Previously this was only done for xterm and alikes. I don't see a ! * reason why it would fail for other terminal emulators. ! * if (term_is_xterm) */ { Window root; Window parent; --- 1931,1939 ---- * keep traversing up the tree until a window with a title/icon is * found. */ ! // Previously this was only done for xterm and alikes. I don't see a ! // reason why it would fail for other terminal emulators. ! // if (term_is_xterm) { Window root; Window parent; *************** *** 2003,2012 **** return retval; } ! /* Xutf8 functions are not available on older systems. Note that on some ! * systems X_HAVE_UTF8_STRING may be defined in a header file but ! * Xutf8SetWMProperties() is not in the X11 library. Configure checks for ! * that and defines HAVE_XUTF8SETWMPROPERTIES. */ #if defined(X_HAVE_UTF8_STRING) # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES # define USE_UTF8_STRING --- 2002,2011 ---- return retval; } ! // Xutf8 functions are not available on older systems. Note that on some ! // systems X_HAVE_UTF8_STRING may be defined in a header file but ! // Xutf8SetWMProperties() is not in the X11 library. Configure checks for ! // that and defines HAVE_XUTF8SETWMPROPERTIES. #if defined(X_HAVE_UTF8_STRING) # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES # define USE_UTF8_STRING *************** *** 2021,2030 **** static void set_x11_title(char_u *title) { ! /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING ! * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't ! * supported everywhere and STRING doesn't work for multi-byte titles. ! */ #ifdef USE_UTF8_STRING if (enc_utf8) Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, --- 2020,2028 ---- static void set_x11_title(char_u *title) { ! // XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING ! // when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't ! // supported everywhere and STRING doesn't work for multi-byte titles. #ifdef USE_UTF8_STRING if (enc_utf8) Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, *************** *** 2040,2046 **** XTextProperty text_prop; char *c_title = (char *)title; ! /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ (void)XStringListToTextProperty(&c_title, 1, &text_prop); XSetWMProperties(x11_display, x11_window, &text_prop, NULL, NULL, 0, NULL, NULL, NULL); --- 2038,2044 ---- XTextProperty text_prop; char *c_title = (char *)title; ! // directly from example 3-18 "basicwin" of Xlib Programming Manual (void)XStringListToTextProperty(&c_title, 1, &text_prop); XSetWMProperties(x11_display, x11_window, &text_prop, NULL, NULL, 0, NULL, NULL, NULL); *************** *** 2060,2066 **** static void set_x11_icon(char_u *icon) { ! /* See above for comments about using X*SetWMProperties(). */ #ifdef USE_UTF8_STRING if (enc_utf8) Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, --- 2058,2064 ---- static void set_x11_icon(char_u *icon) { ! // See above for comments about using X*SetWMProperties(). #ifdef USE_UTF8_STRING if (enc_utf8) Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, *************** *** 2087,2093 **** XFlush(x11_display); } ! #else /* FEAT_X11 */ static int get_x11_title(int test_only UNUSED) --- 2085,2091 ---- XFlush(x11_display); } ! #else // FEAT_X11 static int get_x11_title(int test_only UNUSED) *************** *** 2108,2114 **** return FALSE; } ! #endif /* FEAT_X11 */ int mch_can_restore_title(void) --- 2106,2112 ---- return FALSE; } ! #endif // FEAT_X11 int mch_can_restore_title(void) *************** *** 2131,2143 **** int type = 0; static int recursive = 0; ! if (T_NAME == NULL) /* no terminal name (yet) */ return; ! if (title == NULL && icon == NULL) /* nothing to do */ return; ! /* When one of the X11 functions causes a deadly signal, we get here again ! * recursively. Avoid hanging then (something is probably locked). */ if (recursive) return; ++recursive; --- 2129,2141 ---- int type = 0; static int recursive = 0; ! if (T_NAME == NULL) // no terminal name (yet) return; ! if (title == NULL && icon == NULL) // nothing to do return; ! // When one of the X11 functions causes a deadly signal, we get here again ! // recursively. Avoid hanging then (something is probably locked). if (recursive) return; ++recursive; *************** *** 2170,2186 **** #ifdef FEAT_GUI && !gui.in_use #endif ! ) /* first call but not in GUI, save title */ (void)get_x11_title(FALSE); ! if (*T_TS != NUL) /* it's OK if t_fs is empty */ term_settitle(title); #ifdef FEAT_X11 else # ifdef FEAT_GUI_GTK ! if (!gui.in_use) /* don't do this if GTK+ is running */ # endif ! set_x11_title(title); /* x11 */ #endif #if defined(FEAT_GUI_GTK) \ || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) --- 2168,2184 ---- #ifdef FEAT_GUI && !gui.in_use #endif ! ) // first call but not in GUI, save title (void)get_x11_title(FALSE); ! if (*T_TS != NUL) // it's OK if t_fs is empty term_settitle(title); #ifdef FEAT_X11 else # ifdef FEAT_GUI_GTK ! if (!gui.in_use) // don't do this if GTK+ is running # endif ! set_x11_title(title); // x11 #endif #if defined(FEAT_GUI_GTK) \ || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) *************** *** 2196,2202 **** #ifdef FEAT_GUI && !gui.in_use #endif ! ) /* first call, save icon */ get_x11_icon(FALSE); if (*T_CIS != NUL) --- 2194,2200 ---- #ifdef FEAT_GUI && !gui.in_use #endif ! ) // first call, save icon get_x11_icon(FALSE); if (*T_CIS != NUL) *************** *** 2209,2217 **** #ifdef FEAT_X11 else # ifdef FEAT_GUI_GTK ! if (!gui.in_use) /* don't do this if GTK+ is running */ # endif ! set_x11_icon(icon); /* x11 */ #endif did_set_icon = TRUE; } --- 2207,2215 ---- #ifdef FEAT_X11 else # ifdef FEAT_GUI_GTK ! if (!gui.in_use) // don't do this if GTK+ is running # endif ! set_x11_icon(icon); // x11 #endif did_set_icon = TRUE; } *************** *** 2230,2236 **** { int do_push_pop = unix_did_set_title || did_set_icon; ! /* only restore the title or icon when it has been set */ mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ? (oldtitle ? oldtitle : p_titleold) : NULL, ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL); --- 2228,2234 ---- { int do_push_pop = unix_did_set_title || did_set_icon; ! // only restore the title or icon when it has been set mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ? (oldtitle ? oldtitle : p_titleold) : NULL, ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL); *************** *** 2243,2249 **** } } ! #endif /* FEAT_TITLE */ /* * Return TRUE if "name" looks like some xterm name. --- 2241,2247 ---- } } ! #endif // FEAT_TITLE /* * Return TRUE if "name" looks like some xterm name. *************** *** 2316,2323 **** vim_is_vt300(char_u *name) { if (name == NULL) ! return FALSE; /* actually all ANSI comp. terminals should be here */ ! /* catch VT100 - VT5xx */ return ((STRNICMP(name, "vt", 2) == 0 && vim_strchr((char_u *)"12345", name[2]) != NULL) || STRCMP(name, "builtin_vt320") == 0); --- 2314,2321 ---- vim_is_vt300(char_u *name) { if (name == NULL) ! return FALSE; // actually all ANSI comp. terminals should be here ! // catch VT100 - VT5xx return ((STRNICMP(name, "vt", 2) == 0 && vim_strchr((char_u *)"12345", name[2]) != NULL) || STRCMP(name, "builtin_vt320") == 0); *************** *** 2373,2380 **** return OK; } #endif ! sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ ! return FAIL; /* a number is not a name */ } /* --- 2371,2378 ---- return OK; } #endif ! sprintf((char *)s, "%d", (int)uid); // assumes s is long enough ! return FAIL; // a number is not a name } /* *************** *** 2392,2398 **** else vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); } ! #else /* HAVE_SYS_UTSNAME_H */ # ifdef HAVE_SYS_SYSTEMINFO_H # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) --- 2390,2396 ---- else vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); } ! #else // HAVE_SYS_UTSNAME_H # ifdef HAVE_SYS_SYSTEMINFO_H # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) *************** *** 2406,2414 **** # else gethostname((char *)s, len); # endif ! s[len - 1] = NUL; /* make sure it's terminated */ } ! #endif /* HAVE_SYS_UTSNAME_H */ /* * return process ID --- 2404,2412 ---- # else gethostname((char *)s, len); # endif ! s[len - 1] = NUL; // make sure it's terminated } ! #endif // HAVE_SYS_UTSNAME_H /* * return process ID *************** *** 2474,2492 **** char_u *fname, char_u *buf, int len, ! int force) /* also expand when already absolute path */ { int l; #ifdef HAVE_FCHDIR int fd = -1; ! static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ #endif char_u olddir[MAXPATHL]; char_u *p; int retval = OK; #ifdef __CYGWIN__ ! char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but ! it's not always defined */ #endif #ifdef VMS --- 2472,2490 ---- char_u *fname, char_u *buf, int len, ! int force) // also expand when already absolute path { int l; #ifdef HAVE_FCHDIR int fd = -1; ! static int dont_fchdir = FALSE; // TRUE when fchdir() doesn't work #endif char_u olddir[MAXPATHL]; char_u *p; int retval = OK; #ifdef __CYGWIN__ ! char_u posix_fname[MAXPATHL]; // Cygwin docs mention MAX_PATH, but ! // it's not always defined #endif #ifdef VMS *************** *** 2498,2505 **** * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". */ # if CYGWIN_VERSION_DLL_MAJOR >= 1007 ! /* Use CCP_RELATIVE to avoid that it sometimes returns a path that ends in ! * a forward slash. */ cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, fname, posix_fname, MAXPATHL); # else --- 2496,2503 ---- * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". */ # if CYGWIN_VERSION_DLL_MAJOR >= 1007 ! // Use CCP_RELATIVE to avoid that it sometimes returns a path that ends in ! // a forward slash. cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, fname, posix_fname, MAXPATHL); # else *************** *** 2508,2515 **** fname = posix_fname; #endif ! /* Expand it if forced or not an absolute path. ! * Do not do it for "/file", the result is always "/". */ if ((force || !mch_isFullName(fname)) && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) { --- 2506,2513 ---- fname = posix_fname; #endif ! // Expand it if forced or not an absolute path. ! // Do not do it for "/file", the result is always "/". if ((force || !mch_isFullName(fname)) && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) { *************** *** 2533,2545 **** { close(fd); fd = -1; ! dont_fchdir = TRUE; /* don't try again */ } } #endif ! /* Only change directory when we are sure we can return to where ! * we are now. After doing "su" chdir(".") might not work. */ if ( #ifdef HAVE_FCHDIR fd < 0 && --- 2531,2543 ---- { close(fd); fd = -1; ! dont_fchdir = TRUE; // don't try again } } #endif ! // Only change directory when we are sure we can return to where ! // we are now. After doing "su" chdir(".") might not work. if ( #ifdef HAVE_FCHDIR fd < 0 && *************** *** 2547,2560 **** (mch_dirname(olddir, MAXPATHL) == FAIL || mch_chdir((char *)olddir) != 0)) { ! p = NULL; /* can't get current dir: don't chdir */ retval = FAIL; } else { ! /* The directory is copied into buf[], to be able to remove ! * the file name without changing it (could be a string in ! * read-only memory) */ if (p - fname >= len) retval = FAIL; else --- 2545,2558 ---- (mch_dirname(olddir, MAXPATHL) == FAIL || mch_chdir((char *)olddir) != 0)) { ! p = NULL; // can't get current dir: don't chdir retval = FAIL; } else { ! // The directory is copied into buf[], to be able to remove ! // the file name without changing it (could be a string in ! // read-only memory) if (p - fname >= len) retval = FAIL; else *************** *** 2596,2602 **** l = STRLEN(buf); if (l >= len - 1) ! retval = FAIL; /* no space for trailing "/" */ #ifndef VMS else if (l > 0 && buf[l - 1] != '/' && *fname != NUL && STRCMP(fname, ".") != 0) --- 2594,2600 ---- l = STRLEN(buf); if (l >= len - 1) ! retval = FAIL; // no space for trailing "/" #ifndef VMS else if (l > 0 && buf[l - 1] != '/' && *fname != NUL && STRCMP(fname, ".") != 0) *************** *** 2604,2614 **** #endif } ! /* Catch file names which are too long. */ if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) return FAIL; ! /* Do not append ".", "/dir/." is equal to "/dir". */ if (STRCMP(fname, ".") != 0) STRCAT(buf, fname); --- 2602,2612 ---- #endif } ! // Catch file names which are too long. if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) return FAIL; ! // Do not append ".", "/dir/." is equal to "/dir". if (STRCMP(fname, ".") != 0) STRCAT(buf, fname); *************** *** 2640,2646 **** void fname_case( char_u *name, ! int len UNUSED) /* buffer size, only used when name gets longer */ { struct stat st; char_u *slash, *tail; --- 2638,2644 ---- void fname_case( char_u *name, ! int len UNUSED) // buffer size, only used when name gets longer { struct stat st; char_u *slash, *tail; *************** *** 2649,2655 **** if (mch_lstat((char *)name, &st) >= 0) { ! /* Open the directory where the file is located. */ slash = vim_strrchr(name, '/'); if (slash == NULL) { --- 2647,2653 ---- if (mch_lstat((char *)name, &st) >= 0) { ! // Open the directory where the file is located. slash = vim_strrchr(name, '/'); if (slash == NULL) { *************** *** 2668,2682 **** { while ((dp = readdir(dirp)) != NULL) { ! /* Only accept names that differ in case and are the same byte ! * length. TODO: accept different length name. */ if (STRICMP(tail, dp->d_name) == 0 && STRLEN(tail) == STRLEN(dp->d_name)) { char_u newname[MAXPATHL + 1]; struct stat st2; ! /* Verify the inode is equal. */ vim_strncpy(newname, name, MAXPATHL); vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, MAXPATHL - (tail - name)); --- 2666,2680 ---- { while ((dp = readdir(dirp)) != NULL) { ! // Only accept names that differ in case and are the same byte ! // length. TODO: accept different length name. if (STRICMP(tail, dp->d_name) == 0 && STRLEN(tail) == STRLEN(dp->d_name)) { char_u newname[MAXPATHL + 1]; struct stat st2; ! // Verify the inode is equal. vim_strncpy(newname, name, MAXPATHL); vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, MAXPATHL - (tail - name)); *************** *** 2705,2711 **** { struct stat statb; ! /* Keep the #ifdef outside of stat(), it may be a macro. */ #ifdef VMS if (stat((char *)vms_fixfilename(name), &statb)) #else --- 2703,2709 ---- { struct stat statb; ! // Keep the #ifdef outside of stat(), it may be a macro. #ifdef VMS if (stat((char *)vms_fixfilename(name), &statb)) #else *************** *** 2713,2720 **** #endif return -1; #ifdef __INTERIX ! /* The top bit makes the value negative, which means the file doesn't ! * exist. Remove the bit, we don't use it. */ return statb.st_mode & ~S_ADDACE; #else return statb.st_mode; --- 2711,2718 ---- #endif return -1; #ifdef __INTERIX ! // The top bit makes the value negative, which means the file doesn't ! // exist. Remove the bit, we don't use it. return statb.st_mode & ~S_ADDACE; #else return statb.st_mode; *************** *** 2784,2792 **** if (getfilecon((char *)from_file, &from_context) < 0) { ! /* If the filesystem doesn't support extended attributes, ! the original had no special security context and the ! target cannot have one either. */ if (errno == EOPNOTSUPP) return; --- 2782,2790 ---- if (getfilecon((char *)from_file, &from_context) < 0) { ! // If the filesystem doesn't support extended attributes, ! // the original had no special security context and the ! // target cannot have one either. if (errno == EOPNOTSUPP) return; *************** *** 2816,2822 **** freecon(from_context); } } ! #endif /* HAVE_SELINUX */ #if defined(HAVE_SMACK) && !defined(PROTO) /* --- 2814,2820 ---- freecon(from_context); } } ! #endif // HAVE_SELINUX #if defined(HAVE_SMACK) && !defined(PROTO) /* *************** *** 2844,2857 **** for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) / sizeof(smack_copied_attributes)[0]) ; index++) { ! /* get the name of the attribute to copy */ name = smack_copied_attributes[index]; ! /* get the value of the attribute in buffer */ size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); if (size >= 0) { ! /* copy the attribute value of buffer */ ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); if (ret < 0) { --- 2842,2855 ---- for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) / sizeof(smack_copied_attributes)[0]) ; index++) { ! // get the name of the attribute to copy name = smack_copied_attributes[index]; ! // get the value of the attribute in buffer size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); if (size >= 0) { ! // copy the attribute value of buffer ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); if (ret < 0) { *************** *** 2864,2898 **** } else { ! /* what reason of not having the attribute value? */ switch (errno) { case ENOTSUP: ! /* extended attributes aren't supported or enabled */ ! /* should a message be echoed? not sure... */ ! return; /* leave because it isn't useful to continue */ case ERANGE: default: ! /* no enough size OR unexpected error */ vim_snprintf((char *)IObuff, IOSIZE, _("Could not get security context %s for %s. Removing it!"), name, from_file); msg_puts((char *)IObuff); msg_putchar('\n'); ! /* FALLTHROUGH to remove the attribute */ case ENODATA: ! /* no attribute of this name */ ret = removexattr((char*)to_file, name); ! /* Silently ignore errors, apparently this happens when ! * smack is not actually being used. */ break; } } } } ! #endif /* HAVE_SMACK */ /* * Return a pointer to the ACL of file "fname" in allocated memory. --- 2862,2896 ---- } else { ! // what reason of not having the attribute value? switch (errno) { case ENOTSUP: ! // extended attributes aren't supported or enabled ! // should a message be echoed? not sure... ! return; // leave because it isn't useful to continue case ERANGE: default: ! // no enough size OR unexpected error vim_snprintf((char *)IObuff, IOSIZE, _("Could not get security context %s for %s. Removing it!"), name, from_file); msg_puts((char *)IObuff); msg_putchar('\n'); ! // FALLTHROUGH to remove the attribute case ENODATA: ! // no attribute of this name ret = removexattr((char*)to_file, name); ! // Silently ignore errors, apparently this happens when ! // smack is not actually being used. break; } } } } ! #endif // HAVE_SMACK /* * Return a pointer to the ACL of file "fname" in allocated memory. *************** *** 2955,2964 **** } } ret = (vim_acl_T)aclent; ! #endif /* HAVE_AIX_ACL */ ! #endif /* HAVE_SOLARIS_ACL */ ! #endif /* HAVE_SOLARIS_ZFS_ACL */ ! #endif /* HAVE_POSIX_ACL */ return ret; } --- 2953,2962 ---- } } ret = (vim_acl_T)aclent; ! #endif // HAVE_AIX_ACL ! #endif // HAVE_SOLARIS_ACL ! #endif // HAVE_SOLARIS_ZFS_ACL ! #endif // HAVE_POSIX_ACL return ret; } *************** *** 2982,2991 **** #else #ifdef HAVE_AIX_ACL chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); ! #endif /* HAVE_AIX_ACL */ ! #endif /* HAVE_SOLARIS_ACL */ ! #endif /* HAVE_SOLARIS_ZFS_ACL */ ! #endif /* HAVE_POSIX_ACL */ } void --- 2980,2989 ---- #else #ifdef HAVE_AIX_ACL chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); ! #endif // HAVE_AIX_ACL ! #endif // HAVE_SOLARIS_ACL ! #endif // HAVE_SOLARIS_ZFS_ACL ! #endif // HAVE_POSIX_ACL } void *************** *** 3005,3014 **** #else #ifdef HAVE_AIX_ACL free(aclent); ! #endif /* HAVE_AIX_ACL */ ! #endif /* HAVE_SOLARIS_ACL */ ! #endif /* HAVE_SOLARIS_ZFS_ACL */ ! #endif /* HAVE_POSIX_ACL */ } #endif --- 3003,3012 ---- #else #ifdef HAVE_AIX_ACL free(aclent); ! #endif // HAVE_AIX_ACL ! #endif // HAVE_SOLARIS_ACL ! #endif // HAVE_SOLARIS_ZFS_ACL ! #endif // HAVE_POSIX_ACL } #endif *************** *** 3018,3024 **** void mch_hide(char_u *name UNUSED) { ! /* can't hide a file */ } /* --- 3016,3022 ---- void mch_hide(char_u *name UNUSED) { ! // can't hide a file } /* *************** *** 3031,3037 **** { struct stat statb; ! if (*name == NUL) /* Some stat()s don't flag "" as an error. */ return FALSE; if (stat((char *)name, &statb)) return FALSE; --- 3029,3035 ---- { struct stat statb; ! if (*name == NUL) // Some stat()s don't flag "" as an error. return FALSE; if (stat((char *)name, &statb)) return FALSE; *************** *** 3048,3054 **** { struct stat statb; ! if (*name == NUL) /* Some stat()s don't flag "" as an error. */ return FALSE; if (mch_lstat((char *)name, &statb)) return FALSE; --- 3046,3052 ---- { struct stat statb; ! if (*name == NUL) // Some stat()s don't flag "" as an error. return FALSE; if (mch_lstat((char *)name, &statb)) return FALSE; *************** *** 3066,3079 **** if (stat((char *)name, &st)) return 0; #ifdef VMS ! /* Like on Unix system file can have executable rights but not necessarily ! * be an executable, but on Unix is not a default for an ordinary file to ! * have an executable flag - on VMS it is in most cases. ! * Therefore, this check does not have any sense - let keep us to the ! * conventions instead: ! * *.COM and *.EXE files are the executables - the rest are not. This is ! * not ideal but better then it was. ! */ int vms_executable = 0; if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) { --- 3064,3076 ---- if (stat((char *)name, &st)) return 0; #ifdef VMS ! // Like on Unix system file can have executable rights but not necessarily ! // be an executable, but on Unix is not a default for an ordinary file to ! // have an executable flag - on VMS it is in most cases. ! // Therefore, this check does not have any sense - let keep us to the ! // conventions instead: ! // *.COM and *.EXE files are the executables - the rest are not. This is ! // not ideal but better then it was. int vms_executable = 0; if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) { *************** *** 3099,3110 **** char_u *p, *e; int retval; ! /* When "use_path" is false and if it's an absolute or relative path don't ! * need to use $PATH. */ if (!use_path || gettail(name) != name) { ! /* There must be a path separator, files in the current directory ! * can't be executed. */ if ((use_path || gettail(name) != name) && executable_file(name)) { if (path != NULL) --- 3096,3107 ---- char_u *p, *e; int retval; ! // When "use_path" is false and if it's an absolute or relative path don't ! // need to use $PATH. if (!use_path || gettail(name) != name) { ! // There must be a path separator, files in the current directory ! // can't be executed. if ((use_path || gettail(name) != name) && executable_file(name)) { if (path != NULL) *************** *** 3135,3141 **** e = (char_u *)strchr((char *)p, ':'); if (e == NULL) e = p + STRLEN(p); ! if (e - p <= 1) /* empty entry means current dir */ STRCPY(buf, "./"); else { --- 3132,3138 ---- e = (char_u *)strchr((char *)p, ':'); if (e == NULL) e = p + STRLEN(p); ! if (e - p <= 1) // empty entry means current dir STRCPY(buf, "./"); else { *************** *** 3180,3188 **** return NODE_NORMAL; if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) return NODE_NORMAL; ! if (S_ISBLK(st.st_mode)) /* block device isn't writable */ return NODE_OTHER; ! /* Everything else is writable? */ return NODE_WRITABLE; } --- 3177,3185 ---- return NODE_NORMAL; if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) return NODE_NORMAL; ! if (S_ISBLK(st.st_mode)) // block device isn't writable return NODE_OTHER; ! // Everything else is writable? return NODE_WRITABLE; } *************** *** 3226,3239 **** if (xterm_Shell != (Widget)0) XtDestroyWidget(xterm_Shell); # ifndef LESSTIF_VERSION ! /* Lesstif crashes here, lose some memory */ if (xterm_dpy != NULL) XtCloseDisplay(xterm_dpy); if (app_context != (XtAppContext)NULL) { XtDestroyApplicationContext(app_context); # ifdef FEAT_X11 ! x11_display = NULL; /* freed by XtDestroyApplicationContext() */ # endif } # endif --- 3223,3236 ---- if (xterm_Shell != (Widget)0) XtDestroyWidget(xterm_Shell); # ifndef LESSTIF_VERSION ! // Lesstif crashes here, lose some memory if (xterm_dpy != NULL) XtCloseDisplay(xterm_dpy); if (app_context != (XtAppContext)NULL) { XtDestroyApplicationContext(app_context); # ifdef FEAT_X11 ! x11_display = NULL; // freed by XtDestroyApplicationContext() # endif } # endif *************** *** 3279,3287 **** } else { ! restore_cterm_colors(); /* get original colors back */ ! msg_clr_eos_force(); /* clear the rest of the display */ ! windgoto((int)Rows - 1, 0); /* may have moved the cursor */ } } --- 3276,3284 ---- } else { ! restore_cterm_colors(); // get original colors back ! msg_clr_eos_force(); // clear the rest of the display ! windgoto((int)Rows - 1, 0); // may have moved the cursor } } *************** *** 3313,3320 **** if (swapping_screen() && !newline_on_exit) exit_scroll(); ! /* Stop termcap: May need to check for T_CRV response, which ! * requires RAW mode. */ stoptermcap(); /* --- 3310,3317 ---- if (swapping_screen() && !newline_on_exit) exit_scroll(); ! // Stop termcap: May need to check for T_CRV response, which ! // requires RAW mode. stoptermcap(); /* *************** *** 3324,3336 **** if (!swapping_screen() || newline_on_exit) exit_scroll(); ! /* Cursor may have been switched off without calling starttermcap() ! * when doing "vim -u vimrc" and vimrc contains ":q". */ if (full_screen) cursor_on(); } out_flush(); ! ml_close_all(TRUE); /* remove all memfiles */ may_core_dump(); #ifdef FEAT_GUI if (gui.in_use) --- 3321,3333 ---- if (!swapping_screen() || newline_on_exit) exit_scroll(); ! // Cursor may have been switched off without calling starttermcap() ! // when doing "vim -u vimrc" and vimrc contains ":q". if (full_screen) cursor_on(); } out_flush(); ! ml_close_all(TRUE); // remove all memfiles may_core_dump(); #ifdef FEAT_GUI if (gui.in_use) *************** *** 3342,3349 **** #endif #ifdef __QNX__ ! /* A core dump won't be created if the signal handler ! * doesn't return, so we can't call exit() */ if (deadly_signal != 0) return; #endif --- 3339,3346 ---- #endif #ifdef __QNX__ ! // A core dump won't be created if the signal handler ! // doesn't return, so we can't call exit() if (deadly_signal != 0) return; #endif *************** *** 3365,3371 **** if (deadly_signal != 0) { signal(deadly_signal, SIG_DFL); ! kill(getpid(), deadly_signal); /* Die using the signal we caught */ } } --- 3362,3368 ---- if (deadly_signal != 0) { signal(deadly_signal, SIG_DFL); ! kill(getpid(), deadly_signal); // Die using the signal we caught } } *************** *** 3452,3459 **** tnew.c_iflag &= ~ICRNL; tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE # if defined(IEXTEN) && !defined(__MINT__) ! | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ ! /* but it breaks function keys on MINT */ # endif ); # ifdef ONLCR --- 3449,3456 ---- tnew.c_iflag &= ~ICRNL; tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE # if defined(IEXTEN) && !defined(__MINT__) ! | IEXTEN // IEXTEN enables typing ^V on SOLARIS ! // but it breaks function keys on MINT # endif ); # ifdef ONLCR *************** *** 3474,3492 **** } else if (tmode == TMODE_SLEEP) { ! /* Also reset ICANON here, otherwise on Solaris select() won't see ! * typeahead characters. */ tnew.c_lflag &= ~(ICANON | ECHO); ! tnew.c_cc[VMIN] = 1; /* return after 1 char */ ! tnew.c_cc[VTIME] = 0; /* don't wait */ } # if defined(HAVE_TERMIOS_H) { int n = 10; ! /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a ! * few times. */ while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 && errno == EINTR && n > 0) --n; --- 3471,3489 ---- } else if (tmode == TMODE_SLEEP) { ! // Also reset ICANON here, otherwise on Solaris select() won't see ! // typeahead characters. tnew.c_lflag &= ~(ICANON | ECHO); ! tnew.c_cc[VMIN] = 1; // return after 1 char ! tnew.c_cc[VTIME] = 0; // don't wait } # if defined(HAVE_TERMIOS_H) { int n = 10; ! // A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a ! // few times. while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 && errno == EINTR && n > 0) --n; *************** *** 3500,3506 **** * for "old" tty systems */ # ifndef TIOCSETN ! # define TIOCSETN TIOCSETP /* for hpux 9.0 */ # endif static struct sgttyb ttybold; struct sgttyb ttybnew; --- 3497,3503 ---- * for "old" tty systems */ # ifndef TIOCSETN ! # define TIOCSETN TIOCSETP // for hpux 9.0 # endif static struct sgttyb ttybold; struct sgttyb ttybnew; *************** *** 3547,3553 **** buf[1] = NUL; add_termcode((char_u *)"kb", buf, FALSE); ! /* If and are now the same, redefine . */ p = find_termcode((char_u *)"kD"); if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) do_fixdel(NULL); --- 3544,3550 ---- buf[1] = NUL; add_termcode((char_u *)"kb", buf, FALSE); ! // If and are now the same, redefine . p = find_termcode((char_u *)"kD"); if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) do_fixdel(NULL); *************** *** 3583,3589 **** return OK; } #else ! /* for "old" tty systems */ struct sgttyb keys; if (mch_tcgetattr(fd, &keys) != -1) --- 3580,3586 ---- return OK; } #else ! // for "old" tty systems struct sgttyb keys; if (mch_tcgetattr(fd, &keys) != -1) *************** *** 3598,3604 **** return FAIL; } ! #endif /* VMS */ static int mouse_ison = FALSE; --- 3595,3601 ---- return FAIL; } ! #endif // VMS static int mouse_ison = FALSE; *************** *** 3625,3631 **** && p_bevalterm == bevalterm_ison #endif ) ! /* return quickly if nothing to do */ return; xterm_mouse_vers = use_xterm_mouse(); --- 3622,3628 ---- && p_bevalterm == bevalterm_ison #endif ) ! // return quickly if nothing to do return; xterm_mouse_vers = use_xterm_mouse(); *************** *** 3643,3649 **** if (ttym_flags == TTYM_SGR) { ! /* SGR mode supports columns above 223 */ out_str_nf((char_u *) (on ? IF_EB("\033[?1006h", ESC_STR "[?1006h") --- 3640,3646 ---- if (ttym_flags == TTYM_SGR) { ! // SGR mode supports columns above 223 out_str_nf((char_u *) (on ? IF_EB("\033[?1006h", ESC_STR "[?1006h") *************** *** 3656,3662 **** { bevalterm_ison = (p_bevalterm && on); if (xterm_mouse_vers > 1 && !bevalterm_ison) ! /* disable mouse movement events, enabling is below */ out_str_nf((char_u *) (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); } --- 3653,3659 ---- { bevalterm_ison = (p_bevalterm && on); if (xterm_mouse_vers > 1 && !bevalterm_ison) ! // disable mouse movement events, enabling is below out_str_nf((char_u *) (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); } *************** *** 3664,3670 **** if (xterm_mouse_vers > 0) { ! if (on) /* enable mouse events, use mouse tracking if available */ out_str_nf((char_u *) (xterm_mouse_vers > 1 ? ( --- 3661,3667 ---- if (xterm_mouse_vers > 0) { ! if (on) // enable mouse events, use mouse tracking if available out_str_nf((char_u *) (xterm_mouse_vers > 1 ? ( *************** *** 3674,3680 **** #endif IF_EB("\033[?1002h", ESC_STR "[?1002h")) : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); ! else /* disable mouse events, could probably always send the same */ out_str_nf((char_u *) (xterm_mouse_vers > 1 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") --- 3671,3677 ---- #endif IF_EB("\033[?1002h", ESC_STR "[?1002h")) : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); ! else // disable mouse events, could probably always send the same out_str_nf((char_u *) (xterm_mouse_vers > 1 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") *************** *** 3685,3693 **** #ifdef FEAT_MOUSE_DEC else if (ttym_flags == TTYM_DEC) { ! if (on) /* enable mouse events */ out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); ! else /* disable mouse events */ out_str_nf((char_u *)"\033['z"); mouse_ison = on; } --- 3682,3690 ---- #ifdef FEAT_MOUSE_DEC else if (ttym_flags == TTYM_DEC) { ! if (on) // enable mouse events out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); ! else // disable mouse events out_str_nf((char_u *)"\033['z"); mouse_ison = on; } *************** *** 3730,3752 **** { if (on) { ! /* D - Enable Mouse up/down messages ! * L - Enable Left Button Reporting ! * M - Enable Middle Button Reporting ! * R - Enable Right Button Reporting ! * K - Enable SHIFT and CTRL key Reporting ! * + - Enable Advanced messaging of mouse moves and up/down messages ! * Q - Quiet No Ack ! * # - Numeric value of mouse pointer required ! * 0 = Multiview 2000 cursor, used as standard ! * 1 = Windows Arrow ! * 2 = Windows I Beam ! * 3 = Windows Hour Glass ! * 4 = Windows Cross Hair ! * 5 = Windows UP Arrow ! */ # ifdef JSBTERM_MOUSE_NONADVANCED ! /* Disables full feedback of pointer movements */ out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); # else --- 3727,3748 ---- { if (on) { ! // D - Enable Mouse up/down messages ! // L - Enable Left Button Reporting ! // M - Enable Middle Button Reporting ! // R - Enable Right Button Reporting ! // K - Enable SHIFT and CTRL key Reporting ! // + - Enable Advanced messaging of mouse moves and up/down messages ! // Q - Quiet No Ack ! // # - Numeric value of mouse pointer required ! // 0 = Multiview 2000 cursor, used as standard ! // 1 = Windows Arrow ! // 2 = Windows I Beam ! // 3 = Windows Hour Glass ! // 4 = Windows Cross Hair ! // 5 = Windows UP Arrow # ifdef JSBTERM_MOUSE_NONADVANCED ! // Disables full feedback of pointer movements out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); # else *************** *** 3766,3772 **** #ifdef FEAT_MOUSE_PTERM else { ! /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ if (on) out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); else --- 3762,3768 ---- #ifdef FEAT_MOUSE_PTERM else { ! // 1 = button press, 6 = release, 7 = drag, 1h...9l = right button if (on) out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); else *************** *** 3808,3815 **** : IF_EB("\033[M", ESC_STR "[M"))); if (*p_mouse != NUL) { ! /* force mouse off and maybe on to send possibly new mouse ! * activation sequence to the xterm, with(out) drag tracing. */ mch_setmouse(FALSE); setmouse(); } --- 3804,3811 ---- : IF_EB("\033[M", ESC_STR "[M"))); if (*p_mouse != NUL) { ! // force mouse off and maybe on to send possibly new mouse ! // activation sequence to the xterm, with(out) drag tracing. mch_setmouse(FALSE); setmouse(); } *************** *** 3840,3846 **** # endif # ifdef FEAT_MOUSE_JSB ! /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use --- 3836,3842 ---- # endif # ifdef FEAT_MOUSE_JSB ! // Conflicts with xterm mouse: "\033[" and "\033[M" ??? if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use *************** *** 3853,3860 **** # endif # ifdef FEAT_MOUSE_NET ! /* There is no conflict, but one may type "ESC }" from Insert mode. Don't ! * define it in the GUI or when using an xterm. */ if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use --- 3849,3856 ---- # endif # ifdef FEAT_MOUSE_NET ! // There is no conflict, but one may type "ESC }" from Insert mode. Don't ! // define it in the GUI or when using an xterm. if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use *************** *** 3867,3873 **** # endif # ifdef FEAT_MOUSE_DEC ! /* Conflicts with xterm mouse: "\033[" and "\033[M" */ if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use --- 3863,3869 ---- # endif # ifdef FEAT_MOUSE_DEC ! // Conflicts with xterm mouse: "\033[" and "\033[M" if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use *************** *** 3879,3885 **** del_mouse_termcode(KS_DEC_MOUSE); # endif # ifdef FEAT_MOUSE_PTERM ! /* same conflict as the dec mouse */ if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use --- 3875,3881 ---- del_mouse_termcode(KS_DEC_MOUSE); # endif # ifdef FEAT_MOUSE_PTERM ! // same conflict as the dec mouse if (!use_xterm_mouse() # ifdef FEAT_GUI && !gui.in_use *************** *** 3975,3981 **** struct winsize ws; int fd = 1; ! /* When stdout is not a tty, use stdin for the ioctl(). */ if (!isatty(fd) && isatty(read_cmd_fd)) fd = read_cmd_fd; if (ioctl(fd, TIOCGWINSZ, &ws) == 0) --- 3971,3977 ---- struct winsize ws; int fd = 1; ! // When stdout is not a tty, use stdin for the ioctl(). if (!isatty(fd) && isatty(read_cmd_fd)) fd = read_cmd_fd; if (ioctl(fd, TIOCGWINSZ, &ws) == 0) *************** *** 3984,3996 **** rows = ws.ws_row; } } ! # else /* TIOCGWINSZ */ # ifdef TIOCGSIZE { struct ttysize ts; int fd = 1; ! /* When stdout is not a tty, use stdin for the ioctl(). */ if (!isatty(fd) && isatty(read_cmd_fd)) fd = read_cmd_fd; if (ioctl(fd, TIOCGSIZE, &ts) == 0) --- 3980,3992 ---- rows = ws.ws_row; } } ! # else // TIOCGWINSZ # ifdef TIOCGSIZE { struct ttysize ts; int fd = 1; ! // When stdout is not a tty, use stdin for the ioctl(). if (!isatty(fd) && isatty(read_cmd_fd)) fd = read_cmd_fd; if (ioctl(fd, TIOCGSIZE, &ts) == 0) *************** *** 3999,4006 **** rows = ts.ts_lines; } } ! # endif /* TIOCGSIZE */ ! # endif /* TIOCGWINSZ */ /* * 2. get size from environment --- 3995,4002 ---- rows = ts.ts_lines; } } ! # endif // TIOCGSIZE ! # endif // TIOCGWINSZ /* * 2. get size from environment *************** *** 4089,4099 **** */ term_set_winsize((int)Rows, (int)Columns); out_flush(); ! screen_start(); /* don't know where cursor is now */ } } ! #endif /* VMS */ /* * Rows and/or Columns has changed. --- 4085,4095 ---- */ term_set_winsize((int)Rows, (int)Columns); out_flush(); ! screen_start(); // don't know where cursor is now } } ! #endif // VMS /* * Rows and/or Columns has changed. *************** *** 4101,4107 **** void mch_new_shellsize(void) { ! /* Nothing to do. */ } /* --- 4097,4103 ---- void mch_new_shellsize(void) { ! // Nothing to do. } /* *************** *** 4116,4125 **** while (wait_pid != child) { ! /* When compiled with Python threads are probably used, in which case ! * wait() sometimes hangs for no obvious reason. Use waitpid() ! * instead and loop (like the GUI). Also needed for other interfaces, ! * they might call system(). */ # ifdef __NeXT__ wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); # else --- 4112,4121 ---- while (wait_pid != child) { ! // When compiled with Python threads are probably used, in which case ! // wait() sometimes hangs for no obvious reason. Use waitpid() ! // instead and loop (like the GUI). Also needed for other interfaces, ! // they might call system(). # ifdef __NeXT__ wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); # else *************** *** 4127,4133 **** # endif if (wait_pid == 0) { ! /* Wait for 1 to 10 msec before trying again. */ mch_delay(delay_msec, TRUE); if (++delay_msec > 10) delay_msec = 10; --- 4123,4129 ---- # endif if (wait_pid == 0) { ! // Wait for 1 to 10 msec before trying again. mch_delay(delay_msec, TRUE); if (++delay_msec > 10) delay_msec = 10; *************** *** 4255,4263 **** *pty_master_fd = mch_openpty(&tty_name); // open pty if (*pty_master_fd >= 0) { ! /* Leaving out O_NOCTTY may lead to waitpid() always returning ! * 0 on Mac OS X 10.7 thereby causing freezes. Let's assume ! * adding O_NOCTTY always works when defined. */ #ifdef O_NOCTTY *pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0); #else --- 4251,4259 ---- *pty_master_fd = mch_openpty(&tty_name); // open pty if (*pty_master_fd >= 0) { ! // Leaving out O_NOCTTY may lead to waitpid() always returning ! // 0 on Mac OS X 10.7 thereby causing freezes. Let's assume ! // adding O_NOCTTY always works when defined. #ifdef O_NOCTTY *pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0); #else *************** *** 4301,4306 **** --- 4297,4307 ---- #if !defined(USE_SYSTEM) || defined(FEAT_TERMINAL) || defined(PROTO) + /* + * Parse "cmd" and return the result in "argvp" which is an allocated array of + * pointers, the last one is NULL. + * The "sh_tofree" and "shcf_tofree" must be later freed by the caller. + */ int unix_build_argv( char_u *cmd, *************** *** 4312,4318 **** int argc; *sh_tofree = vim_strsave(p_sh); ! if (*sh_tofree == NULL) /* out of memory */ return FAIL; if (mch_parse_cmd(*sh_tofree, TRUE, &argv, &argc) == FAIL) --- 4313,4319 ---- int argc; *sh_tofree = vim_strsave(p_sh); ! if (*sh_tofree == NULL) // out of memory return FAIL; if (mch_parse_cmd(*sh_tofree, TRUE, &argv, &argc) == FAIL) *************** *** 4327,4336 **** if (extra_shell_arg != NULL) argv[argc++] = (char *)extra_shell_arg; ! /* Break 'shellcmdflag' into white separated parts. This doesn't ! * handle quoted strings, they are very unlikely to appear. */ *shcf_tofree = alloc(STRLEN(p_shcf) + 1); ! if (*shcf_tofree == NULL) /* out of memory */ return FAIL; s = *shcf_tofree; p = p_shcf; --- 4328,4337 ---- if (extra_shell_arg != NULL) argv[argc++] = (char *)extra_shell_arg; ! // Break 'shellcmdflag' into white separated parts. This doesn't ! // handle quoted strings, they are very unlikely to appear. *shcf_tofree = alloc(STRLEN(p_shcf) + 1); ! if (*shcf_tofree == NULL) // out of memory return FAIL; s = *shcf_tofree; p = p_shcf; *************** *** 4357,4363 **** static int mch_call_shell_terminal( char_u *cmd, ! int options UNUSED) /* SHELL_*, see vim.h */ { jobopt_T opt; char **argv = NULL; --- 4358,4364 ---- static int mch_call_shell_terminal( char_u *cmd, ! int options UNUSED) // SHELL_*, see vim.h { jobopt_T opt; char **argv = NULL; *************** *** 4367,4373 **** buf_T *buf; job_T *job; aco_save_T aco; ! oparg_T oa; /* operator arguments */ if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) goto theend; --- 4368,4374 ---- buf_T *buf; job_T *job; aco_save_T aco; ! oparg_T oa; // operator arguments if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) goto theend; *************** *** 4381,4387 **** job = term_getjob(buf->b_term); ++job->jv_refcount; ! /* Find a window to make "buf" curbuf. */ aucmd_prepbuf(&aco, buf); clear_oparg(&oa); --- 4382,4388 ---- job = term_getjob(buf->b_term); ++job->jv_refcount; ! // Find a window to make "buf" curbuf. aucmd_prepbuf(&aco, buf); clear_oparg(&oa); *************** *** 4389,4396 **** { if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! /* If terminal_loop() returns OK we got a key that is handled ! * in Normal model. We don't do redrawing anyway. */ if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } --- 4390,4397 ---- { if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! // If terminal_loop() returns OK we got a key that is handled ! // in Normal model. We don't do redrawing anyway. if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } *************** *** 4402,4408 **** job_unref(job); ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); wait_return(TRUE); --- 4403,4409 ---- job_unref(job); ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); wait_return(TRUE); *************** *** 4423,4442 **** static int mch_call_shell_system( char_u *cmd, ! int options) /* SHELL_*, see vim.h */ { #ifdef VMS char *ifn = NULL; char *ofn = NULL; #endif int tmode = cur_tmode; ! char_u *newcmd; /* only needed for unix */ int x; out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); /* set to normal mode */ # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) save_clipboard(); --- 4424,4443 ---- static int mch_call_shell_system( char_u *cmd, ! int options) // SHELL_*, see vim.h { #ifdef VMS char *ifn = NULL; char *ofn = NULL; #endif int tmode = cur_tmode; ! char_u *newcmd; // only needed for unix int x; out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); // set to normal mode # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) save_clipboard(); *************** *** 4455,4461 **** char *p; *ifn++ = '\0'; ! p = strchr(ifn,' '); /* chop off any trailing spaces */ if (p) *p = '\0'; } --- 4456,4462 ---- char *p; *ifn++ = '\0'; ! p = strchr(ifn,' '); // chop off any trailing spaces if (p) *p = '\0'; } *************** *** 4495,4501 **** } if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); /* set to raw mode */ # ifdef FEAT_TITLE resettitle(); # endif --- 4496,4502 ---- } if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); // set to raw mode # ifdef FEAT_TITLE resettitle(); # endif *************** *** 4505,4515 **** return x; } ! #else /* USE_SYSTEM */ ! # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use ! 127, some shells use that already */ ! # define OPEN_NULL_FAILED 123 /* Exit code if /dev/null can't be opened */ /* * Don't use system(), use fork()/exec(). --- 4506,4516 ---- return x; } ! #else // USE_SYSTEM ! # define EXEC_FAILED 122 // Exit code when shell didn't execute. Don't use ! // 127, some shells use that already ! # define OPEN_NULL_FAILED 123 // Exit code if /dev/null can't be opened /* * Don't use system(), use fork()/exec(). *************** *** 4517,4523 **** static int mch_call_shell_fork( char_u *cmd, ! int options) /* SHELL_*, see vim.h */ { int tmode = cur_tmode; pid_t pid; --- 4518,4524 ---- static int mch_call_shell_fork( char_u *cmd, ! int options) // SHELL_*, see vim.h { int tmode = cur_tmode; pid_t pid; *************** *** 4533,4550 **** char_u *tofree1 = NULL; char_u *tofree2 = NULL; int i; ! int pty_master_fd = -1; /* for pty's */ # ifdef FEAT_GUI int pty_slave_fd = -1; # endif ! int fd_toshell[2]; /* for pipes */ int fd_fromshell[2]; int pipe_error = FALSE; ! int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); /* set to normal mode */ if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) goto error; --- 4534,4551 ---- char_u *tofree1 = NULL; char_u *tofree2 = NULL; int i; ! int pty_master_fd = -1; // for pty's # ifdef FEAT_GUI int pty_slave_fd = -1; # endif ! int fd_toshell[2]; // for pipes int fd_fromshell[2]; int pipe_error = FALSE; ! int did_settmode = FALSE; // settmode(TMODE_RAW) called out_flush(); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); // set to normal mode if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) goto error; *************** *** 4575,4584 **** # endif { pipe_error = (pipe(fd_toshell) < 0); ! if (!pipe_error) /* pipe create OK */ { pipe_error = (pipe(fd_fromshell) < 0); ! if (pipe_error) /* pipe create failed */ { close(fd_toshell[0]); close(fd_toshell[1]); --- 4576,4585 ---- # endif { pipe_error = (pipe(fd_toshell) < 0); ! if (!pipe_error) // pipe create OK { pipe_error = (pipe(fd_fromshell) < 0); ! if (pipe_error) // pipe create failed { close(fd_toshell[0]); close(fd_toshell[1]); *************** *** 4592,4598 **** } } ! if (!pipe_error) /* pty or pipe opened or not used */ { SIGSET_DECL(curset) --- 4593,4599 ---- } } ! if (!pipe_error) // pty or pipe opened or not used { SIGSET_DECL(curset) *************** *** 4601,4607 **** # endif BLOCK_SIGNALS(&curset); ! pid = fork(); /* maybe we should use vfork() */ if (pid == -1) { UNBLOCK_SIGNALS(&curset); --- 4602,4608 ---- # endif BLOCK_SIGNALS(&curset); ! pid = fork(); // maybe we should use vfork() if (pid == -1) { UNBLOCK_SIGNALS(&curset); *************** *** 4614,4625 **** ) { # ifdef FEAT_GUI ! if (pty_master_fd >= 0) /* close the pseudo tty */ { close(pty_master_fd); close(pty_slave_fd); } ! else /* close the pipes */ # endif { close(fd_toshell[0]); --- 4615,4626 ---- ) { # ifdef FEAT_GUI ! if (pty_master_fd >= 0) // close the pseudo tty { close(pty_master_fd); close(pty_slave_fd); } ! else // close the pipes # endif { close(fd_toshell[0]); *************** *** 4629,4642 **** } } } ! else if (pid == 0) /* child */ { ! reset_signals(); /* handle signals normally */ UNBLOCK_SIGNALS(&curset); # ifdef FEAT_JOB_CHANNEL if (ch_log_active()) ! /* close the log file in the child */ ch_logfile((char_u *)"", (char_u *)""); # endif --- 4630,4643 ---- } } } ! else if (pid == 0) // child { ! reset_signals(); // handle signals normally UNBLOCK_SIGNALS(&curset); # ifdef FEAT_JOB_CHANNEL if (ch_log_active()) ! // close the log file in the child ch_logfile((char_u *)"", (char_u *)""); # endif *************** *** 4668,4678 **** */ if (fd >= 0) { ! vim_ignored = dup(fd); /* To replace stdin (fd 0) */ ! vim_ignored = dup(fd); /* To replace stdout (fd 1) */ ! vim_ignored = dup(fd); /* To replace stderr (fd 2) */ ! /* Don't need this now that we've duplicated it */ close(fd); } } --- 4669,4679 ---- */ if (fd >= 0) { ! vim_ignored = dup(fd); // To replace stdin (fd 0) ! vim_ignored = dup(fd); // To replace stdout (fd 1) ! vim_ignored = dup(fd); // To replace stderr (fd 2) ! // Don't need this now that we've duplicated it close(fd); } } *************** *** 4684,4701 **** { # ifdef HAVE_SETSID ! /* Create our own process group, so that the child and all its ! * children can be kill()ed. Don't do this when using pipes, ! * because stdin is not a tty, we would lose /dev/tty. */ if (p_stmp) { (void)setsid(); # if defined(SIGHUP) ! /* When doing "!xterm&" and 'shell' is bash: the shell ! * will exit and send SIGHUP to all processes in its ! * group, killing the just started process. Ignore SIGHUP ! * to avoid that. (suggested by Simon Schubert) ! */ signal(SIGHUP, SIG_IGN); # endif } --- 4685,4701 ---- { # ifdef HAVE_SETSID ! // Create our own process group, so that the child and all its ! // children can be kill()ed. Don't do this when using pipes, ! // because stdin is not a tty, we would lose /dev/tty. if (p_stmp) { (void)setsid(); # if defined(SIGHUP) ! // When doing "!xterm&" and 'shell' is bash: the shell ! // will exit and send SIGHUP to all processes in its ! // group, killing the just started process. Ignore SIGHUP ! // to avoid that. (suggested by Simon Schubert) signal(SIGHUP, SIG_IGN); # endif } *************** *** 4703,4714 **** # ifdef FEAT_GUI if (pty_slave_fd >= 0) { ! /* push stream discipline modules */ if (options & SHELL_COOKED) setup_slavepty(pty_slave_fd); # ifdef TIOCSCTTY ! /* Try to become controlling tty (probably doesn't work, ! * unless run by root) */ ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); # endif } --- 4703,4714 ---- # ifdef FEAT_GUI if (pty_slave_fd >= 0) { ! // push stream discipline modules if (options & SHELL_COOKED) setup_slavepty(pty_slave_fd); # ifdef TIOCSCTTY ! // Try to become controlling tty (probably doesn't work, ! // unless run by root) ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); # endif } *************** *** 4723,4731 **** # ifdef FEAT_GUI if (pty_master_fd >= 0) { ! close(pty_master_fd); /* close master side of pty */ ! /* set up stdin/stdout/stderr for the child */ close(0); vim_ignored = dup(pty_slave_fd); close(1); --- 4723,4731 ---- # ifdef FEAT_GUI if (pty_master_fd >= 0) { ! close(pty_master_fd); // close master side of pty ! // set up stdin/stdout/stderr for the child close(0); vim_ignored = dup(pty_slave_fd); close(1); *************** *** 4736,4753 **** vim_ignored = dup(pty_slave_fd); } ! close(pty_slave_fd); /* has been dupped, close it now */ } else # endif { ! /* set up stdin for the child */ close(fd_toshell[1]); close(0); vim_ignored = dup(fd_toshell[0]); close(fd_toshell[0]); ! /* set up stdout for the child */ close(fd_fromshell[0]); close(1); vim_ignored = dup(fd_fromshell[1]); --- 4736,4753 ---- vim_ignored = dup(pty_slave_fd); } ! close(pty_slave_fd); // has been dupped, close it now } else # endif { ! // set up stdin for the child close(fd_toshell[1]); close(0); vim_ignored = dup(fd_toshell[0]); close(fd_toshell[0]); ! // set up stdout for the child close(fd_fromshell[0]); close(1); vim_ignored = dup(fd_fromshell[1]); *************** *** 4756,4762 **** # ifdef FEAT_GUI if (gui.in_use) { ! /* set up stderr for the child */ close(2); vim_ignored = dup(1); } --- 4756,4762 ---- # ifdef FEAT_GUI if (gui.in_use) { ! // set up stderr for the child close(2); vim_ignored = dup(1); } *************** *** 4772,4780 **** * to the X server (esp. with GTK, which uses atexit()). */ execvp(argv[0], argv); ! _exit(EXEC_FAILED); /* exec failed, return failure code */ } ! else /* parent */ { /* * While child is running, ignore terminating signals. --- 4772,4780 ---- * to the X server (esp. with GTK, which uses atexit()). */ execvp(argv[0], argv); ! _exit(EXEC_FAILED); // exec failed, return failure code } ! else // parent { /* * While child is running, ignore terminating signals. *************** *** 4797,4807 **** # endif ) { ! # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ char_u buffer[BUFLEN + 1]; ! int buffer_off = 0; /* valid bytes in buffer[] */ ! char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ ! int ta_len = 0; /* valid bytes in ta_buf[] */ int len; int p_more_save; int old_State; --- 4797,4807 ---- # endif ) { ! # define BUFLEN 100 // length for buffer, pseudo tty limit is 128 char_u buffer[BUFLEN + 1]; ! int buffer_off = 0; // valid bytes in buffer[] ! char_u ta_buf[BUFLEN + 1]; // TypeAHead ! int ta_len = 0; // valid bytes in ta_buf[] int len; int p_more_save; int old_State; *************** *** 4848,4864 **** p_more_save = p_more; p_more = FALSE; old_State = State; ! State = EXTERNCMD; /* don't redraw at window resize */ if ((options & SHELL_WRITE) && toshell_fd >= 0) { ! /* Fork a process that will write the lines to the ! * external program. */ if ((wpid = fork()) == -1) { msg_puts(_("\nCannot fork\n")); } ! else if (wpid == 0) /* child */ { linenr_T lnum = curbuf->b_op_start.lnum; int written = 0; --- 4848,4864 ---- p_more_save = p_more; p_more = FALSE; old_State = State; ! State = EXTERNCMD; // don't redraw at window resize if ((options & SHELL_WRITE) && toshell_fd >= 0) { ! // Fork a process that will write the lines to the ! // external program. if ((wpid = fork()) == -1) { msg_puts(_("\nCannot fork\n")); } ! else if (wpid == 0) // child { linenr_T lnum = curbuf->b_op_start.lnum; int written = 0; *************** *** 4872,4878 **** if (l == 0) len = 0; else if (lp[written] == NL) ! /* NL -> NUL translation */ len = write(toshell_fd, "", (size_t)1); else { --- 4872,4878 ---- if (l == 0) len = 0; else if (lp[written] == NL) ! // NL -> NUL translation len = write(toshell_fd, "", (size_t)1); else { *************** *** 4884,4891 **** } if (len == (int)l) { ! /* Finished a line, add a NL, unless this line ! * should not have one. */ if (lnum != curbuf->b_op_end.lnum || (!curbuf->b_p_bin && curbuf->b_p_fixeol) --- 4884,4891 ---- } if (len == (int)l) { ! // Finished a line, add a NL, unless this line ! // should not have one. if (lnum != curbuf->b_op_end.lnum || (!curbuf->b_p_bin && curbuf->b_p_fixeol) *************** *** 4898,4904 **** ++lnum; if (lnum > curbuf->b_op_end.lnum) { ! /* finished all the lines, close pipe */ close(toshell_fd); toshell_fd = -1; break; --- 4898,4904 ---- ++lnum; if (lnum > curbuf->b_op_end.lnum) { ! // finished all the lines, close pipe close(toshell_fd); toshell_fd = -1; break; *************** *** 4911,4917 **** } _exit(0); } ! else /* parent */ { close(toshell_fd); toshell_fd = -1; --- 4911,4917 ---- } _exit(0); } ! else // parent { close(toshell_fd); toshell_fd = -1; *************** *** 4955,4962 **** { if (ta_len == 0) { ! /* Get extra characters when we don't have any. ! * Reset the counter and timer. */ noread_cnt = 0; # ifdef ELAPSED_FUNC ELAPSED_INIT(start_tv); --- 4955,4962 ---- { if (ta_len == 0) { ! // Get extra characters when we don't have any. ! // Reset the counter and timer. noread_cnt = 0; # ifdef ELAPSED_FUNC ELAPSED_INIT(start_tv); *************** *** 4986,4992 **** } } ! /* replace K_BS by and K_DEL by */ for (i = ta_len; i < ta_len + len; ++i) { if (ta_buf[i] == CSI && len - i > 2) --- 4986,4992 ---- } } ! // replace K_BS by and K_DEL by for (i = ta_len; i < ta_len + len; ++i) { if (ta_buf[i] == CSI && len - i > 2) *************** *** 5059,5066 **** if (got_int) { ! /* CTRL-C sends a signal to the child, we ignore it ! * ourselves */ # ifdef HAVE_SETSID kill(-pid, SIGINT); # else --- 5059,5066 ---- if (got_int) { ! // CTRL-C sends a signal to the child, we ignore it ! // ourselves # ifdef HAVE_SETSID kill(-pid, SIGINT); # else *************** *** 5086,5099 **** len = read_eintr(fromshell_fd, buffer + buffer_off, (size_t)(BUFLEN - buffer_off) ); ! if (len <= 0) /* end of file or error */ goto finished; noread_cnt = 0; if (options & SHELL_READ) { ! /* Do NUL -> NL translation, append NL separated ! * lines to the current buffer. */ for (i = 0; i < len; ++i) { if (buffer[i] == NL) --- 5086,5099 ---- len = read_eintr(fromshell_fd, buffer + buffer_off, (size_t)(BUFLEN - buffer_off) ); ! if (len <= 0) // end of file or error goto finished; noread_cnt = 0; if (options & SHELL_READ) { ! // Do NUL -> NL translation, append NL separated ! // lines to the current buffer. for (i = 0; i < len; ++i) { if (buffer[i] == NL) *************** *** 5112,5131 **** len += buffer_off; buffer[len] = NUL; ! /* Check if the last character in buffer[] is ! * incomplete, keep these bytes for the next ! * round. */ for (p = buffer; p < buffer + len; p += l) { l = MB_CPTR2LEN(p); if (l == 0) ! l = 1; /* NUL byte? */ else if (MB_BYTE2LEN(*p) != l) break; } ! if (p == buffer) /* no complete character */ { ! /* avoid getting stuck at an illegal byte */ if (len >= 12) ++p; else --- 5112,5131 ---- len += buffer_off; buffer[len] = NUL; ! // Check if the last character in buffer[] is ! // incomplete, keep these bytes for the next ! // round. for (p = buffer; p < buffer + len; p += l) { l = MB_CPTR2LEN(p); if (l == 0) ! l = 1; // NUL byte? else if (MB_BYTE2LEN(*p) != l) break; } ! if (p == buffer) // no complete character { ! // avoid getting stuck at an illegal byte if (len >= 12) ++p; else *************** *** 5163,5171 **** { long msec = ELAPSED_FUNC(start_tv); ! /* Avoid that we keep looping here without ! * checking for a CTRL-C for a long time. Don't ! * break out too often to avoid losing typeahead. */ if (msec > 2000) { noread_cnt = 5; --- 5163,5171 ---- { long msec = ELAPSED_FUNC(start_tv); ! // Avoid that we keep looping here without ! // checking for a CTRL-C for a long time. Don't ! // break out too often to avoid losing typeahead. if (msec > 2000) { noread_cnt = 5; *************** *** 5175,5183 **** # endif } ! /* If we already detected the child has finished, continue ! * reading output for a short while. Some text may be ! * buffered. */ if (wait_pid == pid) { if (noread_cnt < 5) --- 5175,5183 ---- # endif } ! // If we already detected the child has finished, continue ! // reading output for a short while. Some text may be ! // buffered. if (wait_pid == pid) { if (noread_cnt < 5) *************** *** 5197,5213 **** if ((wait_pid == (pid_t)-1 && errno == ECHILD) || (wait_pid == pid && WIFEXITED(status))) { ! /* Don't break the loop yet, try reading more ! * characters from "fromshell_fd" first. When using ! * pipes there might still be something to read and ! * then we'll break the loop at the "break" above. */ wait_pid = pid; } else wait_pid = 0; # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) ! /* Handle any X events, e.g. serving the clipboard. */ clip_update(); # endif } --- 5197,5213 ---- if ((wait_pid == (pid_t)-1 && errno == ECHILD) || (wait_pid == pid && WIFEXITED(status))) { ! // Don't break the loop yet, try reading more ! // characters from "fromshell_fd" first. When using ! // pipes there might still be something to read and ! // then we'll break the loop at the "break" above. wait_pid = pid; } else wait_pid = 0; # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) ! // Handle any X events, e.g. serving the clipboard. clip_update(); # endif } *************** *** 5218,5224 **** if (ga.ga_len > 0) { append_ga_line(&ga); ! /* remember that the NL was missing */ curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; } else --- 5218,5224 ---- if (ga.ga_len > 0) { append_ga_line(&ga); ! // remember that the NL was missing curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; } else *************** *** 5249,5256 **** { if (got_int) { ! /* CTRL-C sends a signal to the child, we ignore it ! * ourselves */ # ifdef HAVE_SETSID kill(-pid, SIGINT); # else --- 5249,5256 ---- { if (got_int) { ! // CTRL-C sends a signal to the child, we ignore it ! // ourselves # ifdef HAVE_SETSID kill(-pid, SIGINT); # else *************** *** 5270,5280 **** break; } ! /* Handle any X events, e.g. serving the clipboard. */ clip_update(); ! /* Wait for 1 to 10 msec. 1 is faster but gives the child ! * less time. */ mch_delay(delay_msec, TRUE); if (++delay_msec > 10) delay_msec = 10; --- 5270,5280 ---- break; } ! // Handle any X events, e.g. serving the clipboard. clip_update(); ! // Wait for 1 to 10 msec. 1 is faster but gives the child ! // less time. mch_delay(delay_msec, TRUE); if (++delay_msec > 10) delay_msec = 10; *************** *** 5293,5307 **** wait_pid = wait4pid(pid, &status); # ifdef FEAT_GUI ! /* Close slave side of pty. Only do this after the child has ! * exited, otherwise the child may hang when it tries to write on ! * the pty. */ if (pty_master_fd >= 0) close(pty_slave_fd); # endif ! /* Make sure the child that writes to the external program is ! * dead. */ if (wpid > 0) { kill(wpid, SIGKILL); --- 5293,5307 ---- wait_pid = wait4pid(pid, &status); # ifdef FEAT_GUI ! // Close slave side of pty. Only do this after the child has ! // exited, otherwise the child may hang when it tries to write on ! // the pty. if (pty_master_fd >= 0) close(pty_slave_fd); # endif ! // Make sure the child that writes to the external program is ! // dead. if (wpid > 0) { kill(wpid, SIGKILL); *************** *** 5323,5329 **** if (WIFEXITED(status)) { ! /* LINTED avoid "bitwise operation on signed value" */ retval = WEXITSTATUS(status); if (retval != 0 && !emsg_silent) { --- 5323,5329 ---- if (WIFEXITED(status)) { ! // LINTED avoid "bitwise operation on signed value" retval = WEXITSTATUS(status); if (retval != 0 && !emsg_silent) { *************** *** 5349,5355 **** error: if (!did_settmode) if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); /* set to raw mode */ # ifdef FEAT_TITLE resettitle(); # endif --- 5349,5355 ---- error: if (!did_settmode) if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); // set to raw mode # ifdef FEAT_TITLE resettitle(); # endif *************** *** 5359,5370 **** return retval; } ! #endif /* USE_SYSTEM */ int mch_call_shell( char_u *cmd, ! int options) /* SHELL_*, see vim.h */ { #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL) --- 5359,5370 ---- return retval; } ! #endif // USE_SYSTEM int mch_call_shell( char_u *cmd, ! int options) // SHELL_*, see vim.h { #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL) *************** *** 5382,5390 **** mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal) { pid_t pid; ! int fd_in[2] = {-1, -1}; /* for stdin */ ! int fd_out[2] = {-1, -1}; /* for stdout */ ! int fd_err[2] = {-1, -1}; /* for stderr */ int pty_master_fd = -1; int pty_slave_fd = -1; channel_T *channel = NULL; --- 5382,5390 ---- mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal) { pid_t pid; ! int fd_in[2] = {-1, -1}; // for stdin ! int fd_out[2] = {-1, -1}; // for stdout ! int fd_err[2] = {-1, -1}; // for stderr int pty_master_fd = -1; int pty_slave_fd = -1; channel_T *channel = NULL; *************** *** 5401,5407 **** if (use_out_for_err && use_null_for_out) use_null_for_err = TRUE; ! /* default is to fail */ job->jv_status = JOB_FAILED; if (options->jo_pty --- 5401,5407 ---- if (use_out_for_err && use_null_for_out) use_null_for_err = TRUE; ! // default is to fail job->jv_status = JOB_FAILED; if (options->jo_pty *************** *** 5411,5418 **** open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out, &job->jv_tty_in); ! /* TODO: without the channel feature connect the child to /dev/null? */ ! /* Open pipes for stdin, stdout, stderr. */ if (use_file_for_in) { char_u *fname = options->jo_io_name[PART_IN]; --- 5411,5418 ---- open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out, &job->jv_tty_in); ! // TODO: without the channel feature connect the child to /dev/null? ! // Open pipes for stdin, stdout, stderr. if (use_file_for_in) { char_u *fname = options->jo_io_name[PART_IN]; *************** *** 5425,5432 **** } } else ! /* When writing buffer lines to the input don't use the pty, so that ! * the pipe can be closed when all lines were written. */ if (!use_null_for_in && (pty_master_fd < 0 || use_buffer_for_in) && pipe(fd_in) < 0) goto failed; --- 5425,5432 ---- } } else ! // When writing buffer lines to the input don't use the pty, so that ! // the pipe can be closed when all lines were written. if (!use_null_for_in && (pty_master_fd < 0 || use_buffer_for_in) && pipe(fd_in) < 0) goto failed; *************** *** 5478,5487 **** } BLOCK_SIGNALS(&curset); ! pid = fork(); /* maybe we should use vfork() */ if (pid == -1) { ! /* failed to fork */ UNBLOCK_SIGNALS(&curset); goto failed; } --- 5478,5487 ---- } BLOCK_SIGNALS(&curset); ! pid = fork(); // maybe we should use vfork() if (pid == -1) { ! // failed to fork UNBLOCK_SIGNALS(&curset); goto failed; } *************** *** 5490,5509 **** int null_fd = -1; int stderr_works = TRUE; ! /* child */ ! reset_signals(); /* handle signals normally */ UNBLOCK_SIGNALS(&curset); # ifdef FEAT_JOB_CHANNEL if (ch_log_active()) ! /* close the log file in the child */ ch_logfile((char_u *)"", (char_u *)""); # endif # ifdef HAVE_SETSID ! /* Create our own process group, so that the child and all its ! * children can be kill()ed. Don't do this when using pipes, ! * because stdin is not a tty, we would lose /dev/tty. */ (void)setsid(); # endif --- 5490,5509 ---- int null_fd = -1; int stderr_works = TRUE; ! // child ! reset_signals(); // handle signals normally UNBLOCK_SIGNALS(&curset); # ifdef FEAT_JOB_CHANNEL if (ch_log_active()) ! // close the log file in the child ch_logfile((char_u *)"", (char_u *)""); # endif # ifdef HAVE_SETSID ! // Create our own process group, so that the child and all its ! // children can be kill()ed. Don't do this when using pipes, ! // because stdin is not a tty, we would lose /dev/tty. (void)setsid(); # endif *************** *** 5514,5524 **** #ifdef FEAT_GUI if (term_is_gui(T_NAME)) ! /* In the GUI 'term' is not what we want, use $TERM. */ term = getenv("TERM"); #endif ! /* Use 'term' or $TERM if it starts with "xterm", otherwise fall ! * back to "xterm". */ if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0) term = "xterm"; set_child_environment( --- 5514,5524 ---- #ifdef FEAT_GUI if (term_is_gui(T_NAME)) ! // In the GUI 'term' is not what we want, use $TERM. term = getenv("TERM"); #endif ! // Use 'term' or $TERM if it starts with "xterm", otherwise fall ! // back to "xterm". if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0) term = "xterm"; set_child_environment( *************** *** 5559,5574 **** if (pty_slave_fd >= 0) { ! /* push stream discipline modules */ setup_slavepty(pty_slave_fd); # ifdef TIOCSCTTY ! /* Try to become controlling tty (probably doesn't work, ! * unless run by root) */ ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); # endif } ! /* set up stdin for the child */ close(0); if (use_null_for_in && null_fd >= 0) vim_ignored = dup(null_fd); --- 5559,5574 ---- if (pty_slave_fd >= 0) { ! // push stream discipline modules setup_slavepty(pty_slave_fd); # ifdef TIOCSCTTY ! // Try to become controlling tty (probably doesn't work, ! // unless run by root) ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); # endif } ! // set up stdin for the child close(0); if (use_null_for_in && null_fd >= 0) vim_ignored = dup(null_fd); *************** *** 5577,5583 **** else vim_ignored = dup(fd_in[0]); ! /* set up stderr for the child */ close(2); if (use_null_for_err && null_fd >= 0) { --- 5577,5583 ---- else vim_ignored = dup(fd_in[0]); ! // set up stderr for the child close(2); if (use_null_for_err && null_fd >= 0) { *************** *** 5591,5597 **** else vim_ignored = dup(fd_err[1]); ! /* set up stdout for the child */ close(1); if (use_null_for_out && null_fd >= 0) vim_ignored = dup(null_fd); --- 5591,5597 ---- else vim_ignored = dup(fd_err[1]); ! // set up stdout for the child close(1); if (use_null_for_out && null_fd >= 0) vim_ignored = dup(null_fd); *************** *** 5614,5621 **** close(fd_err[1]); if (pty_master_fd >= 0) { ! close(pty_master_fd); /* not used in the child */ ! close(pty_slave_fd); /* was duped above */ } if (null_fd >= 0) --- 5614,5621 ---- close(fd_err[1]); if (pty_master_fd >= 0) { ! close(pty_master_fd); // not used in the child ! close(pty_slave_fd); // was duped above } if (null_fd >= 0) *************** *** 5624,5651 **** if (options->jo_cwd != NULL && mch_chdir((char *)options->jo_cwd) != 0) _exit(EXEC_FAILED); ! /* See above for type of argv. */ execvp(argv[0], argv); if (stderr_works) perror("executing job failed"); # ifdef EXITFREE ! /* calling free_all_mem() here causes problems. Ignore valgrind ! * reporting possibly leaked memory. */ # endif ! _exit(EXEC_FAILED); /* exec failed, return failure code */ } ! /* parent */ UNBLOCK_SIGNALS(&curset); job->jv_pid = pid; job->jv_status = JOB_STARTED; ! job->jv_channel = channel; /* ch_refcount was set above */ if (pty_master_fd >= 0) ! close(pty_slave_fd); /* not used in the parent */ ! /* close child stdin, stdout and stderr */ if (fd_in[0] >= 0) close(fd_in[0]); if (fd_out[1] >= 0) --- 5624,5651 ---- if (options->jo_cwd != NULL && mch_chdir((char *)options->jo_cwd) != 0) _exit(EXEC_FAILED); ! // See above for type of argv. execvp(argv[0], argv); if (stderr_works) perror("executing job failed"); # ifdef EXITFREE ! // calling free_all_mem() here causes problems. Ignore valgrind ! // reporting possibly leaked memory. # endif ! _exit(EXEC_FAILED); // exec failed, return failure code } ! // parent UNBLOCK_SIGNALS(&curset); job->jv_pid = pid; job->jv_status = JOB_STARTED; ! job->jv_channel = channel; // ch_refcount was set above if (pty_master_fd >= 0) ! close(pty_slave_fd); // not used in the parent ! // close child stdin, stdout and stderr if (fd_in[0] >= 0) close(fd_in[0]); if (fd_out[1] >= 0) *************** *** 5689,5695 **** close(pty_master_fd); } ! /* success! */ return; failed: --- 5689,5695 ---- close(pty_master_fd); } ! // success! return; failed: *************** *** 5746,5752 **** # endif if (wait_pid == -1) { ! /* process must have exited */ if (job->jv_status < JOB_ENDED) ch_log(job->jv_channel, "Job no longer exists: %s", strerror(errno)); --- 5746,5752 ---- # endif if (wait_pid == -1) { ! // process must have exited if (job->jv_status < JOB_ENDED) ch_log(job->jv_channel, "Job no longer exists: %s", strerror(errno)); *************** *** 5756,5762 **** return "run"; if (WIFEXITED(status)) { ! /* LINTED avoid "bitwise operation on signed value" */ job->jv_exitval = WEXITSTATUS(status); if (job->jv_status < JOB_ENDED) ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval); --- 5756,5762 ---- return "run"; if (WIFEXITED(status)) { ! // LINTED avoid "bitwise operation on signed value" job->jv_exitval = WEXITSTATUS(status); if (job->jv_status < JOB_ENDED) ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval); *************** *** 5791,5799 **** job_T *job; # ifndef USE_SYSTEM ! /* Do not do this when waiting for a shell command to finish, we would get ! * the exit value here (and discard it), the exit value obtained there ! * would then be wrong. */ if (dont_check_job_ended > 0) return NULL; # endif --- 5791,5799 ---- job_T *job; # ifndef USE_SYSTEM ! // Do not do this when waiting for a shell command to finish, we would get ! // the exit value here (and discard it), the exit value obtained there ! // would then be wrong. if (dont_check_job_ended > 0) return NULL; # endif *************** *** 5804,5817 **** wait_pid = waitpid(-1, &status, WNOHANG); # endif if (wait_pid <= 0) ! /* no process ended */ return NULL; for (job = job_list; job != NULL; job = job->jv_next) { if (job->jv_pid == wait_pid) { if (WIFEXITED(status)) ! /* LINTED avoid "bitwise operation on signed value" */ job->jv_exitval = WEXITSTATUS(status); else if (WIFSIGNALED(status)) { --- 5804,5817 ---- wait_pid = waitpid(-1, &status, WNOHANG); # endif if (wait_pid <= 0) ! // no process ended return NULL; for (job = job_list; job != NULL; job = job->jv_next) { if (job->jv_pid == wait_pid) { if (WIFEXITED(status)) ! // LINTED avoid "bitwise operation on signed value" job->jv_exitval = WEXITSTATUS(status); else if (WIFSIGNALED(status)) { *************** *** 5874,5880 **** void mch_clear_job(job_T *job) { ! /* call waitpid because child process may become zombie */ # ifdef __NeXT__ (void)wait4(job->jv_pid, NULL, WNOHANG, (struct rusage *)0); # else --- 5874,5880 ---- void mch_clear_job(job_T *job) { ! // call waitpid because child process may become zombie # ifdef __NeXT__ (void)wait4(job->jv_pid, NULL, WNOHANG, (struct rusage *)0); # else *************** *** 5903,5913 **** if (job->jv_tty_out != NULL) ch_log(channel, "using pty %s on fd %d", job->jv_tty_out, pty_master_fd); ! job->jv_channel = channel; /* ch_refcount was set by add_channel() */ channel->ch_keep_open = TRUE; ! /* Only set the pty_master_fd for stdout, do not duplicate it for stderr, ! * it only needs to be read once. */ channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD); channel_set_job(channel, job, options); return OK; --- 5903,5913 ---- if (job->jv_tty_out != NULL) ch_log(channel, "using pty %s on fd %d", job->jv_tty_out, pty_master_fd); ! job->jv_channel = channel; // ch_refcount was set by add_channel() channel->ch_keep_open = TRUE; ! // Only set the pty_master_fd for stdout, do not duplicate it for stderr, ! // it only needs to be read once. channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD); channel_set_job(channel, job, options); return OK; *************** *** 5969,5979 **** #endif int avail; ! if (!ignore_input && input_available()) /* something in inbuf[] */ return 1; #if defined(FEAT_MOUSE_DEC) ! /* May need to query the mouse position. */ if (WantQueryMouse) { WantQueryMouse = FALSE; --- 5969,5979 ---- #endif int avail; ! if (!ignore_input && input_available()) // something in inbuf[] return 1; #if defined(FEAT_MOUSE_DEC) ! // May need to query the mouse position. if (WantQueryMouse) { WantQueryMouse = FALSE; *************** *** 6066,6077 **** #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) static int busy = FALSE; ! /* May retry getting characters after an event was handled. */ # define MAY_LOOP # ifdef ELAPSED_FUNC ! /* Remember at what time we started, so that we know how much longer we ! * should wait after being interrupted. */ long start_msec = msec; elapsed_T start_tv; --- 6066,6077 ---- #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) static int busy = FALSE; ! // May retry getting characters after an event was handled. # define MAY_LOOP # ifdef ELAPSED_FUNC ! // Remember at what time we started, so that we know how much longer we ! // should wait after being interrupted. long start_msec = msec; elapsed_T start_tv; *************** *** 6079,6086 **** ELAPSED_INIT(start_tv); # endif ! /* Handle being called recursively. This may happen for the session ! * manager stuff, it may save the file, which does a breakcheck. */ if (busy) return 0; #endif --- 6079,6086 ---- ELAPSED_INIT(start_tv); # endif ! // Handle being called recursively. This may happen for the session ! // manager stuff, it may save the file, which does a breakcheck. if (busy) return 0; #endif *************** *** 6090,6102 **** #endif { #ifdef MAY_LOOP ! int finished = TRUE; /* default is to 'loop' just once */ # ifdef FEAT_MZSCHEME int mzquantum_used = FALSE; # endif #endif #ifndef HAVE_SELECT ! /* each channel may use in, out and err */ struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; int nfd; # ifdef FEAT_XCLIPBOARD --- 6090,6102 ---- #endif { #ifdef MAY_LOOP ! int finished = TRUE; // default is to 'loop' just once # ifdef FEAT_MZSCHEME int mzquantum_used = FALSE; # endif #endif #ifndef HAVE_SELECT ! // each channel may use in, out and err struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; int nfd; # ifdef FEAT_XCLIPBOARD *************** *** 6114,6120 **** mzvim_check_threads(); if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) { ! towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ mzquantum_used = TRUE; } # endif --- 6114,6120 ---- mzvim_check_threads(); if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) { ! towait = (int)p_mzq; // don't wait longer than 'mzquantum' mzquantum_used = TRUE; } # endif *************** *** 6164,6179 **** # ifdef FEAT_MZSCHEME if (ret == 0 && mzquantum_used) ! /* MzThreads scheduling is required and timeout occurred */ finished = FALSE; # endif # ifdef FEAT_XCLIPBOARD if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) { ! xterm_update(); /* Maybe we should hand out clipboard */ if (--ret == 0 && !input_available()) ! /* Try again */ finished = FALSE; } # endif --- 6164,6179 ---- # ifdef FEAT_MZSCHEME if (ret == 0 && mzquantum_used) ! // MzThreads scheduling is required and timeout occurred finished = FALSE; # endif # ifdef FEAT_XCLIPBOARD if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) { ! xterm_update(); // Maybe we should hand out clipboard if (--ret == 0 && !input_available()) ! // Try again finished = FALSE; } # endif *************** *** 6197,6203 **** xsmp_close(); } if (--ret == 0) ! finished = FALSE; /* Try again */ } # endif #ifdef FEAT_JOB_CHANNEL --- 6197,6203 ---- xsmp_close(); } if (--ret == 0) ! finished = FALSE; // Try again } # endif #ifdef FEAT_JOB_CHANNEL *************** *** 6206,6212 **** channel_poll_check(ret, &fds); #endif ! #else /* HAVE_SELECT */ struct timeval tv; struct timeval *tvp; --- 6206,6212 ---- channel_poll_check(ret, &fds); #endif ! #else // HAVE_SELECT struct timeval tv; struct timeval *tvp; *************** *** 6220,6226 **** mzvim_check_threads(); if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) { ! towait = p_mzq; /* don't wait longer than 'mzquantum' */ mzquantum_used = TRUE; } # endif --- 6220,6226 ---- mzvim_check_threads(); if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) { ! towait = p_mzq; // don't wait longer than 'mzquantum' mzquantum_used = TRUE; } # endif *************** *** 6243,6249 **** FD_ZERO(&efds); FD_SET(fd, &rfds); # if !defined(__QNX__) && !defined(__CYGWIN32__) ! /* For QNX select() always returns 1 if this is set. Why? */ FD_SET(fd, &efds); # endif maxfd = fd; --- 6243,6249 ---- FD_ZERO(&efds); FD_SET(fd, &rfds); # if !defined(__QNX__) && !defined(__CYGWIN32__) ! // For QNX select() always returns 1 if this is set. Why? FD_SET(fd, &efds); # endif maxfd = fd; *************** *** 6256,6263 **** if (maxfd < ConnectionNumber(xterm_dpy)) maxfd = ConnectionNumber(xterm_dpy); ! /* An event may have already been read but not handled. In ! * particularly, XFlush may cause this. */ xterm_update(); } # endif --- 6256,6263 ---- if (maxfd < ConnectionNumber(xterm_dpy)) maxfd = ConnectionNumber(xterm_dpy); ! // An event may have already been read but not handled. In ! // particularly, XFlush may cause this. xterm_update(); } # endif *************** *** 6296,6310 **** # ifdef EINTR if (ret == -1 && errno == EINTR) { ! /* Check whether window has been resized, EINTR may be caused by ! * SIGWINCH. */ if (do_resize) handle_resize(); ! /* Interrupted by a signal, need to try again. We ignore msec ! * here, because we do want to check even after a timeout if ! * characters are available. Needed for reading output of an ! * external command after the process has finished. */ goto select_eintr; } # endif --- 6296,6310 ---- # ifdef EINTR if (ret == -1 && errno == EINTR) { ! // Check whether window has been resized, EINTR may be caused by ! // SIGWINCH. if (do_resize) handle_resize(); ! // Interrupted by a signal, need to try again. We ignore msec ! // here, because we do want to check even after a timeout if ! // characters are available. Needed for reading output of an ! // external command after the process has finished. goto select_eintr; } # endif *************** *** 6318,6324 **** # endif # ifdef FEAT_MZSCHEME if (ret == 0 && mzquantum_used) ! /* loop if MzThreads must be scheduled and timeout occurred */ finished = FALSE; # endif --- 6318,6324 ---- # endif # ifdef FEAT_MZSCHEME if (ret == 0 && mzquantum_used) ! // loop if MzThreads must be scheduled and timeout occurred finished = FALSE; # endif *************** *** 6326,6337 **** if (ret > 0 && xterm_Shell != (Widget)0 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) { ! xterm_update(); /* Maybe we should hand out clipboard */ ! /* continue looping when we only got the X event and the input ! * buffer is empty */ if (--ret == 0 && !input_available()) { ! /* Try again */ finished = FALSE; } } --- 6326,6337 ---- if (ret > 0 && xterm_Shell != (Widget)0 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) { ! xterm_update(); // Maybe we should hand out clipboard ! // continue looping when we only got the X event and the input ! // buffer is empty if (--ret == 0 && !input_available()) { ! // Try again finished = FALSE; } } *************** *** 6354,6360 **** verb_msg(_("XSMP lost ICE connection")); xsmp_close(); if (--ret == 0) ! finished = FALSE; /* keep going if event was only one */ } else if (FD_ISSET(xsmp_icefd, &rfds)) { --- 6354,6360 ---- verb_msg(_("XSMP lost ICE connection")); xsmp_close(); if (--ret == 0) ! finished = FALSE; // keep going if event was only one } else if (FD_ISSET(xsmp_icefd, &rfds)) { *************** *** 6362,6378 **** xsmp_handle_requests(); busy = FALSE; if (--ret == 0) ! finished = FALSE; /* keep going if event was only one */ } } # endif #ifdef FEAT_JOB_CHANNEL ! /* also call when ret == 0, we may be polling a keep-open channel */ if (ret >= 0) ret = channel_select_check(ret, &rfds, &wfds); #endif ! #endif /* HAVE_SELECT */ #ifdef MAY_LOOP if (finished || msec == 0) --- 6362,6378 ---- xsmp_handle_requests(); busy = FALSE; if (--ret == 0) ! finished = FALSE; // keep going if event was only one } } # endif #ifdef FEAT_JOB_CHANNEL ! // also call when ret == 0, we may be polling a keep-open channel if (ret >= 0) ret = channel_select_check(ret, &rfds, &wfds); #endif ! #endif // HAVE_SELECT #ifdef MAY_LOOP if (finished || msec == 0) *************** *** 6383,6400 **** break; # endif ! /* We're going to loop around again, find out for how long */ if (msec > 0) { # ifdef ELAPSED_FUNC ! /* Compute remaining wait time. */ msec = start_msec - ELAPSED_FUNC(start_tv); # else ! /* Guess we got interrupted halfway. */ msec = msec / 2; # endif if (msec <= 0) ! break; /* waited long enough */ } #endif } --- 6383,6400 ---- break; # endif ! // We're going to loop around again, find out for how long if (msec > 0) { # ifdef ELAPSED_FUNC ! // Compute remaining wait time. msec = start_msec - ELAPSED_FUNC(start_tv); # else ! // Guess we got interrupted halfway. msec = msec / 2; # endif if (msec <= 0) ! break; // waited long enough } #endif } *************** *** 6412,6418 **** mch_expandpath( garray_T *gap, char_u *path, ! int flags) /* EW_* flags */ { return unix_expandpath(gap, path, 0, flags, FALSE); } --- 6412,6418 ---- mch_expandpath( garray_T *gap, char_u *path, ! int flags) // EW_* flags { return unix_expandpath(gap, path, 0, flags, FALSE); } *************** *** 6445,6451 **** char_u **pat, int *num_file, char_u ***file, ! int flags) /* EW_* flags */ { int i; size_t len; --- 6445,6451 ---- char_u **pat, int *num_file, char_u ***file, ! int flags) // EW_* flags { int i; size_t len; *************** *** 6461,6480 **** char_u *command; FILE *fd; char_u *buffer; ! #define STYLE_ECHO 0 /* use "echo", the default */ ! #define STYLE_GLOB 1 /* use "glob", for csh */ ! #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ ! #define STYLE_PRINT 3 /* use "print -N", for zsh */ ! #define STYLE_BT 4 /* `cmd` expansion, execute the pattern ! * directly */ int shell_style = STYLE_ECHO; int check_spaces; static int did_find_nul = FALSE; int ampersand = FALSE; ! /* vimglob() function to define for Posix shell */ static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; ! *num_file = 0; /* default: no files found */ *file = NULL; /* --- 6461,6480 ---- char_u *command; FILE *fd; char_u *buffer; ! #define STYLE_ECHO 0 // use "echo", the default ! #define STYLE_GLOB 1 // use "glob", for csh ! #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh ! #define STYLE_PRINT 3 // use "print -N", for zsh ! #define STYLE_BT 4 // `cmd` expansion, execute the pattern ! // directly int shell_style = STYLE_ECHO; int check_spaces; static int did_find_nul = FALSE; int ampersand = FALSE; ! // vimglob() function to define for Posix shell static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; ! *num_file = 0; // default: no files found *file = NULL; /* *************** *** 6485,6491 **** return save_patterns(num_pat, pat, num_file, file); # ifdef HAVE_SANDBOX ! /* Don't allow any shell command in the sandbox. */ if (sandbox != 0 && check_secure()) return FAIL; # endif --- 6485,6491 ---- return save_patterns(num_pat, pat, num_file, file); # ifdef HAVE_SANDBOX ! // Don't allow any shell command in the sandbox. if (sandbox != 0 && check_secure()) return FAIL; # endif *************** *** 6537,6561 **** "sh") != NULL) shell_style = STYLE_VIMGLOB; ! /* Compute the length of the command. We need 2 extra bytes: for the ! * optional '&' and for the NUL. ! * Worst case: "unset nonomatch; print -N >" plus two is 29 */ len = STRLEN(tempname) + 29; if (shell_style == STYLE_VIMGLOB) len += STRLEN(sh_vimglob_func); for (i = 0; i < num_pat; ++i) { ! /* Count the length of the patterns in the same way as they are put in ! * "command" below. */ #ifdef USE_SYSTEM ! len += STRLEN(pat[i]) + 3; /* add space and two quotes */ #else ! ++len; /* add space */ for (j = 0; pat[i][j] != NUL; ++j) { if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) ! ++len; /* may add a backslash */ ++len; } #endif --- 6537,6561 ---- "sh") != NULL) shell_style = STYLE_VIMGLOB; ! // Compute the length of the command. We need 2 extra bytes: for the ! // optional '&' and for the NUL. ! // Worst case: "unset nonomatch; print -N >" plus two is 29 len = STRLEN(tempname) + 29; if (shell_style == STYLE_VIMGLOB) len += STRLEN(sh_vimglob_func); for (i = 0; i < num_pat; ++i) { ! // Count the length of the patterns in the same way as they are put in ! // "command" below. #ifdef USE_SYSTEM ! len += STRLEN(pat[i]) + 3; // add space and two quotes #else ! ++len; // add space for (j = 0; pat[i][j] != NUL; ++j) { if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) ! ++len; // may add a backslash ++len; } #endif *************** *** 6563,6569 **** command = alloc(len); if (command == NULL) { ! /* out of memory */ vim_free(tempname); return FAIL; } --- 6563,6569 ---- command = alloc(len); if (command == NULL) { ! // out of memory vim_free(tempname); return FAIL; } *************** *** 6578,6591 **** */ if (shell_style == STYLE_BT) { ! /* change `command; command& ` to (command; command ) */ STRCPY(command, "("); ! STRCAT(command, pat[0] + 1); /* exclude first backtick */ p = command + STRLEN(command) - 1; ! *p-- = ')'; /* remove last backtick */ while (p > command && VIM_ISWHITE(*p)) --p; ! if (*p == '&') /* remove trailing '&' */ { ampersand = TRUE; *p = ' '; --- 6578,6591 ---- */ if (shell_style == STYLE_BT) { ! // change `command; command& ` to (command; command ) STRCPY(command, "("); ! STRCAT(command, pat[0] + 1); // exclude first backtick p = command + STRLEN(command) - 1; ! *p-- = ')'; // remove last backtick while (p > command && VIM_ISWHITE(*p)) --p; ! if (*p == '&') // remove trailing '&' { ampersand = TRUE; *p = ' '; *************** *** 6613,6621 **** if (shell_style != STYLE_BT) for (i = 0; i < num_pat; ++i) { ! /* When using system() always add extra quotes, because the shell ! * is started twice. Otherwise put a backslash before special ! * characters, except inside ``. */ #ifdef USE_SYSTEM STRCAT(command, " \""); STRCAT(command, pat[i]); --- 6613,6621 ---- if (shell_style != STYLE_BT) for (i = 0; i < num_pat; ++i) { ! // When using system() always add extra quotes, because the shell ! // is started twice. Otherwise put a backslash before special ! // characters, except inside ``. #ifdef USE_SYSTEM STRCAT(command, " \""); STRCAT(command, pat[i]); *************** *** 6631,6639 **** intick = !intick; else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) { ! /* Remove a backslash, take char literally. But keep ! * backslash inside backticks, before a special character ! * and before a backtick. */ if (intick || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL || pat[i][j + 1] == '`') --- 6631,6639 ---- intick = !intick; else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) { ! // Remove a backslash, take char literally. But keep ! // backslash inside backticks, before a special character ! // and before a backtick. if (intick || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL || pat[i][j + 1] == '`') *************** *** 6643,6654 **** else if (!intick && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) ! /* Put a backslash before a special character, but not ! * when inside ``. And not for $var when EW_KEEPDOLLAR is ! * set. */ *p++ = '\\'; ! /* Copy one character. */ *p++ = pat[i][j]; } *p = NUL; --- 6643,6654 ---- else if (!intick && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) ! // Put a backslash before a special character, but not ! // when inside ``. And not for $var when EW_KEEPDOLLAR is ! // set. *p++ = '\\'; ! // Copy one character. *p++ = pat[i][j]; } *p = NUL; *************** *** 6657,6663 **** if (flags & EW_SILENT) show_shell_mess = FALSE; if (ampersand) ! STRCAT(command, "&"); /* put the '&' after the redirection */ /* * Using zsh -G: If a pattern has no matches, it is just deleted from --- 6657,6663 ---- if (flags & EW_SILENT) show_shell_mess = FALSE; if (ampersand) ! STRCAT(command, "&"); // put the '&' after the redirection /* * Using zsh -G: If a pattern has no matches, it is just deleted from *************** *** 6665,6671 **** * expand any other pattern. */ if (shell_style == STYLE_PRINT) ! extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ /* * If we use -f then shell variables set in .cshrc won't get expanded. --- 6665,6671 ---- * expand any other pattern. */ if (shell_style == STYLE_PRINT) ! extra_shell_arg = (char_u *)"-G"; // Use zsh NULL_GLOB option /* * If we use -f then shell variables set in .cshrc won't get expanded. *************** *** 6673,6695 **** * in one of the patterns, otherwise we can still use the fast option. */ else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) ! extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ /* * execute the shell command */ i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); ! /* When running in the background, give it some time to create the temp ! * file, but don't wait for it to finish. */ if (ampersand) mch_delay(10L, TRUE); ! extra_shell_arg = NULL; /* cleanup */ show_shell_mess = TRUE; vim_free(command); ! if (i != 0) /* mch_call_shell() failed */ { mch_remove(tempname); vim_free(tempname); --- 6673,6695 ---- * in one of the patterns, otherwise we can still use the fast option. */ else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) ! extra_shell_arg = (char_u *)"-f"; // Use csh fast option /* * execute the shell command */ i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); ! // When running in the background, give it some time to create the temp ! // file, but don't wait for it to finish. if (ampersand) mch_delay(10L, TRUE); ! extra_shell_arg = NULL; // cleanup show_shell_mess = TRUE; vim_free(command); ! if (i != 0) // mch_call_shell() failed { mch_remove(tempname); vim_free(tempname); *************** *** 6702,6720 **** if (!(flags & EW_SILENT)) #endif { ! redraw_later_clear(); /* probably messed up screen */ ! msg_putchar('\n'); /* clear bottom line quickly */ ! cmdline_row = Rows - 1; /* continue on last line */ #ifdef USE_SYSTEM if (!(flags & EW_SILENT)) #endif { msg(_(e_wildexpand)); ! msg_start(); /* don't overwrite this message */ } } ! /* If a `cmd` expansion failed, don't list `cmd` as a match, even when ! * EW_NOTFOUND is given */ if (shell_style == STYLE_BT) return FAIL; goto notfound; --- 6702,6720 ---- if (!(flags & EW_SILENT)) #endif { ! redraw_later_clear(); // probably messed up screen ! msg_putchar('\n'); // clear bottom line quickly ! cmdline_row = Rows - 1; // continue on last line #ifdef USE_SYSTEM if (!(flags & EW_SILENT)) #endif { msg(_(e_wildexpand)); ! msg_start(); // don't overwrite this message } } ! // If a `cmd` expansion failed, don't list `cmd` as a match, even when ! // EW_NOTFOUND is given if (shell_style == STYLE_BT) return FAIL; goto notfound; *************** *** 6726,6751 **** fd = fopen((char *)tempname, READBIN); if (fd == NULL) { ! /* Something went wrong, perhaps a file name with a special char. */ if (!(flags & EW_SILENT)) { msg(_(e_wildexpand)); ! msg_start(); /* don't overwrite this message */ } vim_free(tempname); goto notfound; } fseek(fd, 0L, SEEK_END); ! llen = ftell(fd); /* get size of temp file */ fseek(fd, 0L, SEEK_SET); if (llen < 0) ! /* just in case ftell() would fail */ buffer = NULL; else buffer = alloc(llen + 1); if (buffer == NULL) { ! /* out of memory */ mch_remove(tempname); vim_free(tempname); fclose(fd); --- 6726,6751 ---- fd = fopen((char *)tempname, READBIN); if (fd == NULL) { ! // Something went wrong, perhaps a file name with a special char. if (!(flags & EW_SILENT)) { msg(_(e_wildexpand)); ! msg_start(); // don't overwrite this message } vim_free(tempname); goto notfound; } fseek(fd, 0L, SEEK_END); ! llen = ftell(fd); // get size of temp file fseek(fd, 0L, SEEK_SET); if (llen < 0) ! // just in case ftell() would fail buffer = NULL; else buffer = alloc(llen + 1); if (buffer == NULL) { ! // out of memory mch_remove(tempname); vim_free(tempname); fclose(fd); *************** *** 6757,6763 **** mch_remove(tempname); if (i != (int)len) { ! /* unexpected read error */ semsg(_(e_notread), tempname); vim_free(tempname); vim_free(buffer); --- 6757,6763 ---- mch_remove(tempname); if (i != (int)len) { ! // unexpected read error semsg(_(e_notread), tempname); vim_free(tempname); vim_free(buffer); *************** *** 6766,6772 **** vim_free(tempname); # ifdef __CYGWIN__ ! /* Translate into . Caution, buffer may contain NUL. */ p = buffer; for (i = 0; i < (int)len; ++i) if (!(buffer[i] == CAR && buffer[i + 1] == NL)) --- 6766,6772 ---- vim_free(tempname); # ifdef __CYGWIN__ ! // Translate into . Caution, buffer may contain NUL. p = buffer; for (i = 0; i < (int)len; ++i) if (!(buffer[i] == CAR && buffer[i + 1] == NL)) *************** *** 6775,6807 **** # endif ! /* file names are separated with Space */ if (shell_style == STYLE_ECHO) { ! buffer[len] = '\n'; /* make sure the buffer ends in NL */ p = buffer; ! for (i = 0; *p != '\n'; ++i) /* count number of entries */ { while (*p != ' ' && *p != '\n') ++p; ! p = skipwhite(p); /* skip to next entry */ } } ! /* file names are separated with NL */ else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { ! buffer[len] = NUL; /* make sure the buffer ends in NUL */ p = buffer; ! for (i = 0; *p != NUL; ++i) /* count number of entries */ { while (*p != '\n' && *p != NUL) ++p; if (*p != NUL) ++p; ! p = skipwhite(p); /* skip leading white space */ } } ! /* file names are separated with NUL */ else { /* --- 6775,6807 ---- # endif ! // file names are separated with Space if (shell_style == STYLE_ECHO) { ! buffer[len] = '\n'; // make sure the buffer ends in NL p = buffer; ! for (i = 0; *p != '\n'; ++i) // count number of entries { while (*p != ' ' && *p != '\n') ++p; ! p = skipwhite(p); // skip to next entry } } ! // file names are separated with NL else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { ! buffer[len] = NUL; // make sure the buffer ends in NUL p = buffer; ! for (i = 0; *p != NUL; ++i) // count number of entries { while (*p != '\n' && *p != NUL) ++p; if (*p != NUL) ++p; ! p = skipwhite(p); // skip leading white space } } ! // file names are separated with NUL else { /* *************** *** 6815,6821 **** check_spaces = FALSE; if (shell_style == STYLE_PRINT && !did_find_nul) { ! /* If there is a NUL, set did_find_nul, else set check_spaces */ buffer[len] = NUL; if (len && (int)STRLEN(buffer) < (int)len) did_find_nul = TRUE; --- 6815,6821 ---- check_spaces = FALSE; if (shell_style == STYLE_PRINT && !did_find_nul) { ! // If there is a NUL, set did_find_nul, else set check_spaces buffer[len] = NUL; if (len && (int)STRLEN(buffer) < (int)len) did_find_nul = TRUE; *************** *** 6833,6845 **** buffer[len] = NUL; i = 0; for (p = buffer; p < buffer + len; ++p) ! if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ { ++i; *p = NUL; } if (len) ! ++i; /* count last entry */ } if (i == 0) { --- 6833,6845 ---- buffer[len] = NUL; i = 0; for (p = buffer; p < buffer + len; ++p) ! if (*p == NUL || (*p == ' ' && check_spaces)) // count entry { ++i; *p = NUL; } if (len) ! ++i; // count last entry } if (i == 0) { *************** *** 6855,6861 **** *file = ALLOC_MULT(char_u *, i); if (*file == NULL) { ! /* out of memory */ vim_free(buffer); return FAIL; } --- 6855,6861 ---- *file = ALLOC_MULT(char_u *, i); if (*file == NULL) { ! // out of memory vim_free(buffer); return FAIL; } *************** *** 6867,6892 **** for (i = 0; i < *num_file; ++i) { (*file)[i] = p; ! /* Space or NL separates */ if (shell_style == STYLE_ECHO || shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { while (!(shell_style == STYLE_ECHO && *p == ' ') && *p != '\n' && *p != NUL) ++p; ! if (p == buffer + len) /* last entry */ *p = NUL; else { *p++ = NUL; ! p = skipwhite(p); /* skip to next entry */ } } ! else /* NUL separates */ { ! while (*p && p < buffer + len) /* skip entry */ ++p; ! ++p; /* skip NUL */ } } --- 6867,6892 ---- for (i = 0; i < *num_file; ++i) { (*file)[i] = p; ! // Space or NL separates if (shell_style == STYLE_ECHO || shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { while (!(shell_style == STYLE_ECHO && *p == ' ') && *p != '\n' && *p != NUL) ++p; ! if (p == buffer + len) // last entry *p = NUL; else { *p++ = NUL; ! p = skipwhite(p); // skip to next entry } } ! else // NUL separates { ! while (*p && p < buffer + len) // skip entry ++p; ! ++p; // skip NUL } } *************** *** 6895,6910 **** */ for (j = 0, i = 0; i < *num_file; ++i) { ! /* Require the files to exist. Helps when using /bin/sh */ if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) continue; ! /* check if this entry should be included */ dir = (mch_isdir((*file)[i])); if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) continue; ! /* Skip files that are not executable if we check for that. */ if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) continue; --- 6895,6910 ---- */ for (j = 0, i = 0; i < *num_file; ++i) { ! // Require the files to exist. Helps when using /bin/sh if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) continue; ! // check if this entry should be included dir = (mch_isdir((*file)[i])); if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) continue; ! // Skip files that are not executable if we check for that. if (!dir && (flags & EW_EXEC) && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) continue; *************** *** 6914,6927 **** { STRCPY(p, (*file)[i]); if (dir) ! add_pathsep(p); /* add '/' to a directory name */ (*file)[j++] = p; } } vim_free(buffer); *num_file = j; ! if (*num_file == 0) /* rejected all entries */ { VIM_CLEAR(*file); goto notfound; --- 6914,6927 ---- { STRCPY(p, (*file)[i]); if (dir) ! add_pathsep(p); // add '/' to a directory name (*file)[j++] = p; } } vim_free(buffer); *num_file = j; ! if (*num_file == 0) // rejected all entries { VIM_CLEAR(*file); goto notfound; *************** *** 6935,6941 **** return FAIL; } ! #endif /* VMS */ static int save_patterns( --- 6935,6941 ---- return FAIL; } ! #endif // VMS static int save_patterns( *************** *** 6954,6961 **** { s = vim_strsave(pat[i]); if (s != NULL) ! /* Be compatible with expand_filename(): halve the number of ! * backslashes. */ backslash_halve(s); (*file)[i] = s; } --- 6954,6961 ---- { s = vim_strsave(pat[i]); if (s != NULL) ! // Be compatible with expand_filename(): halve the number of ! // backslashes. backslash_halve(s); (*file)[i] = s; } *************** *** 7045,7059 **** { struct stat st; ! if (stat(dest, &st) >= 0) /* fail if destination exists */ return -1; ! if (link(src, dest) != 0) /* link file to new name */ return -1; ! if (mch_remove(src) == 0) /* delete link to old name */ return 0; return -1; } ! #endif /* !HAVE_RENAME */ #if defined(FEAT_MOUSE_GPM) || defined(PROTO) /* --- 7045,7059 ---- { struct stat st; ! if (stat(dest, &st) >= 0) // fail if destination exists return -1; ! if (link(src, dest) != 0) // link file to new name return -1; ! if (mch_remove(src) == 0) // delete link to old name return 0; return -1; } ! #endif // !HAVE_RENAME #if defined(FEAT_MOUSE_GPM) || defined(PROTO) /* *************** *** 7063,7094 **** static int gpm_open(void) { ! static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ if (!gpm_flag) { gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); gpm_connect.defaultMask = ~GPM_HARD; ! /* Default handling for mouse move*/ ! gpm_connect.minMod = 0; /* Handle any modifier keys */ gpm_connect.maxMod = 0xffff; if (Gpm_Open(&gpm_connect, 0) > 0) { ! /* gpm library tries to handling TSTP causes ! * problems. Anyways, we close connection to Gpm whenever ! * we are going to suspend or starting an external process ! * so we shouldn't have problem with this ! */ # ifdef SIGTSTP signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); # endif ! return 1; /* succeed */ } if (gpm_fd == -2) ! Gpm_Close(); /* We don't want to talk to xterm via gpm */ return 0; } ! return 1; /* already open */ } /* --- 7063,7093 ---- static int gpm_open(void) { ! static Gpm_Connect gpm_connect; // Must it be kept till closing ? if (!gpm_flag) { gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); gpm_connect.defaultMask = ~GPM_HARD; ! // Default handling for mouse move ! gpm_connect.minMod = 0; // Handle any modifier keys gpm_connect.maxMod = 0xffff; if (Gpm_Open(&gpm_connect, 0) > 0) { ! // gpm library tries to handling TSTP causes ! // problems. Anyways, we close connection to Gpm whenever ! // we are going to suspend or starting an external process ! // so we shouldn't have problem with this # ifdef SIGTSTP signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); # endif ! return 1; // succeed } if (gpm_fd == -2) ! Gpm_Close(); // We don't want to talk to xterm via gpm return 0; } ! return 1; // already open } /* *************** *** 7130,7136 **** Gpm_GetEvent(&gpm_event); #ifdef FEAT_GUI ! /* Don't put events in the input queue now. */ if (hold_gui_events) return 0; #endif --- 7129,7135 ---- Gpm_GetEvent(&gpm_event); #ifdef FEAT_GUI ! // Don't put events in the input queue now. if (hold_gui_events) return 0; #endif *************** *** 7138,7144 **** row = gpm_event.y - 1; col = gpm_event.x - 1; ! string[0] = ESC; /* Our termcode */ string[1] = 'M'; string[2] = 'G'; switch (GPM_BARE_EVENTS(gpm_event.type)) --- 7137,7143 ---- row = gpm_event.y - 1; col = gpm_event.x - 1; ! string[0] = ESC; // Our termcode string[1] = 'M'; string[2] = 'G'; switch (GPM_BARE_EVENTS(gpm_event.type)) *************** *** 7162,7169 **** break; default: return 0; ! /*Don't know what to do. Can more than one button be ! * reported in one event? */ } string[3] = (char_u)(button | 0x20); SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); --- 7161,7168 ---- break; default: return 0; ! // Don't know what to do. Can more than one button be ! // reported in one event? } string[3] = (char_u)(button | 0x20); SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); *************** *** 7175,7187 **** default: return 0; } ! /*This code is based on gui_x11_mouse_cb in gui_x11.c */ gpm_modifiers = gpm_event.modifiers; vim_modifiers = 0x0; ! /* I ignore capslock stats. Aren't we all just hate capslock mixing with ! * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and ! * K_CAPSSHIFT is defined 8, so it probably isn't even reported ! */ if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) vim_modifiers |= MOUSE_SHIFT; --- 7174,7185 ---- default: return 0; } ! // This code is based on gui_x11_mouse_cb in gui_x11.c gpm_modifiers = gpm_event.modifiers; vim_modifiers = 0x0; ! // I ignore capslock stats. Aren't we all just hate capslock mixing with ! // Vim commands ? Besides, gpm_event.modifiers is unsigned char, and ! // K_CAPSSHIFT is defined 8, so it probably isn't even reported if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) vim_modifiers |= MOUSE_SHIFT; *************** *** 7195,7201 **** add_to_input_buf(string, 6); return 6; } ! #endif /* FEAT_MOUSE_GPM */ #ifdef FEAT_SYSMOUSE /* --- 7193,7199 ---- add_to_input_buf(string, 6); return 6; } ! #endif // FEAT_MOUSE_GPM #ifdef FEAT_SYSMOUSE /* *************** *** 7253,7259 **** static int oldbuttons = 0; #ifdef FEAT_GUI ! /* Don't put events in the input queue now. */ if (hold_gui_events) return; #endif --- 7251,7257 ---- static int oldbuttons = 0; #ifdef FEAT_GUI ! // Don't put events in the input queue now. if (hold_gui_events) return; #endif *************** *** 7267,7273 **** row = mouse.u.data.y / video.vi_cheight; col = mouse.u.data.x / video.vi_cwidth; buttons = mouse.u.data.buttons; ! string[0] = ESC; /* Our termcode */ string[1] = 'M'; string[2] = 'S'; if (oldbuttons == buttons && buttons != 0) --- 7265,7271 ---- row = mouse.u.data.y / video.vi_cheight; col = mouse.u.data.x / video.vi_cwidth; buttons = mouse.u.data.buttons; ! string[0] = ESC; // Our termcode string[1] = 'M'; string[2] = 'S'; if (oldbuttons == buttons && buttons != 0) *************** *** 7302,7308 **** } return; } ! #endif /* FEAT_SYSMOUSE */ #if defined(FEAT_LIBCALL) || defined(PROTO) typedef char_u * (*STRPROCSTR)(char_u *); --- 7300,7306 ---- } return; } ! #endif // FEAT_SYSMOUSE #if defined(FEAT_LIBCALL) || defined(PROTO) typedef char_u * (*STRPROCSTR)(char_u *); *************** *** 7318,7326 **** mch_libcall( char_u *libname, char_u *funcname, ! char_u *argstring, /* NULL when using a argint */ int argint, ! char_u **string_result,/* NULL when using number_result */ int *number_result) { # if defined(USE_DLOPEN) --- 7316,7324 ---- mch_libcall( char_u *libname, char_u *funcname, ! char_u *argstring, // NULL when using a argint int argint, ! char_u **string_result, // NULL when using number_result int *number_result) { # if defined(USE_DLOPEN) *************** *** 7339,7345 **** * Get a handle to the DLL module. */ # if defined(USE_DLOPEN) ! /* First clear any error, it's not cleared by the dlopen() call. */ (void)dlerror(); hinstLib = dlopen((char *)libname, RTLD_LAZY --- 7337,7343 ---- * Get a handle to the DLL module. */ # if defined(USE_DLOPEN) ! // First clear any error, it's not cleared by the dlopen() call. (void)dlerror(); hinstLib = dlopen((char *)libname, RTLD_LAZY *************** *** 7349,7355 **** ); if (hinstLib == NULL) { ! /* "dlerr" must be used before dlclose() */ dlerr = (char *)dlerror(); if (dlerr != NULL) semsg(_("dlerror = \"%s\""), dlerr); --- 7347,7353 ---- ); if (hinstLib == NULL) { ! // "dlerr" must be used before dlclose() dlerr = (char *)dlerror(); if (dlerr != NULL) semsg(_("dlerror = \"%s\""), dlerr); *************** *** 7358,7364 **** hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); # endif ! /* If the handle is valid, try to get the function address. */ if (hinstLib != NULL) { # ifdef USING_SETJMP --- 7356,7362 ---- hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); # endif ! // If the handle is valid, try to get the function address. if (hinstLib != NULL) { # ifdef USING_SETJMP *************** *** 7426,7433 **** } } ! /* Save the string before we free the library. */ ! /* Assume that a "1" or "-1" result is an illegal pointer. */ if (string_result == NULL) *number_result = retval_int; else if (retval_str != NULL --- 7424,7431 ---- } } ! // Save the string before we free the library. ! // Assume that a "1" or "-1" result is an illegal pointer. if (string_result == NULL) *number_result = retval_int; else if (retval_str != NULL *************** *** 7443,7449 **** { int i; ! /* try to find the name of this signal */ for (i = 0; signal_info[i].sig != -1; i++) if (lc_signal == signal_info[i].sig) break; --- 7441,7447 ---- { int i; ! // try to find the name of this signal for (i = 0; signal_info[i].sig != -1; i++) if (lc_signal == signal_info[i].sig) break; *************** *** 7453,7463 **** # endif # if defined(USE_DLOPEN) ! /* "dlerr" must be used before dlclose() */ if (dlerr != NULL) semsg(_("dlerror = \"%s\""), dlerr); ! /* Free the DLL module. */ (void)dlclose(hinstLib); # else (void)shl_unload(hinstLib); --- 7451,7461 ---- # endif # if defined(USE_DLOPEN) ! // "dlerr" must be used before dlclose() if (dlerr != NULL) semsg(_("dlerror = \"%s\""), dlerr); ! // Free the DLL module. (void)dlclose(hinstLib); # else (void)shl_unload(hinstLib); *************** *** 7475,7481 **** #endif #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) ! static int xterm_trace = -1; /* default: disabled */ static int xterm_button; /* --- 7473,7479 ---- #endif #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) ! static int xterm_trace = -1; // default: disabled static int xterm_button; /* *************** *** 7505,7515 **** ELAPSED_INIT(start_tv); # endif ! /* Ignore X errors while opening the display */ oldhandler = XSetErrorHandler(x_error_check); # if defined(USING_SETJMP) ! /* Ignore X IO errors while opening the display */ oldIOhandler = XSetIOErrorHandler(x_IOerror_check); mch_startjmp(); if (SETJMP(lc_jump_env) != 0) --- 7503,7513 ---- ELAPSED_INIT(start_tv); # endif ! // Ignore X errors while opening the display oldhandler = XSetErrorHandler(x_error_check); # if defined(USING_SETJMP) ! // Ignore X IO errors while opening the display oldIOhandler = XSetIOErrorHandler(x_IOerror_check); mch_startjmp(); if (SETJMP(lc_jump_env) != 0) *************** *** 7530,7539 **** } # if defined(USING_SETJMP) ! /* Now handle X IO errors normally. */ (void)XSetIOErrorHandler(oldIOhandler); # endif ! /* Now handle X errors normally. */ (void)XSetErrorHandler(oldhandler); if (xterm_dpy == NULL) --- 7528,7537 ---- } # if defined(USING_SETJMP) ! // Now handle X IO errors normally. (void)XSetIOErrorHandler(oldIOhandler); # endif ! // Now handle X errors normally. (void)XSetErrorHandler(oldhandler); if (xterm_dpy == NULL) *************** *** 7543,7549 **** return; } ! /* Catch terminating error of the X server connection. */ (void)XSetIOErrorHandler(x_IOerror_handler); # ifdef ELAPSED_FUNC --- 7541,7547 ---- return; } ! // Catch terminating error of the X server connection. (void)XSetIOErrorHandler(x_IOerror_handler); # ifdef ELAPSED_FUNC *************** *** 7555,7561 **** } # endif ! /* Create a Shell to make converters work. */ AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", applicationShellWidgetClass, xterm_dpy, NULL); --- 7553,7559 ---- } # endif ! // Create a Shell to make converters work. AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", applicationShellWidgetClass, xterm_dpy, NULL); *************** *** 7584,7590 **** clip_init(TRUE); if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) x11_window = (Window)atol(strp); ! /* Check if $WINDOWID is valid. */ if (test_x11_window(xterm_dpy) == FAIL) x11_window = 0; if (x11_window != 0) --- 7582,7588 ---- clip_init(TRUE); if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) x11_window = (Window)atol(strp); ! // Check if $WINDOWID is valid. if (test_x11_window(xterm_dpy) == FAIL) x11_window = 0; if (x11_window != 0) *************** *** 7636,7660 **** if (xterm_trace == 1) { ! /* Get the hints just before tracking starts. The font size might ! * have changed recently. */ if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) || !(got_hints & PResizeInc) || xterm_hints.width_inc <= 1 || xterm_hints.height_inc <= 1) { ! xterm_trace = -1; /* Not enough data -- disable tracing */ return FALSE; } ! /* Rely on the same mouse code for the duration of this */ mouse_code = find_termcode(mouse_name); prev_row = mouse_row; prev_col = mouse_col; xterm_trace = 2; ! /* Find the offset of the chars, there might be a scrollbar on the ! * left of the window and/or a menu on the top (eterm etc.) */ XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask_return); xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) --- 7634,7658 ---- if (xterm_trace == 1) { ! // Get the hints just before tracking starts. The font size might ! // have changed recently. if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) || !(got_hints & PResizeInc) || xterm_hints.width_inc <= 1 || xterm_hints.height_inc <= 1) { ! xterm_trace = -1; // Not enough data -- disable tracing return FALSE; } ! // Rely on the same mouse code for the duration of this mouse_code = find_termcode(mouse_name); prev_row = mouse_row; prev_col = mouse_col; xterm_trace = 2; ! // Find the offset of the chars, there might be a scrollbar on the ! // left of the window and/or a menu on the top (eterm etc.) XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask_return); xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) *************** *** 7709,7715 **** if (xterm_dpy != NULL) { # if 0 ! /* Lesstif and Solaris crash here, lose some memory */ XtCloseDisplay(xterm_dpy); # endif if (x11_display == xterm_dpy) --- 7707,7713 ---- if (xterm_dpy != NULL) { # if 0 ! // Lesstif and Solaris crash here, lose some memory XtCloseDisplay(xterm_dpy); # endif if (x11_display == xterm_dpy) *************** *** 7719,7725 **** # if 0 if (app_context != (XtAppContext)NULL) { ! /* Lesstif and Solaris crash here, lose some memory */ XtDestroyApplicationContext(app_context); app_context = (XtAppContext)NULL; } --- 7717,7723 ---- # if 0 if (app_context != (XtAppContext)NULL) { ! // Lesstif and Solaris crash here, lose some memory XtDestroyApplicationContext(app_context); app_context = (XtAppContext)NULL; } *************** *** 7762,7768 **** if (mask & XtIMXEvent) { ! /* There is an event to process. */ XtAppNextEvent(app_context, &event); #ifdef FEAT_CLIENTSERVER { --- 7760,7766 ---- if (mask & XtIMXEvent) { ! // There is an event to process. XtAppNextEvent(app_context, &event); #ifdef FEAT_CLIENTSERVER { *************** *** 7777,7783 **** } else { ! /* There is something else than an event to process. */ XtAppProcessEvent(app_context, mask); } } --- 7775,7781 ---- } else { ! // There is something else than an event to process. XtAppProcessEvent(app_context, mask); } } *************** *** 7832,7851 **** save_cmdmod = cmdmod; cmdmod.confirm = TRUE; if (check_changed_any(FALSE, FALSE)) ! /* Mustn't logout */ cancel_shutdown = True; cmdmod = save_cmdmod; ! setcursor(); /* position cursor */ out_flush(); ! /* Done interaction */ SmcInteractDone(smc_conn, cancel_shutdown); ! /* Finish off ! * Only end save-yourself here if we're not cancelling shutdown; ! * we'll get a cancelled callback later in which we'll end it. ! * Hopefully get around glitchy SMs (like GNOME-1) ! */ if (!cancel_shutdown) { xsmp.save_yourself = False; --- 7830,7848 ---- save_cmdmod = cmdmod; cmdmod.confirm = TRUE; if (check_changed_any(FALSE, FALSE)) ! // Mustn't logout cancel_shutdown = True; cmdmod = save_cmdmod; ! setcursor(); // position cursor out_flush(); ! // Done interaction SmcInteractDone(smc_conn, cancel_shutdown); ! // Finish off ! // Only end save-yourself here if we're not cancelling shutdown; ! // we'll get a cancelled callback later in which we'll end it. ! // Hopefully get around glitchy SMs (like GNOME-1) if (!cancel_shutdown) { xsmp.save_yourself = False; *************** *** 7866,7894 **** int interact_style UNUSED, Bool fast UNUSED) { ! /* Handle already being in saveyourself */ if (xsmp.save_yourself) SmcSaveYourselfDone(smc_conn, True); xsmp.save_yourself = True; xsmp.shutdown = shutdown; ! /* First up, preserve all files */ out_flush(); ! ml_sync_all(FALSE, FALSE); /* preserve all swap files */ if (p_verbose > 0) verb_msg(_("XSMP handling save-yourself request")); # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) ! /* Now see if we can ask about unsaved files */ if (shutdown && !fast && gui.in_use) ! /* Need to interact with user, but need SM's permission */ SmcInteractRequest(smc_conn, SmDialogError, xsmp_handle_interaction, client_data); else # endif { ! /* Can stop the cycle here */ SmcSaveYourselfDone(smc_conn, True); xsmp.save_yourself = False; } --- 7863,7891 ---- int interact_style UNUSED, Bool fast UNUSED) { ! // Handle already being in saveyourself if (xsmp.save_yourself) SmcSaveYourselfDone(smc_conn, True); xsmp.save_yourself = True; xsmp.shutdown = shutdown; ! // First up, preserve all files out_flush(); ! ml_sync_all(FALSE, FALSE); // preserve all swap files if (p_verbose > 0) verb_msg(_("XSMP handling save-yourself request")); # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) ! // Now see if we can ask about unsaved files if (shutdown && !fast && gui.in_use) ! // Need to interact with user, but need SM's permission SmcInteractRequest(smc_conn, SmDialogError, xsmp_handle_interaction, client_data); else # endif { ! // Can stop the cycle here SmcSaveYourselfDone(smc_conn, True); xsmp.save_yourself = False; } *************** *** 7903,7909 **** { xsmp_close(); ! /* quit quickly leaving swapfiles for modified buffers behind */ getout_preserve_modified(0); } --- 7900,7906 ---- { xsmp_close(); ! // quit quickly leaving swapfiles for modified buffers behind getout_preserve_modified(0); } *************** *** 7946,7952 **** Bool opening, IcePointer *watchData UNUSED) { ! /* Intercept creation of ICE connection fd */ if (opening) { xsmp_icefd = IceConnectionNumber(iceConn); --- 7943,7949 ---- Bool opening, IcePointer *watchData UNUSED) { ! // Intercept creation of ICE connection fd if (opening) { xsmp_icefd = IceConnectionNumber(iceConn); *************** *** 7955,7961 **** } ! /* Handle any ICE processing that's required; return FAIL if SM lost */ int xsmp_handle_requests(void) { --- 7952,7958 ---- } ! // Handle any ICE processing that's required; return FAIL if SM lost int xsmp_handle_requests(void) { *************** *** 7964,7970 **** if (IceProcessMessages(xsmp.iceconn, NULL, &rep) == IceProcessMessagesIOError) { ! /* Lost ICE */ if (p_verbose > 0) verb_msg(_("XSMP lost ICE connection")); xsmp_close(); --- 7961,7967 ---- if (IceProcessMessages(xsmp.iceconn, NULL, &rep) == IceProcessMessagesIOError) { ! // Lost ICE if (p_verbose > 0) verb_msg(_("XSMP lost ICE connection")); xsmp_close(); *************** *** 7976,7982 **** static int dummy; ! /* Set up X Session Management Protocol */ void xsmp_init(void) { --- 7973,7979 ---- static int dummy; ! // Set up X Session Management Protocol void xsmp_init(void) { *************** *** 7993,7999 **** xsmp.save_yourself = xsmp.shutdown = False; ! /* Set up SM callbacks - must have all, even if they're not used */ smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; smcallbacks.save_yourself.client_data = NULL; smcallbacks.die.callback = xsmp_die; --- 7990,7996 ---- xsmp.save_yourself = xsmp.shutdown = False; ! // Set up SM callbacks - must have all, even if they're not used smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; smcallbacks.save_yourself.client_data = NULL; smcallbacks.die.callback = xsmp_die; *************** *** 8003,8010 **** smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; smcallbacks.shutdown_cancelled.client_data = NULL; ! /* Set up a watch on ICE connection creations. The "dummy" argument is ! * apparently required for FreeBSD (we get a BUS error when using NULL). */ if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) { if (p_verbose > 0) --- 8000,8007 ---- smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; smcallbacks.shutdown_cancelled.client_data = NULL; ! // Set up a watch on ICE connection creations. The "dummy" argument is ! // apparently required for FreeBSD (we get a BUS error when using NULL). if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) { if (p_verbose > 0) *************** *** 8012,8018 **** return; } ! /* Create an SM connection */ xsmp.smcconn = SmcOpenConnection( NULL, NULL, --- 8009,8015 ---- return; } ! // Create an SM connection xsmp.smcconn = SmcOpenConnection( NULL, NULL, *************** *** 8040,8046 **** xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); #if 0 ! /* ID ourselves */ smname.value = "vim"; smname.length = 3; smnameprop.name = "SmProgram"; --- 8037,8043 ---- xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); #if 0 ! // ID ourselves smname.value = "vim"; smname.length = 3; smnameprop.name = "SmProgram"; *************** *** 8054,8060 **** } ! /* Shut down XSMP comms. */ void xsmp_close(void) { --- 8051,8057 ---- } ! // Shut down XSMP comms. void xsmp_close(void) { *************** *** 8067,8077 **** xsmp_icefd = -1; } } ! #endif /* USE_XSMP */ #ifdef EBCDIC ! /* Translate character to its CTRL- value */ char CtrlTable[] = { /* 00 - 5E */ --- 8064,8074 ---- xsmp_icefd = -1; } } ! #endif // USE_XSMP #ifdef EBCDIC ! // Translate character to its CTRL- value char CtrlTable[] = { /* 00 - 5E */ *************** *** 8160,8166 **** }; char MetaCharTable[]= ! {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, --- 8157,8163 ---- }; char MetaCharTable[]= ! {// 0 1 2 3 4 5 6 7 8 9 A B C D E F 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, *************** *** 8168,8176 **** }; ! /* TODO: Use characters NOT numbers!!! */ char CtrlCharTable[]= ! {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, --- 8165,8173 ---- }; ! // TODO: Use characters NOT numbers!!! char CtrlCharTable[]= ! {// 0 1 2 3 4 5 6 7 8 9 A B C D E F 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, *** ../vim-8.1.2392/src/os_vms.c 2019-11-30 22:57:49.936582177 +0100 --- src/os_vms.c 2019-12-05 20:25:16.889446284 +0100 *************** *** 11,29 **** #include "vim.h" ! /* define _generic_64 for use in time functions */ #if !defined(VAX) && !defined(PROTO) # include #else ! /* based on Alpha's gen64def.h; the file is absent on VAX */ typedef struct _generic_64 { # pragma __nomember_alignment ! __union { /* You can treat me as... */ ! /* long long is not available on VAXen */ ! /* unsigned __int64 gen64$q_quadword; ...a single 64-bit value, or */ ! unsigned int gen64$l_longword [2]; /* ...two 32-bit values, or */ ! unsigned short int gen64$w_word [4]; /* ...four 16-bit values */ } gen64$r_quad_overlay; } GENERIC_64; #endif --- 11,29 ---- #include "vim.h" ! // define _generic_64 for use in time functions #if !defined(VAX) && !defined(PROTO) # include #else ! // based on Alpha's gen64def.h; the file is absent on VAX typedef struct _generic_64 { # pragma __nomember_alignment ! __union { // You can treat me as... ! // long long is not available on VAXen ! // unsigned __int64 gen64$q_quadword; ...a single 64-bit value, or ! unsigned int gen64$l_longword [2]; // ...two 32-bit values, or ! unsigned short int gen64$w_word [4]; // ...four 16-bit values } gen64$r_quad_overlay; } GENERIC_64; #endif *************** *** 67,79 **** } ITMLST2; static TT_MODE orgmode; ! static short iochan; /* TTY I/O channel */ ! static short iosb[4]; /* IO status block */ static int vms_match_num = 0; static int vms_match_free = 0; static char_u **vms_fmatch = NULL; ! static char *Fspec_Rms; /* rms file spec, passed implicitly between routines */ --- 67,79 ---- } ITMLST2; static TT_MODE orgmode; ! static short iochan; // TTY I/O channel ! static short iosb[4]; // IO status block static int vms_match_num = 0; static int vms_match_free = 0; static char_u **vms_fmatch = NULL; ! static char *Fspec_Rms; // rms file spec, passed implicitly between routines *************** *** 139,145 **** set_tty(int row, int col) { int status; ! TT_MODE newmode; /* New TTY mode bits */ static short first_time = TRUE; if (first_time) --- 139,145 ---- set_tty(int row, int col) { int status; ! TT_MODE newmode; // New TTY mode bits static short first_time = TRUE; if (first_time) *************** *** 165,171 **** get_tty(void) { ! static $DESCRIPTOR(odsc,"SYS$OUTPUT"); /* output descriptor */ int status; TT_MODE tt_mode; --- 165,171 ---- get_tty(void) { ! static $DESCRIPTOR(odsc,"SYS$OUTPUT"); // output descriptor int status; TT_MODE tt_mode; *************** *** 195,201 **** { TT_MODE tmode; ! tmode = get_tty(); /* get size from VMS */ Columns = tmode.width; Rows = tmode.x.y.length; return OK; --- 195,201 ---- { TT_MODE tmode; ! tmode = get_tty(); // get size from VMS Columns = tmode.width; Rows = tmode.x.y.length; return OK; *************** *** 262,268 **** { int res, dum; long attrib = 0L; ! char acmode = PSL$C_SUPER; /* needs SYSNAM privilege */ DESC tabnam, lognam; ITMLST1 itmlst; --- 262,268 ---- { int res, dum; long attrib = 0L; ! char acmode = PSL$C_SUPER; // needs SYSNAM privilege DESC tabnam, lognam; ITMLST1 itmlst; *************** *** 288,296 **** if (inp) vul_desc(&idsc, inp); ! lib$spawn(cmd ? &cdsc : NULL, /* command string */ ! inp ? &idsc : NULL, /* input file */ ! out ? &odsc : NULL, /* output file */ 0, 0, 0, &status, 0, 0, 0, 0, 0, 0); return status; } --- 288,296 ---- if (inp) vul_desc(&idsc, inp); ! lib$spawn(cmd ? &cdsc : NULL, // command string ! inp ? &idsc : NULL, // input file ! out ? &odsc : NULL, // output file 0, 0, 0, &status, 0, 0, 0, 0, 0, 0); return status; } *************** *** 314,320 **** vms_sys_status(int status) { if (status != SS$_NORMAL && (status & STS$M_SUCCESS) == 0) ! return status; /* Command failed. */ return 0; } --- 314,320 ---- vms_sys_status(int status) { if (status != SS$_NORMAL && (status & STS$M_SUCCESS) == 0) ! return status; // Command failed. return 0; } *************** *** 329,363 **** { int status, function, len; TT_MODE tt_mode; ! ITEM itmlst[2]; /* terminates on everything */ static long trm_mask[8] = {-1, -1, -1, -1, -1, -1, -1, -1}; ! /* whatever happened earlier we need an iochan here */ if (!iochan) tt_mode = get_tty(); ! /* important: clean the inbuf */ memset(inbuf, 0, nbytes); ! /* set up the itemlist for the first read */ vul_item(&itmlst[0], 0, TRM$_MODIFIERS, (char *)( TRM$M_TM_NOECHO | TRM$M_TM_NOEDIT | TRM$M_TM_NOFILTR | TRM$M_TM_TRMNOECHO | TRM$M_TM_NORECALL) , 0); vul_item(&itmlst[1], sizeof(trm_mask), TRM$_TERM, (char *)&trm_mask, 0); ! /* wait forever for a char */ function = (IO$_READLBLK | IO$M_EXTEND); status = sys$qiow(0, iochan, function, &iosb, 0, 0, inbuf, nbytes-1, 0, 0, &itmlst, sizeof(itmlst)); ! len = strlen(inbuf); /* how many chars we got? */ ! /* read immediately the rest in the IO queue */ function = (IO$_READLBLK | IO$M_TIMED | IO$M_ESCAPE | IO$M_NOECHO | IO$M_NOFILTR); status = sys$qiow(0, iochan, function, &iosb, 0, 0, inbuf+len, nbytes-1-len, 0, 0, 0, 0); ! len = strlen(inbuf); /* return the total length */ return len; } --- 329,363 ---- { int status, function, len; TT_MODE tt_mode; ! ITEM itmlst[2]; // terminates on everything static long trm_mask[8] = {-1, -1, -1, -1, -1, -1, -1, -1}; ! // whatever happened earlier we need an iochan here if (!iochan) tt_mode = get_tty(); ! // important: clean the inbuf memset(inbuf, 0, nbytes); ! // set up the itemlist for the first read vul_item(&itmlst[0], 0, TRM$_MODIFIERS, (char *)( TRM$M_TM_NOECHO | TRM$M_TM_NOEDIT | TRM$M_TM_NOFILTR | TRM$M_TM_TRMNOECHO | TRM$M_TM_NORECALL) , 0); vul_item(&itmlst[1], sizeof(trm_mask), TRM$_TERM, (char *)&trm_mask, 0); ! // wait forever for a char function = (IO$_READLBLK | IO$M_EXTEND); status = sys$qiow(0, iochan, function, &iosb, 0, 0, inbuf, nbytes-1, 0, 0, &itmlst, sizeof(itmlst)); ! len = strlen(inbuf); // how many chars we got? ! // read immediately the rest in the IO queue function = (IO$_READLBLK | IO$M_TIMED | IO$M_ESCAPE | IO$M_NOECHO | IO$M_NOFILTR); status = sys$qiow(0, iochan, function, &iosb, 0, 0, inbuf+len, nbytes-1-len, 0, 0, 0, 0); ! len = strlen(inbuf); // return the total length return len; } *************** *** 375,386 **** int i; static int vms_match_alloced = 0; ! if (val == DECC$K_FOREIGN ) /* foreign non VMS files are not counting */ return 1; ! /* accept all DECC$K_FILE and DECC$K_DIRECTORY */ if (vms_match_num == 0) { ! /* first time through, setup some things */ if (NULL == vms_fmatch) { vms_fmatch = ALLOC_MULT(char_u *, EXPL_ALLOC_INC); if (!vms_fmatch) --- 375,386 ---- int i; static int vms_match_alloced = 0; ! if (val == DECC$K_FOREIGN ) // foreign non VMS files are not counting return 1; ! // accept all DECC$K_FILE and DECC$K_DIRECTORY if (vms_match_num == 0) { ! // first time through, setup some things if (NULL == vms_fmatch) { vms_fmatch = ALLOC_MULT(char_u *, EXPL_ALLOC_INC); if (!vms_fmatch) *************** *** 389,404 **** vms_match_free = EXPL_ALLOC_INC; } else { ! /* re-use existing space */ vms_match_free = vms_match_alloced; } } ! /* make matches look uniform */ vms_remove_version(name); name=vms_tolower(name); ! /* if name already exists, don't add it */ for (i = 0; i= 0) /* add existing file */ addfile(gap, vms_fmatch[i], flags); } return cnt; --- 533,539 ---- cnt = vms_match_num; for (i = 0; i < cnt; i++) { ! if (mch_getperm(vms_fmatch[i]) >= 0) // add existing file addfile(gap, vms_fmatch[i], flags); } return cnt; *************** *** 551,560 **** int len; char *out_str=out; ! /* copy vms filename portion up to last colon ! * (node and/or disk) ! */ ! lastcolon = strrchr(in, ':'); /* find last colon */ if (lastcolon != NULL) { len = lastcolon - in + 1; strncpy(out, in, len); --- 551,559 ---- int len; char *out_str=out; ! // copy vms filename portion up to last colon ! // (node and/or disk) ! lastcolon = strrchr(in, ':'); // find last colon if (lastcolon != NULL) { len = lastcolon - in + 1; strncpy(out, in, len); *************** *** 562,610 **** in += len; } ! end_of_dir = NULL; /* default: no directory */ ! /* start of directory portion */ ch = *in; ! if ((ch == '[') || (ch == '/') || (ch == '<')) { /* start of directory(s) ? */ ch = '['; SKIP_FOLLOWING_SLASHES(in); ! } else if (EQN(in, "../", 3)) { /* Unix parent directory? */ *out++ = '['; *out++ = '-'; end_of_dir = out; ch = '.'; in += 2; SKIP_FOLLOWING_SLASHES(in); ! } else { /* not a special character */ ! while (EQN(in, "./", 2)) { /* Ignore Unix "current dir" */ in += 2; SKIP_FOLLOWING_SLASHES(in); } ! if (strchr(in, '/') == NULL) { /* any more Unix directories ? */ ! strcpy(out, in); /* No - get rest of the spec */ return; } else { ! *out++ = '['; /* Yes, denote a Vms subdirectory */ ch = '.'; --in; } } ! /* if we get here, there is a directory part of the filename */ ! /* initialize output file spec */ *out++ = ch; ++in; while (*in != '\0') { ch = *in; ! if ((ch == ']') || (ch == '/') || (ch == '>') ) { /* end of (sub)directory ? */ end_of_dir = out; ch = '.'; SKIP_FOLLOWING_SLASHES(in); } ! else if (EQN(in, "../", 3)) { /* Unix parent directory? */ *out++ = '-'; end_of_dir = out; ch = '.'; --- 561,609 ---- in += len; } ! end_of_dir = NULL; // default: no directory ! // start of directory portion ch = *in; ! if ((ch == '[') || (ch == '/') || (ch == '<')) { // start of directory(s) ? ch = '['; SKIP_FOLLOWING_SLASHES(in); ! } else if (EQN(in, "../", 3)) { // Unix parent directory? *out++ = '['; *out++ = '-'; end_of_dir = out; ch = '.'; in += 2; SKIP_FOLLOWING_SLASHES(in); ! } else { // not a special character ! while (EQN(in, "./", 2)) { // Ignore Unix "current dir" in += 2; SKIP_FOLLOWING_SLASHES(in); } ! if (strchr(in, '/') == NULL) { // any more Unix directories ? ! strcpy(out, in); // No - get rest of the spec return; } else { ! *out++ = '['; // Yes, denote a Vms subdirectory ch = '.'; --in; } } ! // if we get here, there is a directory part of the filename ! // initialize output file spec *out++ = ch; ++in; while (*in != '\0') { ch = *in; ! if ((ch == ']') || (ch == '/') || (ch == '>') ) { // end of (sub)directory ? end_of_dir = out; ch = '.'; SKIP_FOLLOWING_SLASHES(in); } ! else if (EQN(in, "../", 3)) { // Unix parent directory? *out++ = '-'; end_of_dir = out; ch = '.'; *************** *** 612,618 **** SKIP_FOLLOWING_SLASHES(in); } else { ! while (EQN(in, "./", 2)) { /* Ignore Unix "current dir" */ end_of_dir = out; in += 2; SKIP_FOLLOWING_SLASHES(in); --- 611,617 ---- SKIP_FOLLOWING_SLASHES(in); } else { ! while (EQN(in, "./", 2)) { // Ignore Unix "current dir" end_of_dir = out; in += 2; SKIP_FOLLOWING_SLASHES(in); *************** *** 620,633 **** } } ! /* Place next character into output file spec */ *out++ = ch; ++in; } ! *out = '\0'; /* Terminate output file spec */ ! if (end_of_dir != NULL) /* Terminate directory portion */ *end_of_dir = ']'; } --- 619,632 ---- } } ! // Place next character into output file spec *out++ = ch; ++in; } ! *out = '\0'; // Terminate output file spec ! if (end_of_dir != NULL) // Terminate directory portion *end_of_dir = ']'; } *************** *** 651,657 **** static size_t buflen = 0; size_t len; ! /* get a big-enough buffer */ len = strlen(instring) + 1; if (len > buflen) { --- 650,656 ---- static size_t buflen = 0; size_t len; ! // get a big-enough buffer len = strlen(instring) + 1; if (len > buflen) { *************** *** 665,686 **** strcpy(tmpbuf, instring); #endif ! Fspec_Rms = buf; /* for decc$to_vms */ if (strchr(instring,'/') == NULL) ! /* It is already a VMS file spec */ strcpy(buf, instring); ! else if (strchr(instring,'"') == NULL) /* password in the path? */ { ! /* Seems it is a regular file, let guess that it is pure Unix fspec */ if (decc$to_vms(instring, vms_fspec_proc, 0, 0) <= 0) ! /* No... it must be mixed */ vms_unix_mixed_filespec(instring, buf); } else ! /* we have a password in the path */ ! /* decc$ functions can not handle */ ! /* this is our only hope to resolv */ vms_unix_mixed_filespec(instring, buf); return buf; --- 664,685 ---- strcpy(tmpbuf, instring); #endif ! Fspec_Rms = buf; // for decc$to_vms if (strchr(instring,'/') == NULL) ! // It is already a VMS file spec strcpy(buf, instring); ! else if (strchr(instring,'"') == NULL) // password in the path? { ! // Seems it is a regular file, let guess that it is pure Unix fspec if (decc$to_vms(instring, vms_fspec_proc, 0, 0) <= 0) ! // No... it must be mixed vms_unix_mixed_filespec(instring, buf); } else ! // we have a password in the path ! // decc$ functions can not handle ! // this is our only hope to resolv vms_unix_mixed_filespec(instring, buf); return buf; *************** *** 697,703 **** char_u *cp; char_u *fp; ! if ((cp = vim_strchr( fname, ';')) != NULL) /* remove version */ *cp = '\0'; else if ((cp = vim_strrchr( fname, '.')) != NULL ) { --- 696,702 ---- char_u *cp; char_u *fp; ! if ((cp = vim_strchr( fname, ';')) != NULL) // remove version *cp = '\0'; else if ((cp = vim_strrchr( fname, '.')) != NULL ) { *************** *** 726,732 **** */ int RealWaitForChar( ! int fd UNUSED, /* always read from iochan */ long msec, int *check_for_gpm UNUSED, int *interrupted) --- 725,731 ---- */ int RealWaitForChar( ! int fd UNUSED, // always read from iochan long msec, int *check_for_gpm UNUSED, int *interrupted) *************** *** 738,808 **** unsigned int convert_operation = LIB$K_DELTA_SECONDS_F; float sec =(float) msec/1000; ! /* make sure the iochan is set */ if (!iochan) get_tty(); if (sec > 0) { ! /* time-out specified; convert it to absolute time */ ! /* sec>0 requirement of lib$cvtf_to_internal_time()*/ ! /* get current time (number of 100ns ticks since the VMS Epoch) */ status = sys$gettim(&time_curr); if (status != SS$_NORMAL) ! return 0; /* error */ ! /* construct the delta time */ #if __G_FLOAT==0 # ifndef VAX ! /* IEEE is default on IA64, but can be used on Alpha too - but not on VAX */ status = lib$cvts_to_internal_time( &convert_operation, &sec, &time_diff); # endif ! #else /* default on Alpha and VAX */ status = lib$cvtf_to_internal_time( &convert_operation, &sec, &time_diff); #endif if (status != LIB$_NORMAL) ! return 0; /* error */ ! /* add them up */ status = lib$add_times( &time_curr, &time_diff, &time_out); if (status != LIB$_NORMAL) ! return 0; /* error */ } while (TRUE) { ! /* select() */ status = sys$qiow(0, iochan, IO$_SENSEMODE | IO$M_TYPEAHDCNT, iosb, 0, 0, &typeahead, 8, 0, 0, 0, 0); if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) ! return 0; /* error */ if (typeahead.numchars) ! return 1; /* ready to read */ ! /* there's nothing to read; what now? */ if (msec == 0) { ! /* immediate time-out; return impatiently */ return 0; } else if (msec < 0) { ! /* no time-out; wait on indefinitely */ ! return 1; /* fakeout to force a wait in vms_read() */ } else { ! /* time-out needs to be checked */ status = sys$gettim(&time_curr); if (status != SS$_NORMAL) ! return 0; /* error */ status = lib$sub_times( &time_out, &time_curr, &time_diff); if (status != LIB$_NORMAL) ! return 0; /* error, incl. time_diff < 0 (i.e. time-out) */ ! /* otherwise wait some more */ } } } --- 737,807 ---- unsigned int convert_operation = LIB$K_DELTA_SECONDS_F; float sec =(float) msec/1000; ! // make sure the iochan is set if (!iochan) get_tty(); if (sec > 0) { ! // time-out specified; convert it to absolute time ! // sec>0 requirement of lib$cvtf_to_internal_time() ! // get current time (number of 100ns ticks since the VMS Epoch) status = sys$gettim(&time_curr); if (status != SS$_NORMAL) ! return 0; // error ! // construct the delta time #if __G_FLOAT==0 # ifndef VAX ! // IEEE is default on IA64, but can be used on Alpha too - but not on VAX status = lib$cvts_to_internal_time( &convert_operation, &sec, &time_diff); # endif ! #else // default on Alpha and VAX status = lib$cvtf_to_internal_time( &convert_operation, &sec, &time_diff); #endif if (status != LIB$_NORMAL) ! return 0; // error ! // add them up status = lib$add_times( &time_curr, &time_diff, &time_out); if (status != LIB$_NORMAL) ! return 0; // error } while (TRUE) { ! // select() status = sys$qiow(0, iochan, IO$_SENSEMODE | IO$M_TYPEAHDCNT, iosb, 0, 0, &typeahead, 8, 0, 0, 0, 0); if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) ! return 0; // error if (typeahead.numchars) ! return 1; // ready to read ! // there's nothing to read; what now? if (msec == 0) { ! // immediate time-out; return impatiently return 0; } else if (msec < 0) { ! // no time-out; wait on indefinitely ! return 1; // fakeout to force a wait in vms_read() } else { ! // time-out needs to be checked status = sys$gettim(&time_curr); if (status != SS$_NORMAL) ! return 0; // error status = lib$sub_times( &time_out, &time_curr, &time_diff); if (status != LIB$_NORMAL) ! return 0; // error, incl. time_diff < 0 (i.e. time-out) ! // otherwise wait some more } } } *** ../vim-8.1.2392/src/os_win32.c 2019-12-02 21:35:28.009111221 +0100 --- src/os_win32.c 2019-12-05 20:28:14.720855490 +0100 *************** *** 30,36 **** #include #include ! /* cproto fails on missing include files */ #ifndef PROTO # include #endif --- 30,36 ---- #include #include ! // cproto fails on missing include files #ifndef PROTO # include #endif *************** *** 82,89 **** # endif #endif ! /* Record all output and all keyboard & mouse input */ ! /* #define MCH_WRITE_DUMP */ #ifdef MCH_WRITE_DUMP FILE* fdDump = NULL; --- 82,89 ---- # endif #endif ! // Record all output and all keyboard & mouse input ! // #define MCH_WRITE_DUMP #ifdef MCH_WRITE_DUMP FILE* fdDump = NULL; *************** *** 143,167 **** typedef int STARTUPINFO; typedef int PROCESS_INFORMATION; typedef int LPSECURITY_ATTRIBUTES; ! # define __stdcall /* empty */ #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! /* Win32 Console handles for input and output */ static HANDLE g_hConIn = INVALID_HANDLE_VALUE; static HANDLE g_hConOut = INVALID_HANDLE_VALUE; ! /* Win32 Screen buffer,coordinate,console I/O information */ static SMALL_RECT g_srScrollRegion; ! static COORD g_coord; /* 0-based, but external coords are 1-based */ ! /* The attribute of the screen when the editor was started */ ! static WORD g_attrDefault = 7; /* lightgray text on black background */ static WORD g_attrCurrent; ! static int g_fCBrkPressed = FALSE; /* set by ctrl-break interrupt */ ! static int g_fCtrlCPressed = FALSE; /* set when ctrl-C or ctrl-break detected */ ! static int g_fForceExit = FALSE; /* set when forcefully exiting */ static void scroll(unsigned cLines); static void set_scroll_region(unsigned left, unsigned top, --- 143,167 ---- typedef int STARTUPINFO; typedef int PROCESS_INFORMATION; typedef int LPSECURITY_ATTRIBUTES; ! # define __stdcall // empty #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! // Win32 Console handles for input and output static HANDLE g_hConIn = INVALID_HANDLE_VALUE; static HANDLE g_hConOut = INVALID_HANDLE_VALUE; ! // Win32 Screen buffer,coordinate,console I/O information static SMALL_RECT g_srScrollRegion; ! static COORD g_coord; // 0-based, but external coords are 1-based ! // The attribute of the screen when the editor was started ! static WORD g_attrDefault = 7; // lightgray text on black background static WORD g_attrCurrent; ! static int g_fCBrkPressed = FALSE; // set by ctrl-break interrupt ! static int g_fCtrlCPressed = FALSE; // set when ctrl-C or ctrl-break detected ! static int g_fForceExit = FALSE; // set when forcefully exiting static void scroll(unsigned cLines); static void set_scroll_region(unsigned left, unsigned top, *************** *** 219,231 **** static void reset_console_color_rgb(void); #endif ! /* This flag is newly created from Windows 10 */ #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! static int suppress_winsize = 1; /* don't fiddle with console */ #endif static char_u *exe_path = NULL; --- 219,231 ---- static void reset_console_color_rgb(void); #endif ! // This flag is newly created from Windows 10 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #endif #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! static int suppress_winsize = 1; // don't fiddle with console #endif static char_u *exe_path = NULL; *************** *** 233,239 **** static BOOL win8_or_later = FALSE; #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! /* Dynamic loading for portability */ typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX { ULONG cbSize; --- 233,239 ---- static BOOL win8_or_later = FALSE; #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) ! // Dynamic loading for portability typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX { ULONG cbSize; *************** *** 339,345 **** && s_irCache[head + 1].EventType == WINDOW_BUFFER_SIZE_EVENT) { ! /* Remove duplicate event to avoid flicker. */ for (i = head; i < tail; ++i) s_irCache[i] = s_irCache[i + 1]; --tail; --- 339,345 ---- && s_irCache[head + 1].EventType == WINDOW_BUFFER_SIZE_EVENT) { ! // Remove duplicate event to avoid flicker. for (i = head; i < tail; ++i) s_irCache[i] = s_irCache[i + 1]; --tail; *************** *** 403,417 **** static void get_exe_name(void) { ! /* Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned ! * as the maximum length that works (plus a NUL byte). */ #define MAX_ENV_PATH_LEN 8192 char temp[MAX_ENV_PATH_LEN]; char_u *p; if (exe_name == NULL) { ! /* store the name of the executable, may be used for $VIM */ GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); if (*temp != NUL) exe_name = FullName_save((char_u *)temp, FALSE); --- 403,417 ---- static void get_exe_name(void) { ! // Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned ! // as the maximum length that works (plus a NUL byte). #define MAX_ENV_PATH_LEN 8192 char temp[MAX_ENV_PATH_LEN]; char_u *p; if (exe_name == NULL) { ! // store the name of the executable, may be used for $VIM GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1); if (*temp != NUL) exe_name = FullName_save((char_u *)temp, FALSE); *************** *** 423,431 **** (int)(gettail_sep(exe_name) - exe_name)); if (exe_path != NULL) { ! /* Append our starting directory to $PATH, so that when doing ! * "!xxd" it's found in our starting directory. Needed because ! * SearchPath() also looks there. */ p = mch_getenv("PATH"); if (p == NULL || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) --- 423,431 ---- (int)(gettail_sep(exe_name) - exe_name)); if (exe_path != NULL) { ! // Append our starting directory to $PATH, so that when doing ! // "!xxd" it's found in our starting directory. Needed because ! // SearchPath() also looks there. p = mch_getenv("PATH"); if (p == NULL || STRLEN(p) + STRLEN(exe_path) + 2 < MAX_ENV_PATH_LEN) *************** *** 471,478 **** { HINSTANCE dll = NULL; ! /* NOTE: Do not use mch_dirname() and mch_chdir() here, they may call ! * vimLoadLib() recursively, which causes a stack overflow. */ if (exe_path == NULL) get_exe_name(); if (exe_path != NULL) --- 471,478 ---- { HINSTANCE dll = NULL; ! // NOTE: Do not use mch_dirname() and mch_chdir() here, they may call ! // vimLoadLib() recursively, which causes a stack overflow. if (exe_path == NULL) get_exe_name(); if (exe_path != NULL) *************** *** 481,489 **** if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) { ! /* Change directory to where the executable is, both to make ! * sure we find a .dll there and to avoid looking for a .dll ! * in the current directory. */ SetCurrentDirectory((LPCSTR)exe_path); dll = LoadLibrary(name); SetCurrentDirectoryW(old_dirw); --- 481,489 ---- if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) { ! // Change directory to where the executable is, both to make ! // sure we find a .dll there and to avoid looking for a .dll ! // in the current directory. SetCurrentDirectory((LPCSTR)exe_path); dll = LoadLibrary(name); SetCurrentDirectoryW(old_dirw); *************** *** 528,535 **** PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; PIMAGE_NT_HEADERS pPE; PIMAGE_IMPORT_DESCRIPTOR pImpDesc; ! PIMAGE_THUNK_DATA pIAT; /* Import Address Table */ ! PIMAGE_THUNK_DATA pINT; /* Import Name Table */ PIMAGE_IMPORT_BY_NAME pImpName; if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) --- 528,535 ---- PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst; PIMAGE_NT_HEADERS pPE; PIMAGE_IMPORT_DESCRIPTOR pImpDesc; ! PIMAGE_THUNK_DATA pIAT; // Import Address Table ! PIMAGE_THUNK_DATA pINT; // Import Name Table PIMAGE_IMPORT_BY_NAME pImpName; if (pDOS->e_magic != IMAGE_DOS_SIGNATURE) *************** *** 599,605 **** # define GETTEXT_DLL_ALT1 "libintl-8.dll" # define GETTEXT_DLL_ALT2 "intl.dll" # endif ! /* Dummy functions */ static char *null_libintl_gettext(const char *); static char *null_libintl_ngettext(const char *, const char *, unsigned long n); static char *null_libintl_textdomain(const char *); --- 599,605 ---- # define GETTEXT_DLL_ALT1 "libintl-8.dll" # define GETTEXT_DLL_ALT2 "intl.dll" # endif ! // Dummy functions static char *null_libintl_gettext(const char *); static char *null_libintl_ngettext(const char *, const char *, unsigned long n); static char *null_libintl_textdomain(const char *); *************** *** 676,689 **** } } ! /* The bind_textdomain_codeset() function is optional. */ dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, "bind_textdomain_codeset"); if (dyn_libintl_bind_textdomain_codeset == NULL) dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; ! /* _wputenv() function for the libintl.dll is optional. */ hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); if (hmsvcrt != NULL) dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); --- 676,689 ---- } } ! // The bind_textdomain_codeset() function is optional. dyn_libintl_bind_textdomain_codeset = (void *)GetProcAddress(hLibintlDLL, "bind_textdomain_codeset"); if (dyn_libintl_bind_textdomain_codeset == NULL) dyn_libintl_bind_textdomain_codeset = null_libintl_bind_textdomain_codeset; ! // _wputenv() function for the libintl.dll is optional. hmsvcrt = find_imported_module_by_funcname(hLibintlDLL, "getenv"); if (hmsvcrt != NULL) dyn_libintl_wputenv = (void *)GetProcAddress(hmsvcrt, "_wputenv"); *************** *** 750,758 **** return 0; } ! #endif /* DYNAMIC_GETTEXT */ ! /* This symbol is not defined in older versions of the SDK or Visual C++ */ #ifndef VER_PLATFORM_WIN32_WINDOWS # define VER_PLATFORM_WIN32_WINDOWS 1 --- 750,758 ---- return 0; } ! #endif // DYNAMIC_GETTEXT ! // This symbol is not defined in older versions of the SDK or Visual C++ #ifndef VER_PLATFORM_WIN32_WINDOWS # define VER_PLATFORM_WIN32_WINDOWS 1 *************** *** 828,834 **** win8_or_later = TRUE; #ifdef HAVE_ACL ! /* Enable privilege for getting or setting SACLs. */ win32_enable_privilege(SE_SECURITY_NAME, TRUE); #endif done = TRUE; --- 828,834 ---- win8_or_later = TRUE; #ifdef HAVE_ACL ! // Enable privilege for getting or setting SACLs. win32_enable_privilege(SE_SECURITY_NAME, TRUE); #endif done = TRUE; *************** *** 843,855 **** # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) ! /* When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. ! * We map function keys to their ANSI terminal equivalents, as produced ! * by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any ! * ANSI key with a value >= '\300' is nonstandard, but provided anyway ! * so that the user can have access to all SHIFT-, CTRL-, and ALT- ! * combinations of function/arrow/etc keys. ! */ static const struct { --- 843,854 ---- # define ALT_GR (RIGHT_ALT_PRESSED | LEFT_CTRL_PRESSED) ! // When uChar.AsciiChar is 0, then we need to look at wVirtualKeyCode. ! // We map function keys to their ANSI terminal equivalents, as produced ! // by ANSI.SYS, for compatibility with the MS-DOS version of Vim. Any ! // ANSI key with a value >= '\300' is nonstandard, but provided anyway ! // so that the user can have access to all SHIFT-, CTRL-, and ALT- ! // combinations of function/arrow/etc keys. static const struct { *************** *** 927,933 **** # define UChar uChar.UnicodeChar # endif ! /* The return code indicates key code size. */ static int win32_kbd_patch_key( KEY_EVENT_RECORD *pker) --- 926,934 ---- # define UChar uChar.UnicodeChar # endif ! /* ! * The return code indicates key code size. ! */ static int win32_kbd_patch_key( KEY_EVENT_RECORD *pker) *************** *** 950,956 **** vim_memset(abKeystate, 0, sizeof (abKeystate)); ! /* Clear any pending dead keys */ ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); if (uMods & SHIFT_PRESSED) --- 951,957 ---- vim_memset(abKeystate, 0, sizeof (abKeystate)); ! // Clear any pending dead keys ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0); if (uMods & SHIFT_PRESSED) *************** *** 992,1030 **** *pch = *pch2 = NUL; g_fJustGotFocus = FALSE; ! /* ignore key up events */ if (!pker->bKeyDown) return FALSE; ! /* ignore some keystrokes */ switch (pker->wVirtualKeyCode) { ! /* modifiers */ case VK_SHIFT: case VK_CONTROL: ! case VK_MENU: /* Alt key */ return FALSE; default: break; } ! /* special cases */ if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) { ! /* Ctrl-6 is Ctrl-^ */ if (pker->wVirtualKeyCode == '6') { *pch = Ctrl_HAT; return TRUE; } ! /* Ctrl-2 is Ctrl-@ */ else if (pker->wVirtualKeyCode == '2') { *pch = NUL; return TRUE; } ! /* Ctrl-- is Ctrl-_ */ else if (pker->wVirtualKeyCode == 0xBD) { *pch = Ctrl__; --- 993,1031 ---- *pch = *pch2 = NUL; g_fJustGotFocus = FALSE; ! // ignore key up events if (!pker->bKeyDown) return FALSE; ! // ignore some keystrokes switch (pker->wVirtualKeyCode) { ! // modifiers case VK_SHIFT: case VK_CONTROL: ! case VK_MENU: // Alt key return FALSE; default: break; } ! // special cases if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL) { ! // Ctrl-6 is Ctrl-^ if (pker->wVirtualKeyCode == '6') { *pch = Ctrl_HAT; return TRUE; } ! // Ctrl-2 is Ctrl-@ else if (pker->wVirtualKeyCode == '2') { *pch = NUL; return TRUE; } ! // Ctrl-- is Ctrl-_ else if (pker->wVirtualKeyCode == 0xBD) { *pch = Ctrl__; *************** *** 1032,1038 **** } } ! /* Shift-TAB */ if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) { *pch = K_NUL; --- 1033,1039 ---- } } ! // Shift-TAB if (pker->wVirtualKeyCode == VK_TAB && (nModifs & SHIFT_PRESSED)) { *pch = K_NUL; *************** *** 1076,1094 **** if (pmodifiers != NULL) { ! /* Pass on the ALT key as a modifier, but only when not combined ! * with CTRL (which is ALTGR). */ if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) *pmodifiers |= MOD_MASK_ALT; ! /* Pass on SHIFT only for special keys, because we don't know when ! * it's already included with the character. */ if ((nModifs & SHIFT) != 0 && *pch <= 0x20) *pmodifiers |= MOD_MASK_SHIFT; ! /* Pass on CTRL only for non-special keys, because we don't know ! * when it's already included with the character. And not when ! * combined with ALT (which is ALTGR). */ if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 && *pch >= 0x20 && *pch < 0x80) *pmodifiers |= MOD_MASK_CTRL; --- 1077,1095 ---- if (pmodifiers != NULL) { ! // Pass on the ALT key as a modifier, but only when not combined ! // with CTRL (which is ALTGR). if ((nModifs & ALT) != 0 && (nModifs & CTRL) == 0) *pmodifiers |= MOD_MASK_ALT; ! // Pass on SHIFT only for special keys, because we don't know when ! // it's already included with the character. if ((nModifs & SHIFT) != 0 && *pch <= 0x20) *pmodifiers |= MOD_MASK_SHIFT; ! // Pass on CTRL only for non-special keys, because we don't know ! // when it's already included with the character. And not when ! // combined with ALT (which is ALTGR). if ((nModifs & CTRL) != 0 && (nModifs & ALT) == 0 && *pch >= 0x20 && *pch < 0x80) *pmodifiers |= MOD_MASK_CTRL; *************** *** 1098,1104 **** return (*pch != NUL); } ! #endif /* FEAT_GUI_MSWIN */ /* --- 1099,1105 ---- return (*pch != NUL); } ! #endif // FEAT_GUI_MSWIN /* *************** *** 1110,1120 **** { } #else ! static int g_fMouseAvail = FALSE; /* mouse present */ ! static int g_fMouseActive = FALSE; /* mouse enabled */ ! static int g_nMouseClick = -1; /* mouse status */ ! static int g_xMouse; /* mouse x coordinate */ ! static int g_yMouse; /* mouse y coordinate */ /* * Enable or disable mouse input --- 1111,1121 ---- { } #else ! static int g_fMouseAvail = FALSE; // mouse present ! static int g_fMouseActive = FALSE; // mouse enabled ! static int g_nMouseClick = -1; // mouse status ! static int g_xMouse; // mouse x coordinate ! static int g_yMouse; // mouse y coordinate /* * Enable or disable mouse input *************** *** 1198,1204 **** static DWORD s_dwLastClickTime = 0; static BOOL s_fNextIsMiddle = FALSE; ! static DWORD cButtons = 0; /* number of buttons supported */ const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; --- 1199,1205 ---- static DWORD s_dwLastClickTime = 0; static BOOL s_fNextIsMiddle = FALSE; ! static DWORD cButtons = 0; // number of buttons supported const DWORD LEFT = FROM_LEFT_1ST_BUTTON_PRESSED; const DWORD MIDDLE = FROM_LEFT_2ND_BUTTON_PRESSED; *************** *** 1216,1229 **** return FALSE; } ! /* get a spurious MOUSE_EVENT immediately after receiving focus; ignore */ if (g_fJustGotFocus) { g_fJustGotFocus = FALSE; return FALSE; } ! /* unprocessed mouse click? */ if (g_nMouseClick != -1) return TRUE; --- 1217,1230 ---- return FALSE; } ! // get a spurious MOUSE_EVENT immediately after receiving focus; ignore if (g_fJustGotFocus) { g_fJustGotFocus = FALSE; return FALSE; } ! // unprocessed mouse click? if (g_nMouseClick != -1) return TRUE; *************** *** 1233,1254 **** if (pmer->dwEventFlags == MOUSE_MOVED) { ! /* Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these ! * events even when the mouse moves only within a char cell.) */ if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) return FALSE; } ! /* If no buttons are pressed... */ if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) { nButton = MOUSE_RELEASE; ! /* If the last thing returned was MOUSE_RELEASE, ignore this */ if (s_fReleased) { # ifdef FEAT_BEVAL_TERM ! /* do return mouse move events when we want them */ if (p_bevalterm) nButton = MOUSE_DRAG; else --- 1234,1255 ---- if (pmer->dwEventFlags == MOUSE_MOVED) { ! // Ignore MOUSE_MOVED events if (x, y) hasn't changed. (We get these ! // events even when the mouse moves only within a char cell.) if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse) return FALSE; } ! // If no buttons are pressed... if ((pmer->dwButtonState & ((1 << cButtons) - 1)) == 0) { nButton = MOUSE_RELEASE; ! // If the last thing returned was MOUSE_RELEASE, ignore this if (s_fReleased) { # ifdef FEAT_BEVAL_TERM ! // do return mouse move events when we want them if (p_bevalterm) nButton = MOUSE_DRAG; else *************** *** 1258,1279 **** s_fReleased = TRUE; } ! else /* one or more buttons pressed */ { ! /* on a 2-button mouse, hold down left and right buttons ! * simultaneously to get MIDDLE. */ if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) { DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); ! /* if either left or right button only is pressed, see if the ! * next mouse event has both of them pressed */ if (dwLR == LEFT || dwLR == RIGHT) { for (;;) { ! /* wait a short time for next input event */ if (WaitForSingleObject(g_hConIn, p_mouset / 3) != WAIT_OBJECT_0) break; --- 1259,1280 ---- s_fReleased = TRUE; } ! else // one or more buttons pressed { ! // on a 2-button mouse, hold down left and right buttons ! // simultaneously to get MIDDLE. if (cButtons == 2 && s_nOldButton != MOUSE_DRAG) { DWORD dwLR = (pmer->dwButtonState & LEFT_RIGHT); ! // if either left or right button only is pressed, see if the ! // next mouse event has both of them pressed if (dwLR == LEFT || dwLR == RIGHT) { for (;;) { ! // wait a short time for next input event if (WaitForSingleObject(g_hConIn, p_mouset / 3) != WAIT_OBJECT_0) break; *************** *** 1299,1308 **** else if (s_xOldMouse == pmer2->dwMousePosition.X && s_yOldMouse == pmer2->dwMousePosition.Y) { ! /* throw away spurious mouse move */ read_console_input(g_hConIn, &ir, 1, &cRecords); ! /* are there any more mouse events in queue? */ peek_console_input(g_hConIn, &ir, 1, &cRecords); if (cRecords==0 || ir.EventType != MOUSE_EVENT) --- 1300,1309 ---- else if (s_xOldMouse == pmer2->dwMousePosition.X && s_yOldMouse == pmer2->dwMousePosition.Y) { ! // throw away spurious mouse move read_console_input(g_hConIn, &ir, 1, &cRecords); ! // are there any more mouse events in queue? peek_console_input(g_hConIn, &ir, 1, &cRecords); if (cRecords==0 || ir.EventType != MOUSE_EVENT) *************** *** 1349,1355 **** if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) { ! /* button pressed or released, without mouse moving */ if (nButton != -1 && nButton != MOUSE_RELEASE) { DWORD dwCurrentTime = GetTickCount(); --- 1350,1356 ---- if (pmer->dwEventFlags == 0 || pmer->dwEventFlags == DOUBLE_CLICK) { ! // button pressed or released, without mouse moving if (nButton != -1 && nButton != MOUSE_RELEASE) { DWORD dwCurrentTime = GetTickCount(); *************** *** 1399,1405 **** if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); ! /* only pass on interesting (i.e., different) mouse events */ if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse && s_nOldMouseClick == g_nMouseClick) --- 1400,1406 ---- if (nButton != MOUSE_DRAG && nButton != MOUSE_RELEASE) SET_NUM_MOUSE_CLICKS(g_nMouseClick, s_cClicks); ! // only pass on interesting (i.e., different) mouse events if (s_xOldMouse == g_xMouse && s_yOldMouse == g_yMouse && s_nOldMouseClick == g_nMouseClick) *************** *** 1456,1462 **** idx = get_shape_idx(FALSE); if (shape_table[idx].shape == SHAPE_BLOCK) ! thickness = 99; /* 100 doesn't work on W95 */ else thickness = shape_table[idx].percentage; mch_set_cursor_shape(thickness); --- 1457,1463 ---- idx = get_shape_idx(FALSE); if (shape_table[idx].shape == SHAPE_BLOCK) ! thickness = 99; // 100 doesn't work on W95 else thickness = shape_table[idx].percentage; mch_set_cursor_shape(thickness); *************** *** 1494,1503 **** # endif if (msec > 0) ! /* Wait until the specified time has elapsed. */ dwEndTime = GetTickCount() + msec; else if (msec < 0) ! /* Wait forever. */ dwEndTime = INFINITE; // We need to loop until the end of the time period, because --- 1495,1504 ---- # endif if (msec > 0) ! // Wait until the specified time has elapsed. dwEndTime = GetTickCount() + msec; else if (msec < 0) ! // Wait forever. dwEndTime = INFINITE; // We need to loop until the end of the time period, because *************** *** 1527,1534 **** if (msec > 0) { ! /* If the specified wait time has passed, return. Beware that ! * GetTickCount() may wrap around (overflow). */ dwNow = GetTickCount(); if ((int)(dwNow - dwEndTime) >= 0) break; --- 1528,1535 ---- if (msec > 0) { ! // If the specified wait time has passed, return. Beware that ! // GetTickCount() may wrap around (overflow). dwNow = GetTickCount(); if ((int)(dwNow - dwEndTime) >= 0) break; *************** *** 1538,1563 **** DWORD dwWaitTime = dwEndTime - dwNow; # ifdef FEAT_JOB_CHANNEL ! /* Check channel while waiting for input. */ if (dwWaitTime > 100) { dwWaitTime = 100; ! /* If there is readahead then parse_queued_messages() timed out ! * and we should call it again soon. */ if (channel_any_readahead()) dwWaitTime = 10; } # endif # ifdef FEAT_BEVAL_GUI if (p_beval && dwWaitTime > 100) ! /* The 'balloonexpr' may indirectly invoke a callback while ! * waiting for a character, need to check often. */ dwWaitTime = 100; # endif # ifdef FEAT_MZSCHEME if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || (long)dwWaitTime > p_mzq)) ! dwWaitTime = p_mzq; /* don't wait longer than 'mzquantum' */ # endif # ifdef FEAT_TIMERS // When waiting very briefly don't trigger timers. --- 1539,1564 ---- DWORD dwWaitTime = dwEndTime - dwNow; # ifdef FEAT_JOB_CHANNEL ! // Check channel while waiting for input. if (dwWaitTime > 100) { dwWaitTime = 100; ! // If there is readahead then parse_queued_messages() timed out ! // and we should call it again soon. if (channel_any_readahead()) dwWaitTime = 10; } # endif # ifdef FEAT_BEVAL_GUI if (p_beval && dwWaitTime > 100) ! // The 'balloonexpr' may indirectly invoke a callback while ! // waiting for a character, need to check often. dwWaitTime = 100; # endif # ifdef FEAT_MZSCHEME if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || (long)dwWaitTime > p_mzq)) ! dwWaitTime = p_mzq; // don't wait longer than 'mzquantum' # endif # ifdef FEAT_TIMERS // When waiting very briefly don't trigger timers. *************** *** 1603,1610 **** { if (csbi.dwCursorPosition.Y != msg_row) { ! /* The screen is now messed up, must redraw the ! * command line and later all the windows. */ redraw_all_later(CLEAR); cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); redrawcmd(); --- 1604,1611 ---- { if (csbi.dwCursorPosition.Y != msg_row) { ! // The screen is now messed up, must redraw the ! // command line and later all the windows. redraw_all_later(CLEAR); cmdline_row -= (msg_row - csbi.dwCursorPosition.Y); redrawcmd(); *************** *** 1618,1625 **** if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) { # ifdef FEAT_MBYTE_IME ! /* Windows IME sends two '\n's with only one 'ENTER'. First: ! * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */ if (ir.Event.KeyEvent.UChar == 0 && ir.Event.KeyEvent.wVirtualKeyCode == 13) { --- 1619,1626 ---- if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown) { # ifdef FEAT_MBYTE_IME ! // Windows IME sends two '\n's with only one 'ENTER'. First: ! // wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 if (ir.Event.KeyEvent.UChar == 0 && ir.Event.KeyEvent.wVirtualKeyCode == 13) { *************** *** 1660,1666 **** } # ifdef FEAT_CLIENTSERVER ! /* Something might have been received while we were waiting. */ if (input_available()) return TRUE; # endif --- 1661,1667 ---- } # ifdef FEAT_CLIENTSERVER ! // Something might have been received while we were waiting. if (input_available()) return TRUE; # endif *************** *** 1754,1760 **** } } } ! #endif /* !FEAT_GUI_MSWIN */ /* --- 1755,1761 ---- } } } ! #endif // !FEAT_GUI_MSWIN /* *************** *** 1777,1783 **** int len; int c; # define TYPEAHEADLEN 20 ! static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */ static int typeaheadlen = 0; # ifdef VIMDLL --- 1778,1784 ---- int len; int c; # define TYPEAHEADLEN 20 ! static char_u typeahead[TYPEAHEADLEN]; // previously typed bytes. static int typeaheadlen = 0; # ifdef VIMDLL *************** *** 1785,1802 **** return 0; # endif ! /* First use any typeahead that was kept because "buf" was too small. */ if (typeaheadlen > 0) goto theend; if (time >= 0) { ! if (!WaitForChar(time, FALSE)) /* no character available */ return 0; } ! else /* time == -1, wait forever */ { ! mch_set_winsize_now(); /* Allow winsize changes from now on */ /* * If there is no character available within 2 seconds (default) --- 1786,1803 ---- return 0; # endif ! // First use any typeahead that was kept because "buf" was too small. if (typeaheadlen > 0) goto theend; if (time >= 0) { ! if (!WaitForChar(time, FALSE)) // no character available return 0; } ! else // time == -1, wait forever { ! mch_set_winsize_now(); // Allow winsize changes from now on /* * If there is no character available within 2 seconds (default) *************** *** 1820,1826 **** * Try to read as many characters as there are, until the buffer is full. */ ! /* we will get at least one key. Get more if they are available. */ g_fCBrkPressed = FALSE; # ifdef MCH_WRITE_DUMP --- 1821,1827 ---- * Try to read as many characters as there are, until the buffer is full. */ ! // we will get at least one key. Get more if they are available. g_fCBrkPressed = FALSE; # ifdef MCH_WRITE_DUMP *************** *** 1828,1843 **** fputc('[', fdDump); # endif ! /* Keep looping until there is something in the typeahead buffer and more ! * to get and still room in the buffer (up to two bytes for a char and ! * three bytes for a modifier). */ while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) && typeaheadlen + 5 <= TYPEAHEADLEN) { if (typebuf_changed(tb_change_cnt)) { ! /* "buf" may be invalid now if a client put something in the ! * typeahead buffer and "buf" is in the typeahead buffer. */ typeaheadlen = 0; break; } --- 1829,1844 ---- fputc('[', fdDump); # endif ! // Keep looping until there is something in the typeahead buffer and more ! // to get and still room in the buffer (up to two bytes for a char and ! // three bytes for a modifier). while ((typeaheadlen == 0 || WaitForChar(0L, FALSE)) && typeaheadlen + 5 <= TYPEAHEADLEN) { if (typebuf_changed(tb_change_cnt)) { ! // "buf" may be invalid now if a client put something in the ! // typeahead buffer and "buf" is in the typeahead buffer. typeaheadlen = 0; break; } *************** *** 1864,1871 **** if (typebuf_changed(tb_change_cnt)) { ! /* "buf" may be invalid now if a client put something in the ! * typeahead buffer and "buf" is in the typeahead buffer. */ typeaheadlen = 0; break; } --- 1865,1872 ---- if (typebuf_changed(tb_change_cnt)) { ! // "buf" may be invalid now if a client put something in the ! // typeahead buffer and "buf" is in the typeahead buffer. typeaheadlen = 0; break; } *************** *** 1889,1895 **** WCHAR ch[2]; ch[0] = c; ! if (c >= 0xD800 && c <= 0xDBFF) /* High surrogate */ { ch[1] = tgetch(&modifiers, &ch2); n++; --- 1890,1896 ---- WCHAR ch[2]; ch[0] = c; ! if (c >= 0xD800 && c <= 0xDBFF) // High surrogate { ch[1] = tgetch(&modifiers, &ch2); n++; *************** *** 1933,1942 **** } } ! /* Use the ALT key to set the 8th bit of the character ! * when it's one byte, the 8th bit isn't set yet and not ! * using a double-byte encoding (would become a lead ! * byte). */ if ((modifiers & MOD_MASK_ALT) && n == 1 && (typeahead[typeaheadlen] & 0x80) == 0 --- 1934,1943 ---- } } ! // Use the ALT key to set the 8th bit of the character ! // when it's one byte, the 8th bit isn't set yet and not ! // using a double-byte encoding (would become a lead ! // byte). if ((modifiers & MOD_MASK_ALT) && n == 1 && (typeahead[typeaheadlen] & 0x80) == 0 *************** *** 1950,1956 **** if (modifiers != 0) { ! /* Prepend modifiers to the character. */ mch_memmove(typeahead + typeaheadlen + 3, typeahead + typeaheadlen, n); typeahead[typeaheadlen++] = K_SPECIAL; --- 1951,1957 ---- if (modifiers != 0) { ! // Prepend modifiers to the character. mch_memmove(typeahead + typeaheadlen + 3, typeahead + typeaheadlen, n); typeahead[typeaheadlen++] = K_SPECIAL; *************** *** 1977,1983 **** # endif theend: ! /* Move typeahead to "buf", as much as fits. */ len = 0; while (len < maxlen && typeaheadlen > 0) { --- 1978,1984 ---- # endif theend: ! // Move typeahead to "buf", as much as fits. len = 0; while (len < maxlen && typeaheadlen > 0) { *************** *** 1986,1999 **** } return len; ! #else /* FEAT_GUI_MSWIN */ return 0; ! #endif /* FEAT_GUI_MSWIN */ } #ifndef PROTO # ifndef __MINGW32__ ! # include /* required for FindExecutable() */ # endif #endif --- 1987,2000 ---- } return len; ! #else // FEAT_GUI_MSWIN return 0; ! #endif // FEAT_GUI_MSWIN } #ifndef PROTO # ifndef __MINGW32__ ! # include // required for FindExecutable() # endif #endif *************** *** 2092,2122 **** extern int _fmode; # endif ! /* Silently handle invalid parameters to CRT functions */ SET_INVALID_PARAM_HANDLER; ! /* Let critical errors result in a failure, not in a dialog box. Required ! * for the timestamp test to work on removed floppies. */ SetErrorMode(SEM_FAILCRITICALERRORS); ! _fmode = O_BINARY; /* we do our own CR-LF translation */ ! /* Specify window size. Is there a place to get the default from? */ Rows = 25; Columns = 80; ! /* Look for 'vimrun' */ { char_u vimrun_location[_MAX_PATH + 4]; ! /* First try in same directory as gvim.exe */ STRCPY(vimrun_location, exe_name); STRCPY(gettail(vimrun_location), "vimrun.exe"); if (mch_getperm(vimrun_location) >= 0) { if (*skiptowhite(vimrun_location) != NUL) { ! /* Enclose path with white space in double quotes. */ mch_memmove(vimrun_location + 1, vimrun_location, STRLEN(vimrun_location) + 1); *vimrun_location = '"'; --- 2093,2123 ---- extern int _fmode; # endif ! // Silently handle invalid parameters to CRT functions SET_INVALID_PARAM_HANDLER; ! // Let critical errors result in a failure, not in a dialog box. Required ! // for the timestamp test to work on removed floppies. SetErrorMode(SEM_FAILCRITICALERRORS); ! _fmode = O_BINARY; // we do our own CR-LF translation ! // Specify window size. Is there a place to get the default from? Rows = 25; Columns = 80; ! // Look for 'vimrun' { char_u vimrun_location[_MAX_PATH + 4]; ! // First try in same directory as gvim.exe STRCPY(vimrun_location, exe_name); STRCPY(gettail(vimrun_location), "vimrun.exe"); if (mch_getperm(vimrun_location) >= 0) { if (*skiptowhite(vimrun_location) != NUL) { ! // Enclose path with white space in double quotes. mch_memmove(vimrun_location + 1, vimrun_location, STRLEN(vimrun_location) + 1); *vimrun_location = '"'; *************** *** 2131,2139 **** else if (executable_exists("vimrun.exe", NULL, TRUE)) s_dont_use_vimrun = FALSE; ! /* Don't give the warning for a missing vimrun.exe right now, but only ! * when vimrun was supposed to be used. Don't bother people that do ! * not need vimrun.exe. */ if (s_dont_use_vimrun) need_vimrun_warning = TRUE; } --- 2132,2140 ---- else if (executable_exists("vimrun.exe", NULL, TRUE)) s_dont_use_vimrun = FALSE; ! // Don't give the warning for a missing vimrun.exe right now, but only ! // when vimrun was supposed to be used. Don't bother people that do ! // not need vimrun.exe. if (s_dont_use_vimrun) need_vimrun_warning = TRUE; } *************** *** 2153,2159 **** } ! #endif /* FEAT_GUI_MSWIN */ #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) --- 2154,2160 ---- } ! #endif // FEAT_GUI_MSWIN #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) *************** *** 2343,2353 **** */ ReadRegion.Top = Y; ReadRegion.Bottom = Y + Y_incr - 1; ! if (!ReadConsoleOutputW(g_hConOut, /* output handle */ ! cb->Buffer, /* our buffer */ ! cb->BufferSize, /* dimensions of our buffer */ ! BufferCoord, /* offset in our buffer */ ! &ReadRegion)) /* region to save */ { VIM_CLEAR(cb->Buffer); VIM_CLEAR(cb->Regions); --- 2344,2354 ---- */ ReadRegion.Top = Y; ReadRegion.Bottom = Y + Y_incr - 1; ! if (!ReadConsoleOutputW(g_hConOut, // output handle ! cb->Buffer, // our buffer ! cb->BufferSize, // dimensions of our buffer ! BufferCoord, // offset in our buffer ! &ReadRegion)) // region to save { VIM_CLEAR(cb->Buffer); VIM_CLEAR(cb->Regions); *************** *** 2417,2427 **** BufferCoord.X = cb->Regions[i].Left; BufferCoord.Y = cb->Regions[i].Top; WriteRegion = cb->Regions[i]; ! if (!WriteConsoleOutputW(g_hConOut, /* output handle */ ! cb->Buffer, /* our buffer */ ! cb->BufferSize, /* dimensions of our buffer */ ! BufferCoord, /* offset in our buffer */ ! &WriteRegion)) /* region to restore */ return FALSE; } } --- 2418,2428 ---- BufferCoord.X = cb->Regions[i].Left; BufferCoord.Y = cb->Regions[i].Top; WriteRegion = cb->Regions[i]; ! if (!WriteConsoleOutputW(g_hConOut, // output handle ! cb->Buffer, // our buffer ! cb->BufferSize, // dimensions of our buffer ! BufferCoord, // offset in our buffer ! &WriteRegion)) // region to restore return FALSE; } } *************** *** 2438,2450 **** # ifdef FEAT_TITLE char g_szOrigTitle[256] = { 0 }; ! HWND g_hWnd = NULL; /* also used in os_mswin.c */ static HICON g_hOrigIconSmall = NULL; static HICON g_hOrigIcon = NULL; static HICON g_hVimIcon = NULL; static BOOL g_fCanChangeIcon = FALSE; ! /* ICON* are not defined in VC++ 4.0 */ # ifndef ICON_SMALL # define ICON_SMALL 0 # endif --- 2439,2451 ---- # ifdef FEAT_TITLE char g_szOrigTitle[256] = { 0 }; ! HWND g_hWnd = NULL; // also used in os_mswin.c static HICON g_hOrigIconSmall = NULL; static HICON g_hOrigIcon = NULL; static HICON g_hVimIcon = NULL; static BOOL g_fCanChangeIcon = FALSE; ! // ICON* are not defined in VC++ 4.0 # ifndef ICON_SMALL # define ICON_SMALL 0 # endif *************** *** 2516,2522 **** static void SaveConsoleTitleAndIcon(void) { ! /* Save the original title. */ if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) return; --- 2517,2523 ---- static void SaveConsoleTitleAndIcon(void) { ! // Save the original title. if (!GetConsoleTitle(g_szOrigTitle, sizeof(g_szOrigTitle))) return; *************** *** 2531,2542 **** if (g_hWnd == NULL) return; ! /* Save the original console window icon. */ GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) return; ! /* Extract the first icon contained in the Vim executable. */ if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); if (g_hVimIcon != NULL) --- 2532,2543 ---- if (g_hWnd == NULL) return; ! // Save the original console window icon. GetConsoleIcon(g_hWnd, &g_hOrigIconSmall, &g_hOrigIcon); if (g_hOrigIconSmall == NULL || g_hOrigIcon == NULL) return; ! // Extract the first icon contained in the Vim executable. if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); if (g_hVimIcon != NULL) *************** *** 2563,2579 **** extern int _fmode; # endif ! /* Silently handle invalid parameters to CRT functions */ SET_INVALID_PARAM_HANDLER; ! /* Let critical errors result in a failure, not in a dialog box. Required ! * for the timestamp test to work on removed floppies. */ SetErrorMode(SEM_FAILCRITICALERRORS); ! _fmode = O_BINARY; /* we do our own CR-LF translation */ out_flush(); ! /* Obtain handles for the standard Console I/O devices */ if (read_cmd_fd == 0) g_hConIn = GetStdHandle(STD_INPUT_HANDLE); else --- 2564,2580 ---- extern int _fmode; # endif ! // Silently handle invalid parameters to CRT functions SET_INVALID_PARAM_HANDLER; ! // Let critical errors result in a failure, not in a dialog box. Required ! // for the timestamp test to work on removed floppies. SetErrorMode(SEM_FAILCRITICALERRORS); ! _fmode = O_BINARY; // we do our own CR-LF translation out_flush(); ! // Obtain handles for the standard Console I/O devices if (read_cmd_fd == 0) g_hConIn = GetStdHandle(STD_INPUT_HANDLE); else *************** *** 2581,2591 **** g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); # ifdef FEAT_RESTORE_ORIG_SCREEN ! /* Save the initial console buffer for later restoration */ SaveConsoleBuffer(&g_cbOrig); g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; # else ! /* Get current text attributes */ GetConsoleScreenBufferInfo(g_hConOut, &csbi); g_attrCurrent = g_attrDefault = csbi.wAttributes; # endif --- 2582,2592 ---- g_hConOut = GetStdHandle(STD_OUTPUT_HANDLE); # ifdef FEAT_RESTORE_ORIG_SCREEN ! // Save the initial console buffer for later restoration SaveConsoleBuffer(&g_cbOrig); g_attrCurrent = g_attrDefault = g_cbOrig.Info.wAttributes; # else ! // Get current text attributes GetConsoleScreenBufferInfo(g_hConOut, &csbi); g_attrCurrent = g_attrDefault = csbi.wAttributes; # endif *************** *** 2598,2604 **** g_color_index_fg = g_attrDefault & 0xf; g_color_index_bg = (g_attrDefault >> 4) & 0xf; ! /* set termcap codes to current text attributes */ update_tcap(g_attrCurrent); GetConsoleCursorInfo(g_hConOut, &g_cci); --- 2599,2605 ---- g_color_index_fg = g_attrDefault & 0xf; g_color_index_bg = (g_attrDefault >> 4) & 0xf; ! // set termcap codes to current text attributes update_tcap(g_attrCurrent); GetConsoleCursorInfo(g_hConOut, &g_cci); *************** *** 2659,2665 **** if (g_fWindInitCalled) settmode(TMODE_COOK); ! ml_close_all(TRUE); /* remove all memfiles */ if (g_fWindInitCalled) { --- 2660,2666 ---- if (g_fWindInitCalled) settmode(TMODE_COOK); ! ml_close_all(TRUE); // remove all memfiles if (g_fWindInitCalled) { *************** *** 2697,2703 **** exit(r); } ! #endif /* !FEAT_GUI_MSWIN */ void mch_init(void) --- 2698,2704 ---- exit(r); } ! #endif // !FEAT_GUI_MSWIN void mch_init(void) *************** *** 2740,2746 **** get_exe_name(); #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) ! return OK; /* GUI always has a tty */ #else # ifdef VIMDLL if (gui.in_use) --- 2741,2747 ---- get_exe_name(); #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) ! return OK; // GUI always has a tty #else # ifdef VIMDLL if (gui.in_use) *************** *** 2798,2804 **** char_u *s, int len) { ! WCHAR wszUserName[256 + 1]; /* UNLEN is 256 */ DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); if (GetUserNameW(wszUserName, &wcch)) --- 2799,2805 ---- char_u *s, int len) { ! WCHAR wszUserName[256 + 1]; // UNLEN is 256 DWORD wcch = sizeof(wszUserName) / sizeof(WCHAR); if (GetUserNameW(wszUserName, &wcch)) *************** *** 2977,2983 **** int f = win32_getattrs(name); if (f == -1) ! return FALSE; /* file does not exist at all */ return (f & FILE_ATTRIBUTE_HIDDEN) != 0; } --- 2978,2984 ---- int f = win32_getattrs(name); if (f == -1) ! return FALSE; // file does not exist at all return (f & FILE_ATTRIBUTE_HIDDEN) != 0; } *************** *** 2992,2998 **** int f = win32_getattrs(name); if (f == -1) ! return FALSE; /* file does not exist at all */ return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; } --- 2993,2999 ---- int f = win32_getattrs(name); if (f == -1) ! return FALSE; // file does not exist at all return (f & FILE_ATTRIBUTE_DIRECTORY) != 0; } *************** *** 3270,3276 **** { if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) { ! /* A single "." means no extension is added. */ buf[len] = NUL; ++p; if (*p) --- 3271,3277 ---- { if (p[0] == '.' && (p[1] == NUL || p[1] == ';')) { ! // A single "." means no extension is added. buf[len] = NUL; ++p; if (*p) *************** *** 3297,3305 **** int type; WCHAR *wn; ! /* We can't open a file with a name "\\.\con" or "\\.\prn" and trying to ! * read from it later will cause Vim to hang. Thus return NODE_WRITABLE ! * here. */ if (STRNCMP(name, "\\\\.\\", 4) == 0) return NODE_WRITABLE; --- 3298,3306 ---- int type; WCHAR *wn; ! // We can't open a file with a name "\\.\con" or "\\.\prn" and trying to ! // read from it later will cause Vim to hang. Thus return NODE_WRITABLE ! // here. if (STRNCMP(name, "\\\\.\\", 4) == 0) return NODE_WRITABLE; *************** *** 3507,3513 **** case CTRL_BREAK_EVENT: g_fCBrkPressed = TRUE; ctrl_break_was_pressed = TRUE; ! /* ReadConsoleInput is blocking, send a key event to continue. */ ir.EventType = KEY_EVENT; ir.Event.KeyEvent.bKeyDown = TRUE; ir.Event.KeyEvent.wRepeatCount = 1; --- 3508,3514 ---- case CTRL_BREAK_EVENT: g_fCBrkPressed = TRUE; ctrl_break_was_pressed = TRUE; ! // ReadConsoleInput is blocking, send a key event to continue. ir.EventType = KEY_EVENT; ir.Event.KeyEvent.bKeyDown = TRUE; ir.Event.KeyEvent.wRepeatCount = 1; *************** *** 3518,3524 **** WriteConsoleInput(g_hConIn, &ir, 1, &out); return TRUE; ! /* fatal events: shut down gracefully */ case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: --- 3519,3525 ---- WriteConsoleInput(g_hConIn, &ir, 1, &out); return TRUE; ! // fatal events: shut down gracefully case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: *************** *** 3535,3543 **** OutputDebugString(IObuff); # endif ! preserve_exit(); /* output IObuff, preserve files and exit */ ! return TRUE; /* not reached */ default: return FALSE; --- 3536,3544 ---- OutputDebugString(IObuff); # endif ! preserve_exit(); // output IObuff, preserve files and exit ! return TRUE; // not reached default: return FALSE; *************** *** 3569,3576 **** cmodein |= ENABLE_MOUSE_INPUT; cmodeout &= ~( # ifdef FEAT_TERMGUICOLORS ! /* Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using ! * VTP. */ ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | # else ENABLE_PROCESSED_OUTPUT | --- 3570,3577 ---- cmodein |= ENABLE_MOUSE_INPUT; cmodeout &= ~( # ifdef FEAT_TERMGUICOLORS ! // Do not turn off the ENABLE_PROCESSED_OUTPUT flag when using ! // VTP. ((vtp_working) ? 0 : ENABLE_PROCESSED_OUTPUT) | # else ENABLE_PROCESSED_OUTPUT | *************** *** 3578,3584 **** ENABLE_WRAP_AT_EOL_OUTPUT); bEnableHandler = TRUE; } ! else /* cooked */ { cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT); --- 3579,3585 ---- ENABLE_WRAP_AT_EOL_OUTPUT); bEnableHandler = TRUE; } ! else // cooked { cmodein |= (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT); *************** *** 3690,3697 **** int xSize, int ySize) { ! CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ ! SMALL_RECT srWindowRect; /* hold the new console size */ COORD coordScreen; COORD cursor; static int resized = FALSE; --- 3691,3698 ---- int xSize, int ySize) { ! CONSOLE_SCREEN_BUFFER_INFO csbi; // hold current console buffer info ! SMALL_RECT srWindowRect; // hold the new console size COORD coordScreen; COORD cursor; static int resized = FALSE; *************** *** 3704,3713 **** } # endif ! /* get the largest size we can size the console window to */ coordScreen = GetLargestConsoleWindowSize(hConsole); ! /* define the new console window size and scroll position */ srWindowRect.Left = srWindowRect.Top = (SHORT) 0; srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); --- 3705,3714 ---- } # endif ! // get the largest size we can size the console window to coordScreen = GetLargestConsoleWindowSize(hConsole); ! // define the new console window size and scroll position srWindowRect.Left = srWindowRect.Top = (SHORT) 0; srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); *************** *** 3772,3778 **** if (gui.in_use) return; # endif ! /* Don't change window size while still starting up */ if (suppress_winsize != 0) { suppress_winsize = 2; --- 3773,3779 ---- if (gui.in_use) return; # endif ! // Don't change window size while still starting up if (suppress_winsize != 0) { suppress_winsize = 2; *************** *** 3783,3789 **** { coordScreen = GetLargestConsoleWindowSize(g_hConOut); ! /* Clamp Rows and Columns to reasonable values */ if (Rows > coordScreen.Y) Rows = coordScreen.Y; if (Columns > coordScreen.X) --- 3784,3790 ---- { coordScreen = GetLargestConsoleWindowSize(g_hConOut); ! // Clamp Rows and Columns to reasonable values if (Rows > coordScreen.Y) Rows = coordScreen.Y; if (Columns > coordScreen.X) *************** *** 3821,3827 **** } suppress_winsize = 0; } ! #endif /* FEAT_GUI_MSWIN */ static BOOL vim_create_process( --- 3822,3828 ---- } suppress_winsize = 0; } ! #endif // FEAT_GUI_MSWIN static BOOL vim_create_process( *************** *** 3916,3932 **** si.cbReserved2 = 0; si.lpReserved2 = NULL; ! /* Now, run the command */ vim_create_process(cmd, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, &si, &pi, NULL, NULL); ! /* Wait for the command to terminate before continuing */ { # ifdef FEAT_GUI int delay = 1; ! /* Keep updating the window while waiting for the shell to finish. */ for (;;) { MSG msg; --- 3917,3933 ---- si.cbReserved2 = 0; si.lpReserved2 = NULL; ! // Now, run the command vim_create_process(cmd, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NEW_CONSOLE, &si, &pi, NULL, NULL); ! // Wait for the command to terminate before continuing { # ifdef FEAT_GUI int delay = 1; ! // Keep updating the window while waiting for the shell to finish. for (;;) { MSG msg; *************** *** 3941,3949 **** if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) break; ! /* We start waiting for a very short time and then increase it, so ! * that we respond quickly when the process is quick, and don't ! * consume too much overhead when it's slow. */ if (delay < 50) delay += 10; } --- 3942,3950 ---- if (WaitForSingleObject(pi.hProcess, delay) != WAIT_TIMEOUT) break; ! // We start waiting for a very short time and then increase it, so ! // that we respond quickly when the process is quick, and don't ! // consume too much overhead when it's slow. if (delay < 50) delay += 10; } *************** *** 3951,3965 **** WaitForSingleObject(pi.hProcess, INFINITE); # endif ! /* Get the command exit code */ GetExitCodeProcess(pi.hProcess, &ret); } ! /* Close the handles to the subprocess, so that it goes away */ CloseHandle(pi.hThread); CloseHandle(pi.hProcess); ! /* Try to get input focus back. Doesn't always work though. */ PostMessage(hwnd, WM_SETFOCUS, 0, 0); return ret; --- 3952,3966 ---- WaitForSingleObject(pi.hProcess, INFINITE); # endif ! // Get the command exit code GetExitCodeProcess(pi.hProcess, &ret); } ! // Close the handles to the subprocess, so that it goes away CloseHandle(pi.hThread); CloseHandle(pi.hProcess); ! // Try to get input focus back. Doesn't always work though. PostMessage(hwnd, WM_SETFOCUS, 0, 0); return ret; *************** *** 3988,3994 **** len = 0; else if (lp[written] == NL) { ! /* NL -> NUL translation */ WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); } else --- 3989,3995 ---- len = 0; else if (lp[written] == NL) { ! // NL -> NUL translation WriteFile(g_hChildStd_IN_Wr, "", 1, &len, NULL); } else *************** *** 4000,4007 **** } if (len == (int)l) { ! /* Finished a line, add a NL, unless this line should not have ! * one. */ if (lnum != curbuf->b_op_end.lnum || (!curbuf->b_p_bin && curbuf->b_p_fixeol) --- 4001,4008 ---- } if (len == (int)l) { ! // Finished a line, add a NL, unless this line should not have ! // one. if (lnum != curbuf->b_op_end.lnum || (!curbuf->b_p_bin && curbuf->b_p_fixeol) *************** *** 4024,4036 **** written += len; } ! /* finished all the lines, close pipe */ CloseHandle(g_hChildStd_IN_Wr); return 0; } ! # define BUFLEN 100 /* length for buffer, stolen from unix version */ /* * This function read from the children's stdout and write the --- 4025,4037 ---- written += len; } ! // finished all the lines, close pipe CloseHandle(g_hChildStd_IN_Wr); return 0; } ! # define BUFLEN 100 // length for buffer, stolen from unix version /* * This function read from the children's stdout and write the *************** *** 4050,4066 **** DWORD toRead; int repeatCount; ! /* we query the pipe to see if there is any data to read ! * to avoid to perform a blocking read */ ! ret = PeekNamedPipe(g_hChildStd_OUT_Rd, /* pipe to query */ ! NULL, /* optional buffer */ ! 0, /* buffer size */ ! NULL, /* number of read bytes */ ! &availableBytes, /* available bytes total */ ! NULL); /* byteLeft */ repeatCount = 0; ! /* We got real data in the pipe, read it */ while (ret != 0 && availableBytes > 0) { repeatCount++; --- 4051,4067 ---- DWORD toRead; int repeatCount; ! // we query the pipe to see if there is any data to read ! // to avoid to perform a blocking read ! ret = PeekNamedPipe(g_hChildStd_OUT_Rd, // pipe to query ! NULL, // optional buffer ! 0, // buffer size ! NULL, // number of read bytes ! &availableBytes, // available bytes total ! NULL); // byteLeft repeatCount = 0; ! // We got real data in the pipe, read it while (ret != 0 && availableBytes > 0) { repeatCount++; *************** *** 4068,4074 **** toRead = availableBytes < toRead ? availableBytes : toRead; ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); ! /* If we haven't read anything, there is a problem */ if (len == 0) break; --- 4069,4075 ---- toRead = availableBytes < toRead ? availableBytes : toRead; ReadFile(g_hChildStd_OUT_Rd, buffer + *buffer_off, toRead , &len, NULL); ! // If we haven't read anything, there is a problem if (len == 0) break; *************** *** 4076,4083 **** if (options & SHELL_READ) { ! /* Do NUL -> NL translation, append NL separated ! * lines to the current buffer. */ for (i = 0; i < len; ++i) { if (buffer[i] == NL) --- 4077,4084 ---- if (options & SHELL_READ) { ! // Do NUL -> NL translation, append NL separated ! // lines to the current buffer. for (i = 0; i < len; ++i) { if (buffer[i] == NL) *************** *** 4097,4116 **** len += *buffer_off; buffer[len] = NUL; ! /* Check if the last character in buffer[] is ! * incomplete, keep these bytes for the next ! * round. */ for (p = buffer; p < buffer + len; p += l) { l = MB_CPTR2LEN(p); if (l == 0) ! l = 1; /* NUL byte? */ else if (MB_BYTE2LEN(*p) != l) break; } ! if (p == buffer) /* no complete character */ { ! /* avoid getting stuck at an illegal byte */ if (len >= 12) ++p; else --- 4098,4117 ---- len += *buffer_off; buffer[len] = NUL; ! // Check if the last character in buffer[] is ! // incomplete, keep these bytes for the next ! // round. for (p = buffer; p < buffer + len; p += l) { l = MB_CPTR2LEN(p); if (l == 0) ! l = 1; // NUL byte? else if (MB_BYTE2LEN(*p) != l) break; } ! if (p == buffer) // no complete character { ! // avoid getting stuck at an illegal byte if (len >= 12) ++p; else *************** *** 4159,4192 **** HANDLE g_hChildStd_OUT_Rd = NULL; HANDLE g_hChildStd_OUT_Wr = NULL; ! char_u buffer[BUFLEN + 1]; /* reading buffer + size */ DWORD len; ! /* buffer used to receive keys */ ! char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ ! int ta_len = 0; /* valid bytes in ta_buf[] */ DWORD i; int c; int noread_cnt = 0; garray_T ga; int delay = 1; ! DWORD buffer_off = 0; /* valid bytes in buffer[] */ char *p = NULL; SECURITY_ATTRIBUTES saAttr; ! /* Set the bInheritHandle flag so pipe handles are inherited. */ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) ! /* Ensure the read handle to the pipe for STDOUT is not inherited. */ || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) ! /* Create a pipe for the child process's STDIN. */ || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) ! /* Ensure the write handle to the pipe for STDIN is not inherited. */ || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) { CloseHandle(g_hChildStd_IN_Rd); --- 4160,4193 ---- HANDLE g_hChildStd_OUT_Rd = NULL; HANDLE g_hChildStd_OUT_Wr = NULL; ! char_u buffer[BUFLEN + 1]; // reading buffer + size DWORD len; ! // buffer used to receive keys ! char_u ta_buf[BUFLEN + 1]; // TypeAHead ! int ta_len = 0; // valid bytes in ta_buf[] DWORD i; int c; int noread_cnt = 0; garray_T ga; int delay = 1; ! DWORD buffer_off = 0; // valid bytes in buffer[] char *p = NULL; SECURITY_ATTRIBUTES saAttr; ! // Set the bInheritHandle flag so pipe handles are inherited. saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) ! // Ensure the read handle to the pipe for STDOUT is not inherited. || ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) ! // Create a pipe for the child process's STDIN. || ! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0) ! // Ensure the write handle to the pipe for STDIN is not inherited. || ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) ) { CloseHandle(g_hChildStd_IN_Rd); *************** *** 4202,4208 **** si.lpTitle = NULL; si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; ! /* set-up our file redirection */ si.hStdError = g_hChildStd_OUT_Wr; si.hStdOutput = g_hChildStd_OUT_Wr; si.hStdInput = g_hChildStd_IN_Rd; --- 4203,4209 ---- si.lpTitle = NULL; si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; ! // set-up our file redirection si.hStdError = g_hChildStd_OUT_Wr; si.hStdOutput = g_hChildStd_OUT_Wr; si.hStdInput = g_hChildStd_IN_Rd; *************** *** 4222,4255 **** p = cmd; } ! /* Now, run the command. ! * About "Inherit handles" being TRUE: this command can be litigious, ! * handle inheritance was deactivated for pending temp file, but, if we ! * deactivate it, the pipes don't work for some reason. */ vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, &si, &pi, NULL, NULL); if (p != cmd) vim_free(p); ! /* Close our unused side of the pipes */ CloseHandle(g_hChildStd_IN_Rd); CloseHandle(g_hChildStd_OUT_Wr); if (options & SHELL_WRITE) { HANDLE thread = (HANDLE) ! _beginthreadex(NULL, /* security attributes */ ! 0, /* default stack size */ ! sub_process_writer, /* function to be executed */ ! g_hChildStd_IN_Wr, /* parameter */ ! 0, /* creation flag, start immediately */ ! NULL); /* we don't care about thread id */ CloseHandle(thread); g_hChildStd_IN_Wr = NULL; } ! /* Keep updating the window while waiting for the shell to finish. */ for (;;) { MSG msg; --- 4223,4256 ---- p = cmd; } ! // Now, run the command. ! // About "Inherit handles" being TRUE: this command can be litigious, ! // handle inheritance was deactivated for pending temp file, but, if we ! // deactivate it, the pipes don't work for some reason. vim_create_process(p, TRUE, CREATE_DEFAULT_ERROR_MODE, &si, &pi, NULL, NULL); if (p != cmd) vim_free(p); ! // Close our unused side of the pipes CloseHandle(g_hChildStd_IN_Rd); CloseHandle(g_hChildStd_OUT_Wr); if (options & SHELL_WRITE) { HANDLE thread = (HANDLE) ! _beginthreadex(NULL, // security attributes ! 0, // default stack size ! sub_process_writer, // function to be executed ! g_hChildStd_IN_Wr, // parameter ! 0, // creation flag, start immediately ! NULL); // we don't care about thread id CloseHandle(thread); g_hChildStd_IN_Wr = NULL; } ! // Keep updating the window while waiting for the shell to finish. for (;;) { MSG msg; *************** *** 4260,4266 **** pDispatchMessage(&msg); } ! /* write pipe information in the window */ if ((options & (SHELL_READ|SHELL_WRITE)) # ifdef FEAT_GUI || gui.in_use --- 4261,4267 ---- pDispatchMessage(&msg); } ! // write pipe information in the window if ((options & (SHELL_READ|SHELL_WRITE)) # ifdef FEAT_GUI || gui.in_use *************** *** 4280,4287 **** { if (ta_len == 0) { ! /* Get extra characters when we don't have any. Reset the ! * counter and timer. */ noread_cnt = 0; len = ui_inchar(ta_buf, BUFLEN, 10L, 0); } --- 4281,4288 ---- { if (ta_len == 0) { ! // Get extra characters when we don't have any. Reset the ! // counter and timer. noread_cnt = 0; len = ui_inchar(ta_buf, BUFLEN, 10L, 0); } *************** *** 4295,4302 **** { if (ta_buf[ta_len] == Ctrl_C) { ! /* Learn what exit code is expected, for ! * now put 9 as SIGKILL */ TerminateProcess(pi.hProcess, 9); } if (ta_buf[ta_len] == Ctrl_D) --- 4296,4303 ---- { if (ta_buf[ta_len] == Ctrl_C) { ! // Learn what exit code is expected, for ! // now put 9 as SIGKILL TerminateProcess(pi.hProcess, 9); } if (ta_buf[ta_len] == Ctrl_D) *************** *** 4306,4312 **** } } ! /* replace K_BS by and K_DEL by */ for (i = ta_len; i < ta_len + len; ++i) { if (ta_buf[i] == CSI && len - i > 2) --- 4307,4313 ---- } } ! // replace K_BS by and K_DEL by for (i = ta_len; i < ta_len + len; ++i) { if (ta_buf[i] == CSI && len - i > 2) *************** *** 4390,4410 **** ++noread_cnt; dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); ! /* We start waiting for a very short time and then increase it, so ! * that we respond quickly when the process is quick, and don't ! * consume too much overhead when it's slow. */ if (delay < 50) delay += 10; } ! /* Close the pipe */ CloseHandle(g_hChildStd_OUT_Rd); if (g_hChildStd_IN_Wr != NULL) CloseHandle(g_hChildStd_IN_Wr); WaitForSingleObject(pi.hProcess, INFINITE); ! /* Get the command exit code */ GetExitCodeProcess(pi.hProcess, &ret); if (options & SHELL_READ) --- 4391,4411 ---- ++noread_cnt; dump_pipe(options, g_hChildStd_OUT_Rd, &ga, buffer, &buffer_off); ! // We start waiting for a very short time and then increase it, so ! // that we respond quickly when the process is quick, and don't ! // consume too much overhead when it's slow. if (delay < 50) delay += 10; } ! // Close the pipe CloseHandle(g_hChildStd_OUT_Rd); if (g_hChildStd_IN_Wr != NULL) CloseHandle(g_hChildStd_IN_Wr); WaitForSingleObject(pi.hProcess, INFINITE); ! // Get the command exit code GetExitCodeProcess(pi.hProcess, &ret); if (options & SHELL_READ) *************** *** 4412,4418 **** if (ga.ga_len > 0) { append_ga_line(&ga); ! /* remember that the NL was missing */ curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; } else --- 4413,4419 ---- if (ga.ga_len > 0) { append_ga_line(&ga); ! // remember that the NL was missing curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; } else *************** *** 4420,4426 **** ga_clear(&ga); } ! /* Close the handles to the subprocess, so that it goes away */ CloseHandle(pi.hThread); CloseHandle(pi.hProcess); --- 4421,4427 ---- ga_clear(&ga); } ! // Close the handles to the subprocess, so that it goes away CloseHandle(pi.hThread); CloseHandle(pi.hProcess); *************** *** 4430,4436 **** static int mch_system_g(char *cmd, int options) { ! /* if we can pipe and the shelltemp option is off */ if (!p_stmp) return mch_system_piped(cmd, options); else --- 4431,4437 ---- static int mch_system_g(char *cmd, int options) { ! // if we can pipe and the shelltemp option is off if (!p_stmp) return mch_system_piped(cmd, options); else *************** *** 4495,4501 **** static int mch_call_shell_terminal( char_u *cmd, ! int options UNUSED) /* SHELL_*, see vim.h */ { jobopt_T opt; char_u *newcmd = NULL; --- 4496,4502 ---- static int mch_call_shell_terminal( char_u *cmd, ! int options UNUSED) // SHELL_*, see vim.h { jobopt_T opt; char_u *newcmd = NULL; *************** *** 4505,4511 **** buf_T *buf; job_T *job; aco_save_T aco; ! oparg_T oa; /* operator arguments */ if (cmd == NULL) cmdlen = STRLEN(p_sh) + 1; --- 4506,4512 ---- buf_T *buf; job_T *job; aco_save_T aco; ! oparg_T oa; // operator arguments if (cmd == NULL) cmdlen = STRLEN(p_sh) + 1; *************** *** 4540,4546 **** job = term_getjob(buf->b_term); ++job->jv_refcount; ! /* Find a window to make "buf" curbuf. */ aucmd_prepbuf(&aco, buf); clear_oparg(&oa); --- 4541,4547 ---- job = term_getjob(buf->b_term); ++job->jv_refcount; ! // Find a window to make "buf" curbuf. aucmd_prepbuf(&aco, buf); clear_oparg(&oa); *************** *** 4548,4555 **** { if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! /* If terminal_loop() returns OK we got a key that is handled ! * in Normal model. We don't do redrawing anyway. */ if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } --- 4549,4556 ---- { if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! // If terminal_loop() returns OK we got a key that is handled ! // in Normal model. We don't do redrawing anyway. if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } *************** *** 4561,4567 **** job_unref(job); ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); wait_return(TRUE); --- 4562,4568 ---- job_unref(job); ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); wait_return(TRUE); *************** *** 4578,4591 **** int mch_call_shell( char_u *cmd, ! int options) /* SHELL_*, see vim.h */ { int x = 0; int tmode = cur_tmode; #ifdef FEAT_TITLE WCHAR szShellTitle[512]; ! /* Change the title to reflect that we are in a subshell. */ if (GetConsoleTitleW(szShellTitle, sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) { --- 4579,4592 ---- int mch_call_shell( char_u *cmd, ! int options) // SHELL_*, see vim.h { int x = 0; int tmode = cur_tmode; #ifdef FEAT_TITLE WCHAR szShellTitle[512]; ! // Change the title to reflect that we are in a subshell. if (GetConsoleTitleW(szShellTitle, sizeof(szShellTitle)/sizeof(WCHAR) - 4) > 0) { *************** *** 4664,4670 **** signal(SIGABRT, SIG_IGN); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); /* set to normal mode */ if (cmd == NULL) { --- 4665,4671 ---- signal(SIGABRT, SIG_IGN); if (options & SHELL_COOKED) ! settmode(TMODE_COOK); // set to normal mode if (cmd == NULL) { *************** *** 4672,4683 **** } else { ! /* we use "command" or "cmd" to start the shell; slow but easy */ char_u *newcmd = NULL; char_u *cmdbase = cmd; long_u cmdlen; ! /* Skip a leading ", ( and "(. */ if (*cmdbase == '"' ) ++cmdbase; if (*cmdbase == '(') --- 4673,4684 ---- } else { ! // we use "command" or "cmd" to start the shell; slow but easy char_u *newcmd = NULL; char_u *cmdbase = cmd; long_u cmdlen; ! // Skip a leading ", ( and "(. if (*cmdbase == '"' ) ++cmdbase; if (*cmdbase == '(') *************** *** 4726,4733 **** si.hStdError = si.hStdInput; } ! /* Remove a trailing ", ) and )" if they have a match ! * at the start of the command. */ if (cmdbase > cmd) { p = cmdbase + STRLEN(cmdbase); --- 4727,4734 ---- si.hStdError = si.hStdInput; } ! // Remove a trailing ", ) and )" if they have a match ! // at the start of the command. if (cmdbase > cmd) { p = cmdbase + STRLEN(cmdbase); *************** *** 4760,4766 **** (char_u *)"|", '^', FALSE); if (subcmd != NULL) { ! /* make "cmd.exe /c arguments" */ cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; newcmd = alloc(cmdlen); if (newcmd != NULL) --- 4761,4767 ---- (char_u *)"|", '^', FALSE); if (subcmd != NULL) { ! // make "cmd.exe /c arguments" cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5; newcmd = alloc(cmdlen); if (newcmd != NULL) *************** *** 4799,4808 **** if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) { ! /* Close the handle to \\.\NUL created above. */ CloseHandle(si.hStdInput); } ! /* Close the handles to the subprocess, so that it goes away */ CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } --- 4800,4809 ---- if (si.dwFlags == STARTF_USESTDHANDLES && si.hStdInput != NULL) { ! // Close the handle to \\.\NUL created above. CloseHandle(si.hStdInput); } ! // Close the handles to the subprocess, so that it goes away CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } *************** *** 4871,4879 **** } if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); /* set to raw mode */ ! /* Print the return value, unless "vimrun" was used. */ if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent #if defined(FEAT_GUI_MSWIN) && ((gui.in_use || gui.starting) ? --- 4872,4880 ---- } if (tmode == TMODE_RAW) ! settmode(TMODE_RAW); // set to raw mode ! // Print the return value, unless "vimrun" was used. if (x != 0 && !(options & SHELL_SILENT) && !emsg_silent #if defined(FEAT_GUI_MSWIN) && ((gui.in_use || gui.starting) ? *************** *** 4938,4944 **** long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0; LPVOID base = GetEnvironmentStringsW(); ! /* for last \0 */ if (ga_grow(gap, 1) == FAIL) return; --- 4939,4945 ---- long_u todo = env != NULL ? env->dv_hashtab.ht_used : 0; LPVOID base = GetEnvironmentStringsW(); ! // for last \0 if (ga_grow(gap, 1) == FAIL) return; *************** *** 4946,4952 **** { WCHAR *p = (WCHAR*) base; ! /* for last \0 */ if (ga_grow(gap, 1) == FAIL) return; --- 4947,4953 ---- { WCHAR *p = (WCHAR*) base; ! // for last \0 if (ga_grow(gap, 1) == FAIL) return; *************** *** 5228,5235 **** if (!AssignProcessToJobObject(jo, pi.hProcess)) { ! /* if failing, switch the way to terminate ! * process with TerminateProcess. */ CloseHandle(jo); jo = NULL; } --- 5229,5236 ---- if (!AssignProcessToJobObject(jo, pi.hProcess)) { ! // if failing, switch the way to terminate ! // process with TerminateProcess. CloseHandle(jo); jo = NULL; } *************** *** 5373,5379 **** if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) { ! /* deadly signal */ if (job->jv_job_object != NULL) { if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe) --- 5374,5380 ---- if (STRCMP(how, "term") == 0 || STRCMP(how, "kill") == 0 || *how == NUL) { ! // deadly signal if (job->jv_job_object != NULL) { if (job->jv_channel != NULL && job->jv_channel->ch_anonymous_pipe) *************** *** 5523,5529 **** g_fTermcapMode = FALSE; } ! #endif /* FEAT_GUI_MSWIN */ #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) --- 5524,5530 ---- g_fTermcapMode = FALSE; } ! #endif // FEAT_GUI_MSWIN #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) *************** *** 5532,5538 **** char_u *s UNUSED, int len UNUSED) { ! /* never used */ } #else --- 5533,5539 ---- char_u *s UNUSED, int len UNUSED) { ! // never used } #else *************** *** 5960,5966 **** FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, coordOrigin, &dwDummy); ! Sleep(15); /* wait for 15 msec */ if (!USE_VTP) WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, coordOrigin, &dwDummy); --- 5961,5967 ---- FillConsoleOutputAttribute(g_hConOut, attrFlash, Rows * Columns, coordOrigin, &dwDummy); ! Sleep(15); // wait for 15 msec if (!USE_VTP) WriteConsoleOutputAttribute(g_hConOut, oldattrs, Rows * Columns, coordOrigin, &dwDummy); *************** *** 6077,6087 **** return; } ! /* translate ESC | sequences into faked bios calls */ while (len--) { ! /* optimization: use one single write_chars for runs of text, ! * rather than once per character It ain't curses, but it helps. */ DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); if (p_wd) --- 6078,6088 ---- return; } ! // translate ESC | sequences into faked bios calls while (len--) { ! // optimization: use one single write_chars for runs of text, ! // rather than once per character It ain't curses, but it helps. DWORD prefix = (DWORD)strcspn((char *)s, "\n\r\b\a\033"); if (p_wd) *************** *** 6109,6115 **** } else if (s[0] == '\n') { ! /* \n, newline: go to the beginning of the next line or scroll */ if (g_coord.Y == g_srScrollRegion.Bottom) { scroll(1); --- 6110,6116 ---- } else if (s[0] == '\n') { ! // \n, newline: go to the beginning of the next line or scroll if (g_coord.Y == g_srScrollRegion.Bottom) { scroll(1); *************** *** 6127,6133 **** } else if (s[0] == '\r') { ! /* \r, carriage return: go to beginning of line */ gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); # ifdef MCH_WRITE_DUMP if (fdDump) --- 6128,6134 ---- } else if (s[0] == '\r') { ! // \r, carriage return: go to beginning of line gotoxy(g_srScrollRegion.Left+1, g_coord.Y + 1); # ifdef MCH_WRITE_DUMP if (fdDump) *************** *** 6137,6143 **** } else if (s[0] == '\b') { ! /* \b, backspace: move cursor one position left */ if (g_coord.X > g_srScrollRegion.Left) g_coord.X--; else if (g_coord.Y > g_srScrollRegion.Top) --- 6138,6144 ---- } else if (s[0] == '\b') { ! // \b, backspace: move cursor one position left if (g_coord.X > g_srScrollRegion.Left) g_coord.X--; else if (g_coord.Y > g_srScrollRegion.Top) *************** *** 6154,6160 **** } else if (s[0] == '\a') { ! /* \a, bell */ MessageBeep(0xFFFFFFFF); # ifdef MCH_WRITE_DUMP if (fdDump) --- 6155,6161 ---- } else if (s[0] == '\a') { ! // \a, bell MessageBeep(0xFFFFFFFF); # ifdef MCH_WRITE_DUMP if (fdDump) *************** *** 6332,6338 **** } else { ! /* Write a single character */ DWORD nWritten; nWritten = write_chars(s, 1); --- 6333,6339 ---- } else { ! // Write a single character DWORD nWritten; nWritten = write_chars(s, 1); *************** *** 6356,6362 **** # endif } ! #endif /* FEAT_GUI_MSWIN */ /* --- 6357,6363 ---- # endif } ! #endif // FEAT_GUI_MSWIN /* *************** *** 6368,6379 **** int ignoreinput UNUSED) { #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) ! Sleep((int)msec); /* never wait for input */ ! #else /* Console */ # ifdef VIMDLL if (gui.in_use) { ! Sleep((int)msec); /* never wait for input */ return; } # endif --- 6369,6380 ---- int ignoreinput UNUSED) { #if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL) ! Sleep((int)msec); // never wait for input ! #else // Console # ifdef VIMDLL if (gui.in_use) { ! Sleep((int)msec); // never wait for input return; } # endif *************** *** 6383,6389 **** { int towait = p_mzq; ! /* if msec is large enough, wait by portions in p_mzq */ while (msec > 0) { mzvim_check_threads(); --- 6384,6390 ---- { int towait = p_mzq; ! // if msec is large enough, wait by portions in p_mzq while (msec > 0) { mzvim_check_threads(); *************** *** 6451,6457 **** #endif } ! /* physical RAM to leave for the OS */ #define WINNT_RESERVE_BYTES (256*1024*1024) /* --- 6452,6458 ---- #endif } ! // physical RAM to leave for the OS #define WINNT_RESERVE_BYTES (256*1024*1024) /* *************** *** 6462,6482 **** { MEMORYSTATUSEX ms; ! /* Need to use GlobalMemoryStatusEx() when there is more memory than ! * what fits in 32 bits. */ ms.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&ms); if (ms.ullAvailVirtual < ms.ullTotalPhys) { ! /* Process address space fits in physical RAM, use all of it. */ return (long_u)(ms.ullAvailVirtual / 1024); } if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES) { ! /* Catch old NT box or perverse hardware setup. */ return (long_u)((ms.ullTotalPhys / 2) / 1024); } ! /* Use physical RAM less reserve for OS + data. */ return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); } --- 6463,6483 ---- { MEMORYSTATUSEX ms; ! // Need to use GlobalMemoryStatusEx() when there is more memory than ! // what fits in 32 bits. ms.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&ms); if (ms.ullAvailVirtual < ms.ullTotalPhys) { ! // Process address space fits in physical RAM, use all of it. return (long_u)(ms.ullAvailVirtual / 1024); } if (ms.ullTotalPhys <= WINNT_RESERVE_BYTES) { ! // Catch old NT box or perverse hardware setup. return (long_u)((ms.ullTotalPhys / 2) / 1024); } ! // Use physical RAM less reserve for OS + data. return (long_u)((ms.ullTotalPhys - WINNT_RESERVE_BYTES) / 1024); } *************** *** 6610,6616 **** mch_access(char *n, int p) { HANDLE hFile; ! int retval = -1; /* default: fail */ WCHAR *wn; wn = enc_to_utf16((char_u *)n, NULL); --- 6611,6617 ---- mch_access(char *n, int p) { HANDLE hFile; ! int retval = -1; // default: fail WCHAR *wn; wn = enc_to_utf16((char_u *)n, NULL); *************** *** 6623,6630 **** if (p & R_OK) { ! /* Read check is performed by seeing if we can do a find file on ! * the directory for any file. */ int i; WIN32_FIND_DATAW d; --- 6624,6631 ---- if (p & R_OK) { ! // Read check is performed by seeing if we can do a find file on ! // the directory for any file. int i; WIN32_FIND_DATAW d; *************** *** 6644,6653 **** if (p & W_OK) { ! /* Trying to create a temporary file in the directory should catch ! * directories on read-only network shares. However, in ! * directories whose ACL allows writes but denies deletes will end ! * up keeping the temporary file :-(. */ if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) goto getout; else --- 6645,6654 ---- if (p & W_OK) { ! // Trying to create a temporary file in the directory should catch ! // directories on read-only network shares. However, in ! // directories whose ACL allows writes but denies deletes will end ! // up keeping the temporary file :-(. if (!GetTempFileNameW(wn, L"VIM", 0, TempNameW)) goto getout; else *************** *** 6659,6666 **** // Don't consider a file read-only if another process has opened it. DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; ! /* Trying to open the file for the required access does ACL, read-only ! * network share, and file attribute checks. */ DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) | ((p & R_OK) ? GENERIC_READ : 0); --- 6660,6667 ---- // Don't consider a file read-only if another process has opened it. DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; ! // Trying to open the file for the required access does ACL, read-only ! // network share, and file attribute checks. DWORD access_mode = ((p & W_OK) ? GENERIC_WRITE : 0) | ((p & R_OK) ? GENERIC_READ : 0); *************** *** 6671,6677 **** CloseHandle(hFile); } ! retval = 0; /* success */ getout: vim_free(wn); return retval; --- 6672,6678 ---- CloseHandle(hFile); } ! retval = 0; // success getout: vim_free(wn); return retval; *************** *** 6705,6712 **** FILE *f = NULL; #if defined(DEBUG) && _MSC_VER >= 1400 ! /* Work around an annoying assertion in the Microsoft debug CRT ! * when mode's text/binary setting doesn't match _get_fmode(). */ char newMode = mode[strlen(mode) - 1]; int oldMode = 0; --- 6706,6713 ---- FILE *f = NULL; #if defined(DEBUG) && _MSC_VER >= 1400 ! // Work around an annoying assertion in the Microsoft debug CRT ! // when mode's text/binary setting doesn't match _get_fmode(). char newMode = mode[strlen(mode) - 1]; int oldMode = 0; *************** *** 6770,6779 **** DWORD readcnt, written; char buf[4096]; ! /* Copy block of bytes at a time. Abort when something goes wrong. */ for (done = 0; done < len; done += written) { ! /* (size_t) cast for Borland C 5.5 */ todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) : (size_t)(len - done)); if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, --- 6771,6780 ---- DWORD readcnt, written; char buf[4096]; ! // Copy block of bytes at a time. Abort when something goes wrong. for (done = 0; done < len; done += written) { ! // (size_t) cast for Borland C 5.5 todo = (DWORD)((size_t)(len - done) > sizeof(buf) ? sizeof(buf) : (size_t)(len - done)); if (!BackupRead(sh, (LPBYTE)buf, todo, &readcnt, *************** *** 6806,6827 **** DWORD lo, hi; int len; ! /* Convert the file names to wide characters. */ fromw = enc_to_utf16(from, NULL); tow = enc_to_utf16(to, NULL); if (fromw != NULL && tow != NULL) { ! /* Open the file for reading. */ sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (sh != INVALID_HANDLE_VALUE) { ! /* Use BackupRead() to find the info streams. Repeat until we ! * have done them all.*/ for (;;) { ! /* Get the header to find the length of the stream name. If ! * the "readcount" is zero we have done all info streams. */ ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); if (!BackupRead(sh, (LPBYTE)&sid, headersize, --- 6807,6828 ---- DWORD lo, hi; int len; ! // Convert the file names to wide characters. fromw = enc_to_utf16(from, NULL); tow = enc_to_utf16(to, NULL); if (fromw != NULL && tow != NULL) { ! // Open the file for reading. sh = CreateFileW(fromw, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (sh != INVALID_HANDLE_VALUE) { ! // Use BackupRead() to find the info streams. Repeat until we ! // have done them all. for (;;) { ! // Get the header to find the length of the stream name. If ! // the "readcount" is zero we have done all info streams. ZeroMemory(&sid, sizeof(WIN32_STREAM_ID)); headersize = (int)((char *)&sid.cStreamName - (char *)&sid.dwStreamId); if (!BackupRead(sh, (LPBYTE)&sid, headersize, *************** *** 6829,6850 **** || readcount == 0) break; ! /* We only deal with streams that have a name. The normal ! * file data appears to be without a name, even though docs ! * suggest it is called "::$DATA". */ if (sid.dwStreamNameSize > 0) { ! /* Read the stream name. */ if (!BackupRead(sh, (LPBYTE)streamname, sid.dwStreamNameSize, &readcount, FALSE, FALSE, &context)) break; ! /* Copy an info stream with a name ":anything:$DATA". ! * Skip "::$DATA", it has no stream name (examples suggest ! * it might be used for the normal file contents). ! * Note that BackupRead() counts bytes, but the name is in ! * wide characters. */ len = readcount / sizeof(WCHAR); streamname[len] = 0; if (len > 7 && wcsicmp(streamname + len - 6, --- 6830,6851 ---- || readcount == 0) break; ! // We only deal with streams that have a name. The normal ! // file data appears to be without a name, even though docs ! // suggest it is called "::$DATA". if (sid.dwStreamNameSize > 0) { ! // Read the stream name. if (!BackupRead(sh, (LPBYTE)streamname, sid.dwStreamNameSize, &readcount, FALSE, FALSE, &context)) break; ! // Copy an info stream with a name ":anything:$DATA". ! // Skip "::$DATA", it has no stream name (examples suggest ! // it might be used for the normal file contents). ! // Note that BackupRead() counts bytes, but the name is in ! // wide characters. len = readcount / sizeof(WCHAR); streamname[len] = 0; if (len > 7 && wcsicmp(streamname + len - 6, *************** *** 6856,6869 **** } } ! /* Advance to the next stream. We might try seeking too far, ! * but BackupSeek() doesn't skip over stream borders, thus ! * that's OK. */ (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, &lo, &hi, &context); } ! /* Clear the context. */ (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); CloseHandle(sh); --- 6857,6870 ---- } } ! // Advance to the next stream. We might try seeking too far, ! // but BackupSeek() doesn't skip over stream borders, thus ! // that's OK. (void)BackupSeek(sh, sid.Size.u.LowPart, sid.Size.u.HighPart, &lo, &hi, &context); } ! // Clear the context. (void)BackupRead(sh, NULL, 0, &readcount, TRUE, FALSE, &context); CloseHandle(sh); *************** *** 6881,6887 **** int mch_copy_file_attribute(char_u *from, char_u *to) { ! /* File streams only work on Windows NT and later. */ copy_infostreams(from, to); return 0; } --- 6882,6888 ---- int mch_copy_file_attribute(char_u *from, char_u *to) { ! // File streams only work on Windows NT and later. copy_infostreams(from, to); return 0; } *************** *** 6892,6898 **** * Written by Benjamin Peterson. */ ! /* These magic numbers are from the MS header files */ # define MIN_STACK_WINNT 2 /* --- 6893,6899 ---- * Written by Benjamin Peterson. */ ! // These magic numbers are from the MS header files # define MIN_STACK_WINNT 2 /* *************** *** 6912,6937 **** DWORD nPageSize; DWORD dummy; ! /* We need to know the system page size. */ GetSystemInfo(&si); nPageSize = si.dwPageSize; ! /* ...and the current stack pointer */ pStackPtr = (BYTE*)_alloca(1); ! /* ...and the base of the stack. */ if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) return 0; pStackBase = (BYTE*)mbi.AllocationBase; ! /* ...and the page thats min_stack_req pages away from stack base; this is ! * the lowest page we could use. */ pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; { ! /* We want the first committed page in the stack Start at the stack ! * base and move forward through memory until we find a committed block. ! */ BYTE *pBlock = pStackBase; for (;;) --- 6913,6937 ---- DWORD nPageSize; DWORD dummy; ! // We need to know the system page size. GetSystemInfo(&si); nPageSize = si.dwPageSize; ! // ...and the current stack pointer pStackPtr = (BYTE*)_alloca(1); ! // ...and the base of the stack. if (VirtualQuery(pStackPtr, &mbi, sizeof mbi) == 0) return 0; pStackBase = (BYTE*)mbi.AllocationBase; ! // ...and the page thats min_stack_req pages away from stack base; this is ! // the lowest page we could use. pLowestPossiblePage = pStackBase + MIN_STACK_WINNT * nPageSize; { ! // We want the first committed page in the stack Start at the stack ! // base and move forward through memory until we find a committed block. BYTE *pBlock = pStackBase; for (;;) *************** *** 6945,6965 **** break; } ! /* mbi now describes the first committed block in the stack. */ if (mbi.Protect & PAGE_GUARD) return 1; ! /* decide where the guard page should start */ if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) pGuardPage = pLowestPossiblePage; else pGuardPage = (BYTE*)mbi.BaseAddress; ! /* allocate the guard page */ if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) return 0; ! /* apply the guard attribute to the page */ if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, &dummy)) return 0; --- 6945,6965 ---- break; } ! // mbi now describes the first committed block in the stack. if (mbi.Protect & PAGE_GUARD) return 1; ! // decide where the guard page should start if ((long_u)(mbi.BaseAddress) < (long_u)pLowestPossiblePage) pGuardPage = pLowestPossiblePage; else pGuardPage = (BYTE*)mbi.BaseAddress; ! // allocate the guard page if (!VirtualAlloc(pGuardPage, nPageSize, MEM_COMMIT, PAGE_READWRITE)) return 0; ! // apply the guard attribute to the page if (!VirtualProtect(pGuardPage, nPageSize, PAGE_READWRITE | PAGE_GUARD, &dummy)) return 0; *************** *** 6978,6992 **** static int global_argc = 0; static char **global_argv; ! static int used_file_argc = 0; /* last argument in global_argv[] used ! for the argument list. */ ! static int *used_file_indexes = NULL; /* indexes in global_argv[] for ! command line arguments added to ! the argument list */ ! static int used_file_count = 0; /* nr of entries in used_file_indexes */ ! static int used_file_literal = FALSE; /* take file names literally */ ! static int used_file_full_path = FALSE; /* file name was full path */ ! static int used_file_diff_mode = FALSE; /* file name was with diff mode */ static int used_alist_count = 0; --- 6978,6992 ---- static int global_argc = 0; static char **global_argv; ! static int used_file_argc = 0; // last argument in global_argv[] used ! // for the argument list. ! static int *used_file_indexes = NULL; // indexes in global_argv[] for ! // command line arguments added to ! // the argument list ! static int used_file_count = 0; // nr of entries in used_file_indexes ! static int used_file_literal = FALSE; // take file names literally ! static int used_file_full_path = FALSE; // file name was full path ! static int used_file_diff_mode = FALSE; // file name was with diff mode static int used_alist_count = 0; *************** *** 7014,7026 **** { int len; ! /* Convert each Unicode argument to the current codepage. */ WideCharToMultiByte_alloc(GetACP(), 0, ArglistW[i], (int)wcslen(ArglistW[i]) + 1, (LPSTR *)&argv[i], &len, 0, 0); if (argv[i] == NULL) { ! /* Out of memory, clear everything. */ while (i > 0) free(argv[--i]); free(argv); --- 7014,7026 ---- { int len; ! // Convert each Unicode argument to the current codepage. WideCharToMultiByte_alloc(GetACP(), 0, ArglistW[i], (int)wcslen(ArglistW[i]) + 1, (LPSTR *)&argv[i], &len, 0, 0); if (argv[i] == NULL) { ! // Out of memory, clear everything. while (i > 0) free(argv[--i]); free(argv); *************** *** 7102,7113 **** char_u *str; int *fnum_list; ! /* Safety checks: ! * - if argument count differs between the wide and non-wide argument ! * list, something must be wrong. ! * - the file name arguments must have been located. ! * - the length of the argument list wasn't changed by the user. ! */ if (global_argc != nArgsW || ArglistW == NULL || used_file_indexes == NULL --- 7102,7112 ---- char_u *str; int *fnum_list; ! // Safety checks: ! // - if argument count differs between the wide and non-wide argument ! // list, something must be wrong. ! // - the file name arguments must have been located. ! // - the length of the argument list wasn't changed by the user. if (global_argc != nArgsW || ArglistW == NULL || used_file_indexes == NULL *************** *** 7115,7131 **** || used_alist_count != GARGCOUNT) return; ! /* Remember the buffer numbers for the arguments. */ fnum_list = ALLOC_MULT(int, GARGCOUNT); if (fnum_list == NULL) ! return; /* out of memory */ for (i = 0; i < GARGCOUNT; ++i) fnum_list[i] = GARGLIST[i].ae_fnum; ! /* Clear the argument list. Make room for the new arguments. */ alist_clear(&global_alist); if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) ! return; /* out of memory */ for (i = 0; i < used_file_count; ++i) { --- 7114,7130 ---- || used_alist_count != GARGCOUNT) return; ! // Remember the buffer numbers for the arguments. fnum_list = ALLOC_MULT(int, GARGCOUNT); if (fnum_list == NULL) ! return; // out of memory for (i = 0; i < GARGCOUNT; ++i) fnum_list[i] = GARGLIST[i].ae_fnum; ! // Clear the argument list. Make room for the new arguments. alist_clear(&global_alist); if (ga_grow(&global_alist.al_ga, used_file_count) == FAIL) ! return; // out of memory for (i = 0; i < used_file_count; ++i) { *************** *** 7136,7143 **** int literal = used_file_literal; #ifdef FEAT_DIFF ! /* When using diff mode may need to concatenate file name to ! * directory name. Just like it's done in main(). */ if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 && !mch_isdir(alist_name(&GARGLIST[0]))) { --- 7135,7142 ---- int literal = used_file_literal; #ifdef FEAT_DIFF ! // When using diff mode may need to concatenate file name to ! // directory name. Just like it's done in main(). if (used_file_diff_mode && mch_isdir(str) && GARGCOUNT > 0 && !mch_isdir(alist_name(&GARGLIST[0]))) { *************** *** 7151,7163 **** } } #endif ! /* Re-use the old buffer by renaming it. When not using literal ! * names it's done by alist_expand() below. */ if (used_file_literal) buf_set_name(fnum_list[i], str); ! /* Check backtick literal. backtick literal is already expanded in ! * main.c, so this part add str as literal. */ if (literal == FALSE) { size_t len = STRLEN(str); --- 7150,7162 ---- } } #endif ! // Re-use the old buffer by renaming it. When not using literal ! // names it's done by alist_expand() below. if (used_file_literal) buf_set_name(fnum_list[i], str); ! // Check backtick literal. backtick literal is already expanded in ! // main.c, so this part add str as literal. if (literal == FALSE) { size_t len = STRLEN(str); *************** *** 7171,7183 **** if (!used_file_literal) { ! /* Now expand wildcards in the arguments. */ ! /* Temporarily add '(' and ')' to 'isfname'. These are valid ! * filename characters but are excluded from 'isfname' to make ! * "gf" work on a file name in parenthesis (e.g.: see vim.h). ! * Also, unset wildignore to not be influenced by this option. ! * The arguments specified in command-line should be kept even if ! * encoding options were changed. */ do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); alist_expand(fnum_list, used_alist_count); --- 7170,7182 ---- if (!used_file_literal) { ! // Now expand wildcards in the arguments. ! // Temporarily add '(' and ')' to 'isfname'. These are valid ! // filename characters but are excluded from 'isfname' to make ! // "gf" work on a file name in parenthesis (e.g.: see vim.h). ! // Also, unset wildignore to not be influenced by this option. ! // The arguments specified in command-line should be kept even if ! // encoding options were changed. do_cmdline_cmd((char_u *)":let SaVe_ISF = &isf|set isf+=(,)"); do_cmdline_cmd((char_u *)":let SaVe_WIG = &wig|set wig="); alist_expand(fnum_list, used_alist_count); *************** *** 7185,7192 **** do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); } ! /* If wildcard expansion failed, we are editing the first file of the ! * arglist and there is no file name: Edit the first argument now. */ if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) { do_cmdline_cmd((char_u *)":rewind"); --- 7184,7191 ---- do_cmdline_cmd((char_u *)":let &wig = SaVe_WIG|unlet SaVe_WIG"); } ! // If wildcard expansion failed, we are editing the first file of the ! // arglist and there is no file name: Edit the first argument now. if (curwin->w_arg_idx == 0 && curbuf->b_fname == NULL) { do_cmdline_cmd((char_u *)":rewind"); *************** *** 7306,7312 **** COLORREF fg, bg; # endif ! /* Use functions supported from Vista */ hKerneldll = GetModuleHandle("kernel32.dll"); if (hKerneldll != NULL) { --- 7305,7311 ---- COLORREF fg, bg; # endif ! // Use functions supported from Vista hKerneldll = GetModuleHandle("kernel32.dll"); if (hKerneldll != NULL) { *************** *** 7377,7383 **** int *args ) { ! /* 2('\033[') + 4('255.') * 16 + NUL */ char_u buf[2 + (4 * 16) + 1]; char_u *p; int i; --- 7376,7382 ---- int *args ) { ! // 2('\033[') + 4('255.') * 16 + NUL char_u buf[2 + (4 * 16) + 1]; char_u *p; int i; *** ../vim-8.1.2392/src/version.c 2019-12-05 20:12:37.843979529 +0100 --- src/version.c 2019-12-05 20:13:54.063723651 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2393, /**/ -- Press any key to continue, press any other key to quit. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///