comparison src/os_unix.c @ 18810:44b855153d8e v8.1.2393

patch 8.1.2393: using old C style comments Commit: https://github.com/vim/vim/commit/0f8737355d291679659579a48db1861b88970293 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 5 20:28:46 2019 +0100 patch 8.1.2393: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Thu, 05 Dec 2019 20:30:04 +0100
parents e3785af3ba0f
children 8dabdfc7c799
comparison
equal deleted inserted replaced
18809:8c6177fec9cb 18810:44b855153d8e
22 22
23 #ifdef FEAT_MZSCHEME 23 #ifdef FEAT_MZSCHEME
24 # include "if_mzsch.h" 24 # include "if_mzsch.h"
25 #endif 25 #endif
26 26
27 #include "os_unixx.h" /* unix includes for os_unix.c only */ 27 #include "os_unixx.h" // unix includes for os_unix.c only
28 28
29 #ifdef USE_XSMP 29 #ifdef USE_XSMP
30 # include <X11/SM/SMlib.h> 30 # include <X11/SM/SMlib.h>
31 #endif 31 #endif
32 32
49 #endif 49 #endif
50 50
51 #ifdef __CYGWIN__ 51 #ifdef __CYGWIN__
52 # ifndef MSWIN 52 # ifndef MSWIN
53 # include <cygwin/version.h> 53 # include <cygwin/version.h>
54 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or 54 # include <sys/cygwin.h> // for cygwin_conv_to_posix_path() and/or
55 * for cygwin_conv_path() */ 55 // for cygwin_conv_path()
56 # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD 56 # ifdef FEAT_CYGWIN_WIN32_CLIPBOARD
57 # define WIN32_LEAN_AND_MEAN 57 # define WIN32_LEAN_AND_MEAN
58 # include <windows.h> 58 # include <windows.h>
59 # include "winclip.pro" 59 # include "winclip.pro"
60 # endif 60 # endif
61 # endif 61 # endif
62 #endif 62 #endif
63 63
64 #ifdef FEAT_MOUSE_GPM 64 #ifdef FEAT_MOUSE_GPM
65 # include <gpm.h> 65 # include <gpm.h>
66 /* <linux/keyboard.h> contains defines conflicting with "keymap.h", 66 // <linux/keyboard.h> contains defines conflicting with "keymap.h",
67 * I just copied relevant defines here. A cleaner solution would be to put gpm 67 // I just copied relevant defines here. A cleaner solution would be to put gpm
68 * code into separate file and include there linux/keyboard.h 68 // code into separate file and include there linux/keyboard.h
69 */ 69 // #include <linux/keyboard.h>
70 /* #include <linux/keyboard.h> */
71 # define KG_SHIFT 0 70 # define KG_SHIFT 0
72 # define KG_CTRL 2 71 # define KG_CTRL 2
73 # define KG_ALT 3 72 # define KG_ALT 3
74 # define KG_ALTGR 1 73 # define KG_ALTGR 1
75 # define KG_SHIFTL 4 74 # define KG_SHIFTL 4
94 93
95 /* 94 /*
96 * end of autoconf section. To be extended... 95 * end of autoconf section. To be extended...
97 */ 96 */
98 97
99 /* Are the following #ifdefs still required? And why? Is that for X11? */ 98 // Are the following #ifdefs still required? And why? Is that for X11?
100 99
101 #if defined(ESIX) || defined(M_UNIX) && !defined(SCO) 100 #if defined(ESIX) || defined(M_UNIX) && !defined(SCO)
102 # ifdef SIGWINCH 101 # ifdef SIGWINCH
103 # undef SIGWINCH 102 # undef SIGWINCH
104 # endif 103 # endif
105 # ifdef TIOCGWINSZ 104 # ifdef TIOCGWINSZ
106 # undef TIOCGWINSZ 105 # undef TIOCGWINSZ
107 # endif 106 # endif
108 #endif 107 #endif
109 108
110 #if defined(SIGWINDOW) && !defined(SIGWINCH) /* hpux 9.01 has it */ 109 #if defined(SIGWINDOW) && !defined(SIGWINCH) // hpux 9.01 has it
111 # define SIGWINCH SIGWINDOW 110 # define SIGWINCH SIGWINDOW
112 #endif 111 #endif
113 112
114 #ifdef FEAT_X11 113 #ifdef FEAT_X11
115 # include <X11/Xlib.h> 114 # include <X11/Xlib.h>
155 static int RealWaitForChar(int, long, int *, int *interrupted); 154 static int RealWaitForChar(int, long, int *, int *interrupted);
156 #endif 155 #endif
157 156
158 #ifdef FEAT_XCLIPBOARD 157 #ifdef FEAT_XCLIPBOARD
159 static int do_xterm_trace(void); 158 static int do_xterm_trace(void);
160 # define XT_TRACE_DELAY 50 /* delay for xterm tracing */ 159 # define XT_TRACE_DELAY 50 // delay for xterm tracing
161 #endif 160 #endif
162 161
163 static void handle_resize(void); 162 static void handle_resize(void);
164 163
165 #if defined(SIGWINCH) 164 #if defined(SIGWINCH)
173 #endif 172 #endif
174 #if defined(SIGALRM) && defined(FEAT_X11) \ 173 #if defined(SIGALRM) && defined(FEAT_X11) \
175 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK) 174 && defined(FEAT_TITLE) && !defined(FEAT_GUI_GTK)
176 # define SET_SIG_ALARM 175 # define SET_SIG_ALARM
177 static RETSIGTYPE sig_alarm SIGPROTOARG; 176 static RETSIGTYPE sig_alarm SIGPROTOARG;
178 /* volatile because it is used in signal handler sig_alarm(). */ 177 // volatile because it is used in signal handler sig_alarm().
179 static volatile sig_atomic_t sig_alarm_called; 178 static volatile sig_atomic_t sig_alarm_called;
180 #endif 179 #endif
181 static RETSIGTYPE deathtrap SIGPROTOARG; 180 static RETSIGTYPE deathtrap SIGPROTOARG;
182 181
183 static void catch_int_signal(void); 182 static void catch_int_signal(void);
199 198
200 #ifndef SIG_ERR 199 #ifndef SIG_ERR
201 # define SIG_ERR ((RETSIGTYPE (*)())-1) 200 # define SIG_ERR ((RETSIGTYPE (*)())-1)
202 #endif 201 #endif
203 202
204 /* volatile because it is used in signal handler sig_winch(). */ 203 // volatile because it is used in signal handler sig_winch().
205 static volatile sig_atomic_t do_resize = FALSE; 204 static volatile sig_atomic_t do_resize = FALSE;
206 static char_u *extra_shell_arg = NULL; 205 static char_u *extra_shell_arg = NULL;
207 static int show_shell_mess = TRUE; 206 static int show_shell_mess = TRUE;
208 /* volatile because it is used in signal handler deathtrap(). */ 207 // volatile because it is used in signal handler deathtrap().
209 static volatile sig_atomic_t deadly_signal = 0; /* The signal we caught */ 208 static volatile sig_atomic_t deadly_signal = 0; // The signal we caught
210 /* volatile because it is used in signal handler deathtrap(). */ 209 // volatile because it is used in signal handler deathtrap().
211 static volatile sig_atomic_t in_mch_delay = FALSE; /* sleeping in mch_delay() */ 210 static volatile sig_atomic_t in_mch_delay = FALSE; // sleeping in mch_delay()
212 211
213 #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM) 212 #if defined(FEAT_JOB_CHANNEL) && !defined(USE_SYSTEM)
214 static int dont_check_job_ended = 0; 213 static int dont_check_job_ended = 0;
215 #endif 214 #endif
216 215
217 static int curr_tmode = TMODE_COOK; /* contains current terminal mode */ 216 static int curr_tmode = TMODE_COOK; // contains current terminal mode
218 217
219 #ifdef USE_XSMP 218 #ifdef USE_XSMP
220 typedef struct 219 typedef struct
221 { 220 {
222 SmcConn smcconn; /* The SM connection ID */ 221 SmcConn smcconn; // The SM connection ID
223 IceConn iceconn; /* The ICE connection ID */ 222 IceConn iceconn; // The ICE connection ID
224 char *clientid; /* The client ID for the current smc session */ 223 char *clientid; // The client ID for the current smc session
225 Bool save_yourself; /* If we're in the middle of a save_yourself */ 224 Bool save_yourself; // If we're in the middle of a save_yourself
226 Bool shutdown; /* If we're in shutdown mode */ 225 Bool shutdown; // If we're in shutdown mode
227 } xsmp_config_T; 226 } xsmp_config_T;
228 227
229 static xsmp_config_T xsmp; 228 static xsmp_config_T xsmp;
230 #endif 229 #endif
231 230
241 */ 240 */
242 #endif 241 #endif
243 242
244 static struct signalinfo 243 static struct signalinfo
245 { 244 {
246 int sig; /* Signal number, eg. SIGSEGV etc */ 245 int sig; // Signal number, eg. SIGSEGV etc
247 char *name; /* Signal name (not char_u!). */ 246 char *name; // Signal name (not char_u!).
248 char deadly; /* Catch as a deadly signal? */ 247 char deadly; // Catch as a deadly signal?
249 } signal_info[] = 248 } signal_info[] =
250 { 249 {
251 #ifdef SIGHUP 250 #ifdef SIGHUP
252 {SIGHUP, "HUP", TRUE}, 251 {SIGHUP, "HUP", TRUE},
253 #endif 252 #endif
271 #endif 270 #endif
272 #ifdef SIGBUS 271 #ifdef SIGBUS
273 {SIGBUS, "BUS", TRUE}, 272 {SIGBUS, "BUS", TRUE},
274 #endif 273 #endif
275 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME) 274 #if defined(SIGSEGV) && !defined(FEAT_MZSCHEME)
276 /* MzScheme uses SEGV in its garbage collector */ 275 // MzScheme uses SEGV in its garbage collector
277 {SIGSEGV, "SEGV", TRUE}, 276 {SIGSEGV, "SEGV", TRUE},
278 #endif 277 #endif
279 #ifdef SIGSYS 278 #ifdef SIGSYS
280 {SIGSYS, "SYS", TRUE}, 279 {SIGSYS, "SYS", TRUE},
281 #endif 280 #endif
282 #ifdef SIGALRM 281 #ifdef SIGALRM
283 {SIGALRM, "ALRM", FALSE}, /* Perl's alarm() can trigger it */ 282 {SIGALRM, "ALRM", FALSE}, // Perl's alarm() can trigger it
284 #endif 283 #endif
285 #ifdef SIGTERM 284 #ifdef SIGTERM
286 {SIGTERM, "TERM", TRUE}, 285 {SIGTERM, "TERM", TRUE},
287 #endif 286 #endif
288 #if defined(SIGVTALRM) && !defined(FEAT_RUBY) 287 #if defined(SIGVTALRM) && !defined(FEAT_RUBY)
289 {SIGVTALRM, "VTALRM", TRUE}, 288 {SIGVTALRM, "VTALRM", TRUE},
290 #endif 289 #endif
291 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING) 290 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME) && !defined(WE_ARE_PROFILING)
292 /* MzScheme uses SIGPROF for its own needs; On Linux with profiling 291 // MzScheme uses SIGPROF for its own needs; On Linux with profiling
293 * this makes Vim exit. WE_ARE_PROFILING is defined in Makefile. */ 292 // this makes Vim exit. WE_ARE_PROFILING is defined in Makefile.
294 {SIGPROF, "PROF", TRUE}, 293 {SIGPROF, "PROF", TRUE},
295 #endif 294 #endif
296 #ifdef SIGXCPU 295 #ifdef SIGXCPU
297 {SIGXCPU, "XCPU", TRUE}, 296 {SIGXCPU, "XCPU", TRUE},
298 #endif 297 #endif
301 #endif 300 #endif
302 #ifdef SIGUSR1 301 #ifdef SIGUSR1
303 {SIGUSR1, "USR1", TRUE}, 302 {SIGUSR1, "USR1", TRUE},
304 #endif 303 #endif
305 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) 304 #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE)
306 /* Used for sysmouse handling */ 305 // Used for sysmouse handling
307 {SIGUSR2, "USR2", TRUE}, 306 {SIGUSR2, "USR2", TRUE},
308 #endif 307 #endif
309 #ifdef SIGINT 308 #ifdef SIGINT
310 {SIGINT, "INT", FALSE}, 309 {SIGINT, "INT", FALSE},
311 #endif 310 #endif
335 # else 334 # else
336 return chdir(path); 335 return chdir(path);
337 # endif 336 # endif
338 } 337 }
339 338
340 /* Why is NeXT excluded here (and not in os_unixx.h)? */ 339 // Why is NeXT excluded here (and not in os_unixx.h)?
341 #if defined(ECHOE) && defined(ICANON) \ 340 #if defined(ECHOE) && defined(ICANON) \
342 && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) \ 341 && (defined(HAVE_TERMIO_H) || defined(HAVE_TERMIOS_H)) \
343 && !defined(__NeXT__) 342 && !defined(__NeXT__)
344 # define NEW_TTY_SYSTEM 343 # define NEW_TTY_SYSTEM
345 #endif 344 #endif
349 */ 348 */
350 void 349 void
351 mch_write(char_u *s, int len) 350 mch_write(char_u *s, int len)
352 { 351 {
353 vim_ignored = (int)write(1, (char *)s, len); 352 vim_ignored = (int)write(1, (char *)s, len);
354 if (p_wd) /* Unix is too fast, slow down a bit more */ 353 if (p_wd) // Unix is too fast, slow down a bit more
355 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL); 354 RealWaitForChar(read_cmd_fd, p_wd, NULL, NULL);
356 } 355 }
357 356
358 /* 357 /*
359 * Function passed to inchar_loop() to handle window resizing. 358 * Function passed to inchar_loop() to handle window resizing.
380 */ 379 */
381 int 380 int
382 mch_inchar( 381 mch_inchar(
383 char_u *buf, 382 char_u *buf,
384 int maxlen, 383 int maxlen,
385 long wtime, /* don't use "time", MIPS cannot handle it */ 384 long wtime, // don't use "time", MIPS cannot handle it
386 int tb_change_cnt) 385 int tb_change_cnt)
387 { 386 {
388 return inchar_loop(buf, maxlen, wtime, tb_change_cnt, 387 return inchar_loop(buf, maxlen, wtime, tb_change_cnt,
389 WaitForChar, resize_func); 388 WaitForChar, resize_func);
390 } 389 }
437 */ 436 */
438 long_u 437 long_u
439 mch_total_mem(int special UNUSED) 438 mch_total_mem(int special UNUSED)
440 { 439 {
441 long_u mem = 0; 440 long_u mem = 0;
442 long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */ 441 long_u shiftright = 10; // how much to shift "mem" right for Kbyte
443 442
444 # ifdef MACOS_X 443 # ifdef MACOS_X
445 { 444 {
446 /* Mac (Darwin) way of getting the amount of RAM available */ 445 // Mac (Darwin) way of getting the amount of RAM available
447 mach_port_t host = mach_host_self(); 446 mach_port_t host = mach_host_self();
448 kern_return_t kret; 447 kern_return_t kret;
449 # ifdef HOST_VM_INFO64 448 # ifdef HOST_VM_INFO64
450 struct vm_statistics64 vm_stat; 449 struct vm_statistics64 vm_stat;
451 natural_t count = HOST_VM_INFO64_COUNT; 450 natural_t count = HOST_VM_INFO64_COUNT;
458 457
459 kret = host_statistics(host, HOST_VM_INFO, 458 kret = host_statistics(host, HOST_VM_INFO,
460 (host_info_t)&vm_stat, &count); 459 (host_info_t)&vm_stat, &count);
461 # endif 460 # endif
462 if (kret == KERN_SUCCESS) 461 if (kret == KERN_SUCCESS)
463 /* get the amount of user memory by summing each usage */ 462 // get the amount of user memory by summing each usage
464 mem = (long_u)(vm_stat.free_count + vm_stat.active_count 463 mem = (long_u)(vm_stat.free_count + vm_stat.active_count
465 + vm_stat.inactive_count 464 + vm_stat.inactive_count
466 # ifdef MAC_OS_X_VERSION_10_9 465 # ifdef MAC_OS_X_VERSION_10_9
467 + vm_stat.compressor_page_count 466 + vm_stat.compressor_page_count
468 # endif 467 # endif
472 # endif 471 # endif
473 472
474 # ifdef HAVE_SYSCTL 473 # ifdef HAVE_SYSCTL
475 if (mem == 0) 474 if (mem == 0)
476 { 475 {
477 /* BSD way of getting the amount of RAM available. */ 476 // BSD way of getting the amount of RAM available.
478 int mib[2]; 477 int mib[2];
479 size_t len = sizeof(long_u); 478 size_t len = sizeof(long_u);
480 # ifdef HW_USERMEM64 479 # ifdef HW_USERMEM64
481 long_u physmem; 480 long_u physmem;
482 # else 481 # else
483 /* sysctl() may return 32 bit or 64 bit, accept both */ 482 // sysctl() may return 32 bit or 64 bit, accept both
484 union { 483 union {
485 int_u u32; 484 int_u u32;
486 long_u u64; 485 long_u u64;
487 } physmem; 486 } physmem;
488 # endif 487 # endif
510 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO) 509 # if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
511 if (mem == 0) 510 if (mem == 0)
512 { 511 {
513 struct sysinfo sinfo; 512 struct sysinfo sinfo;
514 513
515 /* Linux way of getting amount of RAM available */ 514 // Linux way of getting amount of RAM available
516 if (sysinfo(&sinfo) == 0) 515 if (sysinfo(&sinfo) == 0)
517 { 516 {
518 # ifdef HAVE_SYSINFO_MEM_UNIT 517 # ifdef HAVE_SYSINFO_MEM_UNIT
519 /* avoid overflow as much as possible */ 518 // avoid overflow as much as possible
520 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) 519 while (shiftright > 0 && (sinfo.mem_unit & 1) == 0)
521 { 520 {
522 sinfo.mem_unit = sinfo.mem_unit >> 1; 521 sinfo.mem_unit = sinfo.mem_unit >> 1;
523 --shiftright; 522 --shiftright;
524 } 523 }
533 # ifdef HAVE_SYSCONF 532 # ifdef HAVE_SYSCONF
534 if (mem == 0) 533 if (mem == 0)
535 { 534 {
536 long pagesize, pagecount; 535 long pagesize, pagecount;
537 536
538 /* Solaris way of getting amount of RAM available */ 537 // Solaris way of getting amount of RAM available
539 pagesize = sysconf(_SC_PAGESIZE); 538 pagesize = sysconf(_SC_PAGESIZE);
540 pagecount = sysconf(_SC_PHYS_PAGES); 539 pagecount = sysconf(_SC_PHYS_PAGES);
541 if (pagesize > 0 && pagecount > 0) 540 if (pagesize > 0 && pagecount > 0)
542 { 541 {
543 /* avoid overflow as much as possible */ 542 // avoid overflow as much as possible
544 while (shiftright > 0 && (pagesize & 1) == 0) 543 while (shiftright > 0 && (pagesize & 1) == 0)
545 { 544 {
546 pagesize = (long_u)pagesize >> 1; 545 pagesize = (long_u)pagesize >> 1;
547 --shiftright; 546 --shiftright;
548 } 547 }
549 mem = (long_u)pagesize * pagecount; 548 mem = (long_u)pagesize * pagecount;
550 } 549 }
551 } 550 }
552 # endif 551 # endif
553 552
554 /* Return the minimum of the physical memory and the user limit, because 553 // Return the minimum of the physical memory and the user limit, because
555 * using more than the user limit may cause Vim to be terminated. */ 554 // using more than the user limit may cause Vim to be terminated.
556 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) 555 # if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)
557 { 556 {
558 struct rlimit rlp; 557 struct rlimit rlp;
559 558
560 if (getrlimit(RLIMIT_DATA, &rlp) == 0 559 if (getrlimit(RLIMIT_DATA, &rlp) == 0
580 void 579 void
581 mch_delay(long msec, int ignoreinput) 580 mch_delay(long msec, int ignoreinput)
582 { 581 {
583 int old_tmode; 582 int old_tmode;
584 #ifdef FEAT_MZSCHEME 583 #ifdef FEAT_MZSCHEME
585 long total = msec; /* remember original value */ 584 long total = msec; // remember original value
586 #endif 585 #endif
587 586
588 if (ignoreinput) 587 if (ignoreinput)
589 { 588 {
590 /* Go to cooked mode without echo, to allow SIGINT interrupting us 589 // Go to cooked mode without echo, to allow SIGINT interrupting us
591 * here. But we don't want QUIT to kill us (CTRL-\ used in a 590 // here. But we don't want QUIT to kill us (CTRL-\ used in a
592 * shell may produce SIGQUIT). */ 591 // shell may produce SIGQUIT).
593 in_mch_delay = TRUE; 592 in_mch_delay = TRUE;
594 old_tmode = curr_tmode; 593 old_tmode = curr_tmode;
595 if (curr_tmode == TMODE_RAW) 594 if (curr_tmode == TMODE_RAW)
596 settmode(TMODE_SLEEP); 595 settmode(TMODE_SLEEP);
597 596
601 * one second. 600 * one second.
602 */ 601 */
603 #ifdef FEAT_MZSCHEME 602 #ifdef FEAT_MZSCHEME
604 do 603 do
605 { 604 {
606 /* if total is large enough, wait by portions in p_mzq */ 605 // if total is large enough, wait by portions in p_mzq
607 if (total > p_mzq) 606 if (total > p_mzq)
608 msec = p_mzq; 607 msec = p_mzq;
609 else 608 else
610 msec = total; 609 msec = total;
611 total -= msec; 610 total -= msec;
639 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get 638 * NOTE: Solaris 2.6 has a bug that makes select() hang here. Get
640 * a patch from Sun to fix this. Reported by Gunnar Pedersen. 639 * a patch from Sun to fix this. Reported by Gunnar Pedersen.
641 */ 640 */
642 select(0, NULL, NULL, NULL, &tv); 641 select(0, NULL, NULL, NULL, &tv);
643 } 642 }
644 # endif /* HAVE_SELECT */ 643 # endif // HAVE_SELECT
645 # endif /* HAVE_NANOSLEEP */ 644 # endif // HAVE_NANOSLEEP
646 #endif /* HAVE_USLEEP */ 645 #endif // HAVE_USLEEP
647 #ifdef FEAT_MZSCHEME 646 #ifdef FEAT_MZSCHEME
648 } 647 }
649 while (total > 0); 648 while (total > 0);
650 #endif 649 #endif
651 650
700 { 699 {
701 struct rlimit rlp; 700 struct rlimit rlp;
702 int i; 701 int i;
703 long lim; 702 long lim;
704 703
705 /* Set the stack limit to 15/16 of the allowable size. Skip this when the 704 // Set the stack limit to 15/16 of the allowable size. Skip this when the
706 * limit doesn't fit in a long (rlim_cur might be "long long"). */ 705 // limit doesn't fit in a long (rlim_cur might be "long long").
707 if (getrlimit(RLIMIT_STACK, &rlp) == 0 706 if (getrlimit(RLIMIT_STACK, &rlp) == 0
708 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1)) 707 && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1))
709 # ifdef RLIM_INFINITY 708 # ifdef RLIM_INFINITY
710 && rlp.rlim_cur != RLIM_INFINITY 709 && rlp.rlim_cur != RLIM_INFINITY
711 # endif 710 # endif
715 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H) 714 #if defined(_THREAD_SAFE) && defined(HAVE_PTHREAD_NP_H)
716 { 715 {
717 pthread_attr_t attr; 716 pthread_attr_t attr;
718 size_t size; 717 size_t size;
719 718
720 /* On FreeBSD the initial thread always has a fixed stack size, no 719 // On FreeBSD the initial thread always has a fixed stack size, no
721 * matter what the limits are set to. Normally it's 1 Mbyte. */ 720 // matter what the limits are set to. Normally it's 1 Mbyte.
722 pthread_attr_init(&attr); 721 pthread_attr_init(&attr);
723 if (pthread_attr_get_np(pthread_self(), &attr) == 0) 722 if (pthread_attr_get_np(pthread_self(), &attr) == 0)
724 { 723 {
725 pthread_attr_getstacksize(&attr, &size); 724 pthread_attr_getstacksize(&attr, &size);
726 if (lim > (long)size) 725 if (lim > (long)size)
731 #endif 730 #endif
732 if (stack_grows_downwards) 731 if (stack_grows_downwards)
733 { 732 {
734 stack_limit = (char *)((long)&i - (lim / 16L * 15L)); 733 stack_limit = (char *)((long)&i - (lim / 16L * 15L));
735 if (stack_limit >= (char *)&i) 734 if (stack_limit >= (char *)&i)
736 /* overflow, set to 1/16 of current stack position */ 735 // overflow, set to 1/16 of current stack position
737 stack_limit = (char *)((long)&i / 16L); 736 stack_limit = (char *)((long)&i / 16L);
738 } 737 }
739 else 738 else
740 { 739 {
741 stack_limit = (char *)((long)&i + (lim / 16L * 15L)); 740 stack_limit = (char *)((long)&i + (lim / 16L * 15L));
742 if (stack_limit <= (char *)&i) 741 if (stack_limit <= (char *)&i)
743 stack_limit = NULL; /* overflow */ 742 stack_limit = NULL; // overflow
744 } 743 }
745 } 744 }
746 } 745 }
747 746
748 /* 747 /*
773 * signal handler then must run on another stack, since the normal stack is 772 * signal handler then must run on another stack, since the normal stack is
774 * completely full. 773 * completely full.
775 */ 774 */
776 775
777 #ifndef SIGSTKSZ 776 #ifndef SIGSTKSZ
778 # define SIGSTKSZ 8000 /* just a guess of how much stack is needed... */ 777 # define SIGSTKSZ 8000 // just a guess of how much stack is needed...
779 #endif 778 #endif
780 779
781 # ifdef HAVE_SIGALTSTACK 780 # ifdef HAVE_SIGALTSTACK
782 static stack_t sigstk; /* for sigaltstack() */ 781 static stack_t sigstk; // for sigaltstack()
783 # else 782 # else
784 static struct sigstack sigstk; /* for sigstack() */ 783 static struct sigstack sigstk; // for sigstack()
785 # endif 784 # endif
786 785
787 static char *signal_stack; 786 static char *signal_stack;
788 787
789 static void 788 static void
818 */ 817 */
819 #if defined(SIGWINCH) 818 #if defined(SIGWINCH)
820 static RETSIGTYPE 819 static RETSIGTYPE
821 sig_winch SIGDEFARG(sigarg) 820 sig_winch SIGDEFARG(sigarg)
822 { 821 {
823 /* this is not required on all systems, but it doesn't hurt anybody */ 822 // this is not required on all systems, but it doesn't hurt anybody
824 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); 823 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch);
825 do_resize = TRUE; 824 do_resize = TRUE;
826 SIGRETURN; 825 SIGRETURN;
827 } 826 }
828 #endif 827 #endif
829 828
830 #if defined(SIGINT) 829 #if defined(SIGINT)
831 static RETSIGTYPE 830 static RETSIGTYPE
832 catch_sigint SIGDEFARG(sigarg) 831 catch_sigint SIGDEFARG(sigarg)
833 { 832 {
834 /* this is not required on all systems, but it doesn't hurt anybody */ 833 // this is not required on all systems, but it doesn't hurt anybody
835 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint); 834 signal(SIGINT, (RETSIGTYPE (*)())catch_sigint);
836 got_int = TRUE; 835 got_int = TRUE;
837 SIGRETURN; 836 SIGRETURN;
838 } 837 }
839 #endif 838 #endif
840 839
841 #if defined(SIGPWR) 840 #if defined(SIGPWR)
842 static RETSIGTYPE 841 static RETSIGTYPE
843 catch_sigpwr SIGDEFARG(sigarg) 842 catch_sigpwr SIGDEFARG(sigarg)
844 { 843 {
845 /* this is not required on all systems, but it doesn't hurt anybody */ 844 // this is not required on all systems, but it doesn't hurt anybody
846 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); 845 signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr);
847 /* 846 /*
848 * I'm not sure we get the SIGPWR signal when the system is really going 847 * I'm not sure we get the SIGPWR signal when the system is really going
849 * down or when the batteries are almost empty. Just preserve the swap 848 * down or when the batteries are almost empty. Just preserve the swap
850 * files and don't exit, that can't do any harm. 849 * files and don't exit, that can't do any harm.
859 * signal function for alarm(). 858 * signal function for alarm().
860 */ 859 */
861 static RETSIGTYPE 860 static RETSIGTYPE
862 sig_alarm SIGDEFARG(sigarg) 861 sig_alarm SIGDEFARG(sigarg)
863 { 862 {
864 /* doesn't do anything, just to break a system call */ 863 // doesn't do anything, just to break a system call
865 sig_alarm_called = TRUE; 864 sig_alarm_called = TRUE;
866 SIGRETURN; 865 SIGRETURN;
867 } 866 }
868 #endif 867 #endif
869 868
942 * a deadlock. 941 * a deadlock.
943 */ 942 */
944 static RETSIGTYPE 943 static RETSIGTYPE
945 deathtrap SIGDEFARG(sigarg) 944 deathtrap SIGDEFARG(sigarg)
946 { 945 {
947 static int entered = 0; /* count the number of times we got here. 946 static int entered = 0; // count the number of times we got here.
948 Note: when memory has been corrupted 947 // Note: when memory has been corrupted
949 this may get an arbitrary value! */ 948 // this may get an arbitrary value!
950 #ifdef SIGHASARG 949 #ifdef SIGHASARG
951 int i; 950 int i;
952 #endif 951 #endif
953 952
954 #if defined(USING_SETJMP) 953 #if defined(USING_SETJMP)
960 if (lc_active) 959 if (lc_active)
961 { 960 {
962 # if defined(SIGHASARG) 961 # if defined(SIGHASARG)
963 lc_signal = sigarg; 962 lc_signal = sigarg;
964 # endif 963 # endif
965 lc_active = FALSE; /* don't jump again */ 964 lc_active = FALSE; // don't jump again
966 LONGJMP(lc_jump_env, 1); 965 LONGJMP(lc_jump_env, 1);
967 /* NOTREACHED */ 966 // NOTREACHED
968 } 967 }
969 #endif 968 #endif
970 969
971 #ifdef SIGHASARG 970 #ifdef SIGHASARG
972 # ifdef SIGQUIT 971 # ifdef SIGQUIT
973 /* While in mch_delay() we go to cooked mode to allow a CTRL-C to 972 // While in mch_delay() we go to cooked mode to allow a CTRL-C to
974 * interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when 973 // interrupt us. But in cooked mode we may also get SIGQUIT, e.g., when
975 * pressing CTRL-\, but we don't want Vim to exit then. */ 974 // pressing CTRL-\, but we don't want Vim to exit then.
976 if (in_mch_delay && sigarg == SIGQUIT) 975 if (in_mch_delay && sigarg == SIGQUIT)
977 SIGRETURN; 976 SIGRETURN;
978 # endif 977 # endif
979 978
980 /* When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return 979 // When SIGHUP, SIGQUIT, etc. are blocked: postpone the effect and return
981 * here. This avoids that a non-reentrant function is interrupted, e.g., 980 // here. This avoids that a non-reentrant function is interrupted, e.g.,
982 * free(). Calling free() again may then cause a crash. */ 981 // free(). Calling free() again may then cause a crash.
983 if (entered == 0 982 if (entered == 0
984 && (0 983 && (0
985 # ifdef SIGHUP 984 # ifdef SIGHUP
986 || sigarg == SIGHUP 985 || sigarg == SIGHUP
987 # endif 986 # endif
1003 ) 1002 )
1004 && !vim_handle_signal(sigarg)) 1003 && !vim_handle_signal(sigarg))
1005 SIGRETURN; 1004 SIGRETURN;
1006 #endif 1005 #endif
1007 1006
1008 /* Remember how often we have been called. */ 1007 // Remember how often we have been called.
1009 ++entered; 1008 ++entered;
1010 1009
1011 /* Executing autocommands is likely to use more stack space than we have 1010 // Executing autocommands is likely to use more stack space than we have
1012 * available in the signal stack. */ 1011 // available in the signal stack.
1013 block_autocmds(); 1012 block_autocmds();
1014 1013
1015 #ifdef FEAT_EVAL 1014 #ifdef FEAT_EVAL
1016 /* Set the v:dying variable. */ 1015 // Set the v:dying variable.
1017 set_vim_var_nr(VV_DYING, (long)entered); 1016 set_vim_var_nr(VV_DYING, (long)entered);
1018 #endif 1017 #endif
1019 v_dying = entered; 1018 v_dying = entered;
1020 1019
1021 #ifdef HAVE_STACK_LIMIT 1020 #ifdef HAVE_STACK_LIMIT
1022 /* Since we are now using the signal stack, need to reset the stack 1021 // Since we are now using the signal stack, need to reset the stack
1023 * limit. Otherwise using a regexp will fail. */ 1022 // limit. Otherwise using a regexp will fail.
1024 get_stack_limit(); 1023 get_stack_limit();
1025 #endif 1024 #endif
1026 1025
1027 #if 0 1026 #if 0
1028 /* This is for opening gdb the moment Vim crashes. 1027 // This is for opening gdb the moment Vim crashes.
1029 * You need to manually adjust the file name and Vim executable name. 1028 // You need to manually adjust the file name and Vim executable name.
1030 * Suggested by SungHyun Nam. */ 1029 // Suggested by SungHyun Nam.
1031 { 1030 {
1032 # define VI_GDB_FILE "/tmp/vimgdb" 1031 # define VI_GDB_FILE "/tmp/vimgdb"
1033 # define VIM_NAME "/usr/bin/vim" 1032 # define VIM_NAME "/usr/bin/vim"
1034 FILE *fp = fopen(VI_GDB_FILE, "w"); 1033 FILE *fp = fopen(VI_GDB_FILE, "w");
1035 if (fp) 1034 if (fp)
1046 } 1045 }
1047 } 1046 }
1048 #endif 1047 #endif
1049 1048
1050 #ifdef SIGHASARG 1049 #ifdef SIGHASARG
1051 /* try to find the name of this signal */ 1050 // try to find the name of this signal
1052 for (i = 0; signal_info[i].sig != -1; i++) 1051 for (i = 0; signal_info[i].sig != -1; i++)
1053 if (sigarg == signal_info[i].sig) 1052 if (sigarg == signal_info[i].sig)
1054 break; 1053 break;
1055 deadly_signal = sigarg; 1054 deadly_signal = sigarg;
1056 #endif 1055 #endif
1057 1056
1058 full_screen = FALSE; /* don't write message to the GUI, it might be 1057 full_screen = FALSE; // don't write message to the GUI, it might be
1059 * part of the problem... */ 1058 // part of the problem...
1060 /* 1059 /*
1061 * If something goes wrong after entering here, we may get here again. 1060 * If something goes wrong after entering here, we may get here again.
1062 * When this happens, give a message and try to exit nicely (resetting the 1061 * When this happens, give a message and try to exit nicely (resetting the
1063 * terminal mode, etc.) 1062 * terminal mode, etc.)
1064 * When this happens twice, just exit, don't even try to give a message, 1063 * When this happens twice, just exit, don't even try to give a message,
1066 * When this still happens again (or memory was corrupted in such a way 1065 * When this still happens again (or memory was corrupted in such a way
1067 * that "entered" was clobbered) use _exit(), don't try freeing resources. 1066 * that "entered" was clobbered) use _exit(), don't try freeing resources.
1068 */ 1067 */
1069 if (entered >= 3) 1068 if (entered >= 3)
1070 { 1069 {
1071 reset_signals(); /* don't catch any signals anymore */ 1070 reset_signals(); // don't catch any signals anymore
1072 may_core_dump(); 1071 may_core_dump();
1073 if (entered >= 4) 1072 if (entered >= 4)
1074 _exit(8); 1073 _exit(8);
1075 exit(7); 1074 exit(7);
1076 } 1075 }
1077 if (entered == 2) 1076 if (entered == 2)
1078 { 1077 {
1079 /* No translation, it may call malloc(). */ 1078 // No translation, it may call malloc().
1080 OUT_STR("Vim: Double signal, exiting\n"); 1079 OUT_STR("Vim: Double signal, exiting\n");
1081 out_flush(); 1080 out_flush();
1082 getout(1); 1081 getout(1);
1083 } 1082 }
1084 1083
1085 /* No translation, it may call malloc(). */ 1084 // No translation, it may call malloc().
1086 #ifdef SIGHASARG 1085 #ifdef SIGHASARG
1087 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n", 1086 sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n",
1088 signal_info[i].name); 1087 signal_info[i].name);
1089 #else 1088 #else
1090 sprintf((char *)IObuff, "Vim: Caught deadly signal\n"); 1089 sprintf((char *)IObuff, "Vim: Caught deadly signal\n");
1091 #endif 1090 #endif
1092 1091
1093 /* Preserve files and exit. This sets the really_exiting flag to prevent 1092 // Preserve files and exit. This sets the really_exiting flag to prevent
1094 * calling free(). */ 1093 // calling free().
1095 preserve_exit(); 1094 preserve_exit();
1096 1095
1097 /* NOTREACHED */ 1096 // NOTREACHED
1098 1097
1099 #ifdef NBDEBUG 1098 #ifdef NBDEBUG
1100 reset_signals(); 1099 reset_signals();
1101 may_core_dump(); 1100 may_core_dump();
1102 abort(); 1101 abort();
1236 * otherwise fake it by starting a new shell. 1235 * otherwise fake it by starting a new shell.
1237 */ 1236 */
1238 void 1237 void
1239 mch_suspend(void) 1238 mch_suspend(void)
1240 { 1239 {
1241 /* BeOS does have SIGTSTP, but it doesn't work. */ 1240 // BeOS does have SIGTSTP, but it doesn't work.
1242 #if defined(SIGTSTP) && !defined(__BEOS__) 1241 #if defined(SIGTSTP) && !defined(__BEOS__)
1243 in_mch_suspend = TRUE; 1242 in_mch_suspend = TRUE;
1244 1243
1245 out_flush(); /* needed to make cursor visible on some systems */ 1244 out_flush(); // needed to make cursor visible on some systems
1246 settmode(TMODE_COOK); 1245 settmode(TMODE_COOK);
1247 out_flush(); /* needed to disable mouse on some systems */ 1246 out_flush(); // needed to disable mouse on some systems
1248 1247
1249 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) 1248 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1250 loose_clipboard(); 1249 loose_clipboard();
1251 # endif 1250 # endif
1252 # if defined(SIGCONT) 1251 # if defined(SIGCONT)
1253 sigcont_received = FALSE; 1252 sigcont_received = FALSE;
1254 # endif 1253 # endif
1255 1254
1256 kill(0, SIGTSTP); /* send ourselves a STOP signal */ 1255 kill(0, SIGTSTP); // send ourselves a STOP signal
1257 1256
1258 # if defined(SIGCONT) 1257 # if defined(SIGCONT)
1259 /* 1258 /*
1260 * Wait for the SIGCONT signal to be handled. It generally happens 1259 * Wait for the SIGCONT signal to be handled. It generally happens
1261 * immediately, but somehow not all the time, probably because it's handled 1260 * immediately, but somehow not all the time, probably because it's handled
1372 void 1371 void
1373 reset_signals(void) 1372 reset_signals(void)
1374 { 1373 {
1375 catch_signals(SIG_DFL, SIG_DFL); 1374 catch_signals(SIG_DFL, SIG_DFL);
1376 #if defined(SIGCONT) 1375 #if defined(SIGCONT)
1377 /* SIGCONT isn't in the list, because its default action is ignore */ 1376 // SIGCONT isn't in the list, because its default action is ignore
1378 signal(SIGCONT, SIG_DFL); 1377 signal(SIGCONT, SIG_DFL);
1379 #endif 1378 #endif
1380 } 1379 }
1381 1380
1382 static void 1381 static void
1390 if (signal_info[i].deadly) 1389 if (signal_info[i].deadly)
1391 { 1390 {
1392 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) 1391 #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
1393 struct sigaction sa; 1392 struct sigaction sa;
1394 1393
1395 /* Setup to use the alternate stack for the signal function. */ 1394 // Setup to use the alternate stack for the signal function.
1396 sa.sa_handler = func_deadly; 1395 sa.sa_handler = func_deadly;
1397 sigemptyset(&sa.sa_mask); 1396 sigemptyset(&sa.sa_mask);
1398 # if defined(__linux__) && defined(_REENTRANT) 1397 # if defined(__linux__) && defined(_REENTRANT)
1399 /* On Linux, with glibc compiled for kernel 2.2, there is a bug in 1398 // On Linux, with glibc compiled for kernel 2.2, there is a bug in
1400 * thread handling in combination with using the alternate stack: 1399 // thread handling in combination with using the alternate stack:
1401 * pthread library functions try to use the stack pointer to 1400 // pthread library functions try to use the stack pointer to
1402 * identify the current thread, causing a SEGV signal, which 1401 // identify the current thread, causing a SEGV signal, which
1403 * recursively calls deathtrap() and hangs. */ 1402 // recursively calls deathtrap() and hangs.
1404 sa.sa_flags = 0; 1403 sa.sa_flags = 0;
1405 # else 1404 # else
1406 sa.sa_flags = SA_ONSTACK; 1405 sa.sa_flags = SA_ONSTACK;
1407 # endif 1406 # endif
1408 sigaction(signal_info[i].sig, &sa, NULL); 1407 sigaction(signal_info[i].sig, &sa, NULL);
1409 #else 1408 #else
1410 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC) 1409 # if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGVEC)
1411 struct sigvec sv; 1410 struct sigvec sv;
1412 1411
1413 /* Setup to use the alternate stack for the signal function. */ 1412 // Setup to use the alternate stack for the signal function.
1414 sv.sv_handler = func_deadly; 1413 sv.sv_handler = func_deadly;
1415 sv.sv_mask = 0; 1414 sv.sv_mask = 0;
1416 sv.sv_flags = SV_ONSTACK; 1415 sv.sv_flags = SV_ONSTACK;
1417 sigvec(signal_info[i].sig, &sv, NULL); 1416 sigvec(signal_info[i].sig, &sv, NULL);
1418 # else 1417 # else
1435 1434
1436 for (i = 0; signal_info[i].sig != -1; i++) 1435 for (i = 0; signal_info[i].sig != -1; i++)
1437 sigaddset(&newset, signal_info[i].sig); 1436 sigaddset(&newset, signal_info[i].sig);
1438 1437
1439 # if defined(SIGCONT) 1438 # if defined(SIGCONT)
1440 /* SIGCONT isn't in the list, because its default action is ignore */ 1439 // SIGCONT isn't in the list, because its default action is ignore
1441 sigaddset(&newset, SIGCONT); 1440 sigaddset(&newset, SIGCONT);
1442 # endif 1441 # endif
1443 1442
1444 sigprocmask(SIG_BLOCK, &newset, set); 1443 sigprocmask(SIG_BLOCK, &newset, set);
1445 } 1444 }
1478 got_signal = 0; 1477 got_signal = 0;
1479 } 1478 }
1480 break; 1479 break;
1481 1480
1482 default: if (!blocked) 1481 default: if (!blocked)
1483 return TRUE; /* exit! */ 1482 return TRUE; // exit!
1484 got_signal = sig; 1483 got_signal = sig;
1485 #ifdef SIGPWR 1484 #ifdef SIGPWR
1486 if (sig != SIGPWR) 1485 if (sig != SIGPWR)
1487 #endif 1486 #endif
1488 got_int = TRUE; /* break any loops */ 1487 got_int = TRUE; // break any loops
1489 break; 1488 break;
1490 } 1489 }
1491 return FALSE; 1490 return FALSE;
1492 } 1491 }
1493 1492
1543 x_error_handler(Display *dpy, XErrorEvent *error_event) 1542 x_error_handler(Display *dpy, XErrorEvent *error_event)
1544 { 1543 {
1545 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE); 1544 XGetErrorText(dpy, error_event->error_code, (char *)IObuff, IOSIZE);
1546 STRCAT(IObuff, _("\nVim: Got X error\n")); 1545 STRCAT(IObuff, _("\nVim: Got X error\n"));
1547 1546
1548 /* We cannot print a message and continue, because no X calls are allowed 1547 // We cannot print a message and continue, because no X calls are allowed
1549 * here (causes my system to hang). Silently continuing might be an 1548 // here (causes my system to hang). Silently continuing might be an
1550 * alternative... */ 1549 // alternative...
1551 preserve_exit(); /* preserve files and exit */ 1550 preserve_exit(); // preserve files and exit
1552 1551
1553 return 0; /* NOTREACHED */ 1552 return 0; // NOTREACHED
1554 } 1553 }
1555 1554
1556 /* 1555 /*
1557 * Another X Error handler, just used to check for errors. 1556 * Another X Error handler, just used to check for errors.
1558 */ 1557 */
1601 * An X IO Error handler, used to catch error while opening the display. 1600 * An X IO Error handler, used to catch error while opening the display.
1602 */ 1601 */
1603 static int 1602 static int
1604 x_IOerror_check(Display *dpy UNUSED) 1603 x_IOerror_check(Display *dpy UNUSED)
1605 { 1604 {
1606 /* This function should not return, it causes exit(). Longjump instead. */ 1605 // This function should not return, it causes exit(). Longjump instead.
1607 LONGJMP(lc_jump_env, 1); 1606 LONGJMP(lc_jump_env, 1);
1608 # if defined(VMS) || defined(__CYGWIN__) 1607 # if defined(VMS) || defined(__CYGWIN__)
1609 return 0; /* avoid the compiler complains about missing return value */ 1608 return 0; // avoid the compiler complains about missing return value
1610 # endif 1609 # endif
1611 } 1610 }
1612 # endif 1611 # endif
1613 1612
1614 /* 1613 /*
1623 xterm_dpy_retry_count = 5; // Try reconnecting five times 1622 xterm_dpy_retry_count = 5; // Try reconnecting five times
1624 x11_window = 0; 1623 x11_window = 0;
1625 x11_display = NULL; 1624 x11_display = NULL;
1626 xterm_Shell = (Widget)0; 1625 xterm_Shell = (Widget)0;
1627 1626
1628 /* This function should not return, it causes exit(). Longjump instead. */ 1627 // This function should not return, it causes exit(). Longjump instead.
1629 LONGJMP(x_jump_env, 1); 1628 LONGJMP(x_jump_env, 1);
1630 # if defined(VMS) || defined(__CYGWIN__) 1629 # if defined(VMS) || defined(__CYGWIN__)
1631 return 0; /* avoid the compiler complains about missing return value */ 1630 return 0; // avoid the compiler complains about missing return value
1632 # endif 1631 # endif
1633 } 1632 }
1634 1633
1635 /* 1634 /*
1636 * If the X11 connection was lost try to restore it. 1635 * If the X11 connection was lost try to restore it.
1644 if (!exiting && !v_dying && xterm_dpy_retry_count > 0) 1643 if (!exiting && !v_dying && xterm_dpy_retry_count > 0)
1645 { 1644 {
1646 --xterm_dpy_retry_count; 1645 --xterm_dpy_retry_count;
1647 1646
1648 # ifndef LESSTIF_VERSION 1647 # ifndef LESSTIF_VERSION
1649 /* This has been reported to avoid Vim getting stuck. */ 1648 // This has been reported to avoid Vim getting stuck.
1650 if (app_context != (XtAppContext)NULL) 1649 if (app_context != (XtAppContext)NULL)
1651 { 1650 {
1652 XtDestroyApplicationContext(app_context); 1651 XtDestroyApplicationContext(app_context);
1653 app_context = (XtAppContext)NULL; 1652 app_context = (XtAppContext)NULL;
1654 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ 1653 x11_display = NULL; // freed by XtDestroyApplicationContext()
1655 } 1654 }
1656 # endif 1655 # endif
1657 1656
1658 setup_term_clip(); 1657 setup_term_clip();
1659 get_x11_title(FALSE); 1658 get_x11_title(FALSE);
1721 static int 1720 static int
1722 get_x11_windis(void) 1721 get_x11_windis(void)
1723 { 1722 {
1724 char *winid; 1723 char *winid;
1725 static int result = -1; 1724 static int result = -1;
1726 #define XD_NONE 0 /* x11_display not set here */ 1725 #define XD_NONE 0 // x11_display not set here
1727 #define XD_HERE 1 /* x11_display opened here */ 1726 #define XD_HERE 1 // x11_display opened here
1728 #define XD_GUI 2 /* x11_display used from gui.dpy */ 1727 #define XD_GUI 2 // x11_display used from gui.dpy
1729 #define XD_XTERM 3 /* x11_display used from xterm_dpy */ 1728 #define XD_XTERM 3 // x11_display used from xterm_dpy
1730 static int x11_display_from = XD_NONE; 1729 static int x11_display_from = XD_NONE;
1731 static int did_set_error_handler = FALSE; 1730 static int did_set_error_handler = FALSE;
1732 1731
1733 if (!did_set_error_handler) 1732 if (!did_set_error_handler)
1734 { 1733 {
1735 /* X just exits if it finds an error otherwise! */ 1734 // X just exits if it finds an error otherwise!
1736 (void)XSetErrorHandler(x_error_handler); 1735 (void)XSetErrorHandler(x_error_handler);
1737 did_set_error_handler = TRUE; 1736 did_set_error_handler = TRUE;
1738 } 1737 }
1739 1738
1740 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) 1739 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
1757 x11_display = NULL; 1756 x11_display = NULL;
1758 return FAIL; 1757 return FAIL;
1759 } 1758 }
1760 else if (x11_display_from == XD_GUI) 1759 else if (x11_display_from == XD_GUI)
1761 { 1760 {
1762 /* GUI must have stopped somehow, clear x11_display */ 1761 // GUI must have stopped somehow, clear x11_display
1763 x11_window = 0; 1762 x11_window = 0;
1764 x11_display = NULL; 1763 x11_display = NULL;
1765 x11_display_from = XD_NONE; 1764 x11_display_from = XD_NONE;
1766 } 1765 }
1767 #endif 1766 #endif
1768 1767
1769 /* When started with the "-X" argument, don't try connecting. */ 1768 // When started with the "-X" argument, don't try connecting.
1770 if (!x_connect_to_server()) 1769 if (!x_connect_to_server())
1771 return FAIL; 1770 return FAIL;
1772 1771
1773 /* 1772 /*
1774 * If WINDOWID not set, should try another method to find out 1773 * If WINDOWID not set, should try another method to find out
1784 // x11_display may have been set to xterm_dpy elsewhere 1783 // x11_display may have been set to xterm_dpy elsewhere
1785 x11_display_from = XD_XTERM; 1784 x11_display_from = XD_XTERM;
1786 1785
1787 if (xterm_dpy != NULL && x11_window != 0) 1786 if (xterm_dpy != NULL && x11_window != 0)
1788 { 1787 {
1789 /* We may have checked it already, but Gnome terminal can move us to 1788 // We may have checked it already, but Gnome terminal can move us to
1790 * another window, so we need to check every time. */ 1789 // another window, so we need to check every time.
1791 if (x11_display_from != XD_XTERM) 1790 if (x11_display_from != XD_XTERM)
1792 { 1791 {
1793 /* 1792 /*
1794 * If the X11 display was opened here before, for the window where 1793 * If the X11 display was opened here before, for the window where
1795 * Vim was started, close that one now to avoid a memory leak. 1794 * Vim was started, close that one now to avoid a memory leak.
1799 x11_display = xterm_dpy; 1798 x11_display = xterm_dpy;
1800 x11_display_from = XD_XTERM; 1799 x11_display_from = XD_XTERM;
1801 } 1800 }
1802 if (test_x11_window(x11_display) == FAIL) 1801 if (test_x11_window(x11_display) == FAIL)
1803 { 1802 {
1804 /* probably bad $WINDOWID */ 1803 // probably bad $WINDOWID
1805 x11_window = 0; 1804 x11_window = 0;
1806 x11_display = NULL; 1805 x11_display = NULL;
1807 x11_display_from = XD_NONE; 1806 x11_display_from = XD_NONE;
1808 return FAIL; 1807 return FAIL;
1809 } 1808 }
1812 #endif 1811 #endif
1813 1812
1814 if (x11_window == 0 || x11_display == NULL) 1813 if (x11_window == 0 || x11_display == NULL)
1815 result = -1; 1814 result = -1;
1816 1815
1817 if (result != -1) /* Have already been here and set this */ 1816 if (result != -1) // Have already been here and set this
1818 return result; /* Don't do all these X calls again */ 1817 return result; // Don't do all these X calls again
1819 1818
1820 if (x11_window != 0 && x11_display == NULL) 1819 if (x11_window != 0 && x11_display == NULL)
1821 { 1820 {
1822 #ifdef SET_SIG_ALARM 1821 #ifdef SET_SIG_ALARM
1823 RETSIGTYPE (*sig_save)(); 1822 RETSIGTYPE (*sig_save)();
1857 verbose_leave(); 1856 verbose_leave();
1858 } 1857 }
1859 # endif 1858 # endif
1860 if (test_x11_window(x11_display) == FAIL) 1859 if (test_x11_window(x11_display) == FAIL)
1861 { 1860 {
1862 /* Maybe window id is bad */ 1861 // Maybe window id is bad
1863 x11_window = 0; 1862 x11_window = 0;
1864 XCloseDisplay(x11_display); 1863 XCloseDisplay(x11_display);
1865 x11_display = NULL; 1864 x11_display = NULL;
1866 } 1865 }
1867 else 1866 else
1895 { 1894 {
1896 int retval = FALSE; 1895 int retval = FALSE;
1897 1896
1898 retval = get_x11_thing(FALSE, test_only); 1897 retval = get_x11_thing(FALSE, test_only);
1899 1898
1900 /* could not get old icon, use terminal name */ 1899 // could not get old icon, use terminal name
1901 if (oldicon == NULL && !test_only) 1900 if (oldicon == NULL && !test_only)
1902 { 1901 {
1903 if (STRNCMP(T_NAME, "builtin_", 8) == 0) 1902 if (STRNCMP(T_NAME, "builtin_", 8) == 0)
1904 oldicon = vim_strsave(T_NAME + 8); 1903 oldicon = vim_strsave(T_NAME + 8);
1905 else 1904 else
1909 return retval; 1908 return retval;
1910 } 1909 }
1911 1910
1912 static int 1911 static int
1913 get_x11_thing( 1912 get_x11_thing(
1914 int get_title, /* get title string */ 1913 int get_title, // get title string
1915 int test_only) 1914 int test_only)
1916 { 1915 {
1917 XTextProperty text_prop; 1916 XTextProperty text_prop;
1918 int retval = FALSE; 1917 int retval = FALSE;
1919 Status status; 1918 Status status;
1920 1919
1921 if (get_x11_windis() == OK) 1920 if (get_x11_windis() == OK)
1922 { 1921 {
1923 /* Get window/icon name if any */ 1922 // Get window/icon name if any
1924 if (get_title) 1923 if (get_title)
1925 status = XGetWMName(x11_display, x11_window, &text_prop); 1924 status = XGetWMName(x11_display, x11_window, &text_prop);
1926 else 1925 else
1927 status = XGetWMIconName(x11_display, x11_window, &text_prop); 1926 status = XGetWMIconName(x11_display, x11_window, &text_prop);
1928 1927
1930 * If terminal is xterm, then x11_window may be a child window of the 1929 * If terminal is xterm, then x11_window may be a child window of the
1931 * outer xterm window that actually contains the window/icon name, so 1930 * outer xterm window that actually contains the window/icon name, so
1932 * keep traversing up the tree until a window with a title/icon is 1931 * keep traversing up the tree until a window with a title/icon is
1933 * found. 1932 * found.
1934 */ 1933 */
1935 /* Previously this was only done for xterm and alikes. I don't see a 1934 // Previously this was only done for xterm and alikes. I don't see a
1936 * reason why it would fail for other terminal emulators. 1935 // reason why it would fail for other terminal emulators.
1937 * if (term_is_xterm) */ 1936 // if (term_is_xterm)
1938 { 1937 {
1939 Window root; 1938 Window root;
1940 Window parent; 1939 Window parent;
1941 Window win = x11_window; 1940 Window win = x11_window;
1942 Window *children; 1941 Window *children;
2001 } 2000 }
2002 } 2001 }
2003 return retval; 2002 return retval;
2004 } 2003 }
2005 2004
2006 /* Xutf8 functions are not available on older systems. Note that on some 2005 // Xutf8 functions are not available on older systems. Note that on some
2007 * systems X_HAVE_UTF8_STRING may be defined in a header file but 2006 // systems X_HAVE_UTF8_STRING may be defined in a header file but
2008 * Xutf8SetWMProperties() is not in the X11 library. Configure checks for 2007 // Xutf8SetWMProperties() is not in the X11 library. Configure checks for
2009 * that and defines HAVE_XUTF8SETWMPROPERTIES. */ 2008 // that and defines HAVE_XUTF8SETWMPROPERTIES.
2010 #if defined(X_HAVE_UTF8_STRING) 2009 #if defined(X_HAVE_UTF8_STRING)
2011 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES 2010 # if X_HAVE_UTF8_STRING && HAVE_XUTF8SETWMPROPERTIES
2012 # define USE_UTF8_STRING 2011 # define USE_UTF8_STRING
2013 # endif 2012 # endif
2014 #endif 2013 #endif
2019 * get_x11_windis() must be called before this and have returned OK 2018 * get_x11_windis() must be called before this and have returned OK
2020 */ 2019 */
2021 static void 2020 static void
2022 set_x11_title(char_u *title) 2021 set_x11_title(char_u *title)
2023 { 2022 {
2024 /* XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING 2023 // XmbSetWMProperties() and Xutf8SetWMProperties() should use a STRING
2025 * when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't 2024 // when possible, COMPOUND_TEXT otherwise. COMPOUND_TEXT isn't
2026 * supported everywhere and STRING doesn't work for multi-byte titles. 2025 // supported everywhere and STRING doesn't work for multi-byte titles.
2027 */
2028 #ifdef USE_UTF8_STRING 2026 #ifdef USE_UTF8_STRING
2029 if (enc_utf8) 2027 if (enc_utf8)
2030 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title, 2028 Xutf8SetWMProperties(x11_display, x11_window, (const char *)title,
2031 NULL, NULL, 0, NULL, NULL, NULL); 2029 NULL, NULL, 0, NULL, NULL, NULL);
2032 else 2030 else
2038 NULL, NULL, 0, NULL, NULL, NULL); 2036 NULL, NULL, 0, NULL, NULL, NULL);
2039 # else 2037 # else
2040 XTextProperty text_prop; 2038 XTextProperty text_prop;
2041 char *c_title = (char *)title; 2039 char *c_title = (char *)title;
2042 2040
2043 /* directly from example 3-18 "basicwin" of Xlib Programming Manual */ 2041 // directly from example 3-18 "basicwin" of Xlib Programming Manual
2044 (void)XStringListToTextProperty(&c_title, 1, &text_prop); 2042 (void)XStringListToTextProperty(&c_title, 1, &text_prop);
2045 XSetWMProperties(x11_display, x11_window, &text_prop, 2043 XSetWMProperties(x11_display, x11_window, &text_prop,
2046 NULL, NULL, 0, NULL, NULL, NULL); 2044 NULL, NULL, 0, NULL, NULL, NULL);
2047 # endif 2045 # endif
2048 #else 2046 #else
2058 * get_x11_windis() must be called before this and have returned OK 2056 * get_x11_windis() must be called before this and have returned OK
2059 */ 2057 */
2060 static void 2058 static void
2061 set_x11_icon(char_u *icon) 2059 set_x11_icon(char_u *icon)
2062 { 2060 {
2063 /* See above for comments about using X*SetWMProperties(). */ 2061 // See above for comments about using X*SetWMProperties().
2064 #ifdef USE_UTF8_STRING 2062 #ifdef USE_UTF8_STRING
2065 if (enc_utf8) 2063 if (enc_utf8)
2066 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon, 2064 Xutf8SetWMProperties(x11_display, x11_window, NULL, (const char *)icon,
2067 NULL, 0, NULL, NULL, NULL); 2065 NULL, 0, NULL, NULL, NULL);
2068 else 2066 else
2085 #endif 2083 #endif
2086 } 2084 }
2087 XFlush(x11_display); 2085 XFlush(x11_display);
2088 } 2086 }
2089 2087
2090 #else /* FEAT_X11 */ 2088 #else // FEAT_X11
2091 2089
2092 static int 2090 static int
2093 get_x11_title(int test_only UNUSED) 2091 get_x11_title(int test_only UNUSED)
2094 { 2092 {
2095 return FALSE; 2093 return FALSE;
2106 oldicon = vim_strsave(T_NAME); 2104 oldicon = vim_strsave(T_NAME);
2107 } 2105 }
2108 return FALSE; 2106 return FALSE;
2109 } 2107 }
2110 2108
2111 #endif /* FEAT_X11 */ 2109 #endif // FEAT_X11
2112 2110
2113 int 2111 int
2114 mch_can_restore_title(void) 2112 mch_can_restore_title(void)
2115 { 2113 {
2116 return get_x11_title(TRUE); 2114 return get_x11_title(TRUE);
2129 mch_settitle(char_u *title, char_u *icon) 2127 mch_settitle(char_u *title, char_u *icon)
2130 { 2128 {
2131 int type = 0; 2129 int type = 0;
2132 static int recursive = 0; 2130 static int recursive = 0;
2133 2131
2134 if (T_NAME == NULL) /* no terminal name (yet) */ 2132 if (T_NAME == NULL) // no terminal name (yet)
2135 return; 2133 return;
2136 if (title == NULL && icon == NULL) /* nothing to do */ 2134 if (title == NULL && icon == NULL) // nothing to do
2137 return; 2135 return;
2138 2136
2139 /* When one of the X11 functions causes a deadly signal, we get here again 2137 // When one of the X11 functions causes a deadly signal, we get here again
2140 * recursively. Avoid hanging then (something is probably locked). */ 2138 // recursively. Avoid hanging then (something is probably locked).
2141 if (recursive) 2139 if (recursive)
2142 return; 2140 return;
2143 ++recursive; 2141 ++recursive;
2144 2142
2145 /* 2143 /*
2168 } 2166 }
2169 if (oldtitle == NULL 2167 if (oldtitle == NULL
2170 #ifdef FEAT_GUI 2168 #ifdef FEAT_GUI
2171 && !gui.in_use 2169 && !gui.in_use
2172 #endif 2170 #endif
2173 ) /* first call but not in GUI, save title */ 2171 ) // first call but not in GUI, save title
2174 (void)get_x11_title(FALSE); 2172 (void)get_x11_title(FALSE);
2175 2173
2176 if (*T_TS != NUL) /* it's OK if t_fs is empty */ 2174 if (*T_TS != NUL) // it's OK if t_fs is empty
2177 term_settitle(title); 2175 term_settitle(title);
2178 #ifdef FEAT_X11 2176 #ifdef FEAT_X11
2179 else 2177 else
2180 # ifdef FEAT_GUI_GTK 2178 # ifdef FEAT_GUI_GTK
2181 if (!gui.in_use) /* don't do this if GTK+ is running */ 2179 if (!gui.in_use) // don't do this if GTK+ is running
2182 # endif 2180 # endif
2183 set_x11_title(title); /* x11 */ 2181 set_x11_title(title); // x11
2184 #endif 2182 #endif
2185 #if defined(FEAT_GUI_GTK) \ 2183 #if defined(FEAT_GUI_GTK) \
2186 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) 2184 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC)
2187 else 2185 else
2188 gui_mch_settitle(title, icon); 2186 gui_mch_settitle(title, icon);
2194 { 2192 {
2195 if (oldicon == NULL 2193 if (oldicon == NULL
2196 #ifdef FEAT_GUI 2194 #ifdef FEAT_GUI
2197 && !gui.in_use 2195 && !gui.in_use
2198 #endif 2196 #endif
2199 ) /* first call, save icon */ 2197 ) // first call, save icon
2200 get_x11_icon(FALSE); 2198 get_x11_icon(FALSE);
2201 2199
2202 if (*T_CIS != NUL) 2200 if (*T_CIS != NUL)
2203 { 2201 {
2204 out_str(T_CIS); // set icon start 2202 out_str(T_CIS); // set icon start
2207 out_flush(); 2205 out_flush();
2208 } 2206 }
2209 #ifdef FEAT_X11 2207 #ifdef FEAT_X11
2210 else 2208 else
2211 # ifdef FEAT_GUI_GTK 2209 # ifdef FEAT_GUI_GTK
2212 if (!gui.in_use) /* don't do this if GTK+ is running */ 2210 if (!gui.in_use) // don't do this if GTK+ is running
2213 # endif 2211 # endif
2214 set_x11_icon(icon); /* x11 */ 2212 set_x11_icon(icon); // x11
2215 #endif 2213 #endif
2216 did_set_icon = TRUE; 2214 did_set_icon = TRUE;
2217 } 2215 }
2218 --recursive; 2216 --recursive;
2219 } 2217 }
2228 void 2226 void
2229 mch_restore_title(int which) 2227 mch_restore_title(int which)
2230 { 2228 {
2231 int do_push_pop = unix_did_set_title || did_set_icon; 2229 int do_push_pop = unix_did_set_title || did_set_icon;
2232 2230
2233 /* only restore the title or icon when it has been set */ 2231 // only restore the title or icon when it has been set
2234 mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ? 2232 mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ?
2235 (oldtitle ? oldtitle : p_titleold) : NULL, 2233 (oldtitle ? oldtitle : p_titleold) : NULL,
2236 ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL); 2234 ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL);
2237 2235
2238 if (do_push_pop) 2236 if (do_push_pop)
2241 term_pop_title(which); 2239 term_pop_title(which);
2242 term_push_title(which); 2240 term_push_title(which);
2243 } 2241 }
2244 } 2242 }
2245 2243
2246 #endif /* FEAT_TITLE */ 2244 #endif // FEAT_TITLE
2247 2245
2248 /* 2246 /*
2249 * Return TRUE if "name" looks like some xterm name. 2247 * Return TRUE if "name" looks like some xterm name.
2250 * Seiichi Sato mentioned that "mlterm" works like xterm. 2248 * Seiichi Sato mentioned that "mlterm" works like xterm.
2251 */ 2249 */
2314 2312
2315 int 2313 int
2316 vim_is_vt300(char_u *name) 2314 vim_is_vt300(char_u *name)
2317 { 2315 {
2318 if (name == NULL) 2316 if (name == NULL)
2319 return FALSE; /* actually all ANSI comp. terminals should be here */ 2317 return FALSE; // actually all ANSI comp. terminals should be here
2320 /* catch VT100 - VT5xx */ 2318 // catch VT100 - VT5xx
2321 return ((STRNICMP(name, "vt", 2) == 0 2319 return ((STRNICMP(name, "vt", 2) == 0
2322 && vim_strchr((char_u *)"12345", name[2]) != NULL) 2320 && vim_strchr((char_u *)"12345", name[2]) != NULL)
2323 || STRCMP(name, "builtin_vt320") == 0); 2321 || STRCMP(name, "builtin_vt320") == 0);
2324 } 2322 }
2325 2323
2371 { 2369 {
2372 vim_strncpy(s, (char_u *)pw->pw_name, len - 1); 2370 vim_strncpy(s, (char_u *)pw->pw_name, len - 1);
2373 return OK; 2371 return OK;
2374 } 2372 }
2375 #endif 2373 #endif
2376 sprintf((char *)s, "%d", (int)uid); /* assumes s is long enough */ 2374 sprintf((char *)s, "%d", (int)uid); // assumes s is long enough
2377 return FAIL; /* a number is not a name */ 2375 return FAIL; // a number is not a name
2378 } 2376 }
2379 2377
2380 /* 2378 /*
2381 * Insert host name is s[len]. 2379 * Insert host name is s[len].
2382 */ 2380 */
2390 if (uname(&vutsname) < 0) 2388 if (uname(&vutsname) < 0)
2391 *s = NUL; 2389 *s = NUL;
2392 else 2390 else
2393 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1); 2391 vim_strncpy(s, (char_u *)vutsname.nodename, len - 1);
2394 } 2392 }
2395 #else /* HAVE_SYS_UTSNAME_H */ 2393 #else // HAVE_SYS_UTSNAME_H
2396 2394
2397 # ifdef HAVE_SYS_SYSTEMINFO_H 2395 # ifdef HAVE_SYS_SYSTEMINFO_H
2398 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len) 2396 # define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len)
2399 # endif 2397 # endif
2400 2398
2404 # ifdef VAXC 2402 # ifdef VAXC
2405 vaxc$gethostname((char *)s, len); 2403 vaxc$gethostname((char *)s, len);
2406 # else 2404 # else
2407 gethostname((char *)s, len); 2405 gethostname((char *)s, len);
2408 # endif 2406 # endif
2409 s[len - 1] = NUL; /* make sure it's terminated */ 2407 s[len - 1] = NUL; // make sure it's terminated
2410 } 2408 }
2411 #endif /* HAVE_SYS_UTSNAME_H */ 2409 #endif // HAVE_SYS_UTSNAME_H
2412 2410
2413 /* 2411 /*
2414 * return process ID 2412 * return process ID
2415 */ 2413 */
2416 long 2414 long
2472 int 2470 int
2473 mch_FullName( 2471 mch_FullName(
2474 char_u *fname, 2472 char_u *fname,
2475 char_u *buf, 2473 char_u *buf,
2476 int len, 2474 int len,
2477 int force) /* also expand when already absolute path */ 2475 int force) // also expand when already absolute path
2478 { 2476 {
2479 int l; 2477 int l;
2480 #ifdef HAVE_FCHDIR 2478 #ifdef HAVE_FCHDIR
2481 int fd = -1; 2479 int fd = -1;
2482 static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */ 2480 static int dont_fchdir = FALSE; // TRUE when fchdir() doesn't work
2483 #endif 2481 #endif
2484 char_u olddir[MAXPATHL]; 2482 char_u olddir[MAXPATHL];
2485 char_u *p; 2483 char_u *p;
2486 int retval = OK; 2484 int retval = OK;
2487 #ifdef __CYGWIN__ 2485 #ifdef __CYGWIN__
2488 char_u posix_fname[MAXPATHL]; /* Cygwin docs mention MAX_PATH, but 2486 char_u posix_fname[MAXPATHL]; // Cygwin docs mention MAX_PATH, but
2489 it's not always defined */ 2487 // it's not always defined
2490 #endif 2488 #endif
2491 2489
2492 #ifdef VMS 2490 #ifdef VMS
2493 fname = vms_fixfilename(fname); 2491 fname = vms_fixfilename(fname);
2494 #endif 2492 #endif
2496 #ifdef __CYGWIN__ 2494 #ifdef __CYGWIN__
2497 /* 2495 /*
2498 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts". 2496 * This helps for when "/etc/hosts" is a symlink to "c:/something/hosts".
2499 */ 2497 */
2500 # if CYGWIN_VERSION_DLL_MAJOR >= 1007 2498 # if CYGWIN_VERSION_DLL_MAJOR >= 1007
2501 /* Use CCP_RELATIVE to avoid that it sometimes returns a path that ends in 2499 // Use CCP_RELATIVE to avoid that it sometimes returns a path that ends in
2502 * a forward slash. */ 2500 // a forward slash.
2503 cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, 2501 cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE,
2504 fname, posix_fname, MAXPATHL); 2502 fname, posix_fname, MAXPATHL);
2505 # else 2503 # else
2506 cygwin_conv_to_posix_path(fname, posix_fname); 2504 cygwin_conv_to_posix_path(fname, posix_fname);
2507 # endif 2505 # endif
2508 fname = posix_fname; 2506 fname = posix_fname;
2509 #endif 2507 #endif
2510 2508
2511 /* Expand it if forced or not an absolute path. 2509 // Expand it if forced or not an absolute path.
2512 * Do not do it for "/file", the result is always "/". */ 2510 // Do not do it for "/file", the result is always "/".
2513 if ((force || !mch_isFullName(fname)) 2511 if ((force || !mch_isFullName(fname))
2514 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname)) 2512 && ((p = vim_strrchr(fname, '/')) == NULL || p != fname))
2515 { 2513 {
2516 /* 2514 /*
2517 * If the file name has a path, change to that directory for a moment, 2515 * If the file name has a path, change to that directory for a moment,
2531 fd = open(".", O_RDONLY | O_EXTRA, 0); 2529 fd = open(".", O_RDONLY | O_EXTRA, 0);
2532 if (fd >= 0 && fchdir(fd) < 0) 2530 if (fd >= 0 && fchdir(fd) < 0)
2533 { 2531 {
2534 close(fd); 2532 close(fd);
2535 fd = -1; 2533 fd = -1;
2536 dont_fchdir = TRUE; /* don't try again */ 2534 dont_fchdir = TRUE; // don't try again
2537 } 2535 }
2538 } 2536 }
2539 #endif 2537 #endif
2540 2538
2541 /* Only change directory when we are sure we can return to where 2539 // Only change directory when we are sure we can return to where
2542 * we are now. After doing "su" chdir(".") might not work. */ 2540 // we are now. After doing "su" chdir(".") might not work.
2543 if ( 2541 if (
2544 #ifdef HAVE_FCHDIR 2542 #ifdef HAVE_FCHDIR
2545 fd < 0 && 2543 fd < 0 &&
2546 #endif 2544 #endif
2547 (mch_dirname(olddir, MAXPATHL) == FAIL 2545 (mch_dirname(olddir, MAXPATHL) == FAIL
2548 || mch_chdir((char *)olddir) != 0)) 2546 || mch_chdir((char *)olddir) != 0))
2549 { 2547 {
2550 p = NULL; /* can't get current dir: don't chdir */ 2548 p = NULL; // can't get current dir: don't chdir
2551 retval = FAIL; 2549 retval = FAIL;
2552 } 2550 }
2553 else 2551 else
2554 { 2552 {
2555 /* The directory is copied into buf[], to be able to remove 2553 // The directory is copied into buf[], to be able to remove
2556 * the file name without changing it (could be a string in 2554 // the file name without changing it (could be a string in
2557 * read-only memory) */ 2555 // read-only memory)
2558 if (p - fname >= len) 2556 if (p - fname >= len)
2559 retval = FAIL; 2557 retval = FAIL;
2560 else 2558 else
2561 { 2559 {
2562 vim_strncpy(buf, fname, p - fname); 2560 vim_strncpy(buf, fname, p - fname);
2594 emsg(_(e_prev_dir)); 2592 emsg(_(e_prev_dir));
2595 } 2593 }
2596 2594
2597 l = STRLEN(buf); 2595 l = STRLEN(buf);
2598 if (l >= len - 1) 2596 if (l >= len - 1)
2599 retval = FAIL; /* no space for trailing "/" */ 2597 retval = FAIL; // no space for trailing "/"
2600 #ifndef VMS 2598 #ifndef VMS
2601 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL 2599 else if (l > 0 && buf[l - 1] != '/' && *fname != NUL
2602 && STRCMP(fname, ".") != 0) 2600 && STRCMP(fname, ".") != 0)
2603 STRCAT(buf, "/"); 2601 STRCAT(buf, "/");
2604 #endif 2602 #endif
2605 } 2603 }
2606 2604
2607 /* Catch file names which are too long. */ 2605 // Catch file names which are too long.
2608 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len) 2606 if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len)
2609 return FAIL; 2607 return FAIL;
2610 2608
2611 /* Do not append ".", "/dir/." is equal to "/dir". */ 2609 // Do not append ".", "/dir/." is equal to "/dir".
2612 if (STRCMP(fname, ".") != 0) 2610 if (STRCMP(fname, ".") != 0)
2613 STRCAT(buf, fname); 2611 STRCAT(buf, fname);
2614 2612
2615 return OK; 2613 return OK;
2616 } 2614 }
2638 * Only required for file systems where case is ignored and preserved. 2636 * Only required for file systems where case is ignored and preserved.
2639 */ 2637 */
2640 void 2638 void
2641 fname_case( 2639 fname_case(
2642 char_u *name, 2640 char_u *name,
2643 int len UNUSED) /* buffer size, only used when name gets longer */ 2641 int len UNUSED) // buffer size, only used when name gets longer
2644 { 2642 {
2645 struct stat st; 2643 struct stat st;
2646 char_u *slash, *tail; 2644 char_u *slash, *tail;
2647 DIR *dirp; 2645 DIR *dirp;
2648 struct dirent *dp; 2646 struct dirent *dp;
2649 2647
2650 if (mch_lstat((char *)name, &st) >= 0) 2648 if (mch_lstat((char *)name, &st) >= 0)
2651 { 2649 {
2652 /* Open the directory where the file is located. */ 2650 // Open the directory where the file is located.
2653 slash = vim_strrchr(name, '/'); 2651 slash = vim_strrchr(name, '/');
2654 if (slash == NULL) 2652 if (slash == NULL)
2655 { 2653 {
2656 dirp = opendir("."); 2654 dirp = opendir(".");
2657 tail = name; 2655 tail = name;
2666 2664
2667 if (dirp != NULL) 2665 if (dirp != NULL)
2668 { 2666 {
2669 while ((dp = readdir(dirp)) != NULL) 2667 while ((dp = readdir(dirp)) != NULL)
2670 { 2668 {
2671 /* Only accept names that differ in case and are the same byte 2669 // Only accept names that differ in case and are the same byte
2672 * length. TODO: accept different length name. */ 2670 // length. TODO: accept different length name.
2673 if (STRICMP(tail, dp->d_name) == 0 2671 if (STRICMP(tail, dp->d_name) == 0
2674 && STRLEN(tail) == STRLEN(dp->d_name)) 2672 && STRLEN(tail) == STRLEN(dp->d_name))
2675 { 2673 {
2676 char_u newname[MAXPATHL + 1]; 2674 char_u newname[MAXPATHL + 1];
2677 struct stat st2; 2675 struct stat st2;
2678 2676
2679 /* Verify the inode is equal. */ 2677 // Verify the inode is equal.
2680 vim_strncpy(newname, name, MAXPATHL); 2678 vim_strncpy(newname, name, MAXPATHL);
2681 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name, 2679 vim_strncpy(newname + (tail - name), (char_u *)dp->d_name,
2682 MAXPATHL - (tail - name)); 2680 MAXPATHL - (tail - name));
2683 if (mch_lstat((char *)newname, &st2) >= 0 2681 if (mch_lstat((char *)newname, &st2) >= 0
2684 && st.st_ino == st2.st_ino 2682 && st.st_ino == st2.st_ino
2703 long 2701 long
2704 mch_getperm(char_u *name) 2702 mch_getperm(char_u *name)
2705 { 2703 {
2706 struct stat statb; 2704 struct stat statb;
2707 2705
2708 /* Keep the #ifdef outside of stat(), it may be a macro. */ 2706 // Keep the #ifdef outside of stat(), it may be a macro.
2709 #ifdef VMS 2707 #ifdef VMS
2710 if (stat((char *)vms_fixfilename(name), &statb)) 2708 if (stat((char *)vms_fixfilename(name), &statb))
2711 #else 2709 #else
2712 if (stat((char *)name, &statb)) 2710 if (stat((char *)name, &statb))
2713 #endif 2711 #endif
2714 return -1; 2712 return -1;
2715 #ifdef __INTERIX 2713 #ifdef __INTERIX
2716 /* The top bit makes the value negative, which means the file doesn't 2714 // The top bit makes the value negative, which means the file doesn't
2717 * exist. Remove the bit, we don't use it. */ 2715 // exist. Remove the bit, we don't use it.
2718 return statb.st_mode & ~S_ADDACE; 2716 return statb.st_mode & ~S_ADDACE;
2719 #else 2717 #else
2720 return statb.st_mode; 2718 return statb.st_mode;
2721 #endif 2719 #endif
2722 } 2720 }
2782 security_context_t from_context = NULL; 2780 security_context_t from_context = NULL;
2783 security_context_t to_context = NULL; 2781 security_context_t to_context = NULL;
2784 2782
2785 if (getfilecon((char *)from_file, &from_context) < 0) 2783 if (getfilecon((char *)from_file, &from_context) < 0)
2786 { 2784 {
2787 /* If the filesystem doesn't support extended attributes, 2785 // If the filesystem doesn't support extended attributes,
2788 the original had no special security context and the 2786 // the original had no special security context and the
2789 target cannot have one either. */ 2787 // target cannot have one either.
2790 if (errno == EOPNOTSUPP) 2788 if (errno == EOPNOTSUPP)
2791 return; 2789 return;
2792 2790
2793 msg_puts(_("\nCould not get security context for ")); 2791 msg_puts(_("\nCould not get security context for "));
2794 msg_outtrans(from_file); 2792 msg_outtrans(from_file);
2814 } 2812 }
2815 freecon(to_context); 2813 freecon(to_context);
2816 freecon(from_context); 2814 freecon(from_context);
2817 } 2815 }
2818 } 2816 }
2819 #endif /* HAVE_SELINUX */ 2817 #endif // HAVE_SELINUX
2820 2818
2821 #if defined(HAVE_SMACK) && !defined(PROTO) 2819 #if defined(HAVE_SMACK) && !defined(PROTO)
2822 /* 2820 /*
2823 * Copy security info from "from_file" to "to_file". 2821 * Copy security info from "from_file" to "to_file".
2824 */ 2822 */
2842 return; 2840 return;
2843 2841
2844 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes) 2842 for (index = 0 ; index < (int)(sizeof(smack_copied_attributes)
2845 / sizeof(smack_copied_attributes)[0]) ; index++) 2843 / sizeof(smack_copied_attributes)[0]) ; index++)
2846 { 2844 {
2847 /* get the name of the attribute to copy */ 2845 // get the name of the attribute to copy
2848 name = smack_copied_attributes[index]; 2846 name = smack_copied_attributes[index];
2849 2847
2850 /* get the value of the attribute in buffer */ 2848 // get the value of the attribute in buffer
2851 size = getxattr((char*)from_file, name, buffer, sizeof(buffer)); 2849 size = getxattr((char*)from_file, name, buffer, sizeof(buffer));
2852 if (size >= 0) 2850 if (size >= 0)
2853 { 2851 {
2854 /* copy the attribute value of buffer */ 2852 // copy the attribute value of buffer
2855 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0); 2853 ret = setxattr((char*)to_file, name, buffer, (size_t)size, 0);
2856 if (ret < 0) 2854 if (ret < 0)
2857 { 2855 {
2858 vim_snprintf((char *)IObuff, IOSIZE, 2856 vim_snprintf((char *)IObuff, IOSIZE,
2859 _("Could not set security context %s for %s"), 2857 _("Could not set security context %s for %s"),
2862 msg_putchar('\n'); 2860 msg_putchar('\n');
2863 } 2861 }
2864 } 2862 }
2865 else 2863 else
2866 { 2864 {
2867 /* what reason of not having the attribute value? */ 2865 // what reason of not having the attribute value?
2868 switch (errno) 2866 switch (errno)
2869 { 2867 {
2870 case ENOTSUP: 2868 case ENOTSUP:
2871 /* extended attributes aren't supported or enabled */ 2869 // extended attributes aren't supported or enabled
2872 /* should a message be echoed? not sure... */ 2870 // should a message be echoed? not sure...
2873 return; /* leave because it isn't useful to continue */ 2871 return; // leave because it isn't useful to continue
2874 2872
2875 case ERANGE: 2873 case ERANGE:
2876 default: 2874 default:
2877 /* no enough size OR unexpected error */ 2875 // no enough size OR unexpected error
2878 vim_snprintf((char *)IObuff, IOSIZE, 2876 vim_snprintf((char *)IObuff, IOSIZE,
2879 _("Could not get security context %s for %s. Removing it!"), 2877 _("Could not get security context %s for %s. Removing it!"),
2880 name, from_file); 2878 name, from_file);
2881 msg_puts((char *)IObuff); 2879 msg_puts((char *)IObuff);
2882 msg_putchar('\n'); 2880 msg_putchar('\n');
2883 /* FALLTHROUGH to remove the attribute */ 2881 // FALLTHROUGH to remove the attribute
2884 2882
2885 case ENODATA: 2883 case ENODATA:
2886 /* no attribute of this name */ 2884 // no attribute of this name
2887 ret = removexattr((char*)to_file, name); 2885 ret = removexattr((char*)to_file, name);
2888 /* Silently ignore errors, apparently this happens when 2886 // Silently ignore errors, apparently this happens when
2889 * smack is not actually being used. */ 2887 // smack is not actually being used.
2890 break; 2888 break;
2891 } 2889 }
2892 } 2890 }
2893 } 2891 }
2894 } 2892 }
2895 #endif /* HAVE_SMACK */ 2893 #endif // HAVE_SMACK
2896 2894
2897 /* 2895 /*
2898 * Return a pointer to the ACL of file "fname" in allocated memory. 2896 * Return a pointer to the ACL of file "fname" in allocated memory.
2899 * Return NULL if the ACL is not available for whatever reason. 2897 * Return NULL if the ACL is not available for whatever reason.
2900 */ 2898 */
2953 free(aclent); 2951 free(aclent);
2954 return NULL; 2952 return NULL;
2955 } 2953 }
2956 } 2954 }
2957 ret = (vim_acl_T)aclent; 2955 ret = (vim_acl_T)aclent;
2958 #endif /* HAVE_AIX_ACL */ 2956 #endif // HAVE_AIX_ACL
2959 #endif /* HAVE_SOLARIS_ACL */ 2957 #endif // HAVE_SOLARIS_ACL
2960 #endif /* HAVE_SOLARIS_ZFS_ACL */ 2958 #endif // HAVE_SOLARIS_ZFS_ACL
2961 #endif /* HAVE_POSIX_ACL */ 2959 #endif // HAVE_POSIX_ACL
2962 return ret; 2960 return ret;
2963 } 2961 }
2964 2962
2965 /* 2963 /*
2966 * Set the ACL of file "fname" to "acl" (unless it's NULL). 2964 * Set the ACL of file "fname" to "acl" (unless it's NULL).
2980 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt, 2978 acl((char *)fname, SETACL, ((vim_acl_solaris_T *)aclent)->acl_cnt,
2981 ((vim_acl_solaris_T *)aclent)->acl_entry); 2979 ((vim_acl_solaris_T *)aclent)->acl_entry);
2982 #else 2980 #else
2983 #ifdef HAVE_AIX_ACL 2981 #ifdef HAVE_AIX_ACL
2984 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len); 2982 chacl((char *)fname, aclent, ((struct acl *)aclent)->acl_len);
2985 #endif /* HAVE_AIX_ACL */ 2983 #endif // HAVE_AIX_ACL
2986 #endif /* HAVE_SOLARIS_ACL */ 2984 #endif // HAVE_SOLARIS_ACL
2987 #endif /* HAVE_SOLARIS_ZFS_ACL */ 2985 #endif // HAVE_SOLARIS_ZFS_ACL
2988 #endif /* HAVE_POSIX_ACL */ 2986 #endif // HAVE_POSIX_ACL
2989 } 2987 }
2990 2988
2991 void 2989 void
2992 mch_free_acl(vim_acl_T aclent) 2990 mch_free_acl(vim_acl_T aclent)
2993 { 2991 {
3003 free(((vim_acl_solaris_T *)aclent)->acl_entry); 3001 free(((vim_acl_solaris_T *)aclent)->acl_entry);
3004 free(aclent); 3002 free(aclent);
3005 #else 3003 #else
3006 #ifdef HAVE_AIX_ACL 3004 #ifdef HAVE_AIX_ACL
3007 free(aclent); 3005 free(aclent);
3008 #endif /* HAVE_AIX_ACL */ 3006 #endif // HAVE_AIX_ACL
3009 #endif /* HAVE_SOLARIS_ACL */ 3007 #endif // HAVE_SOLARIS_ACL
3010 #endif /* HAVE_SOLARIS_ZFS_ACL */ 3008 #endif // HAVE_SOLARIS_ZFS_ACL
3011 #endif /* HAVE_POSIX_ACL */ 3009 #endif // HAVE_POSIX_ACL
3012 } 3010 }
3013 #endif 3011 #endif
3014 3012
3015 /* 3013 /*
3016 * Set hidden flag for "name". 3014 * Set hidden flag for "name".
3017 */ 3015 */
3018 void 3016 void
3019 mch_hide(char_u *name UNUSED) 3017 mch_hide(char_u *name UNUSED)
3020 { 3018 {
3021 /* can't hide a file */ 3019 // can't hide a file
3022 } 3020 }
3023 3021
3024 /* 3022 /*
3025 * return TRUE if "name" is a directory or a symlink to a directory 3023 * return TRUE if "name" is a directory or a symlink to a directory
3026 * return FALSE if "name" is not a directory 3024 * return FALSE if "name" is not a directory
3029 int 3027 int
3030 mch_isdir(char_u *name) 3028 mch_isdir(char_u *name)
3031 { 3029 {
3032 struct stat statb; 3030 struct stat statb;
3033 3031
3034 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ 3032 if (*name == NUL) // Some stat()s don't flag "" as an error.
3035 return FALSE; 3033 return FALSE;
3036 if (stat((char *)name, &statb)) 3034 if (stat((char *)name, &statb))
3037 return FALSE; 3035 return FALSE;
3038 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); 3036 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE);
3039 } 3037 }
3046 int 3044 int
3047 mch_isrealdir(char_u *name) 3045 mch_isrealdir(char_u *name)
3048 { 3046 {
3049 struct stat statb; 3047 struct stat statb;
3050 3048
3051 if (*name == NUL) /* Some stat()s don't flag "" as an error. */ 3049 if (*name == NUL) // Some stat()s don't flag "" as an error.
3052 return FALSE; 3050 return FALSE;
3053 if (mch_lstat((char *)name, &statb)) 3051 if (mch_lstat((char *)name, &statb))
3054 return FALSE; 3052 return FALSE;
3055 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE); 3053 return (S_ISDIR(statb.st_mode) ? TRUE : FALSE);
3056 } 3054 }
3064 struct stat st; 3062 struct stat st;
3065 3063
3066 if (stat((char *)name, &st)) 3064 if (stat((char *)name, &st))
3067 return 0; 3065 return 0;
3068 #ifdef VMS 3066 #ifdef VMS
3069 /* Like on Unix system file can have executable rights but not necessarily 3067 // Like on Unix system file can have executable rights but not necessarily
3070 * be an executable, but on Unix is not a default for an ordinary file to 3068 // be an executable, but on Unix is not a default for an ordinary file to
3071 * have an executable flag - on VMS it is in most cases. 3069 // have an executable flag - on VMS it is in most cases.
3072 * Therefore, this check does not have any sense - let keep us to the 3070 // Therefore, this check does not have any sense - let keep us to the
3073 * conventions instead: 3071 // conventions instead:
3074 * *.COM and *.EXE files are the executables - the rest are not. This is 3072 // *.COM and *.EXE files are the executables - the rest are not. This is
3075 * not ideal but better then it was. 3073 // not ideal but better then it was.
3076 */
3077 int vms_executable = 0; 3074 int vms_executable = 0;
3078 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0) 3075 if (S_ISREG(st.st_mode) && mch_access((char *)name, X_OK) == 0)
3079 { 3076 {
3080 if (strstr(vms_tolower((char*)name),".exe") != NULL 3077 if (strstr(vms_tolower((char*)name),".exe") != NULL
3081 || strstr(vms_tolower((char*)name),".com")!= NULL) 3078 || strstr(vms_tolower((char*)name),".com")!= NULL)
3097 { 3094 {
3098 char_u *buf; 3095 char_u *buf;
3099 char_u *p, *e; 3096 char_u *p, *e;
3100 int retval; 3097 int retval;
3101 3098
3102 /* When "use_path" is false and if it's an absolute or relative path don't 3099 // When "use_path" is false and if it's an absolute or relative path don't
3103 * need to use $PATH. */ 3100 // need to use $PATH.
3104 if (!use_path || gettail(name) != name) 3101 if (!use_path || gettail(name) != name)
3105 { 3102 {
3106 /* There must be a path separator, files in the current directory 3103 // There must be a path separator, files in the current directory
3107 * can't be executed. */ 3104 // can't be executed.
3108 if ((use_path || gettail(name) != name) && executable_file(name)) 3105 if ((use_path || gettail(name) != name) && executable_file(name))
3109 { 3106 {
3110 if (path != NULL) 3107 if (path != NULL)
3111 { 3108 {
3112 if (name[0] != '/') 3109 if (name[0] != '/')
3133 for (;;) 3130 for (;;)
3134 { 3131 {
3135 e = (char_u *)strchr((char *)p, ':'); 3132 e = (char_u *)strchr((char *)p, ':');
3136 if (e == NULL) 3133 if (e == NULL)
3137 e = p + STRLEN(p); 3134 e = p + STRLEN(p);
3138 if (e - p <= 1) /* empty entry means current dir */ 3135 if (e - p <= 1) // empty entry means current dir
3139 STRCPY(buf, "./"); 3136 STRCPY(buf, "./");
3140 else 3137 else
3141 { 3138 {
3142 vim_strncpy(buf, p, e - p); 3139 vim_strncpy(buf, p, e - p);
3143 add_pathsep(buf); 3140 add_pathsep(buf);
3178 3175
3179 if (stat((char *)name, &st)) 3176 if (stat((char *)name, &st))
3180 return NODE_NORMAL; 3177 return NODE_NORMAL;
3181 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) 3178 if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))
3182 return NODE_NORMAL; 3179 return NODE_NORMAL;
3183 if (S_ISBLK(st.st_mode)) /* block device isn't writable */ 3180 if (S_ISBLK(st.st_mode)) // block device isn't writable
3184 return NODE_OTHER; 3181 return NODE_OTHER;
3185 /* Everything else is writable? */ 3182 // Everything else is writable?
3186 return NODE_WRITABLE; 3183 return NODE_WRITABLE;
3187 } 3184 }
3188 3185
3189 void 3186 void
3190 mch_early_init(void) 3187 mch_early_init(void)
3224 # endif 3221 # endif
3225 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) 3222 # if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)
3226 if (xterm_Shell != (Widget)0) 3223 if (xterm_Shell != (Widget)0)
3227 XtDestroyWidget(xterm_Shell); 3224 XtDestroyWidget(xterm_Shell);
3228 # ifndef LESSTIF_VERSION 3225 # ifndef LESSTIF_VERSION
3229 /* Lesstif crashes here, lose some memory */ 3226 // Lesstif crashes here, lose some memory
3230 if (xterm_dpy != NULL) 3227 if (xterm_dpy != NULL)
3231 XtCloseDisplay(xterm_dpy); 3228 XtCloseDisplay(xterm_dpy);
3232 if (app_context != (XtAppContext)NULL) 3229 if (app_context != (XtAppContext)NULL)
3233 { 3230 {
3234 XtDestroyApplicationContext(app_context); 3231 XtDestroyApplicationContext(app_context);
3235 # ifdef FEAT_X11 3232 # ifdef FEAT_X11
3236 x11_display = NULL; /* freed by XtDestroyApplicationContext() */ 3233 x11_display = NULL; // freed by XtDestroyApplicationContext()
3237 # endif 3234 # endif
3238 } 3235 }
3239 # endif 3236 # endif
3240 # endif 3237 # endif
3241 # if defined(FEAT_X11) 3238 # if defined(FEAT_X11)
3277 else 3274 else
3278 out_char('\n'); 3275 out_char('\n');
3279 } 3276 }
3280 else 3277 else
3281 { 3278 {
3282 restore_cterm_colors(); /* get original colors back */ 3279 restore_cterm_colors(); // get original colors back
3283 msg_clr_eos_force(); /* clear the rest of the display */ 3280 msg_clr_eos_force(); // clear the rest of the display
3284 windgoto((int)Rows - 1, 0); /* may have moved the cursor */ 3281 windgoto((int)Rows - 1, 0); // may have moved the cursor
3285 } 3282 }
3286 } 3283 }
3287 3284
3288 void 3285 void
3289 mch_exit(int r) 3286 mch_exit(int r)
3311 * before stoptermcap(). 3308 * before stoptermcap().
3312 */ 3309 */
3313 if (swapping_screen() && !newline_on_exit) 3310 if (swapping_screen() && !newline_on_exit)
3314 exit_scroll(); 3311 exit_scroll();
3315 3312
3316 /* Stop termcap: May need to check for T_CRV response, which 3313 // Stop termcap: May need to check for T_CRV response, which
3317 * requires RAW mode. */ 3314 // requires RAW mode.
3318 stoptermcap(); 3315 stoptermcap();
3319 3316
3320 /* 3317 /*
3321 * A newline is only required after a message in the alternate screen. 3318 * A newline is only required after a message in the alternate screen.
3322 * This is set to TRUE by wait_return(). 3319 * This is set to TRUE by wait_return().
3323 */ 3320 */
3324 if (!swapping_screen() || newline_on_exit) 3321 if (!swapping_screen() || newline_on_exit)
3325 exit_scroll(); 3322 exit_scroll();
3326 3323
3327 /* Cursor may have been switched off without calling starttermcap() 3324 // Cursor may have been switched off without calling starttermcap()
3328 * when doing "vim -u vimrc" and vimrc contains ":q". */ 3325 // when doing "vim -u vimrc" and vimrc contains ":q".
3329 if (full_screen) 3326 if (full_screen)
3330 cursor_on(); 3327 cursor_on();
3331 } 3328 }
3332 out_flush(); 3329 out_flush();
3333 ml_close_all(TRUE); /* remove all memfiles */ 3330 ml_close_all(TRUE); // remove all memfiles
3334 may_core_dump(); 3331 may_core_dump();
3335 #ifdef FEAT_GUI 3332 #ifdef FEAT_GUI
3336 if (gui.in_use) 3333 if (gui.in_use)
3337 gui_exit(r); 3334 gui_exit(r);
3338 #endif 3335 #endif
3340 #ifdef MACOS_CONVERT 3337 #ifdef MACOS_CONVERT
3341 mac_conv_cleanup(); 3338 mac_conv_cleanup();
3342 #endif 3339 #endif
3343 3340
3344 #ifdef __QNX__ 3341 #ifdef __QNX__
3345 /* A core dump won't be created if the signal handler 3342 // A core dump won't be created if the signal handler
3346 * doesn't return, so we can't call exit() */ 3343 // doesn't return, so we can't call exit()
3347 if (deadly_signal != 0) 3344 if (deadly_signal != 0)
3348 return; 3345 return;
3349 #endif 3346 #endif
3350 3347
3351 #ifdef FEAT_NETBEANS_INTG 3348 #ifdef FEAT_NETBEANS_INTG
3363 may_core_dump(void) 3360 may_core_dump(void)
3364 { 3361 {
3365 if (deadly_signal != 0) 3362 if (deadly_signal != 0)
3366 { 3363 {
3367 signal(deadly_signal, SIG_DFL); 3364 signal(deadly_signal, SIG_DFL);
3368 kill(getpid(), deadly_signal); /* Die using the signal we caught */ 3365 kill(getpid(), deadly_signal); // Die using the signal we caught
3369 } 3366 }
3370 } 3367 }
3371 3368
3372 #ifndef VMS 3369 #ifndef VMS
3373 3370
3450 * ~ICRNL enables typing ^V^M 3447 * ~ICRNL enables typing ^V^M
3451 */ 3448 */
3452 tnew.c_iflag &= ~ICRNL; 3449 tnew.c_iflag &= ~ICRNL;
3453 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE 3450 tnew.c_lflag &= ~(ICANON | ECHO | ISIG | ECHOE
3454 # if defined(IEXTEN) && !defined(__MINT__) 3451 # if defined(IEXTEN) && !defined(__MINT__)
3455 | IEXTEN /* IEXTEN enables typing ^V on SOLARIS */ 3452 | IEXTEN // IEXTEN enables typing ^V on SOLARIS
3456 /* but it breaks function keys on MINT */ 3453 // but it breaks function keys on MINT
3457 # endif 3454 # endif
3458 ); 3455 );
3459 # ifdef ONLCR 3456 # ifdef ONLCR
3460 // Don't map NL -> CR NL, we do it ourselves. 3457 // Don't map NL -> CR NL, we do it ourselves.
3461 // Also disable expanding tabs if possible. 3458 // Also disable expanding tabs if possible.
3472 tnew.c_cc[VMIN] = 1; // return after 1 char 3469 tnew.c_cc[VMIN] = 1; // return after 1 char
3473 tnew.c_cc[VTIME] = 0; // don't wait 3470 tnew.c_cc[VTIME] = 0; // don't wait
3474 } 3471 }
3475 else if (tmode == TMODE_SLEEP) 3472 else if (tmode == TMODE_SLEEP)
3476 { 3473 {
3477 /* Also reset ICANON here, otherwise on Solaris select() won't see 3474 // Also reset ICANON here, otherwise on Solaris select() won't see
3478 * typeahead characters. */ 3475 // typeahead characters.
3479 tnew.c_lflag &= ~(ICANON | ECHO); 3476 tnew.c_lflag &= ~(ICANON | ECHO);
3480 tnew.c_cc[VMIN] = 1; /* return after 1 char */ 3477 tnew.c_cc[VMIN] = 1; // return after 1 char
3481 tnew.c_cc[VTIME] = 0; /* don't wait */ 3478 tnew.c_cc[VTIME] = 0; // don't wait
3482 } 3479 }
3483 3480
3484 # if defined(HAVE_TERMIOS_H) 3481 # if defined(HAVE_TERMIOS_H)
3485 { 3482 {
3486 int n = 10; 3483 int n = 10;
3487 3484
3488 /* A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a 3485 // A signal may cause tcsetattr() to fail (e.g., SIGCONT). Retry a
3489 * few times. */ 3486 // few times.
3490 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1 3487 while (tcsetattr(read_cmd_fd, TCSANOW, &tnew) == -1
3491 && errno == EINTR && n > 0) 3488 && errno == EINTR && n > 0)
3492 --n; 3489 --n;
3493 } 3490 }
3494 # else 3491 # else
3498 #else 3495 #else
3499 /* 3496 /*
3500 * for "old" tty systems 3497 * for "old" tty systems
3501 */ 3498 */
3502 # ifndef TIOCSETN 3499 # ifndef TIOCSETN
3503 # define TIOCSETN TIOCSETP /* for hpux 9.0 */ 3500 # define TIOCSETN TIOCSETP // for hpux 9.0
3504 # endif 3501 # endif
3505 static struct sgttyb ttybold; 3502 static struct sgttyb ttybold;
3506 struct sgttyb ttybnew; 3503 struct sgttyb ttybnew;
3507 3504
3508 if (first) 3505 if (first)
3545 intr_char = info.interrupt; 3542 intr_char = info.interrupt;
3546 buf[0] = info.backspace; 3543 buf[0] = info.backspace;
3547 buf[1] = NUL; 3544 buf[1] = NUL;
3548 add_termcode((char_u *)"kb", buf, FALSE); 3545 add_termcode((char_u *)"kb", buf, FALSE);
3549 3546
3550 /* If <BS> and <DEL> are now the same, redefine <DEL>. */ 3547 // If <BS> and <DEL> are now the same, redefine <DEL>.
3551 p = find_termcode((char_u *)"kD"); 3548 p = find_termcode((char_u *)"kD");
3552 if (p != NULL && p[0] == buf[0] && p[1] == buf[1]) 3549 if (p != NULL && p[0] == buf[0] && p[1] == buf[1])
3553 do_fixdel(NULL); 3550 do_fixdel(NULL);
3554 } 3551 }
3555 } 3552 }
3581 else 3578 else
3582 info->nl_does_cr = FALSE; 3579 info->nl_does_cr = FALSE;
3583 return OK; 3580 return OK;
3584 } 3581 }
3585 #else 3582 #else
3586 /* for "old" tty systems */ 3583 // for "old" tty systems
3587 struct sgttyb keys; 3584 struct sgttyb keys;
3588 3585
3589 if (mch_tcgetattr(fd, &keys) != -1) 3586 if (mch_tcgetattr(fd, &keys) != -1)
3590 { 3587 {
3591 info->backspace = keys.sg_erase; 3588 info->backspace = keys.sg_erase;
3596 } 3593 }
3597 #endif 3594 #endif
3598 return FAIL; 3595 return FAIL;
3599 } 3596 }
3600 3597
3601 #endif /* VMS */ 3598 #endif // VMS
3602 3599
3603 static int mouse_ison = FALSE; 3600 static int mouse_ison = FALSE;
3604 3601
3605 /* 3602 /*
3606 * Set mouse clicks on or off. 3603 * Set mouse clicks on or off.
3623 if (on == mouse_ison 3620 if (on == mouse_ison
3624 #ifdef FEAT_BEVAL_TERM 3621 #ifdef FEAT_BEVAL_TERM
3625 && p_bevalterm == bevalterm_ison 3622 && p_bevalterm == bevalterm_ison
3626 #endif 3623 #endif
3627 ) 3624 )
3628 /* return quickly if nothing to do */ 3625 // return quickly if nothing to do
3629 return; 3626 return;
3630 3627
3631 xterm_mouse_vers = use_xterm_mouse(); 3628 xterm_mouse_vers = use_xterm_mouse();
3632 3629
3633 #ifdef FEAT_MOUSE_URXVT 3630 #ifdef FEAT_MOUSE_URXVT
3641 } 3638 }
3642 #endif 3639 #endif
3643 3640
3644 if (ttym_flags == TTYM_SGR) 3641 if (ttym_flags == TTYM_SGR)
3645 { 3642 {
3646 /* SGR mode supports columns above 223 */ 3643 // SGR mode supports columns above 223
3647 out_str_nf((char_u *) 3644 out_str_nf((char_u *)
3648 (on 3645 (on
3649 ? IF_EB("\033[?1006h", ESC_STR "[?1006h") 3646 ? IF_EB("\033[?1006h", ESC_STR "[?1006h")
3650 : IF_EB("\033[?1006l", ESC_STR "[?1006l"))); 3647 : IF_EB("\033[?1006l", ESC_STR "[?1006l")));
3651 mouse_ison = on; 3648 mouse_ison = on;
3654 #ifdef FEAT_BEVAL_TERM 3651 #ifdef FEAT_BEVAL_TERM
3655 if (bevalterm_ison != (p_bevalterm && on)) 3652 if (bevalterm_ison != (p_bevalterm && on))
3656 { 3653 {
3657 bevalterm_ison = (p_bevalterm && on); 3654 bevalterm_ison = (p_bevalterm && on);
3658 if (xterm_mouse_vers > 1 && !bevalterm_ison) 3655 if (xterm_mouse_vers > 1 && !bevalterm_ison)
3659 /* disable mouse movement events, enabling is below */ 3656 // disable mouse movement events, enabling is below
3660 out_str_nf((char_u *) 3657 out_str_nf((char_u *)
3661 (IF_EB("\033[?1003l", ESC_STR "[?1003l"))); 3658 (IF_EB("\033[?1003l", ESC_STR "[?1003l")));
3662 } 3659 }
3663 #endif 3660 #endif
3664 3661
3665 if (xterm_mouse_vers > 0) 3662 if (xterm_mouse_vers > 0)
3666 { 3663 {
3667 if (on) /* enable mouse events, use mouse tracking if available */ 3664 if (on) // enable mouse events, use mouse tracking if available
3668 out_str_nf((char_u *) 3665 out_str_nf((char_u *)
3669 (xterm_mouse_vers > 1 3666 (xterm_mouse_vers > 1
3670 ? ( 3667 ? (
3671 #ifdef FEAT_BEVAL_TERM 3668 #ifdef FEAT_BEVAL_TERM
3672 bevalterm_ison 3669 bevalterm_ison
3673 ? IF_EB("\033[?1003h", ESC_STR "[?1003h") : 3670 ? IF_EB("\033[?1003h", ESC_STR "[?1003h") :
3674 #endif 3671 #endif
3675 IF_EB("\033[?1002h", ESC_STR "[?1002h")) 3672 IF_EB("\033[?1002h", ESC_STR "[?1002h"))
3676 : IF_EB("\033[?1000h", ESC_STR "[?1000h"))); 3673 : IF_EB("\033[?1000h", ESC_STR "[?1000h")));
3677 else /* disable mouse events, could probably always send the same */ 3674 else // disable mouse events, could probably always send the same
3678 out_str_nf((char_u *) 3675 out_str_nf((char_u *)
3679 (xterm_mouse_vers > 1 3676 (xterm_mouse_vers > 1
3680 ? IF_EB("\033[?1002l", ESC_STR "[?1002l") 3677 ? IF_EB("\033[?1002l", ESC_STR "[?1002l")
3681 : IF_EB("\033[?1000l", ESC_STR "[?1000l"))); 3678 : IF_EB("\033[?1000l", ESC_STR "[?1000l")));
3682 mouse_ison = on; 3679 mouse_ison = on;
3683 } 3680 }
3684 3681
3685 #ifdef FEAT_MOUSE_DEC 3682 #ifdef FEAT_MOUSE_DEC
3686 else if (ttym_flags == TTYM_DEC) 3683 else if (ttym_flags == TTYM_DEC)
3687 { 3684 {
3688 if (on) /* enable mouse events */ 3685 if (on) // enable mouse events
3689 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{"); 3686 out_str_nf((char_u *)"\033[1;2'z\033[1;3'{");
3690 else /* disable mouse events */ 3687 else // disable mouse events
3691 out_str_nf((char_u *)"\033['z"); 3688 out_str_nf((char_u *)"\033['z");
3692 mouse_ison = on; 3689 mouse_ison = on;
3693 } 3690 }
3694 #endif 3691 #endif
3695 3692
3728 #ifdef FEAT_MOUSE_JSB 3725 #ifdef FEAT_MOUSE_JSB
3729 else 3726 else
3730 { 3727 {
3731 if (on) 3728 if (on)
3732 { 3729 {
3733 /* D - Enable Mouse up/down messages 3730 // D - Enable Mouse up/down messages
3734 * L - Enable Left Button Reporting 3731 // L - Enable Left Button Reporting
3735 * M - Enable Middle Button Reporting 3732 // M - Enable Middle Button Reporting
3736 * R - Enable Right Button Reporting 3733 // R - Enable Right Button Reporting
3737 * K - Enable SHIFT and CTRL key Reporting 3734 // K - Enable SHIFT and CTRL key Reporting
3738 * + - Enable Advanced messaging of mouse moves and up/down messages 3735 // + - Enable Advanced messaging of mouse moves and up/down messages
3739 * Q - Quiet No Ack 3736 // Q - Quiet No Ack
3740 * # - Numeric value of mouse pointer required 3737 // # - Numeric value of mouse pointer required
3741 * 0 = Multiview 2000 cursor, used as standard 3738 // 0 = Multiview 2000 cursor, used as standard
3742 * 1 = Windows Arrow 3739 // 1 = Windows Arrow
3743 * 2 = Windows I Beam 3740 // 2 = Windows I Beam
3744 * 3 = Windows Hour Glass 3741 // 3 = Windows Hour Glass
3745 * 4 = Windows Cross Hair 3742 // 4 = Windows Cross Hair
3746 * 5 = Windows UP Arrow 3743 // 5 = Windows UP Arrow
3747 */
3748 # ifdef JSBTERM_MOUSE_NONADVANCED 3744 # ifdef JSBTERM_MOUSE_NONADVANCED
3749 /* Disables full feedback of pointer movements */ 3745 // Disables full feedback of pointer movements
3750 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\", 3746 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK1Q\033\\",
3751 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\")); 3747 ESC_STR "[0~ZwLMRK1Q" ESC_STR "\\"));
3752 # else 3748 # else
3753 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\", 3749 out_str_nf((char_u *)IF_EB("\033[0~ZwLMRK+1Q\033\\",
3754 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\")); 3750 ESC_STR "[0~ZwLMRK+1Q" ESC_STR "\\"));
3764 } 3760 }
3765 #endif 3761 #endif
3766 #ifdef FEAT_MOUSE_PTERM 3762 #ifdef FEAT_MOUSE_PTERM
3767 else 3763 else
3768 { 3764 {
3769 /* 1 = button press, 6 = release, 7 = drag, 1h...9l = right button */ 3765 // 1 = button press, 6 = release, 7 = drag, 1h...9l = right button
3770 if (on) 3766 if (on)
3771 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l"); 3767 out_str_nf("\033[>1h\033[>6h\033[>7h\033[>1h\033[>9l");
3772 else 3768 else
3773 out_str_nf("\033[>1l\033[>6l\033[>7l\033[>1l\033[>9h"); 3769 out_str_nf("\033[>1l\033[>6l\033[>7l\033[>1l\033[>9h");
3774 mouse_ison = on; 3770 mouse_ison = on;
3806 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME) 3802 set_mouse_termcode(KS_MOUSE, (char_u *)(term_is_8bit(T_NAME)
3807 ? IF_EB("\233M", CSI_STR "M") 3803 ? IF_EB("\233M", CSI_STR "M")
3808 : IF_EB("\033[M", ESC_STR "[M"))); 3804 : IF_EB("\033[M", ESC_STR "[M")));
3809 if (*p_mouse != NUL) 3805 if (*p_mouse != NUL)
3810 { 3806 {
3811 /* force mouse off and maybe on to send possibly new mouse 3807 // force mouse off and maybe on to send possibly new mouse
3812 * activation sequence to the xterm, with(out) drag tracing. */ 3808 // activation sequence to the xterm, with(out) drag tracing.
3813 mch_setmouse(FALSE); 3809 mch_setmouse(FALSE);
3814 setmouse(); 3810 setmouse();
3815 } 3811 }
3816 } 3812 }
3817 else 3813 else
3838 ) 3834 )
3839 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS")); 3835 set_mouse_termcode(KS_MOUSE, (char_u *)IF_EB("\033MS", ESC_STR "MS"));
3840 # endif 3836 # endif
3841 3837
3842 # ifdef FEAT_MOUSE_JSB 3838 # ifdef FEAT_MOUSE_JSB
3843 /* Conflicts with xterm mouse: "\033[" and "\033[M" ??? */ 3839 // Conflicts with xterm mouse: "\033[" and "\033[M" ???
3844 if (!use_xterm_mouse() 3840 if (!use_xterm_mouse()
3845 # ifdef FEAT_GUI 3841 # ifdef FEAT_GUI
3846 && !gui.in_use 3842 && !gui.in_use
3847 # endif 3843 # endif
3848 ) 3844 )
3851 else 3847 else
3852 del_mouse_termcode(KS_JSBTERM_MOUSE); 3848 del_mouse_termcode(KS_JSBTERM_MOUSE);
3853 # endif 3849 # endif
3854 3850
3855 # ifdef FEAT_MOUSE_NET 3851 # ifdef FEAT_MOUSE_NET
3856 /* There is no conflict, but one may type "ESC }" from Insert mode. Don't 3852 // There is no conflict, but one may type "ESC }" from Insert mode. Don't
3857 * define it in the GUI or when using an xterm. */ 3853 // define it in the GUI or when using an xterm.
3858 if (!use_xterm_mouse() 3854 if (!use_xterm_mouse()
3859 # ifdef FEAT_GUI 3855 # ifdef FEAT_GUI
3860 && !gui.in_use 3856 && !gui.in_use
3861 # endif 3857 # endif
3862 ) 3858 )
3865 else 3861 else
3866 del_mouse_termcode(KS_NETTERM_MOUSE); 3862 del_mouse_termcode(KS_NETTERM_MOUSE);
3867 # endif 3863 # endif
3868 3864
3869 # ifdef FEAT_MOUSE_DEC 3865 # ifdef FEAT_MOUSE_DEC
3870 /* Conflicts with xterm mouse: "\033[" and "\033[M" */ 3866 // Conflicts with xterm mouse: "\033[" and "\033[M"
3871 if (!use_xterm_mouse() 3867 if (!use_xterm_mouse()
3872 # ifdef FEAT_GUI 3868 # ifdef FEAT_GUI
3873 && !gui.in_use 3869 && !gui.in_use
3874 # endif 3870 # endif
3875 ) 3871 )
3877 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); 3873 ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "[")));
3878 else 3874 else
3879 del_mouse_termcode(KS_DEC_MOUSE); 3875 del_mouse_termcode(KS_DEC_MOUSE);
3880 # endif 3876 # endif
3881 # ifdef FEAT_MOUSE_PTERM 3877 # ifdef FEAT_MOUSE_PTERM
3882 /* same conflict as the dec mouse */ 3878 // same conflict as the dec mouse
3883 if (!use_xterm_mouse() 3879 if (!use_xterm_mouse()
3884 # ifdef FEAT_GUI 3880 # ifdef FEAT_GUI
3885 && !gui.in_use 3881 && !gui.in_use
3886 # endif 3882 # endif
3887 ) 3883 )
3973 # ifdef TIOCGWINSZ 3969 # ifdef TIOCGWINSZ
3974 { 3970 {
3975 struct winsize ws; 3971 struct winsize ws;
3976 int fd = 1; 3972 int fd = 1;
3977 3973
3978 /* When stdout is not a tty, use stdin for the ioctl(). */ 3974 // When stdout is not a tty, use stdin for the ioctl().
3979 if (!isatty(fd) && isatty(read_cmd_fd)) 3975 if (!isatty(fd) && isatty(read_cmd_fd))
3980 fd = read_cmd_fd; 3976 fd = read_cmd_fd;
3981 if (ioctl(fd, TIOCGWINSZ, &ws) == 0) 3977 if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
3982 { 3978 {
3983 columns = ws.ws_col; 3979 columns = ws.ws_col;
3984 rows = ws.ws_row; 3980 rows = ws.ws_row;
3985 } 3981 }
3986 } 3982 }
3987 # else /* TIOCGWINSZ */ 3983 # else // TIOCGWINSZ
3988 # ifdef TIOCGSIZE 3984 # ifdef TIOCGSIZE
3989 { 3985 {
3990 struct ttysize ts; 3986 struct ttysize ts;
3991 int fd = 1; 3987 int fd = 1;
3992 3988
3993 /* When stdout is not a tty, use stdin for the ioctl(). */ 3989 // When stdout is not a tty, use stdin for the ioctl().
3994 if (!isatty(fd) && isatty(read_cmd_fd)) 3990 if (!isatty(fd) && isatty(read_cmd_fd))
3995 fd = read_cmd_fd; 3991 fd = read_cmd_fd;
3996 if (ioctl(fd, TIOCGSIZE, &ts) == 0) 3992 if (ioctl(fd, TIOCGSIZE, &ts) == 0)
3997 { 3993 {
3998 columns = ts.ts_cols; 3994 columns = ts.ts_cols;
3999 rows = ts.ts_lines; 3995 rows = ts.ts_lines;
4000 } 3996 }
4001 } 3997 }
4002 # endif /* TIOCGSIZE */ 3998 # endif // TIOCGSIZE
4003 # endif /* TIOCGWINSZ */ 3999 # endif // TIOCGWINSZ
4004 4000
4005 /* 4001 /*
4006 * 2. get size from environment 4002 * 2. get size from environment
4007 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules 4003 * When being POSIX compliant ('|' flag in 'cpoptions') this overrules
4008 * the ioctl() values! 4004 * the ioctl() values!
4087 * undefined, check the output of configure. It could probably not 4083 * undefined, check the output of configure. It could probably not
4088 * find a ncurses, termcap or termlib library. 4084 * find a ncurses, termcap or termlib library.
4089 */ 4085 */
4090 term_set_winsize((int)Rows, (int)Columns); 4086 term_set_winsize((int)Rows, (int)Columns);
4091 out_flush(); 4087 out_flush();
4092 screen_start(); /* don't know where cursor is now */ 4088 screen_start(); // don't know where cursor is now
4093 } 4089 }
4094 } 4090 }
4095 4091
4096 #endif /* VMS */ 4092 #endif // VMS
4097 4093
4098 /* 4094 /*
4099 * Rows and/or Columns has changed. 4095 * Rows and/or Columns has changed.
4100 */ 4096 */
4101 void 4097 void
4102 mch_new_shellsize(void) 4098 mch_new_shellsize(void)
4103 { 4099 {
4104 /* Nothing to do. */ 4100 // Nothing to do.
4105 } 4101 }
4106 4102
4107 /* 4103 /*
4108 * Wait for process "child" to end. 4104 * Wait for process "child" to end.
4109 * Return "child" if it exited properly, <= 0 on error. 4105 * Return "child" if it exited properly, <= 0 on error.
4114 pid_t wait_pid = 0; 4110 pid_t wait_pid = 0;
4115 long delay_msec = 1; 4111 long delay_msec = 1;
4116 4112
4117 while (wait_pid != child) 4113 while (wait_pid != child)
4118 { 4114 {
4119 /* When compiled with Python threads are probably used, in which case 4115 // When compiled with Python threads are probably used, in which case
4120 * wait() sometimes hangs for no obvious reason. Use waitpid() 4116 // wait() sometimes hangs for no obvious reason. Use waitpid()
4121 * instead and loop (like the GUI). Also needed for other interfaces, 4117 // instead and loop (like the GUI). Also needed for other interfaces,
4122 * they might call system(). */ 4118 // they might call system().
4123 # ifdef __NeXT__ 4119 # ifdef __NeXT__
4124 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0); 4120 wait_pid = wait4(child, status, WNOHANG, (struct rusage *)0);
4125 # else 4121 # else
4126 wait_pid = waitpid(child, status, WNOHANG); 4122 wait_pid = waitpid(child, status, WNOHANG);
4127 # endif 4123 # endif
4128 if (wait_pid == 0) 4124 if (wait_pid == 0)
4129 { 4125 {
4130 /* Wait for 1 to 10 msec before trying again. */ 4126 // Wait for 1 to 10 msec before trying again.
4131 mch_delay(delay_msec, TRUE); 4127 mch_delay(delay_msec, TRUE);
4132 if (++delay_msec > 10) 4128 if (++delay_msec > 10)
4133 delay_msec = 10; 4129 delay_msec = 10;
4134 continue; 4130 continue;
4135 } 4131 }
4253 *name2 = NULL; 4249 *name2 = NULL;
4254 4250
4255 *pty_master_fd = mch_openpty(&tty_name); // open pty 4251 *pty_master_fd = mch_openpty(&tty_name); // open pty
4256 if (*pty_master_fd >= 0) 4252 if (*pty_master_fd >= 0)
4257 { 4253 {
4258 /* Leaving out O_NOCTTY may lead to waitpid() always returning 4254 // Leaving out O_NOCTTY may lead to waitpid() always returning
4259 * 0 on Mac OS X 10.7 thereby causing freezes. Let's assume 4255 // 0 on Mac OS X 10.7 thereby causing freezes. Let's assume
4260 * adding O_NOCTTY always works when defined. */ 4256 // adding O_NOCTTY always works when defined.
4261 #ifdef O_NOCTTY 4257 #ifdef O_NOCTTY
4262 *pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0); 4258 *pty_slave_fd = open(tty_name, O_RDWR | O_NOCTTY | O_EXTRA, 0);
4263 #else 4259 #else
4264 *pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0); 4260 *pty_slave_fd = open(tty_name, O_RDWR | O_EXTRA, 0);
4265 #endif 4261 #endif
4299 # endif 4295 # endif
4300 } 4296 }
4301 4297
4302 #if !defined(USE_SYSTEM) || defined(FEAT_TERMINAL) || defined(PROTO) 4298 #if !defined(USE_SYSTEM) || defined(FEAT_TERMINAL) || defined(PROTO)
4303 4299
4300 /*
4301 * Parse "cmd" and return the result in "argvp" which is an allocated array of
4302 * pointers, the last one is NULL.
4303 * The "sh_tofree" and "shcf_tofree" must be later freed by the caller.
4304 */
4304 int 4305 int
4305 unix_build_argv( 4306 unix_build_argv(
4306 char_u *cmd, 4307 char_u *cmd,
4307 char ***argvp, 4308 char ***argvp,
4308 char_u **sh_tofree, 4309 char_u **sh_tofree,
4310 { 4311 {
4311 char **argv = NULL; 4312 char **argv = NULL;
4312 int argc; 4313 int argc;
4313 4314
4314 *sh_tofree = vim_strsave(p_sh); 4315 *sh_tofree = vim_strsave(p_sh);
4315 if (*sh_tofree == NULL) /* out of memory */ 4316 if (*sh_tofree == NULL) // out of memory
4316 return FAIL; 4317 return FAIL;
4317 4318
4318 if (mch_parse_cmd(*sh_tofree, TRUE, &argv, &argc) == FAIL) 4319 if (mch_parse_cmd(*sh_tofree, TRUE, &argv, &argc) == FAIL)
4319 return FAIL; 4320 return FAIL;
4320 *argvp = argv; 4321 *argvp = argv;
4325 char_u *p; 4326 char_u *p;
4326 4327
4327 if (extra_shell_arg != NULL) 4328 if (extra_shell_arg != NULL)
4328 argv[argc++] = (char *)extra_shell_arg; 4329 argv[argc++] = (char *)extra_shell_arg;
4329 4330
4330 /* Break 'shellcmdflag' into white separated parts. This doesn't 4331 // Break 'shellcmdflag' into white separated parts. This doesn't
4331 * handle quoted strings, they are very unlikely to appear. */ 4332 // handle quoted strings, they are very unlikely to appear.
4332 *shcf_tofree = alloc(STRLEN(p_shcf) + 1); 4333 *shcf_tofree = alloc(STRLEN(p_shcf) + 1);
4333 if (*shcf_tofree == NULL) /* out of memory */ 4334 if (*shcf_tofree == NULL) // out of memory
4334 return FAIL; 4335 return FAIL;
4335 s = *shcf_tofree; 4336 s = *shcf_tofree;
4336 p = p_shcf; 4337 p = p_shcf;
4337 while (*p != NUL) 4338 while (*p != NUL)
4338 { 4339 {
4355 * Use a terminal window to run a shell command in. 4356 * Use a terminal window to run a shell command in.
4356 */ 4357 */
4357 static int 4358 static int
4358 mch_call_shell_terminal( 4359 mch_call_shell_terminal(
4359 char_u *cmd, 4360 char_u *cmd,
4360 int options UNUSED) /* SHELL_*, see vim.h */ 4361 int options UNUSED) // SHELL_*, see vim.h
4361 { 4362 {
4362 jobopt_T opt; 4363 jobopt_T opt;
4363 char **argv = NULL; 4364 char **argv = NULL;
4364 char_u *tofree1 = NULL; 4365 char_u *tofree1 = NULL;
4365 char_u *tofree2 = NULL; 4366 char_u *tofree2 = NULL;
4366 int retval = -1; 4367 int retval = -1;
4367 buf_T *buf; 4368 buf_T *buf;
4368 job_T *job; 4369 job_T *job;
4369 aco_save_T aco; 4370 aco_save_T aco;
4370 oparg_T oa; /* operator arguments */ 4371 oparg_T oa; // operator arguments
4371 4372
4372 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) 4373 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL)
4373 goto theend; 4374 goto theend;
4374 4375
4375 init_job_options(&opt); 4376 init_job_options(&opt);
4379 goto theend; 4380 goto theend;
4380 4381
4381 job = term_getjob(buf->b_term); 4382 job = term_getjob(buf->b_term);
4382 ++job->jv_refcount; 4383 ++job->jv_refcount;
4383 4384
4384 /* Find a window to make "buf" curbuf. */ 4385 // Find a window to make "buf" curbuf.
4385 aucmd_prepbuf(&aco, buf); 4386 aucmd_prepbuf(&aco, buf);
4386 4387
4387 clear_oparg(&oa); 4388 clear_oparg(&oa);
4388 while (term_use_loop()) 4389 while (term_use_loop())
4389 { 4390 {
4390 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) 4391 if (oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active)
4391 { 4392 {
4392 /* If terminal_loop() returns OK we got a key that is handled 4393 // If terminal_loop() returns OK we got a key that is handled
4393 * in Normal model. We don't do redrawing anyway. */ 4394 // in Normal model. We don't do redrawing anyway.
4394 if (terminal_loop(TRUE) == OK) 4395 if (terminal_loop(TRUE) == OK)
4395 normal_cmd(&oa, TRUE); 4396 normal_cmd(&oa, TRUE);
4396 } 4397 }
4397 else 4398 else
4398 normal_cmd(&oa, TRUE); 4399 normal_cmd(&oa, TRUE);
4400 retval = job->jv_exitval; 4401 retval = job->jv_exitval;
4401 ch_log(NULL, "system command finished"); 4402 ch_log(NULL, "system command finished");
4402 4403
4403 job_unref(job); 4404 job_unref(job);
4404 4405
4405 /* restore curwin/curbuf and a few other things */ 4406 // restore curwin/curbuf and a few other things
4406 aucmd_restbuf(&aco); 4407 aucmd_restbuf(&aco);
4407 4408
4408 wait_return(TRUE); 4409 wait_return(TRUE);
4409 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); 4410 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE);
4410 4411
4421 * Use system() to start the shell: simple but slow. 4422 * Use system() to start the shell: simple but slow.
4422 */ 4423 */
4423 static int 4424 static int
4424 mch_call_shell_system( 4425 mch_call_shell_system(
4425 char_u *cmd, 4426 char_u *cmd,
4426 int options) /* SHELL_*, see vim.h */ 4427 int options) // SHELL_*, see vim.h
4427 { 4428 {
4428 #ifdef VMS 4429 #ifdef VMS
4429 char *ifn = NULL; 4430 char *ifn = NULL;
4430 char *ofn = NULL; 4431 char *ofn = NULL;
4431 #endif 4432 #endif
4432 int tmode = cur_tmode; 4433 int tmode = cur_tmode;
4433 char_u *newcmd; /* only needed for unix */ 4434 char_u *newcmd; // only needed for unix
4434 int x; 4435 int x;
4435 4436
4436 out_flush(); 4437 out_flush();
4437 4438
4438 if (options & SHELL_COOKED) 4439 if (options & SHELL_COOKED)
4439 settmode(TMODE_COOK); /* set to normal mode */ 4440 settmode(TMODE_COOK); // set to normal mode
4440 4441
4441 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) 4442 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
4442 save_clipboard(); 4443 save_clipboard();
4443 loose_clipboard(); 4444 loose_clipboard();
4444 # endif 4445 # endif
4453 if (ifn = strchr((char *)cmd, '<')) 4454 if (ifn = strchr((char *)cmd, '<'))
4454 { 4455 {
4455 char *p; 4456 char *p;
4456 4457
4457 *ifn++ = '\0'; 4458 *ifn++ = '\0';
4458 p = strchr(ifn,' '); /* chop off any trailing spaces */ 4459 p = strchr(ifn,' '); // chop off any trailing spaces
4459 if (p) 4460 if (p)
4460 *p = '\0'; 4461 *p = '\0';
4461 } 4462 }
4462 if (ofn) 4463 if (ofn)
4463 x = vms_sys((char *)cmd, ofn, ifn); 4464 x = vms_sys((char *)cmd, ofn, ifn);
4493 msg_outnum((long)x); 4494 msg_outnum((long)x);
4494 msg_putchar('\n'); 4495 msg_putchar('\n');
4495 } 4496 }
4496 4497
4497 if (tmode == TMODE_RAW) 4498 if (tmode == TMODE_RAW)
4498 settmode(TMODE_RAW); /* set to raw mode */ 4499 settmode(TMODE_RAW); // set to raw mode
4499 # ifdef FEAT_TITLE 4500 # ifdef FEAT_TITLE
4500 resettitle(); 4501 resettitle();
4501 # endif 4502 # endif
4502 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) 4503 # if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
4503 restore_clipboard(); 4504 restore_clipboard();
4504 # endif 4505 # endif
4505 return x; 4506 return x;
4506 } 4507 }
4507 4508
4508 #else /* USE_SYSTEM */ 4509 #else // USE_SYSTEM
4509 4510
4510 # define EXEC_FAILED 122 /* Exit code when shell didn't execute. Don't use 4511 # define EXEC_FAILED 122 // Exit code when shell didn't execute. Don't use
4511 127, some shells use that already */ 4512 // 127, some shells use that already
4512 # define OPEN_NULL_FAILED 123 /* Exit code if /dev/null can't be opened */ 4513 # define OPEN_NULL_FAILED 123 // Exit code if /dev/null can't be opened
4513 4514
4514 /* 4515 /*
4515 * Don't use system(), use fork()/exec(). 4516 * Don't use system(), use fork()/exec().
4516 */ 4517 */
4517 static int 4518 static int
4518 mch_call_shell_fork( 4519 mch_call_shell_fork(
4519 char_u *cmd, 4520 char_u *cmd,
4520 int options) /* SHELL_*, see vim.h */ 4521 int options) // SHELL_*, see vim.h
4521 { 4522 {
4522 int tmode = cur_tmode; 4523 int tmode = cur_tmode;
4523 pid_t pid; 4524 pid_t pid;
4524 pid_t wpid = 0; 4525 pid_t wpid = 0;
4525 pid_t wait_pid = 0; 4526 pid_t wait_pid = 0;
4531 int retval = -1; 4532 int retval = -1;
4532 char **argv = NULL; 4533 char **argv = NULL;
4533 char_u *tofree1 = NULL; 4534 char_u *tofree1 = NULL;
4534 char_u *tofree2 = NULL; 4535 char_u *tofree2 = NULL;
4535 int i; 4536 int i;
4536 int pty_master_fd = -1; /* for pty's */ 4537 int pty_master_fd = -1; // for pty's
4537 # ifdef FEAT_GUI 4538 # ifdef FEAT_GUI
4538 int pty_slave_fd = -1; 4539 int pty_slave_fd = -1;
4539 # endif 4540 # endif
4540 int fd_toshell[2]; /* for pipes */ 4541 int fd_toshell[2]; // for pipes
4541 int fd_fromshell[2]; 4542 int fd_fromshell[2];
4542 int pipe_error = FALSE; 4543 int pipe_error = FALSE;
4543 int did_settmode = FALSE; /* settmode(TMODE_RAW) called */ 4544 int did_settmode = FALSE; // settmode(TMODE_RAW) called
4544 4545
4545 out_flush(); 4546 out_flush();
4546 if (options & SHELL_COOKED) 4547 if (options & SHELL_COOKED)
4547 settmode(TMODE_COOK); /* set to normal mode */ 4548 settmode(TMODE_COOK); // set to normal mode
4548 4549
4549 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL) 4550 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == FAIL)
4550 goto error; 4551 goto error;
4551 4552
4552 /* 4553 /*
4573 */ 4574 */
4574 if (pty_master_fd < 0) 4575 if (pty_master_fd < 0)
4575 # endif 4576 # endif
4576 { 4577 {
4577 pipe_error = (pipe(fd_toshell) < 0); 4578 pipe_error = (pipe(fd_toshell) < 0);
4578 if (!pipe_error) /* pipe create OK */ 4579 if (!pipe_error) // pipe create OK
4579 { 4580 {
4580 pipe_error = (pipe(fd_fromshell) < 0); 4581 pipe_error = (pipe(fd_fromshell) < 0);
4581 if (pipe_error) /* pipe create failed */ 4582 if (pipe_error) // pipe create failed
4582 { 4583 {
4583 close(fd_toshell[0]); 4584 close(fd_toshell[0]);
4584 close(fd_toshell[1]); 4585 close(fd_toshell[1]);
4585 } 4586 }
4586 } 4587 }
4590 out_flush(); 4591 out_flush();
4591 } 4592 }
4592 } 4593 }
4593 } 4594 }
4594 4595
4595 if (!pipe_error) /* pty or pipe opened or not used */ 4596 if (!pipe_error) // pty or pipe opened or not used
4596 { 4597 {
4597 SIGSET_DECL(curset) 4598 SIGSET_DECL(curset)
4598 4599
4599 # ifdef __BEOS__ 4600 # ifdef __BEOS__
4600 beos_cleanup_read_thread(); 4601 beos_cleanup_read_thread();
4601 # endif 4602 # endif
4602 4603
4603 BLOCK_SIGNALS(&curset); 4604 BLOCK_SIGNALS(&curset);
4604 pid = fork(); /* maybe we should use vfork() */ 4605 pid = fork(); // maybe we should use vfork()
4605 if (pid == -1) 4606 if (pid == -1)
4606 { 4607 {
4607 UNBLOCK_SIGNALS(&curset); 4608 UNBLOCK_SIGNALS(&curset);
4608 4609
4609 msg_puts(_("\nCannot fork\n")); 4610 msg_puts(_("\nCannot fork\n"));
4612 || (gui.in_use && show_shell_mess) 4613 || (gui.in_use && show_shell_mess)
4613 # endif 4614 # endif
4614 ) 4615 )
4615 { 4616 {
4616 # ifdef FEAT_GUI 4617 # ifdef FEAT_GUI
4617 if (pty_master_fd >= 0) /* close the pseudo tty */ 4618 if (pty_master_fd >= 0) // close the pseudo tty
4618 { 4619 {
4619 close(pty_master_fd); 4620 close(pty_master_fd);
4620 close(pty_slave_fd); 4621 close(pty_slave_fd);
4621 } 4622 }
4622 else /* close the pipes */ 4623 else // close the pipes
4623 # endif 4624 # endif
4624 { 4625 {
4625 close(fd_toshell[0]); 4626 close(fd_toshell[0]);
4626 close(fd_toshell[1]); 4627 close(fd_toshell[1]);
4627 close(fd_fromshell[0]); 4628 close(fd_fromshell[0]);
4628 close(fd_fromshell[1]); 4629 close(fd_fromshell[1]);
4629 } 4630 }
4630 } 4631 }
4631 } 4632 }
4632 else if (pid == 0) /* child */ 4633 else if (pid == 0) // child
4633 { 4634 {
4634 reset_signals(); /* handle signals normally */ 4635 reset_signals(); // handle signals normally
4635 UNBLOCK_SIGNALS(&curset); 4636 UNBLOCK_SIGNALS(&curset);
4636 4637
4637 # ifdef FEAT_JOB_CHANNEL 4638 # ifdef FEAT_JOB_CHANNEL
4638 if (ch_log_active()) 4639 if (ch_log_active())
4639 /* close the log file in the child */ 4640 // close the log file in the child
4640 ch_logfile((char_u *)"", (char_u *)""); 4641 ch_logfile((char_u *)"", (char_u *)"");
4641 # endif 4642 # endif
4642 4643
4643 if (!show_shell_mess || (options & SHELL_EXPAND)) 4644 if (!show_shell_mess || (options & SHELL_EXPAND))
4644 { 4645 {
4666 * or dup() failed we'd just do the same thing ourselves 4667 * or dup() failed we'd just do the same thing ourselves
4667 * anyway -- webb 4668 * anyway -- webb
4668 */ 4669 */
4669 if (fd >= 0) 4670 if (fd >= 0)
4670 { 4671 {
4671 vim_ignored = dup(fd); /* To replace stdin (fd 0) */ 4672 vim_ignored = dup(fd); // To replace stdin (fd 0)
4672 vim_ignored = dup(fd); /* To replace stdout (fd 1) */ 4673 vim_ignored = dup(fd); // To replace stdout (fd 1)
4673 vim_ignored = dup(fd); /* To replace stderr (fd 2) */ 4674 vim_ignored = dup(fd); // To replace stderr (fd 2)
4674 4675
4675 /* Don't need this now that we've duplicated it */ 4676 // Don't need this now that we've duplicated it
4676 close(fd); 4677 close(fd);
4677 } 4678 }
4678 } 4679 }
4679 else if ((options & (SHELL_READ|SHELL_WRITE)) 4680 else if ((options & (SHELL_READ|SHELL_WRITE))
4680 # ifdef FEAT_GUI 4681 # ifdef FEAT_GUI
4682 # endif 4683 # endif
4683 ) 4684 )
4684 { 4685 {
4685 4686
4686 # ifdef HAVE_SETSID 4687 # ifdef HAVE_SETSID
4687 /* Create our own process group, so that the child and all its 4688 // Create our own process group, so that the child and all its
4688 * children can be kill()ed. Don't do this when using pipes, 4689 // children can be kill()ed. Don't do this when using pipes,
4689 * because stdin is not a tty, we would lose /dev/tty. */ 4690 // because stdin is not a tty, we would lose /dev/tty.
4690 if (p_stmp) 4691 if (p_stmp)
4691 { 4692 {
4692 (void)setsid(); 4693 (void)setsid();
4693 # if defined(SIGHUP) 4694 # if defined(SIGHUP)
4694 /* When doing "!xterm&" and 'shell' is bash: the shell 4695 // When doing "!xterm&" and 'shell' is bash: the shell
4695 * will exit and send SIGHUP to all processes in its 4696 // will exit and send SIGHUP to all processes in its
4696 * group, killing the just started process. Ignore SIGHUP 4697 // group, killing the just started process. Ignore SIGHUP
4697 * to avoid that. (suggested by Simon Schubert) 4698 // to avoid that. (suggested by Simon Schubert)
4698 */
4699 signal(SIGHUP, SIG_IGN); 4699 signal(SIGHUP, SIG_IGN);
4700 # endif 4700 # endif
4701 } 4701 }
4702 # endif 4702 # endif
4703 # ifdef FEAT_GUI 4703 # ifdef FEAT_GUI
4704 if (pty_slave_fd >= 0) 4704 if (pty_slave_fd >= 0)
4705 { 4705 {
4706 /* push stream discipline modules */ 4706 // push stream discipline modules
4707 if (options & SHELL_COOKED) 4707 if (options & SHELL_COOKED)
4708 setup_slavepty(pty_slave_fd); 4708 setup_slavepty(pty_slave_fd);
4709 # ifdef TIOCSCTTY 4709 # ifdef TIOCSCTTY
4710 /* Try to become controlling tty (probably doesn't work, 4710 // Try to become controlling tty (probably doesn't work,
4711 * unless run by root) */ 4711 // unless run by root)
4712 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); 4712 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL);
4713 # endif 4713 # endif
4714 } 4714 }
4715 # endif 4715 # endif
4716 set_default_child_environment(FALSE); 4716 set_default_child_environment(FALSE);
4721 * passphrase using stderr. 4721 * passphrase using stderr.
4722 */ 4722 */
4723 # ifdef FEAT_GUI 4723 # ifdef FEAT_GUI
4724 if (pty_master_fd >= 0) 4724 if (pty_master_fd >= 0)
4725 { 4725 {
4726 close(pty_master_fd); /* close master side of pty */ 4726 close(pty_master_fd); // close master side of pty
4727 4727
4728 /* set up stdin/stdout/stderr for the child */ 4728 // set up stdin/stdout/stderr for the child
4729 close(0); 4729 close(0);
4730 vim_ignored = dup(pty_slave_fd); 4730 vim_ignored = dup(pty_slave_fd);
4731 close(1); 4731 close(1);
4732 vim_ignored = dup(pty_slave_fd); 4732 vim_ignored = dup(pty_slave_fd);
4733 if (gui.in_use) 4733 if (gui.in_use)
4734 { 4734 {
4735 close(2); 4735 close(2);
4736 vim_ignored = dup(pty_slave_fd); 4736 vim_ignored = dup(pty_slave_fd);
4737 } 4737 }
4738 4738
4739 close(pty_slave_fd); /* has been dupped, close it now */ 4739 close(pty_slave_fd); // has been dupped, close it now
4740 } 4740 }
4741 else 4741 else
4742 # endif 4742 # endif
4743 { 4743 {
4744 /* set up stdin for the child */ 4744 // set up stdin for the child
4745 close(fd_toshell[1]); 4745 close(fd_toshell[1]);
4746 close(0); 4746 close(0);
4747 vim_ignored = dup(fd_toshell[0]); 4747 vim_ignored = dup(fd_toshell[0]);
4748 close(fd_toshell[0]); 4748 close(fd_toshell[0]);
4749 4749
4750 /* set up stdout for the child */ 4750 // set up stdout for the child
4751 close(fd_fromshell[0]); 4751 close(fd_fromshell[0]);
4752 close(1); 4752 close(1);
4753 vim_ignored = dup(fd_fromshell[1]); 4753 vim_ignored = dup(fd_fromshell[1]);
4754 close(fd_fromshell[1]); 4754 close(fd_fromshell[1]);
4755 4755
4756 # ifdef FEAT_GUI 4756 # ifdef FEAT_GUI
4757 if (gui.in_use) 4757 if (gui.in_use)
4758 { 4758 {
4759 /* set up stderr for the child */ 4759 // set up stderr for the child
4760 close(2); 4760 close(2);
4761 vim_ignored = dup(1); 4761 vim_ignored = dup(1);
4762 } 4762 }
4763 # endif 4763 # endif
4764 } 4764 }
4770 * message with strict compilers, don't worry about it. 4770 * message with strict compilers, don't worry about it.
4771 * Call _exit() instead of exit() to avoid closing the connection 4771 * Call _exit() instead of exit() to avoid closing the connection
4772 * to the X server (esp. with GTK, which uses atexit()). 4772 * to the X server (esp. with GTK, which uses atexit()).
4773 */ 4773 */
4774 execvp(argv[0], argv); 4774 execvp(argv[0], argv);
4775 _exit(EXEC_FAILED); /* exec failed, return failure code */ 4775 _exit(EXEC_FAILED); // exec failed, return failure code
4776 } 4776 }
4777 else /* parent */ 4777 else // parent
4778 { 4778 {
4779 /* 4779 /*
4780 * While child is running, ignore terminating signals. 4780 * While child is running, ignore terminating signals.
4781 * Do catch CTRL-C, so that "got_int" is set. 4781 * Do catch CTRL-C, so that "got_int" is set.
4782 */ 4782 */
4795 # ifdef FEAT_GUI 4795 # ifdef FEAT_GUI
4796 || (gui.in_use && show_shell_mess) 4796 || (gui.in_use && show_shell_mess)
4797 # endif 4797 # endif
4798 ) 4798 )
4799 { 4799 {
4800 # define BUFLEN 100 /* length for buffer, pseudo tty limit is 128 */ 4800 # define BUFLEN 100 // length for buffer, pseudo tty limit is 128
4801 char_u buffer[BUFLEN + 1]; 4801 char_u buffer[BUFLEN + 1];
4802 int buffer_off = 0; /* valid bytes in buffer[] */ 4802 int buffer_off = 0; // valid bytes in buffer[]
4803 char_u ta_buf[BUFLEN + 1]; /* TypeAHead */ 4803 char_u ta_buf[BUFLEN + 1]; // TypeAHead
4804 int ta_len = 0; /* valid bytes in ta_buf[] */ 4804 int ta_len = 0; // valid bytes in ta_buf[]
4805 int len; 4805 int len;
4806 int p_more_save; 4806 int p_more_save;
4807 int old_State; 4807 int old_State;
4808 int c; 4808 int c;
4809 int toshell_fd; 4809 int toshell_fd;
4846 * This can probably dead-lock when the write blocks! 4846 * This can probably dead-lock when the write blocks!
4847 */ 4847 */
4848 p_more_save = p_more; 4848 p_more_save = p_more;
4849 p_more = FALSE; 4849 p_more = FALSE;
4850 old_State = State; 4850 old_State = State;
4851 State = EXTERNCMD; /* don't redraw at window resize */ 4851 State = EXTERNCMD; // don't redraw at window resize
4852 4852
4853 if ((options & SHELL_WRITE) && toshell_fd >= 0) 4853 if ((options & SHELL_WRITE) && toshell_fd >= 0)
4854 { 4854 {
4855 /* Fork a process that will write the lines to the 4855 // Fork a process that will write the lines to the
4856 * external program. */ 4856 // external program.
4857 if ((wpid = fork()) == -1) 4857 if ((wpid = fork()) == -1)
4858 { 4858 {
4859 msg_puts(_("\nCannot fork\n")); 4859 msg_puts(_("\nCannot fork\n"));
4860 } 4860 }
4861 else if (wpid == 0) /* child */ 4861 else if (wpid == 0) // child
4862 { 4862 {
4863 linenr_T lnum = curbuf->b_op_start.lnum; 4863 linenr_T lnum = curbuf->b_op_start.lnum;
4864 int written = 0; 4864 int written = 0;
4865 char_u *lp = ml_get(lnum); 4865 char_u *lp = ml_get(lnum);
4866 size_t l; 4866 size_t l;
4870 { 4870 {
4871 l = STRLEN(lp + written); 4871 l = STRLEN(lp + written);
4872 if (l == 0) 4872 if (l == 0)
4873 len = 0; 4873 len = 0;
4874 else if (lp[written] == NL) 4874 else if (lp[written] == NL)
4875 /* NL -> NUL translation */ 4875 // NL -> NUL translation
4876 len = write(toshell_fd, "", (size_t)1); 4876 len = write(toshell_fd, "", (size_t)1);
4877 else 4877 else
4878 { 4878 {
4879 char_u *s = vim_strchr(lp + written, NL); 4879 char_u *s = vim_strchr(lp + written, NL);
4880 4880
4882 s == NULL ? l 4882 s == NULL ? l
4883 : (size_t)(s - (lp + written))); 4883 : (size_t)(s - (lp + written)));
4884 } 4884 }
4885 if (len == (int)l) 4885 if (len == (int)l)
4886 { 4886 {
4887 /* Finished a line, add a NL, unless this line 4887 // Finished a line, add a NL, unless this line
4888 * should not have one. */ 4888 // should not have one.
4889 if (lnum != curbuf->b_op_end.lnum 4889 if (lnum != curbuf->b_op_end.lnum
4890 || (!curbuf->b_p_bin 4890 || (!curbuf->b_p_bin
4891 && curbuf->b_p_fixeol) 4891 && curbuf->b_p_fixeol)
4892 || (lnum != curbuf->b_no_eol_lnum 4892 || (lnum != curbuf->b_no_eol_lnum
4893 && (lnum != 4893 && (lnum !=
4896 vim_ignored = write(toshell_fd, "\n", 4896 vim_ignored = write(toshell_fd, "\n",
4897 (size_t)1); 4897 (size_t)1);
4898 ++lnum; 4898 ++lnum;
4899 if (lnum > curbuf->b_op_end.lnum) 4899 if (lnum > curbuf->b_op_end.lnum)
4900 { 4900 {
4901 /* finished all the lines, close pipe */ 4901 // finished all the lines, close pipe
4902 close(toshell_fd); 4902 close(toshell_fd);
4903 toshell_fd = -1; 4903 toshell_fd = -1;
4904 break; 4904 break;
4905 } 4905 }
4906 lp = ml_get(lnum); 4906 lp = ml_get(lnum);
4909 else if (len > 0) 4909 else if (len > 0)
4910 written += len; 4910 written += len;
4911 } 4911 }
4912 _exit(0); 4912 _exit(0);
4913 } 4913 }
4914 else /* parent */ 4914 else // parent
4915 { 4915 {
4916 close(toshell_fd); 4916 close(toshell_fd);
4917 toshell_fd = -1; 4917 toshell_fd = -1;
4918 } 4918 }
4919 } 4919 }
4953 && wait_pid == 0 4953 && wait_pid == 0
4954 && (ta_len > 0 || noread_cnt > 4)) 4954 && (ta_len > 0 || noread_cnt > 4))
4955 { 4955 {
4956 if (ta_len == 0) 4956 if (ta_len == 0)
4957 { 4957 {
4958 /* Get extra characters when we don't have any. 4958 // Get extra characters when we don't have any.
4959 * Reset the counter and timer. */ 4959 // Reset the counter and timer.
4960 noread_cnt = 0; 4960 noread_cnt = 0;
4961 # ifdef ELAPSED_FUNC 4961 # ifdef ELAPSED_FUNC
4962 ELAPSED_INIT(start_tv); 4962 ELAPSED_INIT(start_tv);
4963 # endif 4963 # endif
4964 len = ui_inchar(ta_buf, BUFLEN, 10L, 0); 4964 len = ui_inchar(ta_buf, BUFLEN, 10L, 0);
4984 close(toshell_fd); 4984 close(toshell_fd);
4985 toshell_fd = -1; 4985 toshell_fd = -1;
4986 } 4986 }
4987 } 4987 }
4988 4988
4989 /* replace K_BS by <BS> and K_DEL by <DEL> */ 4989 // replace K_BS by <BS> and K_DEL by <DEL>
4990 for (i = ta_len; i < ta_len + len; ++i) 4990 for (i = ta_len; i < ta_len + len; ++i)
4991 { 4991 {
4992 if (ta_buf[i] == CSI && len - i > 2) 4992 if (ta_buf[i] == CSI && len - i > 2)
4993 { 4993 {
4994 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]); 4994 c = TERMCAP2KEY(ta_buf[i + 1], ta_buf[i + 2]);
5057 } 5057 }
5058 } 5058 }
5059 5059
5060 if (got_int) 5060 if (got_int)
5061 { 5061 {
5062 /* CTRL-C sends a signal to the child, we ignore it 5062 // CTRL-C sends a signal to the child, we ignore it
5063 * ourselves */ 5063 // ourselves
5064 # ifdef HAVE_SETSID 5064 # ifdef HAVE_SETSID
5065 kill(-pid, SIGINT); 5065 kill(-pid, SIGINT);
5066 # else 5066 # else
5067 kill(0, SIGINT); 5067 kill(0, SIGINT);
5068 # endif 5068 # endif
5084 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL)) 5084 while (RealWaitForChar(fromshell_fd, 10L, NULL, NULL))
5085 { 5085 {
5086 len = read_eintr(fromshell_fd, buffer 5086 len = read_eintr(fromshell_fd, buffer
5087 + buffer_off, (size_t)(BUFLEN - buffer_off) 5087 + buffer_off, (size_t)(BUFLEN - buffer_off)
5088 ); 5088 );
5089 if (len <= 0) /* end of file or error */ 5089 if (len <= 0) // end of file or error
5090 goto finished; 5090 goto finished;
5091 5091
5092 noread_cnt = 0; 5092 noread_cnt = 0;
5093 if (options & SHELL_READ) 5093 if (options & SHELL_READ)
5094 { 5094 {
5095 /* Do NUL -> NL translation, append NL separated 5095 // Do NUL -> NL translation, append NL separated
5096 * lines to the current buffer. */ 5096 // lines to the current buffer.
5097 for (i = 0; i < len; ++i) 5097 for (i = 0; i < len; ++i)
5098 { 5098 {
5099 if (buffer[i] == NL) 5099 if (buffer[i] == NL)
5100 append_ga_line(&ga); 5100 append_ga_line(&ga);
5101 else if (buffer[i] == NUL) 5101 else if (buffer[i] == NUL)
5110 char_u *p; 5110 char_u *p;
5111 5111
5112 len += buffer_off; 5112 len += buffer_off;
5113 buffer[len] = NUL; 5113 buffer[len] = NUL;
5114 5114
5115 /* Check if the last character in buffer[] is 5115 // Check if the last character in buffer[] is
5116 * incomplete, keep these bytes for the next 5116 // incomplete, keep these bytes for the next
5117 * round. */ 5117 // round.
5118 for (p = buffer; p < buffer + len; p += l) 5118 for (p = buffer; p < buffer + len; p += l)
5119 { 5119 {
5120 l = MB_CPTR2LEN(p); 5120 l = MB_CPTR2LEN(p);
5121 if (l == 0) 5121 if (l == 0)
5122 l = 1; /* NUL byte? */ 5122 l = 1; // NUL byte?
5123 else if (MB_BYTE2LEN(*p) != l) 5123 else if (MB_BYTE2LEN(*p) != l)
5124 break; 5124 break;
5125 } 5125 }
5126 if (p == buffer) /* no complete character */ 5126 if (p == buffer) // no complete character
5127 { 5127 {
5128 /* avoid getting stuck at an illegal byte */ 5128 // avoid getting stuck at an illegal byte
5129 if (len >= 12) 5129 if (len >= 12)
5130 ++p; 5130 ++p;
5131 else 5131 else
5132 { 5132 {
5133 buffer_off = len; 5133 buffer_off = len;
5161 # ifdef ELAPSED_FUNC 5161 # ifdef ELAPSED_FUNC
5162 if (wait_pid == 0) 5162 if (wait_pid == 0)
5163 { 5163 {
5164 long msec = ELAPSED_FUNC(start_tv); 5164 long msec = ELAPSED_FUNC(start_tv);
5165 5165
5166 /* Avoid that we keep looping here without 5166 // Avoid that we keep looping here without
5167 * checking for a CTRL-C for a long time. Don't 5167 // checking for a CTRL-C for a long time. Don't
5168 * break out too often to avoid losing typeahead. */ 5168 // break out too often to avoid losing typeahead.
5169 if (msec > 2000) 5169 if (msec > 2000)
5170 { 5170 {
5171 noread_cnt = 5; 5171 noread_cnt = 5;
5172 break; 5172 break;
5173 } 5173 }
5174 } 5174 }
5175 # endif 5175 # endif
5176 } 5176 }
5177 5177
5178 /* If we already detected the child has finished, continue 5178 // If we already detected the child has finished, continue
5179 * reading output for a short while. Some text may be 5179 // reading output for a short while. Some text may be
5180 * buffered. */ 5180 // buffered.
5181 if (wait_pid == pid) 5181 if (wait_pid == pid)
5182 { 5182 {
5183 if (noread_cnt < 5) 5183 if (noread_cnt < 5)
5184 continue; 5184 continue;
5185 break; 5185 break;
5195 wait_pid = waitpid(pid, &status, WNOHANG); 5195 wait_pid = waitpid(pid, &status, WNOHANG);
5196 # endif 5196 # endif
5197 if ((wait_pid == (pid_t)-1 && errno == ECHILD) 5197 if ((wait_pid == (pid_t)-1 && errno == ECHILD)
5198 || (wait_pid == pid && WIFEXITED(status))) 5198 || (wait_pid == pid && WIFEXITED(status)))
5199 { 5199 {
5200 /* Don't break the loop yet, try reading more 5200 // Don't break the loop yet, try reading more
5201 * characters from "fromshell_fd" first. When using 5201 // characters from "fromshell_fd" first. When using
5202 * pipes there might still be something to read and 5202 // pipes there might still be something to read and
5203 * then we'll break the loop at the "break" above. */ 5203 // then we'll break the loop at the "break" above.
5204 wait_pid = pid; 5204 wait_pid = pid;
5205 } 5205 }
5206 else 5206 else
5207 wait_pid = 0; 5207 wait_pid = 0;
5208 5208
5209 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11) 5209 # if defined(FEAT_XCLIPBOARD) && defined(FEAT_X11)
5210 /* Handle any X events, e.g. serving the clipboard. */ 5210 // Handle any X events, e.g. serving the clipboard.
5211 clip_update(); 5211 clip_update();
5212 # endif 5212 # endif
5213 } 5213 }
5214 finished: 5214 finished:
5215 p_more = p_more_save; 5215 p_more = p_more_save;
5216 if (options & SHELL_READ) 5216 if (options & SHELL_READ)
5217 { 5217 {
5218 if (ga.ga_len > 0) 5218 if (ga.ga_len > 0)
5219 { 5219 {
5220 append_ga_line(&ga); 5220 append_ga_line(&ga);
5221 /* remember that the NL was missing */ 5221 // remember that the NL was missing
5222 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum; 5222 curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
5223 } 5223 }
5224 else 5224 else
5225 curbuf->b_no_eol_lnum = 0; 5225 curbuf->b_no_eol_lnum = 0;
5226 ga_clear(&ga); 5226 ga_clear(&ga);
5247 */ 5247 */
5248 for (;;) 5248 for (;;)
5249 { 5249 {
5250 if (got_int) 5250 if (got_int)
5251 { 5251 {
5252 /* CTRL-C sends a signal to the child, we ignore it 5252 // CTRL-C sends a signal to the child, we ignore it
5253 * ourselves */ 5253 // ourselves
5254 # ifdef HAVE_SETSID 5254 # ifdef HAVE_SETSID
5255 kill(-pid, SIGINT); 5255 kill(-pid, SIGINT);
5256 # else 5256 # else
5257 kill(0, SIGINT); 5257 kill(0, SIGINT);
5258 # endif 5258 # endif
5268 { 5268 {
5269 wait_pid = pid; 5269 wait_pid = pid;
5270 break; 5270 break;
5271 } 5271 }
5272 5272
5273 /* Handle any X events, e.g. serving the clipboard. */ 5273 // Handle any X events, e.g. serving the clipboard.
5274 clip_update(); 5274 clip_update();
5275 5275
5276 /* Wait for 1 to 10 msec. 1 is faster but gives the child 5276 // Wait for 1 to 10 msec. 1 is faster but gives the child
5277 * less time. */ 5277 // less time.
5278 mch_delay(delay_msec, TRUE); 5278 mch_delay(delay_msec, TRUE);
5279 if (++delay_msec > 10) 5279 if (++delay_msec > 10)
5280 delay_msec = 10; 5280 delay_msec = 10;
5281 } 5281 }
5282 } 5282 }
5291 */ 5291 */
5292 if (wait_pid != pid) 5292 if (wait_pid != pid)
5293 wait_pid = wait4pid(pid, &status); 5293 wait_pid = wait4pid(pid, &status);
5294 5294
5295 # ifdef FEAT_GUI 5295 # ifdef FEAT_GUI
5296 /* Close slave side of pty. Only do this after the child has 5296 // Close slave side of pty. Only do this after the child has
5297 * exited, otherwise the child may hang when it tries to write on 5297 // exited, otherwise the child may hang when it tries to write on
5298 * the pty. */ 5298 // the pty.
5299 if (pty_master_fd >= 0) 5299 if (pty_master_fd >= 0)
5300 close(pty_slave_fd); 5300 close(pty_slave_fd);
5301 # endif 5301 # endif
5302 5302
5303 /* Make sure the child that writes to the external program is 5303 // Make sure the child that writes to the external program is
5304 * dead. */ 5304 // dead.
5305 if (wpid > 0) 5305 if (wpid > 0)
5306 { 5306 {
5307 kill(wpid, SIGKILL); 5307 kill(wpid, SIGKILL);
5308 wait4pid(wpid, NULL); 5308 wait4pid(wpid, NULL);
5309 } 5309 }
5321 did_settmode = TRUE; 5321 did_settmode = TRUE;
5322 set_signals(); 5322 set_signals();
5323 5323
5324 if (WIFEXITED(status)) 5324 if (WIFEXITED(status))
5325 { 5325 {
5326 /* LINTED avoid "bitwise operation on signed value" */ 5326 // LINTED avoid "bitwise operation on signed value"
5327 retval = WEXITSTATUS(status); 5327 retval = WEXITSTATUS(status);
5328 if (retval != 0 && !emsg_silent) 5328 if (retval != 0 && !emsg_silent)
5329 { 5329 {
5330 if (retval == EXEC_FAILED) 5330 if (retval == EXEC_FAILED)
5331 { 5331 {
5347 } 5347 }
5348 5348
5349 error: 5349 error:
5350 if (!did_settmode) 5350 if (!did_settmode)
5351 if (tmode == TMODE_RAW) 5351 if (tmode == TMODE_RAW)
5352 settmode(TMODE_RAW); /* set to raw mode */ 5352 settmode(TMODE_RAW); // set to raw mode
5353 # ifdef FEAT_TITLE 5353 # ifdef FEAT_TITLE
5354 resettitle(); 5354 resettitle();
5355 # endif 5355 # endif
5356 vim_free(argv); 5356 vim_free(argv);
5357 vim_free(tofree1); 5357 vim_free(tofree1);
5358 vim_free(tofree2); 5358 vim_free(tofree2);
5359 5359
5360 return retval; 5360 return retval;
5361 } 5361 }
5362 #endif /* USE_SYSTEM */ 5362 #endif // USE_SYSTEM
5363 5363
5364 int 5364 int
5365 mch_call_shell( 5365 mch_call_shell(
5366 char_u *cmd, 5366 char_u *cmd,
5367 int options) /* SHELL_*, see vim.h */ 5367 int options) // SHELL_*, see vim.h
5368 { 5368 {
5369 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL) 5369 #if defined(FEAT_GUI) && defined(FEAT_TERMINAL)
5370 if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL) 5370 if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL)
5371 return mch_call_shell_terminal(cmd, options); 5371 return mch_call_shell_terminal(cmd, options);
5372 #endif 5372 #endif
5380 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) 5380 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
5381 void 5381 void
5382 mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal) 5382 mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal)
5383 { 5383 {
5384 pid_t pid; 5384 pid_t pid;
5385 int fd_in[2] = {-1, -1}; /* for stdin */ 5385 int fd_in[2] = {-1, -1}; // for stdin
5386 int fd_out[2] = {-1, -1}; /* for stdout */ 5386 int fd_out[2] = {-1, -1}; // for stdout
5387 int fd_err[2] = {-1, -1}; /* for stderr */ 5387 int fd_err[2] = {-1, -1}; // for stderr
5388 int pty_master_fd = -1; 5388 int pty_master_fd = -1;
5389 int pty_slave_fd = -1; 5389 int pty_slave_fd = -1;
5390 channel_T *channel = NULL; 5390 channel_T *channel = NULL;
5391 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL; 5391 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL;
5392 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL; 5392 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL;
5399 SIGSET_DECL(curset) 5399 SIGSET_DECL(curset)
5400 5400
5401 if (use_out_for_err && use_null_for_out) 5401 if (use_out_for_err && use_null_for_out)
5402 use_null_for_err = TRUE; 5402 use_null_for_err = TRUE;
5403 5403
5404 /* default is to fail */ 5404 // default is to fail
5405 job->jv_status = JOB_FAILED; 5405 job->jv_status = JOB_FAILED;
5406 5406
5407 if (options->jo_pty 5407 if (options->jo_pty
5408 && (!(use_file_for_in || use_null_for_in) 5408 && (!(use_file_for_in || use_null_for_in)
5409 || !(use_file_for_out || use_null_for_out) 5409 || !(use_file_for_out || use_null_for_out)
5410 || !(use_out_for_err || use_file_for_err || use_null_for_err))) 5410 || !(use_out_for_err || use_file_for_err || use_null_for_err)))
5411 open_pty(&pty_master_fd, &pty_slave_fd, 5411 open_pty(&pty_master_fd, &pty_slave_fd,
5412 &job->jv_tty_out, &job->jv_tty_in); 5412 &job->jv_tty_out, &job->jv_tty_in);
5413 5413
5414 /* TODO: without the channel feature connect the child to /dev/null? */ 5414 // TODO: without the channel feature connect the child to /dev/null?
5415 /* Open pipes for stdin, stdout, stderr. */ 5415 // Open pipes for stdin, stdout, stderr.
5416 if (use_file_for_in) 5416 if (use_file_for_in)
5417 { 5417 {
5418 char_u *fname = options->jo_io_name[PART_IN]; 5418 char_u *fname = options->jo_io_name[PART_IN];
5419 5419
5420 fd_in[0] = mch_open((char *)fname, O_RDONLY, 0); 5420 fd_in[0] = mch_open((char *)fname, O_RDONLY, 0);
5423 semsg(_(e_notopen), fname); 5423 semsg(_(e_notopen), fname);
5424 goto failed; 5424 goto failed;
5425 } 5425 }
5426 } 5426 }
5427 else 5427 else
5428 /* When writing buffer lines to the input don't use the pty, so that 5428 // When writing buffer lines to the input don't use the pty, so that
5429 * the pipe can be closed when all lines were written. */ 5429 // the pipe can be closed when all lines were written.
5430 if (!use_null_for_in && (pty_master_fd < 0 || use_buffer_for_in) 5430 if (!use_null_for_in && (pty_master_fd < 0 || use_buffer_for_in)
5431 && pipe(fd_in) < 0) 5431 && pipe(fd_in) < 0)
5432 goto failed; 5432 goto failed;
5433 5433
5434 if (use_file_for_out) 5434 if (use_file_for_out)
5476 ch_log(channel, "using pty %s on fd %d", 5476 ch_log(channel, "using pty %s on fd %d",
5477 job->jv_tty_out, pty_master_fd); 5477 job->jv_tty_out, pty_master_fd);
5478 } 5478 }
5479 5479
5480 BLOCK_SIGNALS(&curset); 5480 BLOCK_SIGNALS(&curset);
5481 pid = fork(); /* maybe we should use vfork() */ 5481 pid = fork(); // maybe we should use vfork()
5482 if (pid == -1) 5482 if (pid == -1)
5483 { 5483 {
5484 /* failed to fork */ 5484 // failed to fork
5485 UNBLOCK_SIGNALS(&curset); 5485 UNBLOCK_SIGNALS(&curset);
5486 goto failed; 5486 goto failed;
5487 } 5487 }
5488 if (pid == 0) 5488 if (pid == 0)
5489 { 5489 {
5490 int null_fd = -1; 5490 int null_fd = -1;
5491 int stderr_works = TRUE; 5491 int stderr_works = TRUE;
5492 5492
5493 /* child */ 5493 // child
5494 reset_signals(); /* handle signals normally */ 5494 reset_signals(); // handle signals normally
5495 UNBLOCK_SIGNALS(&curset); 5495 UNBLOCK_SIGNALS(&curset);
5496 5496
5497 # ifdef FEAT_JOB_CHANNEL 5497 # ifdef FEAT_JOB_CHANNEL
5498 if (ch_log_active()) 5498 if (ch_log_active())
5499 /* close the log file in the child */ 5499 // close the log file in the child
5500 ch_logfile((char_u *)"", (char_u *)""); 5500 ch_logfile((char_u *)"", (char_u *)"");
5501 # endif 5501 # endif
5502 5502
5503 # ifdef HAVE_SETSID 5503 # ifdef HAVE_SETSID
5504 /* Create our own process group, so that the child and all its 5504 // Create our own process group, so that the child and all its
5505 * children can be kill()ed. Don't do this when using pipes, 5505 // children can be kill()ed. Don't do this when using pipes,
5506 * because stdin is not a tty, we would lose /dev/tty. */ 5506 // because stdin is not a tty, we would lose /dev/tty.
5507 (void)setsid(); 5507 (void)setsid();
5508 # endif 5508 # endif
5509 5509
5510 # ifdef FEAT_TERMINAL 5510 # ifdef FEAT_TERMINAL
5511 if (options->jo_term_rows > 0) 5511 if (options->jo_term_rows > 0)
5512 { 5512 {
5513 char *term = (char *)T_NAME; 5513 char *term = (char *)T_NAME;
5514 5514
5515 #ifdef FEAT_GUI 5515 #ifdef FEAT_GUI
5516 if (term_is_gui(T_NAME)) 5516 if (term_is_gui(T_NAME))
5517 /* In the GUI 'term' is not what we want, use $TERM. */ 5517 // In the GUI 'term' is not what we want, use $TERM.
5518 term = getenv("TERM"); 5518 term = getenv("TERM");
5519 #endif 5519 #endif
5520 /* Use 'term' or $TERM if it starts with "xterm", otherwise fall 5520 // Use 'term' or $TERM if it starts with "xterm", otherwise fall
5521 * back to "xterm". */ 5521 // back to "xterm".
5522 if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0) 5522 if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0)
5523 term = "xterm"; 5523 term = "xterm";
5524 set_child_environment( 5524 set_child_environment(
5525 (long)options->jo_term_rows, 5525 (long)options->jo_term_rows,
5526 (long)options->jo_term_cols, 5526 (long)options->jo_term_cols,
5557 } 5557 }
5558 } 5558 }
5559 5559
5560 if (pty_slave_fd >= 0) 5560 if (pty_slave_fd >= 0)
5561 { 5561 {
5562 /* push stream discipline modules */ 5562 // push stream discipline modules
5563 setup_slavepty(pty_slave_fd); 5563 setup_slavepty(pty_slave_fd);
5564 # ifdef TIOCSCTTY 5564 # ifdef TIOCSCTTY
5565 /* Try to become controlling tty (probably doesn't work, 5565 // Try to become controlling tty (probably doesn't work,
5566 * unless run by root) */ 5566 // unless run by root)
5567 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); 5567 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL);
5568 # endif 5568 # endif
5569 } 5569 }
5570 5570
5571 /* set up stdin for the child */ 5571 // set up stdin for the child
5572 close(0); 5572 close(0);
5573 if (use_null_for_in && null_fd >= 0) 5573 if (use_null_for_in && null_fd >= 0)
5574 vim_ignored = dup(null_fd); 5574 vim_ignored = dup(null_fd);
5575 else if (fd_in[0] < 0) 5575 else if (fd_in[0] < 0)
5576 vim_ignored = dup(pty_slave_fd); 5576 vim_ignored = dup(pty_slave_fd);
5577 else 5577 else
5578 vim_ignored = dup(fd_in[0]); 5578 vim_ignored = dup(fd_in[0]);
5579 5579
5580 /* set up stderr for the child */ 5580 // set up stderr for the child
5581 close(2); 5581 close(2);
5582 if (use_null_for_err && null_fd >= 0) 5582 if (use_null_for_err && null_fd >= 0)
5583 { 5583 {
5584 vim_ignored = dup(null_fd); 5584 vim_ignored = dup(null_fd);
5585 stderr_works = FALSE; 5585 stderr_works = FALSE;
5589 else if (fd_err[1] < 0) 5589 else if (fd_err[1] < 0)
5590 vim_ignored = dup(pty_slave_fd); 5590 vim_ignored = dup(pty_slave_fd);
5591 else 5591 else
5592 vim_ignored = dup(fd_err[1]); 5592 vim_ignored = dup(fd_err[1]);
5593 5593
5594 /* set up stdout for the child */ 5594 // set up stdout for the child
5595 close(1); 5595 close(1);
5596 if (use_null_for_out && null_fd >= 0) 5596 if (use_null_for_out && null_fd >= 0)
5597 vim_ignored = dup(null_fd); 5597 vim_ignored = dup(null_fd);
5598 else if (fd_out[1] < 0) 5598 else if (fd_out[1] < 0)
5599 vim_ignored = dup(pty_slave_fd); 5599 vim_ignored = dup(pty_slave_fd);
5612 close(fd_err[0]); 5612 close(fd_err[0]);
5613 if (fd_err[1] >= 0) 5613 if (fd_err[1] >= 0)
5614 close(fd_err[1]); 5614 close(fd_err[1]);
5615 if (pty_master_fd >= 0) 5615 if (pty_master_fd >= 0)
5616 { 5616 {
5617 close(pty_master_fd); /* not used in the child */ 5617 close(pty_master_fd); // not used in the child
5618 close(pty_slave_fd); /* was duped above */ 5618 close(pty_slave_fd); // was duped above
5619 } 5619 }
5620 5620
5621 if (null_fd >= 0) 5621 if (null_fd >= 0)
5622 close(null_fd); 5622 close(null_fd);
5623 5623
5624 if (options->jo_cwd != NULL && mch_chdir((char *)options->jo_cwd) != 0) 5624 if (options->jo_cwd != NULL && mch_chdir((char *)options->jo_cwd) != 0)
5625 _exit(EXEC_FAILED); 5625 _exit(EXEC_FAILED);
5626 5626
5627 /* See above for type of argv. */ 5627 // See above for type of argv.
5628 execvp(argv[0], argv); 5628 execvp(argv[0], argv);
5629 5629
5630 if (stderr_works) 5630 if (stderr_works)
5631 perror("executing job failed"); 5631 perror("executing job failed");
5632 # ifdef EXITFREE 5632 # ifdef EXITFREE
5633 /* calling free_all_mem() here causes problems. Ignore valgrind 5633 // calling free_all_mem() here causes problems. Ignore valgrind
5634 * reporting possibly leaked memory. */ 5634 // reporting possibly leaked memory.
5635 # endif 5635 # endif
5636 _exit(EXEC_FAILED); /* exec failed, return failure code */ 5636 _exit(EXEC_FAILED); // exec failed, return failure code
5637 } 5637 }
5638 5638
5639 /* parent */ 5639 // parent
5640 UNBLOCK_SIGNALS(&curset); 5640 UNBLOCK_SIGNALS(&curset);
5641 5641
5642 job->jv_pid = pid; 5642 job->jv_pid = pid;
5643 job->jv_status = JOB_STARTED; 5643 job->jv_status = JOB_STARTED;
5644 job->jv_channel = channel; /* ch_refcount was set above */ 5644 job->jv_channel = channel; // ch_refcount was set above
5645 5645
5646 if (pty_master_fd >= 0) 5646 if (pty_master_fd >= 0)
5647 close(pty_slave_fd); /* not used in the parent */ 5647 close(pty_slave_fd); // not used in the parent
5648 /* close child stdin, stdout and stderr */ 5648 // close child stdin, stdout and stderr
5649 if (fd_in[0] >= 0) 5649 if (fd_in[0] >= 0)
5650 close(fd_in[0]); 5650 close(fd_in[0]);
5651 if (fd_out[1] >= 0) 5651 if (fd_out[1] >= 0)
5652 close(fd_out[1]); 5652 close(fd_out[1]);
5653 if (fd_err[1] >= 0) 5653 if (fd_err[1] >= 0)
5687 close(fd_err[0]); 5687 close(fd_err[0]);
5688 if (pty_master_fd >= 0) 5688 if (pty_master_fd >= 0)
5689 close(pty_master_fd); 5689 close(pty_master_fd);
5690 } 5690 }
5691 5691
5692 /* success! */ 5692 // success!
5693 return; 5693 return;
5694 5694
5695 failed: 5695 failed:
5696 channel_unref(channel); 5696 channel_unref(channel);
5697 if (fd_in[0] >= 0) 5697 if (fd_in[0] >= 0)
5744 # else 5744 # else
5745 wait_pid = waitpid(job->jv_pid, &status, WNOHANG); 5745 wait_pid = waitpid(job->jv_pid, &status, WNOHANG);
5746 # endif 5746 # endif
5747 if (wait_pid == -1) 5747 if (wait_pid == -1)
5748 { 5748 {
5749 /* process must have exited */ 5749 // process must have exited
5750 if (job->jv_status < JOB_ENDED) 5750 if (job->jv_status < JOB_ENDED)
5751 ch_log(job->jv_channel, "Job no longer exists: %s", 5751 ch_log(job->jv_channel, "Job no longer exists: %s",
5752 strerror(errno)); 5752 strerror(errno));
5753 goto return_dead; 5753 goto return_dead;
5754 } 5754 }
5755 if (wait_pid == 0) 5755 if (wait_pid == 0)
5756 return "run"; 5756 return "run";
5757 if (WIFEXITED(status)) 5757 if (WIFEXITED(status))
5758 { 5758 {
5759 /* LINTED avoid "bitwise operation on signed value" */ 5759 // LINTED avoid "bitwise operation on signed value"
5760 job->jv_exitval = WEXITSTATUS(status); 5760 job->jv_exitval = WEXITSTATUS(status);
5761 if (job->jv_status < JOB_ENDED) 5761 if (job->jv_status < JOB_ENDED)
5762 ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval); 5762 ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval);
5763 goto return_dead; 5763 goto return_dead;
5764 } 5764 }
5789 # endif 5789 # endif
5790 pid_t wait_pid = 0; 5790 pid_t wait_pid = 0;
5791 job_T *job; 5791 job_T *job;
5792 5792
5793 # ifndef USE_SYSTEM 5793 # ifndef USE_SYSTEM
5794 /* Do not do this when waiting for a shell command to finish, we would get 5794 // Do not do this when waiting for a shell command to finish, we would get
5795 * the exit value here (and discard it), the exit value obtained there 5795 // the exit value here (and discard it), the exit value obtained there
5796 * would then be wrong. */ 5796 // would then be wrong.
5797 if (dont_check_job_ended > 0) 5797 if (dont_check_job_ended > 0)
5798 return NULL; 5798 return NULL;
5799 # endif 5799 # endif
5800 5800
5801 # ifdef __NeXT__ 5801 # ifdef __NeXT__
5802 wait_pid = wait4(-1, &status, WNOHANG, (struct rusage *)0); 5802 wait_pid = wait4(-1, &status, WNOHANG, (struct rusage *)0);
5803 # else 5803 # else
5804 wait_pid = waitpid(-1, &status, WNOHANG); 5804 wait_pid = waitpid(-1, &status, WNOHANG);
5805 # endif 5805 # endif
5806 if (wait_pid <= 0) 5806 if (wait_pid <= 0)
5807 /* no process ended */ 5807 // no process ended
5808 return NULL; 5808 return NULL;
5809 for (job = job_list; job != NULL; job = job->jv_next) 5809 for (job = job_list; job != NULL; job = job->jv_next)
5810 { 5810 {
5811 if (job->jv_pid == wait_pid) 5811 if (job->jv_pid == wait_pid)
5812 { 5812 {
5813 if (WIFEXITED(status)) 5813 if (WIFEXITED(status))
5814 /* LINTED avoid "bitwise operation on signed value" */ 5814 // LINTED avoid "bitwise operation on signed value"
5815 job->jv_exitval = WEXITSTATUS(status); 5815 job->jv_exitval = WEXITSTATUS(status);
5816 else if (WIFSIGNALED(status)) 5816 else if (WIFSIGNALED(status))
5817 { 5817 {
5818 job->jv_exitval = -1; 5818 job->jv_exitval = -1;
5819 job->jv_termsig = get_signal_name(WTERMSIG(status)); 5819 job->jv_termsig = get_signal_name(WTERMSIG(status));
5872 * Clear the data related to "job". 5872 * Clear the data related to "job".
5873 */ 5873 */
5874 void 5874 void
5875 mch_clear_job(job_T *job) 5875 mch_clear_job(job_T *job)
5876 { 5876 {
5877 /* call waitpid because child process may become zombie */ 5877 // call waitpid because child process may become zombie
5878 # ifdef __NeXT__ 5878 # ifdef __NeXT__
5879 (void)wait4(job->jv_pid, NULL, WNOHANG, (struct rusage *)0); 5879 (void)wait4(job->jv_pid, NULL, WNOHANG, (struct rusage *)0);
5880 # else 5880 # else
5881 (void)waitpid(job->jv_pid, NULL, WNOHANG); 5881 (void)waitpid(job->jv_pid, NULL, WNOHANG);
5882 # endif 5882 # endif
5901 return FAIL; 5901 return FAIL;
5902 } 5902 }
5903 if (job->jv_tty_out != NULL) 5903 if (job->jv_tty_out != NULL)
5904 ch_log(channel, "using pty %s on fd %d", 5904 ch_log(channel, "using pty %s on fd %d",
5905 job->jv_tty_out, pty_master_fd); 5905 job->jv_tty_out, pty_master_fd);
5906 job->jv_channel = channel; /* ch_refcount was set by add_channel() */ 5906 job->jv_channel = channel; // ch_refcount was set by add_channel()
5907 channel->ch_keep_open = TRUE; 5907 channel->ch_keep_open = TRUE;
5908 5908
5909 /* Only set the pty_master_fd for stdout, do not duplicate it for stderr, 5909 // Only set the pty_master_fd for stdout, do not duplicate it for stderr,
5910 * it only needs to be read once. */ 5910 // it only needs to be read once.
5911 channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD); 5911 channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD);
5912 channel_set_job(channel, job, options); 5912 channel_set_job(channel, job, options);
5913 return OK; 5913 return OK;
5914 } 5914 }
5915 #endif 5915 #endif
5967 #ifdef FEAT_XCLIPBOARD 5967 #ifdef FEAT_XCLIPBOARD
5968 int rest; 5968 int rest;
5969 #endif 5969 #endif
5970 int avail; 5970 int avail;
5971 5971
5972 if (!ignore_input && input_available()) /* something in inbuf[] */ 5972 if (!ignore_input && input_available()) // something in inbuf[]
5973 return 1; 5973 return 1;
5974 5974
5975 #if defined(FEAT_MOUSE_DEC) 5975 #if defined(FEAT_MOUSE_DEC)
5976 /* May need to query the mouse position. */ 5976 // May need to query the mouse position.
5977 if (WantQueryMouse) 5977 if (WantQueryMouse)
5978 { 5978 {
5979 WantQueryMouse = FALSE; 5979 WantQueryMouse = FALSE;
5980 if (!no_query_mouse_for_testing) 5980 if (!no_query_mouse_for_testing)
5981 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5); 5981 mch_write((char_u *)IF_EB("\033[1'|", ESC_STR "[1'|"), 5);
6064 int ret; 6064 int ret;
6065 int result; 6065 int result;
6066 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME) 6066 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME)
6067 static int busy = FALSE; 6067 static int busy = FALSE;
6068 6068
6069 /* May retry getting characters after an event was handled. */ 6069 // May retry getting characters after an event was handled.
6070 # define MAY_LOOP 6070 # define MAY_LOOP
6071 6071
6072 # ifdef ELAPSED_FUNC 6072 # ifdef ELAPSED_FUNC
6073 /* Remember at what time we started, so that we know how much longer we 6073 // Remember at what time we started, so that we know how much longer we
6074 * should wait after being interrupted. */ 6074 // should wait after being interrupted.
6075 long start_msec = msec; 6075 long start_msec = msec;
6076 elapsed_T start_tv; 6076 elapsed_T start_tv;
6077 6077
6078 if (msec > 0) 6078 if (msec > 0)
6079 ELAPSED_INIT(start_tv); 6079 ELAPSED_INIT(start_tv);
6080 # endif 6080 # endif
6081 6081
6082 /* Handle being called recursively. This may happen for the session 6082 // Handle being called recursively. This may happen for the session
6083 * manager stuff, it may save the file, which does a breakcheck. */ 6083 // manager stuff, it may save the file, which does a breakcheck.
6084 if (busy) 6084 if (busy)
6085 return 0; 6085 return 0;
6086 #endif 6086 #endif
6087 6087
6088 #ifdef MAY_LOOP 6088 #ifdef MAY_LOOP
6089 for (;;) 6089 for (;;)
6090 #endif 6090 #endif
6091 { 6091 {
6092 #ifdef MAY_LOOP 6092 #ifdef MAY_LOOP
6093 int finished = TRUE; /* default is to 'loop' just once */ 6093 int finished = TRUE; // default is to 'loop' just once
6094 # ifdef FEAT_MZSCHEME 6094 # ifdef FEAT_MZSCHEME
6095 int mzquantum_used = FALSE; 6095 int mzquantum_used = FALSE;
6096 # endif 6096 # endif
6097 #endif 6097 #endif
6098 #ifndef HAVE_SELECT 6098 #ifndef HAVE_SELECT
6099 /* each channel may use in, out and err */ 6099 // each channel may use in, out and err
6100 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS]; 6100 struct pollfd fds[6 + 3 * MAX_OPEN_CHANNELS];
6101 int nfd; 6101 int nfd;
6102 # ifdef FEAT_XCLIPBOARD 6102 # ifdef FEAT_XCLIPBOARD
6103 int xterm_idx = -1; 6103 int xterm_idx = -1;
6104 # endif 6104 # endif
6112 6112
6113 # ifdef FEAT_MZSCHEME 6113 # ifdef FEAT_MZSCHEME
6114 mzvim_check_threads(); 6114 mzvim_check_threads();
6115 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) 6115 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq))
6116 { 6116 {
6117 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */ 6117 towait = (int)p_mzq; // don't wait longer than 'mzquantum'
6118 mzquantum_used = TRUE; 6118 mzquantum_used = TRUE;
6119 } 6119 }
6120 # endif 6120 # endif
6121 fds[0].fd = fd; 6121 fds[0].fd = fd;
6122 fds[0].events = POLLIN; 6122 fds[0].events = POLLIN;
6162 if (result == 0 && interrupted != NULL && ret > 0) 6162 if (result == 0 && interrupted != NULL && ret > 0)
6163 *interrupted = TRUE; 6163 *interrupted = TRUE;
6164 6164
6165 # ifdef FEAT_MZSCHEME 6165 # ifdef FEAT_MZSCHEME
6166 if (ret == 0 && mzquantum_used) 6166 if (ret == 0 && mzquantum_used)
6167 /* MzThreads scheduling is required and timeout occurred */ 6167 // MzThreads scheduling is required and timeout occurred
6168 finished = FALSE; 6168 finished = FALSE;
6169 # endif 6169 # endif
6170 6170
6171 # ifdef FEAT_XCLIPBOARD 6171 # ifdef FEAT_XCLIPBOARD
6172 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN)) 6172 if (xterm_Shell != (Widget)0 && (fds[xterm_idx].revents & POLLIN))
6173 { 6173 {
6174 xterm_update(); /* Maybe we should hand out clipboard */ 6174 xterm_update(); // Maybe we should hand out clipboard
6175 if (--ret == 0 && !input_available()) 6175 if (--ret == 0 && !input_available())
6176 /* Try again */ 6176 // Try again
6177 finished = FALSE; 6177 finished = FALSE;
6178 } 6178 }
6179 # endif 6179 # endif
6180 # ifdef FEAT_MOUSE_GPM 6180 # ifdef FEAT_MOUSE_GPM
6181 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN)) 6181 if (gpm_idx >= 0 && (fds[gpm_idx].revents & POLLIN))
6195 if (p_verbose > 0) 6195 if (p_verbose > 0)
6196 verb_msg(_("XSMP lost ICE connection")); 6196 verb_msg(_("XSMP lost ICE connection"));
6197 xsmp_close(); 6197 xsmp_close();
6198 } 6198 }
6199 if (--ret == 0) 6199 if (--ret == 0)
6200 finished = FALSE; /* Try again */ 6200 finished = FALSE; // Try again
6201 } 6201 }
6202 # endif 6202 # endif
6203 #ifdef FEAT_JOB_CHANNEL 6203 #ifdef FEAT_JOB_CHANNEL
6204 // also call when ret == 0, we may be polling a keep-open channel 6204 // also call when ret == 0, we may be polling a keep-open channel
6205 if (ret >= 0) 6205 if (ret >= 0)
6206 channel_poll_check(ret, &fds); 6206 channel_poll_check(ret, &fds);
6207 #endif 6207 #endif
6208 6208
6209 #else /* HAVE_SELECT */ 6209 #else // HAVE_SELECT
6210 6210
6211 struct timeval tv; 6211 struct timeval tv;
6212 struct timeval *tvp; 6212 struct timeval *tvp;
6213 // These are static because they can take 8 Kbyte each and cause the 6213 // These are static because they can take 8 Kbyte each and cause the
6214 // signal stack to run out with -O3. 6214 // signal stack to run out with -O3.
6218 6218
6219 # ifdef FEAT_MZSCHEME 6219 # ifdef FEAT_MZSCHEME
6220 mzvim_check_threads(); 6220 mzvim_check_threads();
6221 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq)) 6221 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq))
6222 { 6222 {
6223 towait = p_mzq; /* don't wait longer than 'mzquantum' */ 6223 towait = p_mzq; // don't wait longer than 'mzquantum'
6224 mzquantum_used = TRUE; 6224 mzquantum_used = TRUE;
6225 } 6225 }
6226 # endif 6226 # endif
6227 6227
6228 if (towait >= 0) 6228 if (towait >= 0)
6241 FD_ZERO(&rfds); 6241 FD_ZERO(&rfds);
6242 FD_ZERO(&wfds); 6242 FD_ZERO(&wfds);
6243 FD_ZERO(&efds); 6243 FD_ZERO(&efds);
6244 FD_SET(fd, &rfds); 6244 FD_SET(fd, &rfds);
6245 # if !defined(__QNX__) && !defined(__CYGWIN32__) 6245 # if !defined(__QNX__) && !defined(__CYGWIN32__)
6246 /* For QNX select() always returns 1 if this is set. Why? */ 6246 // For QNX select() always returns 1 if this is set. Why?
6247 FD_SET(fd, &efds); 6247 FD_SET(fd, &efds);
6248 # endif 6248 # endif
6249 maxfd = fd; 6249 maxfd = fd;
6250 6250
6251 # ifdef FEAT_XCLIPBOARD 6251 # ifdef FEAT_XCLIPBOARD
6254 { 6254 {
6255 FD_SET(ConnectionNumber(xterm_dpy), &rfds); 6255 FD_SET(ConnectionNumber(xterm_dpy), &rfds);
6256 if (maxfd < ConnectionNumber(xterm_dpy)) 6256 if (maxfd < ConnectionNumber(xterm_dpy))
6257 maxfd = ConnectionNumber(xterm_dpy); 6257 maxfd = ConnectionNumber(xterm_dpy);
6258 6258
6259 /* An event may have already been read but not handled. In 6259 // An event may have already been read but not handled. In
6260 * particularly, XFlush may cause this. */ 6260 // particularly, XFlush may cause this.
6261 xterm_update(); 6261 xterm_update();
6262 } 6262 }
6263 # endif 6263 # endif
6264 # ifdef FEAT_MOUSE_GPM 6264 # ifdef FEAT_MOUSE_GPM
6265 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0) 6265 if (check_for_gpm != NULL && gpm_flag && gpm_fd >= 0)
6294 *interrupted = TRUE; 6294 *interrupted = TRUE;
6295 6295
6296 # ifdef EINTR 6296 # ifdef EINTR
6297 if (ret == -1 && errno == EINTR) 6297 if (ret == -1 && errno == EINTR)
6298 { 6298 {
6299 /* Check whether window has been resized, EINTR may be caused by 6299 // Check whether window has been resized, EINTR may be caused by
6300 * SIGWINCH. */ 6300 // SIGWINCH.
6301 if (do_resize) 6301 if (do_resize)
6302 handle_resize(); 6302 handle_resize();
6303 6303
6304 /* Interrupted by a signal, need to try again. We ignore msec 6304 // Interrupted by a signal, need to try again. We ignore msec
6305 * here, because we do want to check even after a timeout if 6305 // here, because we do want to check even after a timeout if
6306 * characters are available. Needed for reading output of an 6306 // characters are available. Needed for reading output of an
6307 * external command after the process has finished. */ 6307 // external command after the process has finished.
6308 goto select_eintr; 6308 goto select_eintr;
6309 } 6309 }
6310 # endif 6310 # endif
6311 # ifdef __TANDEM 6311 # ifdef __TANDEM
6312 if (ret == -1 && errno == ENOTSUP) 6312 if (ret == -1 && errno == ENOTSUP)
6316 ret = 0; 6316 ret = 0;
6317 } 6317 }
6318 # endif 6318 # endif
6319 # ifdef FEAT_MZSCHEME 6319 # ifdef FEAT_MZSCHEME
6320 if (ret == 0 && mzquantum_used) 6320 if (ret == 0 && mzquantum_used)
6321 /* loop if MzThreads must be scheduled and timeout occurred */ 6321 // loop if MzThreads must be scheduled and timeout occurred
6322 finished = FALSE; 6322 finished = FALSE;
6323 # endif 6323 # endif
6324 6324
6325 # ifdef FEAT_XCLIPBOARD 6325 # ifdef FEAT_XCLIPBOARD
6326 if (ret > 0 && xterm_Shell != (Widget)0 6326 if (ret > 0 && xterm_Shell != (Widget)0
6327 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds)) 6327 && FD_ISSET(ConnectionNumber(xterm_dpy), &rfds))
6328 { 6328 {
6329 xterm_update(); /* Maybe we should hand out clipboard */ 6329 xterm_update(); // Maybe we should hand out clipboard
6330 /* continue looping when we only got the X event and the input 6330 // continue looping when we only got the X event and the input
6331 * buffer is empty */ 6331 // buffer is empty
6332 if (--ret == 0 && !input_available()) 6332 if (--ret == 0 && !input_available())
6333 { 6333 {
6334 /* Try again */ 6334 // Try again
6335 finished = FALSE; 6335 finished = FALSE;
6336 } 6336 }
6337 } 6337 }
6338 # endif 6338 # endif
6339 # ifdef FEAT_MOUSE_GPM 6339 # ifdef FEAT_MOUSE_GPM
6352 { 6352 {
6353 if (p_verbose > 0) 6353 if (p_verbose > 0)
6354 verb_msg(_("XSMP lost ICE connection")); 6354 verb_msg(_("XSMP lost ICE connection"));
6355 xsmp_close(); 6355 xsmp_close();
6356 if (--ret == 0) 6356 if (--ret == 0)
6357 finished = FALSE; /* keep going if event was only one */ 6357 finished = FALSE; // keep going if event was only one
6358 } 6358 }
6359 else if (FD_ISSET(xsmp_icefd, &rfds)) 6359 else if (FD_ISSET(xsmp_icefd, &rfds))
6360 { 6360 {
6361 busy = TRUE; 6361 busy = TRUE;
6362 xsmp_handle_requests(); 6362 xsmp_handle_requests();
6363 busy = FALSE; 6363 busy = FALSE;
6364 if (--ret == 0) 6364 if (--ret == 0)
6365 finished = FALSE; /* keep going if event was only one */ 6365 finished = FALSE; // keep going if event was only one
6366 } 6366 }
6367 } 6367 }
6368 # endif 6368 # endif
6369 #ifdef FEAT_JOB_CHANNEL 6369 #ifdef FEAT_JOB_CHANNEL
6370 /* also call when ret == 0, we may be polling a keep-open channel */ 6370 // also call when ret == 0, we may be polling a keep-open channel
6371 if (ret >= 0) 6371 if (ret >= 0)
6372 ret = channel_select_check(ret, &rfds, &wfds); 6372 ret = channel_select_check(ret, &rfds, &wfds);
6373 #endif 6373 #endif
6374 6374
6375 #endif /* HAVE_SELECT */ 6375 #endif // HAVE_SELECT
6376 6376
6377 #ifdef MAY_LOOP 6377 #ifdef MAY_LOOP
6378 if (finished || msec == 0) 6378 if (finished || msec == 0)
6379 break; 6379 break;
6380 6380
6381 # ifdef FEAT_CLIENTSERVER 6381 # ifdef FEAT_CLIENTSERVER
6382 if (server_waiting()) 6382 if (server_waiting())
6383 break; 6383 break;
6384 # endif 6384 # endif
6385 6385
6386 /* We're going to loop around again, find out for how long */ 6386 // We're going to loop around again, find out for how long
6387 if (msec > 0) 6387 if (msec > 0)
6388 { 6388 {
6389 # ifdef ELAPSED_FUNC 6389 # ifdef ELAPSED_FUNC
6390 /* Compute remaining wait time. */ 6390 // Compute remaining wait time.
6391 msec = start_msec - ELAPSED_FUNC(start_tv); 6391 msec = start_msec - ELAPSED_FUNC(start_tv);
6392 # else 6392 # else
6393 /* Guess we got interrupted halfway. */ 6393 // Guess we got interrupted halfway.
6394 msec = msec / 2; 6394 msec = msec / 2;
6395 # endif 6395 # endif
6396 if (msec <= 0) 6396 if (msec <= 0)
6397 break; /* waited long enough */ 6397 break; // waited long enough
6398 } 6398 }
6399 #endif 6399 #endif
6400 } 6400 }
6401 6401
6402 return result; 6402 return result;
6410 */ 6410 */
6411 int 6411 int
6412 mch_expandpath( 6412 mch_expandpath(
6413 garray_T *gap, 6413 garray_T *gap,
6414 char_u *path, 6414 char_u *path,
6415 int flags) /* EW_* flags */ 6415 int flags) // EW_* flags
6416 { 6416 {
6417 return unix_expandpath(gap, path, 0, flags, FALSE); 6417 return unix_expandpath(gap, path, 0, flags, FALSE);
6418 } 6418 }
6419 6419
6420 /* 6420 /*
6443 mch_expand_wildcards( 6443 mch_expand_wildcards(
6444 int num_pat, 6444 int num_pat,
6445 char_u **pat, 6445 char_u **pat,
6446 int *num_file, 6446 int *num_file,
6447 char_u ***file, 6447 char_u ***file,
6448 int flags) /* EW_* flags */ 6448 int flags) // EW_* flags
6449 { 6449 {
6450 int i; 6450 int i;
6451 size_t len; 6451 size_t len;
6452 long llen; 6452 long llen;
6453 char_u *p; 6453 char_u *p;
6459 int j; 6459 int j;
6460 char_u *tempname; 6460 char_u *tempname;
6461 char_u *command; 6461 char_u *command;
6462 FILE *fd; 6462 FILE *fd;
6463 char_u *buffer; 6463 char_u *buffer;
6464 #define STYLE_ECHO 0 /* use "echo", the default */ 6464 #define STYLE_ECHO 0 // use "echo", the default
6465 #define STYLE_GLOB 1 /* use "glob", for csh */ 6465 #define STYLE_GLOB 1 // use "glob", for csh
6466 #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ 6466 #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh
6467 #define STYLE_PRINT 3 /* use "print -N", for zsh */ 6467 #define STYLE_PRINT 3 // use "print -N", for zsh
6468 #define STYLE_BT 4 /* `cmd` expansion, execute the pattern 6468 #define STYLE_BT 4 // `cmd` expansion, execute the pattern
6469 * directly */ 6469 // directly
6470 int shell_style = STYLE_ECHO; 6470 int shell_style = STYLE_ECHO;
6471 int check_spaces; 6471 int check_spaces;
6472 static int did_find_nul = FALSE; 6472 static int did_find_nul = FALSE;
6473 int ampersand = FALSE; 6473 int ampersand = FALSE;
6474 /* vimglob() function to define for Posix shell */ 6474 // vimglob() function to define for Posix shell
6475 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; 6475 static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >";
6476 6476
6477 *num_file = 0; /* default: no files found */ 6477 *num_file = 0; // default: no files found
6478 *file = NULL; 6478 *file = NULL;
6479 6479
6480 /* 6480 /*
6481 * If there are no wildcards, just copy the names to allocated memory. 6481 * If there are no wildcards, just copy the names to allocated memory.
6482 * Saves a lot of time, because we don't have to start a new shell. 6482 * Saves a lot of time, because we don't have to start a new shell.
6483 */ 6483 */
6484 if (!have_wildcard(num_pat, pat)) 6484 if (!have_wildcard(num_pat, pat))
6485 return save_patterns(num_pat, pat, num_file, file); 6485 return save_patterns(num_pat, pat, num_file, file);
6486 6486
6487 # ifdef HAVE_SANDBOX 6487 # ifdef HAVE_SANDBOX
6488 /* Don't allow any shell command in the sandbox. */ 6488 // Don't allow any shell command in the sandbox.
6489 if (sandbox != 0 && check_secure()) 6489 if (sandbox != 0 && check_secure())
6490 return FAIL; 6490 return FAIL;
6491 # endif 6491 # endif
6492 6492
6493 /* 6493 /*
6535 } 6535 }
6536 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), 6536 if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh),
6537 "sh") != NULL) 6537 "sh") != NULL)
6538 shell_style = STYLE_VIMGLOB; 6538 shell_style = STYLE_VIMGLOB;
6539 6539
6540 /* Compute the length of the command. We need 2 extra bytes: for the 6540 // Compute the length of the command. We need 2 extra bytes: for the
6541 * optional '&' and for the NUL. 6541 // optional '&' and for the NUL.
6542 * Worst case: "unset nonomatch; print -N >" plus two is 29 */ 6542 // Worst case: "unset nonomatch; print -N >" plus two is 29
6543 len = STRLEN(tempname) + 29; 6543 len = STRLEN(tempname) + 29;
6544 if (shell_style == STYLE_VIMGLOB) 6544 if (shell_style == STYLE_VIMGLOB)
6545 len += STRLEN(sh_vimglob_func); 6545 len += STRLEN(sh_vimglob_func);
6546 6546
6547 for (i = 0; i < num_pat; ++i) 6547 for (i = 0; i < num_pat; ++i)
6548 { 6548 {
6549 /* Count the length of the patterns in the same way as they are put in 6549 // Count the length of the patterns in the same way as they are put in
6550 * "command" below. */ 6550 // "command" below.
6551 #ifdef USE_SYSTEM 6551 #ifdef USE_SYSTEM
6552 len += STRLEN(pat[i]) + 3; /* add space and two quotes */ 6552 len += STRLEN(pat[i]) + 3; // add space and two quotes
6553 #else 6553 #else
6554 ++len; /* add space */ 6554 ++len; // add space
6555 for (j = 0; pat[i][j] != NUL; ++j) 6555 for (j = 0; pat[i][j] != NUL; ++j)
6556 { 6556 {
6557 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) 6557 if (vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL)
6558 ++len; /* may add a backslash */ 6558 ++len; // may add a backslash
6559 ++len; 6559 ++len;
6560 } 6560 }
6561 #endif 6561 #endif
6562 } 6562 }
6563 command = alloc(len); 6563 command = alloc(len);
6564 if (command == NULL) 6564 if (command == NULL)
6565 { 6565 {
6566 /* out of memory */ 6566 // out of memory
6567 vim_free(tempname); 6567 vim_free(tempname);
6568 return FAIL; 6568 return FAIL;
6569 } 6569 }
6570 6570
6571 /* 6571 /*
6576 * - Add the temp file name. 6576 * - Add the temp file name.
6577 * - Add the file name patterns. 6577 * - Add the file name patterns.
6578 */ 6578 */
6579 if (shell_style == STYLE_BT) 6579 if (shell_style == STYLE_BT)
6580 { 6580 {
6581 /* change `command; command& ` to (command; command ) */ 6581 // change `command; command& ` to (command; command )
6582 STRCPY(command, "("); 6582 STRCPY(command, "(");
6583 STRCAT(command, pat[0] + 1); /* exclude first backtick */ 6583 STRCAT(command, pat[0] + 1); // exclude first backtick
6584 p = command + STRLEN(command) - 1; 6584 p = command + STRLEN(command) - 1;
6585 *p-- = ')'; /* remove last backtick */ 6585 *p-- = ')'; // remove last backtick
6586 while (p > command && VIM_ISWHITE(*p)) 6586 while (p > command && VIM_ISWHITE(*p))
6587 --p; 6587 --p;
6588 if (*p == '&') /* remove trailing '&' */ 6588 if (*p == '&') // remove trailing '&'
6589 { 6589 {
6590 ampersand = TRUE; 6590 ampersand = TRUE;
6591 *p = ' '; 6591 *p = ' ';
6592 } 6592 }
6593 STRCAT(command, ">"); 6593 STRCAT(command, ">");
6611 STRCAT(command, tempname); 6611 STRCAT(command, tempname);
6612 6612
6613 if (shell_style != STYLE_BT) 6613 if (shell_style != STYLE_BT)
6614 for (i = 0; i < num_pat; ++i) 6614 for (i = 0; i < num_pat; ++i)
6615 { 6615 {
6616 /* When using system() always add extra quotes, because the shell 6616 // When using system() always add extra quotes, because the shell
6617 * is started twice. Otherwise put a backslash before special 6617 // is started twice. Otherwise put a backslash before special
6618 * characters, except inside ``. */ 6618 // characters, except inside ``.
6619 #ifdef USE_SYSTEM 6619 #ifdef USE_SYSTEM
6620 STRCAT(command, " \""); 6620 STRCAT(command, " \"");
6621 STRCAT(command, pat[i]); 6621 STRCAT(command, pat[i]);
6622 STRCAT(command, "\""); 6622 STRCAT(command, "\"");
6623 #else 6623 #else
6629 { 6629 {
6630 if (pat[i][j] == '`') 6630 if (pat[i][j] == '`')
6631 intick = !intick; 6631 intick = !intick;
6632 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL) 6632 else if (pat[i][j] == '\\' && pat[i][j + 1] != NUL)
6633 { 6633 {
6634 /* Remove a backslash, take char literally. But keep 6634 // Remove a backslash, take char literally. But keep
6635 * backslash inside backticks, before a special character 6635 // backslash inside backticks, before a special character
6636 * and before a backtick. */ 6636 // and before a backtick.
6637 if (intick 6637 if (intick
6638 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL 6638 || vim_strchr(SHELL_SPECIAL, pat[i][j + 1]) != NULL
6639 || pat[i][j + 1] == '`') 6639 || pat[i][j + 1] == '`')
6640 *p++ = '\\'; 6640 *p++ = '\\';
6641 ++j; 6641 ++j;
6642 } 6642 }
6643 else if (!intick 6643 else if (!intick
6644 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$') 6644 && ((flags & EW_KEEPDOLLAR) == 0 || pat[i][j] != '$')
6645 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL) 6645 && vim_strchr(SHELL_SPECIAL, pat[i][j]) != NULL)
6646 /* Put a backslash before a special character, but not 6646 // Put a backslash before a special character, but not
6647 * when inside ``. And not for $var when EW_KEEPDOLLAR is 6647 // when inside ``. And not for $var when EW_KEEPDOLLAR is
6648 * set. */ 6648 // set.
6649 *p++ = '\\'; 6649 *p++ = '\\';
6650 6650
6651 /* Copy one character. */ 6651 // Copy one character.
6652 *p++ = pat[i][j]; 6652 *p++ = pat[i][j];
6653 } 6653 }
6654 *p = NUL; 6654 *p = NUL;
6655 #endif 6655 #endif
6656 } 6656 }
6657 if (flags & EW_SILENT) 6657 if (flags & EW_SILENT)
6658 show_shell_mess = FALSE; 6658 show_shell_mess = FALSE;
6659 if (ampersand) 6659 if (ampersand)
6660 STRCAT(command, "&"); /* put the '&' after the redirection */ 6660 STRCAT(command, "&"); // put the '&' after the redirection
6661 6661
6662 /* 6662 /*
6663 * Using zsh -G: If a pattern has no matches, it is just deleted from 6663 * Using zsh -G: If a pattern has no matches, it is just deleted from
6664 * the argument list, otherwise zsh gives an error message and doesn't 6664 * the argument list, otherwise zsh gives an error message and doesn't
6665 * expand any other pattern. 6665 * expand any other pattern.
6666 */ 6666 */
6667 if (shell_style == STYLE_PRINT) 6667 if (shell_style == STYLE_PRINT)
6668 extra_shell_arg = (char_u *)"-G"; /* Use zsh NULL_GLOB option */ 6668 extra_shell_arg = (char_u *)"-G"; // Use zsh NULL_GLOB option
6669 6669
6670 /* 6670 /*
6671 * If we use -f then shell variables set in .cshrc won't get expanded. 6671 * If we use -f then shell variables set in .cshrc won't get expanded.
6672 * vi can do it, so we will too, but it is only necessary if there is a "$" 6672 * vi can do it, so we will too, but it is only necessary if there is a "$"
6673 * in one of the patterns, otherwise we can still use the fast option. 6673 * in one of the patterns, otherwise we can still use the fast option.
6674 */ 6674 */
6675 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat)) 6675 else if (shell_style == STYLE_GLOB && !have_dollars(num_pat, pat))
6676 extra_shell_arg = (char_u *)"-f"; /* Use csh fast option */ 6676 extra_shell_arg = (char_u *)"-f"; // Use csh fast option
6677 6677
6678 /* 6678 /*
6679 * execute the shell command 6679 * execute the shell command
6680 */ 6680 */
6681 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT); 6681 i = call_shell(command, SHELL_EXPAND | SHELL_SILENT);
6682 6682
6683 /* When running in the background, give it some time to create the temp 6683 // When running in the background, give it some time to create the temp
6684 * file, but don't wait for it to finish. */ 6684 // file, but don't wait for it to finish.
6685 if (ampersand) 6685 if (ampersand)
6686 mch_delay(10L, TRUE); 6686 mch_delay(10L, TRUE);
6687 6687
6688 extra_shell_arg = NULL; /* cleanup */ 6688 extra_shell_arg = NULL; // cleanup
6689 show_shell_mess = TRUE; 6689 show_shell_mess = TRUE;
6690 vim_free(command); 6690 vim_free(command);
6691 6691
6692 if (i != 0) /* mch_call_shell() failed */ 6692 if (i != 0) // mch_call_shell() failed
6693 { 6693 {
6694 mch_remove(tempname); 6694 mch_remove(tempname);
6695 vim_free(tempname); 6695 vim_free(tempname);
6696 /* 6696 /*
6697 * With interactive completion, the error message is not printed. 6697 * With interactive completion, the error message is not printed.
6700 */ 6700 */
6701 #ifndef USE_SYSTEM 6701 #ifndef USE_SYSTEM
6702 if (!(flags & EW_SILENT)) 6702 if (!(flags & EW_SILENT))
6703 #endif 6703 #endif
6704 { 6704 {
6705 redraw_later_clear(); /* probably messed up screen */ 6705 redraw_later_clear(); // probably messed up screen
6706 msg_putchar('\n'); /* clear bottom line quickly */ 6706 msg_putchar('\n'); // clear bottom line quickly
6707 cmdline_row = Rows - 1; /* continue on last line */ 6707 cmdline_row = Rows - 1; // continue on last line
6708 #ifdef USE_SYSTEM 6708 #ifdef USE_SYSTEM
6709 if (!(flags & EW_SILENT)) 6709 if (!(flags & EW_SILENT))
6710 #endif 6710 #endif
6711 { 6711 {
6712 msg(_(e_wildexpand)); 6712 msg(_(e_wildexpand));
6713 msg_start(); /* don't overwrite this message */ 6713 msg_start(); // don't overwrite this message
6714 } 6714 }
6715 } 6715 }
6716 /* If a `cmd` expansion failed, don't list `cmd` as a match, even when 6716 // If a `cmd` expansion failed, don't list `cmd` as a match, even when
6717 * EW_NOTFOUND is given */ 6717 // EW_NOTFOUND is given
6718 if (shell_style == STYLE_BT) 6718 if (shell_style == STYLE_BT)
6719 return FAIL; 6719 return FAIL;
6720 goto notfound; 6720 goto notfound;
6721 } 6721 }
6722 6722
6724 * read the names from the file into memory 6724 * read the names from the file into memory
6725 */ 6725 */
6726 fd = fopen((char *)tempname, READBIN); 6726 fd = fopen((char *)tempname, READBIN);
6727 if (fd == NULL) 6727 if (fd == NULL)
6728 { 6728 {
6729 /* Something went wrong, perhaps a file name with a special char. */ 6729 // Something went wrong, perhaps a file name with a special char.
6730 if (!(flags & EW_SILENT)) 6730 if (!(flags & EW_SILENT))
6731 { 6731 {
6732 msg(_(e_wildexpand)); 6732 msg(_(e_wildexpand));
6733 msg_start(); /* don't overwrite this message */ 6733 msg_start(); // don't overwrite this message
6734 } 6734 }
6735 vim_free(tempname); 6735 vim_free(tempname);
6736 goto notfound; 6736 goto notfound;
6737 } 6737 }
6738 fseek(fd, 0L, SEEK_END); 6738 fseek(fd, 0L, SEEK_END);
6739 llen = ftell(fd); /* get size of temp file */ 6739 llen = ftell(fd); // get size of temp file
6740 fseek(fd, 0L, SEEK_SET); 6740 fseek(fd, 0L, SEEK_SET);
6741 if (llen < 0) 6741 if (llen < 0)
6742 /* just in case ftell() would fail */ 6742 // just in case ftell() would fail
6743 buffer = NULL; 6743 buffer = NULL;
6744 else 6744 else
6745 buffer = alloc(llen + 1); 6745 buffer = alloc(llen + 1);
6746 if (buffer == NULL) 6746 if (buffer == NULL)
6747 { 6747 {
6748 /* out of memory */ 6748 // out of memory
6749 mch_remove(tempname); 6749 mch_remove(tempname);
6750 vim_free(tempname); 6750 vim_free(tempname);
6751 fclose(fd); 6751 fclose(fd);
6752 return FAIL; 6752 return FAIL;
6753 } 6753 }
6755 i = fread((char *)buffer, 1, len, fd); 6755 i = fread((char *)buffer, 1, len, fd);
6756 fclose(fd); 6756 fclose(fd);
6757 mch_remove(tempname); 6757 mch_remove(tempname);
6758 if (i != (int)len) 6758 if (i != (int)len)
6759 { 6759 {
6760 /* unexpected read error */ 6760 // unexpected read error
6761 semsg(_(e_notread), tempname); 6761 semsg(_(e_notread), tempname);
6762 vim_free(tempname); 6762 vim_free(tempname);
6763 vim_free(buffer); 6763 vim_free(buffer);
6764 return FAIL; 6764 return FAIL;
6765 } 6765 }
6766 vim_free(tempname); 6766 vim_free(tempname);
6767 6767
6768 # ifdef __CYGWIN__ 6768 # ifdef __CYGWIN__
6769 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ 6769 // Translate <CR><NL> into <NL>. Caution, buffer may contain NUL.
6770 p = buffer; 6770 p = buffer;
6771 for (i = 0; i < (int)len; ++i) 6771 for (i = 0; i < (int)len; ++i)
6772 if (!(buffer[i] == CAR && buffer[i + 1] == NL)) 6772 if (!(buffer[i] == CAR && buffer[i + 1] == NL))
6773 *p++ = buffer[i]; 6773 *p++ = buffer[i];
6774 len = p - buffer; 6774 len = p - buffer;
6775 # endif 6775 # endif
6776 6776
6777 6777
6778 /* file names are separated with Space */ 6778 // file names are separated with Space
6779 if (shell_style == STYLE_ECHO) 6779 if (shell_style == STYLE_ECHO)
6780 { 6780 {
6781 buffer[len] = '\n'; /* make sure the buffer ends in NL */ 6781 buffer[len] = '\n'; // make sure the buffer ends in NL
6782 p = buffer; 6782 p = buffer;
6783 for (i = 0; *p != '\n'; ++i) /* count number of entries */ 6783 for (i = 0; *p != '\n'; ++i) // count number of entries
6784 { 6784 {
6785 while (*p != ' ' && *p != '\n') 6785 while (*p != ' ' && *p != '\n')
6786 ++p; 6786 ++p;
6787 p = skipwhite(p); /* skip to next entry */ 6787 p = skipwhite(p); // skip to next entry
6788 } 6788 }
6789 } 6789 }
6790 /* file names are separated with NL */ 6790 // file names are separated with NL
6791 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) 6791 else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB)
6792 { 6792 {
6793 buffer[len] = NUL; /* make sure the buffer ends in NUL */ 6793 buffer[len] = NUL; // make sure the buffer ends in NUL
6794 p = buffer; 6794 p = buffer;
6795 for (i = 0; *p != NUL; ++i) /* count number of entries */ 6795 for (i = 0; *p != NUL; ++i) // count number of entries
6796 { 6796 {
6797 while (*p != '\n' && *p != NUL) 6797 while (*p != '\n' && *p != NUL)
6798 ++p; 6798 ++p;
6799 if (*p != NUL) 6799 if (*p != NUL)
6800 ++p; 6800 ++p;
6801 p = skipwhite(p); /* skip leading white space */ 6801 p = skipwhite(p); // skip leading white space
6802 } 6802 }
6803 } 6803 }
6804 /* file names are separated with NUL */ 6804 // file names are separated with NUL
6805 else 6805 else
6806 { 6806 {
6807 /* 6807 /*
6808 * Some versions of zsh use spaces instead of NULs to separate 6808 * Some versions of zsh use spaces instead of NULs to separate
6809 * results. Only do this when there is no NUL before the end of the 6809 * results. Only do this when there is no NUL before the end of the
6813 * don't check for spaces again. 6813 * don't check for spaces again.
6814 */ 6814 */
6815 check_spaces = FALSE; 6815 check_spaces = FALSE;
6816 if (shell_style == STYLE_PRINT && !did_find_nul) 6816 if (shell_style == STYLE_PRINT && !did_find_nul)
6817 { 6817 {
6818 /* If there is a NUL, set did_find_nul, else set check_spaces */ 6818 // If there is a NUL, set did_find_nul, else set check_spaces
6819 buffer[len] = NUL; 6819 buffer[len] = NUL;
6820 if (len && (int)STRLEN(buffer) < (int)len) 6820 if (len && (int)STRLEN(buffer) < (int)len)
6821 did_find_nul = TRUE; 6821 did_find_nul = TRUE;
6822 else 6822 else
6823 check_spaces = TRUE; 6823 check_spaces = TRUE;
6831 --len; 6831 --len;
6832 else 6832 else
6833 buffer[len] = NUL; 6833 buffer[len] = NUL;
6834 i = 0; 6834 i = 0;
6835 for (p = buffer; p < buffer + len; ++p) 6835 for (p = buffer; p < buffer + len; ++p)
6836 if (*p == NUL || (*p == ' ' && check_spaces)) /* count entry */ 6836 if (*p == NUL || (*p == ' ' && check_spaces)) // count entry
6837 { 6837 {
6838 ++i; 6838 ++i;
6839 *p = NUL; 6839 *p = NUL;
6840 } 6840 }
6841 if (len) 6841 if (len)
6842 ++i; /* count last entry */ 6842 ++i; // count last entry
6843 } 6843 }
6844 if (i == 0) 6844 if (i == 0)
6845 { 6845 {
6846 /* 6846 /*
6847 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I". 6847 * Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I".
6853 } 6853 }
6854 *num_file = i; 6854 *num_file = i;
6855 *file = ALLOC_MULT(char_u *, i); 6855 *file = ALLOC_MULT(char_u *, i);
6856 if (*file == NULL) 6856 if (*file == NULL)
6857 { 6857 {
6858 /* out of memory */ 6858 // out of memory
6859 vim_free(buffer); 6859 vim_free(buffer);
6860 return FAIL; 6860 return FAIL;
6861 } 6861 }
6862 6862
6863 /* 6863 /*
6865 */ 6865 */
6866 p = buffer; 6866 p = buffer;
6867 for (i = 0; i < *num_file; ++i) 6867 for (i = 0; i < *num_file; ++i)
6868 { 6868 {
6869 (*file)[i] = p; 6869 (*file)[i] = p;
6870 /* Space or NL separates */ 6870 // Space or NL separates
6871 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT 6871 if (shell_style == STYLE_ECHO || shell_style == STYLE_BT
6872 || shell_style == STYLE_VIMGLOB) 6872 || shell_style == STYLE_VIMGLOB)
6873 { 6873 {
6874 while (!(shell_style == STYLE_ECHO && *p == ' ') 6874 while (!(shell_style == STYLE_ECHO && *p == ' ')
6875 && *p != '\n' && *p != NUL) 6875 && *p != '\n' && *p != NUL)
6876 ++p; 6876 ++p;
6877 if (p == buffer + len) /* last entry */ 6877 if (p == buffer + len) // last entry
6878 *p = NUL; 6878 *p = NUL;
6879 else 6879 else
6880 { 6880 {
6881 *p++ = NUL; 6881 *p++ = NUL;
6882 p = skipwhite(p); /* skip to next entry */ 6882 p = skipwhite(p); // skip to next entry
6883 } 6883 }
6884 } 6884 }
6885 else /* NUL separates */ 6885 else // NUL separates
6886 { 6886 {
6887 while (*p && p < buffer + len) /* skip entry */ 6887 while (*p && p < buffer + len) // skip entry
6888 ++p; 6888 ++p;
6889 ++p; /* skip NUL */ 6889 ++p; // skip NUL
6890 } 6890 }
6891 } 6891 }
6892 6892
6893 /* 6893 /*
6894 * Move the file names to allocated memory. 6894 * Move the file names to allocated memory.
6895 */ 6895 */
6896 for (j = 0, i = 0; i < *num_file; ++i) 6896 for (j = 0, i = 0; i < *num_file; ++i)
6897 { 6897 {
6898 /* Require the files to exist. Helps when using /bin/sh */ 6898 // Require the files to exist. Helps when using /bin/sh
6899 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0) 6899 if (!(flags & EW_NOTFOUND) && mch_getperm((*file)[i]) < 0)
6900 continue; 6900 continue;
6901 6901
6902 /* check if this entry should be included */ 6902 // check if this entry should be included
6903 dir = (mch_isdir((*file)[i])); 6903 dir = (mch_isdir((*file)[i]));
6904 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) 6904 if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE)))
6905 continue; 6905 continue;
6906 6906
6907 /* Skip files that are not executable if we check for that. */ 6907 // Skip files that are not executable if we check for that.
6908 if (!dir && (flags & EW_EXEC) 6908 if (!dir && (flags & EW_EXEC)
6909 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD))) 6909 && !mch_can_exe((*file)[i], NULL, !(flags & EW_SHELLCMD)))
6910 continue; 6910 continue;
6911 6911
6912 p = alloc(STRLEN((*file)[i]) + 1 + dir); 6912 p = alloc(STRLEN((*file)[i]) + 1 + dir);
6913 if (p) 6913 if (p)
6914 { 6914 {
6915 STRCPY(p, (*file)[i]); 6915 STRCPY(p, (*file)[i]);
6916 if (dir) 6916 if (dir)
6917 add_pathsep(p); /* add '/' to a directory name */ 6917 add_pathsep(p); // add '/' to a directory name
6918 (*file)[j++] = p; 6918 (*file)[j++] = p;
6919 } 6919 }
6920 } 6920 }
6921 vim_free(buffer); 6921 vim_free(buffer);
6922 *num_file = j; 6922 *num_file = j;
6923 6923
6924 if (*num_file == 0) /* rejected all entries */ 6924 if (*num_file == 0) // rejected all entries
6925 { 6925 {
6926 VIM_CLEAR(*file); 6926 VIM_CLEAR(*file);
6927 goto notfound; 6927 goto notfound;
6928 } 6928 }
6929 6929
6933 if (flags & EW_NOTFOUND) 6933 if (flags & EW_NOTFOUND)
6934 return save_patterns(num_pat, pat, num_file, file); 6934 return save_patterns(num_pat, pat, num_file, file);
6935 return FAIL; 6935 return FAIL;
6936 } 6936 }
6937 6937
6938 #endif /* VMS */ 6938 #endif // VMS
6939 6939
6940 static int 6940 static int
6941 save_patterns( 6941 save_patterns(
6942 int num_pat, 6942 int num_pat,
6943 char_u **pat, 6943 char_u **pat,
6952 return FAIL; 6952 return FAIL;
6953 for (i = 0; i < num_pat; i++) 6953 for (i = 0; i < num_pat; i++)
6954 { 6954 {
6955 s = vim_strsave(pat[i]); 6955 s = vim_strsave(pat[i]);
6956 if (s != NULL) 6956 if (s != NULL)
6957 /* Be compatible with expand_filename(): halve the number of 6957 // Be compatible with expand_filename(): halve the number of
6958 * backslashes. */ 6958 // backslashes.
6959 backslash_halve(s); 6959 backslash_halve(s);
6960 (*file)[i] = s; 6960 (*file)[i] = s;
6961 } 6961 }
6962 *num_file = num_pat; 6962 *num_file = num_pat;
6963 return OK; 6963 return OK;
7043 int 7043 int
7044 mch_rename(const char *src, const char *dest) 7044 mch_rename(const char *src, const char *dest)
7045 { 7045 {
7046 struct stat st; 7046 struct stat st;
7047 7047
7048 if (stat(dest, &st) >= 0) /* fail if destination exists */ 7048 if (stat(dest, &st) >= 0) // fail if destination exists
7049 return -1; 7049 return -1;
7050 if (link(src, dest) != 0) /* link file to new name */ 7050 if (link(src, dest) != 0) // link file to new name
7051 return -1; 7051 return -1;
7052 if (mch_remove(src) == 0) /* delete link to old name */ 7052 if (mch_remove(src) == 0) // delete link to old name
7053 return 0; 7053 return 0;
7054 return -1; 7054 return -1;
7055 } 7055 }
7056 #endif /* !HAVE_RENAME */ 7056 #endif // !HAVE_RENAME
7057 7057
7058 #if defined(FEAT_MOUSE_GPM) || defined(PROTO) 7058 #if defined(FEAT_MOUSE_GPM) || defined(PROTO)
7059 /* 7059 /*
7060 * Initializes connection with gpm (if it isn't already opened) 7060 * Initializes connection with gpm (if it isn't already opened)
7061 * Return 1 if succeeded (or connection already opened), 0 if failed 7061 * Return 1 if succeeded (or connection already opened), 0 if failed
7062 */ 7062 */
7063 static int 7063 static int
7064 gpm_open(void) 7064 gpm_open(void)
7065 { 7065 {
7066 static Gpm_Connect gpm_connect; /* Must it be kept till closing ? */ 7066 static Gpm_Connect gpm_connect; // Must it be kept till closing ?
7067 7067
7068 if (!gpm_flag) 7068 if (!gpm_flag)
7069 { 7069 {
7070 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN); 7070 gpm_connect.eventMask = (GPM_UP | GPM_DRAG | GPM_DOWN);
7071 gpm_connect.defaultMask = ~GPM_HARD; 7071 gpm_connect.defaultMask = ~GPM_HARD;
7072 /* Default handling for mouse move*/ 7072 // Default handling for mouse move
7073 gpm_connect.minMod = 0; /* Handle any modifier keys */ 7073 gpm_connect.minMod = 0; // Handle any modifier keys
7074 gpm_connect.maxMod = 0xffff; 7074 gpm_connect.maxMod = 0xffff;
7075 if (Gpm_Open(&gpm_connect, 0) > 0) 7075 if (Gpm_Open(&gpm_connect, 0) > 0)
7076 { 7076 {
7077 /* gpm library tries to handling TSTP causes 7077 // gpm library tries to handling TSTP causes
7078 * problems. Anyways, we close connection to Gpm whenever 7078 // problems. Anyways, we close connection to Gpm whenever
7079 * we are going to suspend or starting an external process 7079 // we are going to suspend or starting an external process
7080 * so we shouldn't have problem with this 7080 // so we shouldn't have problem with this
7081 */
7082 # ifdef SIGTSTP 7081 # ifdef SIGTSTP
7083 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); 7082 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL);
7084 # endif 7083 # endif
7085 return 1; /* succeed */ 7084 return 1; // succeed
7086 } 7085 }
7087 if (gpm_fd == -2) 7086 if (gpm_fd == -2)
7088 Gpm_Close(); /* We don't want to talk to xterm via gpm */ 7087 Gpm_Close(); // We don't want to talk to xterm via gpm
7089 return 0; 7088 return 0;
7090 } 7089 }
7091 return 1; /* already open */ 7090 return 1; // already open
7092 } 7091 }
7093 7092
7094 /* 7093 /*
7095 * Returns TRUE if the GPM mouse is enabled. 7094 * Returns TRUE if the GPM mouse is enabled.
7096 */ 7095 */
7128 static unsigned char old_buttons = 0; 7127 static unsigned char old_buttons = 0;
7129 7128
7130 Gpm_GetEvent(&gpm_event); 7129 Gpm_GetEvent(&gpm_event);
7131 7130
7132 #ifdef FEAT_GUI 7131 #ifdef FEAT_GUI
7133 /* Don't put events in the input queue now. */ 7132 // Don't put events in the input queue now.
7134 if (hold_gui_events) 7133 if (hold_gui_events)
7135 return 0; 7134 return 0;
7136 #endif 7135 #endif
7137 7136
7138 row = gpm_event.y - 1; 7137 row = gpm_event.y - 1;
7139 col = gpm_event.x - 1; 7138 col = gpm_event.x - 1;
7140 7139
7141 string[0] = ESC; /* Our termcode */ 7140 string[0] = ESC; // Our termcode
7142 string[1] = 'M'; 7141 string[1] = 'M';
7143 string[2] = 'G'; 7142 string[2] = 'G';
7144 switch (GPM_BARE_EVENTS(gpm_event.type)) 7143 switch (GPM_BARE_EVENTS(gpm_event.type))
7145 { 7144 {
7146 case GPM_DRAG: 7145 case GPM_DRAG:
7160 case GPM_B_RIGHT: 7159 case GPM_B_RIGHT:
7161 button = MOUSE_RIGHT; 7160 button = MOUSE_RIGHT;
7162 break; 7161 break;
7163 default: 7162 default:
7164 return 0; 7163 return 0;
7165 /*Don't know what to do. Can more than one button be 7164 // Don't know what to do. Can more than one button be
7166 * reported in one event? */ 7165 // reported in one event?
7167 } 7166 }
7168 string[3] = (char_u)(button | 0x20); 7167 string[3] = (char_u)(button | 0x20);
7169 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1); 7168 SET_NUM_MOUSE_CLICKS(string[3], gpm_event.clicks + 1);
7170 break; 7169 break;
7171 case GPM_UP: 7170 case GPM_UP:
7173 old_buttons &= ~gpm_event.buttons; 7172 old_buttons &= ~gpm_event.buttons;
7174 break; 7173 break;
7175 default: 7174 default:
7176 return 0; 7175 return 0;
7177 } 7176 }
7178 /*This code is based on gui_x11_mouse_cb in gui_x11.c */ 7177 // This code is based on gui_x11_mouse_cb in gui_x11.c
7179 gpm_modifiers = gpm_event.modifiers; 7178 gpm_modifiers = gpm_event.modifiers;
7180 vim_modifiers = 0x0; 7179 vim_modifiers = 0x0;
7181 /* I ignore capslock stats. Aren't we all just hate capslock mixing with 7180 // I ignore capslock stats. Aren't we all just hate capslock mixing with
7182 * Vim commands ? Besides, gpm_event.modifiers is unsigned char, and 7181 // Vim commands ? Besides, gpm_event.modifiers is unsigned char, and
7183 * K_CAPSSHIFT is defined 8, so it probably isn't even reported 7182 // K_CAPSSHIFT is defined 8, so it probably isn't even reported
7184 */
7185 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL))) 7183 if (gpm_modifiers & ((1 << KG_SHIFT) | (1 << KG_SHIFTR) | (1 << KG_SHIFTL)))
7186 vim_modifiers |= MOUSE_SHIFT; 7184 vim_modifiers |= MOUSE_SHIFT;
7187 7185
7188 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL))) 7186 if (gpm_modifiers & ((1 << KG_CTRL) | (1 << KG_CTRLR) | (1 << KG_CTRLL)))
7189 vim_modifiers |= MOUSE_CTRL; 7187 vim_modifiers |= MOUSE_CTRL;
7193 string[4] = (char_u)(col + ' ' + 1); 7191 string[4] = (char_u)(col + ' ' + 1);
7194 string[5] = (char_u)(row + ' ' + 1); 7192 string[5] = (char_u)(row + ' ' + 1);
7195 add_to_input_buf(string, 6); 7193 add_to_input_buf(string, 6);
7196 return 6; 7194 return 6;
7197 } 7195 }
7198 #endif /* FEAT_MOUSE_GPM */ 7196 #endif // FEAT_MOUSE_GPM
7199 7197
7200 #ifdef FEAT_SYSMOUSE 7198 #ifdef FEAT_SYSMOUSE
7201 /* 7199 /*
7202 * Initialize connection with sysmouse. 7200 * Initialize connection with sysmouse.
7203 * Let virtual console inform us with SIGUSR2 for pending sysmouse 7201 * Let virtual console inform us with SIGUSR2 for pending sysmouse
7251 int button; 7249 int button;
7252 int buttons; 7250 int buttons;
7253 static int oldbuttons = 0; 7251 static int oldbuttons = 0;
7254 7252
7255 #ifdef FEAT_GUI 7253 #ifdef FEAT_GUI
7256 /* Don't put events in the input queue now. */ 7254 // Don't put events in the input queue now.
7257 if (hold_gui_events) 7255 if (hold_gui_events)
7258 return; 7256 return;
7259 #endif 7257 #endif
7260 7258
7261 mouse.operation = MOUSE_GETINFO; 7259 mouse.operation = MOUSE_GETINFO;
7265 && video.vi_cheight > 0 && video.vi_cwidth > 0) 7263 && video.vi_cheight > 0 && video.vi_cwidth > 0)
7266 { 7264 {
7267 row = mouse.u.data.y / video.vi_cheight; 7265 row = mouse.u.data.y / video.vi_cheight;
7268 col = mouse.u.data.x / video.vi_cwidth; 7266 col = mouse.u.data.x / video.vi_cwidth;
7269 buttons = mouse.u.data.buttons; 7267 buttons = mouse.u.data.buttons;
7270 string[0] = ESC; /* Our termcode */ 7268 string[0] = ESC; // Our termcode
7271 string[1] = 'M'; 7269 string[1] = 'M';
7272 string[2] = 'S'; 7270 string[2] = 'S';
7273 if (oldbuttons == buttons && buttons != 0) 7271 if (oldbuttons == buttons && buttons != 0)
7274 { 7272 {
7275 button = MOUSE_DRAG; 7273 button = MOUSE_DRAG;
7300 string[5] = (char_u)(row + ' ' + 1); 7298 string[5] = (char_u)(row + ' ' + 1);
7301 add_to_input_buf(string, 6); 7299 add_to_input_buf(string, 6);
7302 } 7300 }
7303 return; 7301 return;
7304 } 7302 }
7305 #endif /* FEAT_SYSMOUSE */ 7303 #endif // FEAT_SYSMOUSE
7306 7304
7307 #if defined(FEAT_LIBCALL) || defined(PROTO) 7305 #if defined(FEAT_LIBCALL) || defined(PROTO)
7308 typedef char_u * (*STRPROCSTR)(char_u *); 7306 typedef char_u * (*STRPROCSTR)(char_u *);
7309 typedef char_u * (*INTPROCSTR)(int); 7307 typedef char_u * (*INTPROCSTR)(int);
7310 typedef int (*STRPROCINT)(char_u *); 7308 typedef int (*STRPROCINT)(char_u *);
7316 */ 7314 */
7317 int 7315 int
7318 mch_libcall( 7316 mch_libcall(
7319 char_u *libname, 7317 char_u *libname,
7320 char_u *funcname, 7318 char_u *funcname,
7321 char_u *argstring, /* NULL when using a argint */ 7319 char_u *argstring, // NULL when using a argint
7322 int argint, 7320 int argint,
7323 char_u **string_result,/* NULL when using number_result */ 7321 char_u **string_result, // NULL when using number_result
7324 int *number_result) 7322 int *number_result)
7325 { 7323 {
7326 # if defined(USE_DLOPEN) 7324 # if defined(USE_DLOPEN)
7327 void *hinstLib; 7325 void *hinstLib;
7328 char *dlerr = NULL; 7326 char *dlerr = NULL;
7337 7335
7338 /* 7336 /*
7339 * Get a handle to the DLL module. 7337 * Get a handle to the DLL module.
7340 */ 7338 */
7341 # if defined(USE_DLOPEN) 7339 # if defined(USE_DLOPEN)
7342 /* First clear any error, it's not cleared by the dlopen() call. */ 7340 // First clear any error, it's not cleared by the dlopen() call.
7343 (void)dlerror(); 7341 (void)dlerror();
7344 7342
7345 hinstLib = dlopen((char *)libname, RTLD_LAZY 7343 hinstLib = dlopen((char *)libname, RTLD_LAZY
7346 # ifdef RTLD_LOCAL 7344 # ifdef RTLD_LOCAL
7347 | RTLD_LOCAL 7345 | RTLD_LOCAL
7348 # endif 7346 # endif
7349 ); 7347 );
7350 if (hinstLib == NULL) 7348 if (hinstLib == NULL)
7351 { 7349 {
7352 /* "dlerr" must be used before dlclose() */ 7350 // "dlerr" must be used before dlclose()
7353 dlerr = (char *)dlerror(); 7351 dlerr = (char *)dlerror();
7354 if (dlerr != NULL) 7352 if (dlerr != NULL)
7355 semsg(_("dlerror = \"%s\""), dlerr); 7353 semsg(_("dlerror = \"%s\""), dlerr);
7356 } 7354 }
7357 # else 7355 # else
7358 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L); 7356 hinstLib = shl_load((const char*)libname, BIND_IMMEDIATE|BIND_VERBOSE, 0L);
7359 # endif 7357 # endif
7360 7358
7361 /* If the handle is valid, try to get the function address. */ 7359 // If the handle is valid, try to get the function address.
7362 if (hinstLib != NULL) 7360 if (hinstLib != NULL)
7363 { 7361 {
7364 # ifdef USING_SETJMP 7362 # ifdef USING_SETJMP
7365 /* 7363 /*
7366 * Catch a crash when calling the library function. For example when 7364 * Catch a crash when calling the library function. For example when
7424 else 7422 else
7425 retval_str = (ProcAddI)(argint); 7423 retval_str = (ProcAddI)(argint);
7426 } 7424 }
7427 } 7425 }
7428 7426
7429 /* Save the string before we free the library. */ 7427 // Save the string before we free the library.
7430 /* Assume that a "1" or "-1" result is an illegal pointer. */ 7428 // Assume that a "1" or "-1" result is an illegal pointer.
7431 if (string_result == NULL) 7429 if (string_result == NULL)
7432 *number_result = retval_int; 7430 *number_result = retval_int;
7433 else if (retval_str != NULL 7431 else if (retval_str != NULL
7434 && retval_str != (char_u *)1 7432 && retval_str != (char_u *)1
7435 && retval_str != (char_u *)-1) 7433 && retval_str != (char_u *)-1)
7441 # ifdef SIGHASARG 7439 # ifdef SIGHASARG
7442 if (lc_signal != 0) 7440 if (lc_signal != 0)
7443 { 7441 {
7444 int i; 7442 int i;
7445 7443
7446 /* try to find the name of this signal */ 7444 // try to find the name of this signal
7447 for (i = 0; signal_info[i].sig != -1; i++) 7445 for (i = 0; signal_info[i].sig != -1; i++)
7448 if (lc_signal == signal_info[i].sig) 7446 if (lc_signal == signal_info[i].sig)
7449 break; 7447 break;
7450 semsg("E368: got SIG%s in libcall()", signal_info[i].name); 7448 semsg("E368: got SIG%s in libcall()", signal_info[i].name);
7451 } 7449 }
7452 # endif 7450 # endif
7453 # endif 7451 # endif
7454 7452
7455 # if defined(USE_DLOPEN) 7453 # if defined(USE_DLOPEN)
7456 /* "dlerr" must be used before dlclose() */ 7454 // "dlerr" must be used before dlclose()
7457 if (dlerr != NULL) 7455 if (dlerr != NULL)
7458 semsg(_("dlerror = \"%s\""), dlerr); 7456 semsg(_("dlerror = \"%s\""), dlerr);
7459 7457
7460 /* Free the DLL module. */ 7458 // Free the DLL module.
7461 (void)dlclose(hinstLib); 7459 (void)dlclose(hinstLib);
7462 # else 7460 # else
7463 (void)shl_unload(hinstLib); 7461 (void)shl_unload(hinstLib);
7464 # endif 7462 # endif
7465 } 7463 }
7473 return OK; 7471 return OK;
7474 } 7472 }
7475 #endif 7473 #endif
7476 7474
7477 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO) 7475 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO)
7478 static int xterm_trace = -1; /* default: disabled */ 7476 static int xterm_trace = -1; // default: disabled
7479 static int xterm_button; 7477 static int xterm_button;
7480 7478
7481 /* 7479 /*
7482 * Setup a dummy window for X selections in a terminal. 7480 * Setup a dummy window for X selections in a terminal.
7483 */ 7481 */
7503 7501
7504 if (p_verbose > 0) 7502 if (p_verbose > 0)
7505 ELAPSED_INIT(start_tv); 7503 ELAPSED_INIT(start_tv);
7506 # endif 7504 # endif
7507 7505
7508 /* Ignore X errors while opening the display */ 7506 // Ignore X errors while opening the display
7509 oldhandler = XSetErrorHandler(x_error_check); 7507 oldhandler = XSetErrorHandler(x_error_check);
7510 7508
7511 # if defined(USING_SETJMP) 7509 # if defined(USING_SETJMP)
7512 /* Ignore X IO errors while opening the display */ 7510 // Ignore X IO errors while opening the display
7513 oldIOhandler = XSetIOErrorHandler(x_IOerror_check); 7511 oldIOhandler = XSetIOErrorHandler(x_IOerror_check);
7514 mch_startjmp(); 7512 mch_startjmp();
7515 if (SETJMP(lc_jump_env) != 0) 7513 if (SETJMP(lc_jump_env) != 0)
7516 { 7514 {
7517 mch_didjmp(); 7515 mch_didjmp();
7528 mch_endjmp(); 7526 mch_endjmp();
7529 # endif 7527 # endif
7530 } 7528 }
7531 7529
7532 # if defined(USING_SETJMP) 7530 # if defined(USING_SETJMP)
7533 /* Now handle X IO errors normally. */ 7531 // Now handle X IO errors normally.
7534 (void)XSetIOErrorHandler(oldIOhandler); 7532 (void)XSetIOErrorHandler(oldIOhandler);
7535 # endif 7533 # endif
7536 /* Now handle X errors normally. */ 7534 // Now handle X errors normally.
7537 (void)XSetErrorHandler(oldhandler); 7535 (void)XSetErrorHandler(oldhandler);
7538 7536
7539 if (xterm_dpy == NULL) 7537 if (xterm_dpy == NULL)
7540 { 7538 {
7541 if (p_verbose > 0) 7539 if (p_verbose > 0)
7542 verb_msg(_("Opening the X display failed")); 7540 verb_msg(_("Opening the X display failed"));
7543 return; 7541 return;
7544 } 7542 }
7545 7543
7546 /* Catch terminating error of the X server connection. */ 7544 // Catch terminating error of the X server connection.
7547 (void)XSetIOErrorHandler(x_IOerror_handler); 7545 (void)XSetIOErrorHandler(x_IOerror_handler);
7548 7546
7549 # ifdef ELAPSED_FUNC 7547 # ifdef ELAPSED_FUNC
7550 if (p_verbose > 0) 7548 if (p_verbose > 0)
7551 { 7549 {
7553 xopen_message(ELAPSED_FUNC(start_tv)); 7551 xopen_message(ELAPSED_FUNC(start_tv));
7554 verbose_leave(); 7552 verbose_leave();
7555 } 7553 }
7556 # endif 7554 # endif
7557 7555
7558 /* Create a Shell to make converters work. */ 7556 // Create a Shell to make converters work.
7559 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm", 7557 AppShell = XtVaAppCreateShell("vim_xterm", "Vim_xterm",
7560 applicationShellWidgetClass, xterm_dpy, 7558 applicationShellWidgetClass, xterm_dpy,
7561 NULL); 7559 NULL);
7562 if (AppShell == (Widget)0) 7560 if (AppShell == (Widget)0)
7563 return; 7561 return;
7582 if (xterm_Shell != (Widget)0) 7580 if (xterm_Shell != (Widget)0)
7583 { 7581 {
7584 clip_init(TRUE); 7582 clip_init(TRUE);
7585 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL) 7583 if (x11_window == 0 && (strp = getenv("WINDOWID")) != NULL)
7586 x11_window = (Window)atol(strp); 7584 x11_window = (Window)atol(strp);
7587 /* Check if $WINDOWID is valid. */ 7585 // Check if $WINDOWID is valid.
7588 if (test_x11_window(xterm_dpy) == FAIL) 7586 if (test_x11_window(xterm_dpy) == FAIL)
7589 x11_window = 0; 7587 x11_window = 0;
7590 if (x11_window != 0) 7588 if (x11_window != 0)
7591 xterm_trace = 0; 7589 xterm_trace = 0;
7592 } 7590 }
7634 if (xterm_trace <= 0) 7632 if (xterm_trace <= 0)
7635 return FALSE; 7633 return FALSE;
7636 7634
7637 if (xterm_trace == 1) 7635 if (xterm_trace == 1)
7638 { 7636 {
7639 /* Get the hints just before tracking starts. The font size might 7637 // Get the hints just before tracking starts. The font size might
7640 * have changed recently. */ 7638 // have changed recently.
7641 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints) 7639 if (!XGetWMNormalHints(xterm_dpy, x11_window, &xterm_hints, &got_hints)
7642 || !(got_hints & PResizeInc) 7640 || !(got_hints & PResizeInc)
7643 || xterm_hints.width_inc <= 1 7641 || xterm_hints.width_inc <= 1
7644 || xterm_hints.height_inc <= 1) 7642 || xterm_hints.height_inc <= 1)
7645 { 7643 {
7646 xterm_trace = -1; /* Not enough data -- disable tracing */ 7644 xterm_trace = -1; // Not enough data -- disable tracing
7647 return FALSE; 7645 return FALSE;
7648 } 7646 }
7649 7647
7650 /* Rely on the same mouse code for the duration of this */ 7648 // Rely on the same mouse code for the duration of this
7651 mouse_code = find_termcode(mouse_name); 7649 mouse_code = find_termcode(mouse_name);
7652 prev_row = mouse_row; 7650 prev_row = mouse_row;
7653 prev_col = mouse_col; 7651 prev_col = mouse_col;
7654 xterm_trace = 2; 7652 xterm_trace = 2;
7655 7653
7656 /* Find the offset of the chars, there might be a scrollbar on the 7654 // Find the offset of the chars, there might be a scrollbar on the
7657 * left of the window and/or a menu on the top (eterm etc.) */ 7655 // left of the window and/or a menu on the top (eterm etc.)
7658 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y, 7656 XQueryPointer(xterm_dpy, x11_window, &root, &child, &root_x, &root_y,
7659 &win_x, &win_y, &mask_return); 7657 &win_x, &win_y, &mask_return);
7660 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row) 7658 xterm_hints.y = win_y - (xterm_hints.height_inc * mouse_row)
7661 - (xterm_hints.height_inc / 2); 7659 - (xterm_hints.height_inc / 2);
7662 if (xterm_hints.y <= xterm_hints.height_inc / 2) 7660 if (xterm_hints.y <= xterm_hints.height_inc / 2)
7707 xterm_Shell = (Widget)0; 7705 xterm_Shell = (Widget)0;
7708 } 7706 }
7709 if (xterm_dpy != NULL) 7707 if (xterm_dpy != NULL)
7710 { 7708 {
7711 # if 0 7709 # if 0
7712 /* Lesstif and Solaris crash here, lose some memory */ 7710 // Lesstif and Solaris crash here, lose some memory
7713 XtCloseDisplay(xterm_dpy); 7711 XtCloseDisplay(xterm_dpy);
7714 # endif 7712 # endif
7715 if (x11_display == xterm_dpy) 7713 if (x11_display == xterm_dpy)
7716 x11_display = NULL; 7714 x11_display = NULL;
7717 xterm_dpy = NULL; 7715 xterm_dpy = NULL;
7718 } 7716 }
7719 # if 0 7717 # if 0
7720 if (app_context != (XtAppContext)NULL) 7718 if (app_context != (XtAppContext)NULL)
7721 { 7719 {
7722 /* Lesstif and Solaris crash here, lose some memory */ 7720 // Lesstif and Solaris crash here, lose some memory
7723 XtDestroyApplicationContext(app_context); 7721 XtDestroyApplicationContext(app_context);
7724 app_context = (XtAppContext)NULL; 7722 app_context = (XtAppContext)NULL;
7725 } 7723 }
7726 # endif 7724 # endif
7727 } 7725 }
7760 if (mask == 0 || vim_is_input_buf_full()) 7758 if (mask == 0 || vim_is_input_buf_full())
7761 break; 7759 break;
7762 7760
7763 if (mask & XtIMXEvent) 7761 if (mask & XtIMXEvent)
7764 { 7762 {
7765 /* There is an event to process. */ 7763 // There is an event to process.
7766 XtAppNextEvent(app_context, &event); 7764 XtAppNextEvent(app_context, &event);
7767 #ifdef FEAT_CLIENTSERVER 7765 #ifdef FEAT_CLIENTSERVER
7768 { 7766 {
7769 XPropertyEvent *e = (XPropertyEvent *)&event; 7767 XPropertyEvent *e = (XPropertyEvent *)&event;
7770 7768
7775 #endif 7773 #endif
7776 XtDispatchEvent(&event); 7774 XtDispatchEvent(&event);
7777 } 7775 }
7778 else 7776 else
7779 { 7777 {
7780 /* There is something else than an event to process. */ 7778 // There is something else than an event to process.
7781 XtAppProcessEvent(app_context, mask); 7779 XtAppProcessEvent(app_context, mask);
7782 } 7780 }
7783 } 7781 }
7784 } 7782 }
7785 7783
7830 int cancel_shutdown = False; 7828 int cancel_shutdown = False;
7831 7829
7832 save_cmdmod = cmdmod; 7830 save_cmdmod = cmdmod;
7833 cmdmod.confirm = TRUE; 7831 cmdmod.confirm = TRUE;
7834 if (check_changed_any(FALSE, FALSE)) 7832 if (check_changed_any(FALSE, FALSE))
7835 /* Mustn't logout */ 7833 // Mustn't logout
7836 cancel_shutdown = True; 7834 cancel_shutdown = True;
7837 cmdmod = save_cmdmod; 7835 cmdmod = save_cmdmod;
7838 setcursor(); /* position cursor */ 7836 setcursor(); // position cursor
7839 out_flush(); 7837 out_flush();
7840 7838
7841 /* Done interaction */ 7839 // Done interaction
7842 SmcInteractDone(smc_conn, cancel_shutdown); 7840 SmcInteractDone(smc_conn, cancel_shutdown);
7843 7841
7844 /* Finish off 7842 // Finish off
7845 * Only end save-yourself here if we're not cancelling shutdown; 7843 // Only end save-yourself here if we're not cancelling shutdown;
7846 * we'll get a cancelled callback later in which we'll end it. 7844 // we'll get a cancelled callback later in which we'll end it.
7847 * Hopefully get around glitchy SMs (like GNOME-1) 7845 // Hopefully get around glitchy SMs (like GNOME-1)
7848 */
7849 if (!cancel_shutdown) 7846 if (!cancel_shutdown)
7850 { 7847 {
7851 xsmp.save_yourself = False; 7848 xsmp.save_yourself = False;
7852 SmcSaveYourselfDone(smc_conn, True); 7849 SmcSaveYourselfDone(smc_conn, True);
7853 } 7850 }
7864 int save_type UNUSED, 7861 int save_type UNUSED,
7865 Bool shutdown, 7862 Bool shutdown,
7866 int interact_style UNUSED, 7863 int interact_style UNUSED,
7867 Bool fast UNUSED) 7864 Bool fast UNUSED)
7868 { 7865 {
7869 /* Handle already being in saveyourself */ 7866 // Handle already being in saveyourself
7870 if (xsmp.save_yourself) 7867 if (xsmp.save_yourself)
7871 SmcSaveYourselfDone(smc_conn, True); 7868 SmcSaveYourselfDone(smc_conn, True);
7872 xsmp.save_yourself = True; 7869 xsmp.save_yourself = True;
7873 xsmp.shutdown = shutdown; 7870 xsmp.shutdown = shutdown;
7874 7871
7875 /* First up, preserve all files */ 7872 // First up, preserve all files
7876 out_flush(); 7873 out_flush();
7877 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ 7874 ml_sync_all(FALSE, FALSE); // preserve all swap files
7878 7875
7879 if (p_verbose > 0) 7876 if (p_verbose > 0)
7880 verb_msg(_("XSMP handling save-yourself request")); 7877 verb_msg(_("XSMP handling save-yourself request"));
7881 7878
7882 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT) 7879 # if defined(FEAT_GUI) && defined(USE_XSMP_INTERACT)
7883 /* Now see if we can ask about unsaved files */ 7880 // Now see if we can ask about unsaved files
7884 if (shutdown && !fast && gui.in_use) 7881 if (shutdown && !fast && gui.in_use)
7885 /* Need to interact with user, but need SM's permission */ 7882 // Need to interact with user, but need SM's permission
7886 SmcInteractRequest(smc_conn, SmDialogError, 7883 SmcInteractRequest(smc_conn, SmDialogError,
7887 xsmp_handle_interaction, client_data); 7884 xsmp_handle_interaction, client_data);
7888 else 7885 else
7889 # endif 7886 # endif
7890 { 7887 {
7891 /* Can stop the cycle here */ 7888 // Can stop the cycle here
7892 SmcSaveYourselfDone(smc_conn, True); 7889 SmcSaveYourselfDone(smc_conn, True);
7893 xsmp.save_yourself = False; 7890 xsmp.save_yourself = False;
7894 } 7891 }
7895 } 7892 }
7896 7893
7901 static void 7898 static void
7902 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED) 7899 xsmp_die(SmcConn smc_conn UNUSED, SmPointer client_data UNUSED)
7903 { 7900 {
7904 xsmp_close(); 7901 xsmp_close();
7905 7902
7906 /* quit quickly leaving swapfiles for modified buffers behind */ 7903 // quit quickly leaving swapfiles for modified buffers behind
7907 getout_preserve_modified(0); 7904 getout_preserve_modified(0);
7908 } 7905 }
7909 7906
7910 7907
7911 /* 7908 /*
7944 IceConn iceConn, 7941 IceConn iceConn,
7945 IcePointer clientData UNUSED, 7942 IcePointer clientData UNUSED,
7946 Bool opening, 7943 Bool opening,
7947 IcePointer *watchData UNUSED) 7944 IcePointer *watchData UNUSED)
7948 { 7945 {
7949 /* Intercept creation of ICE connection fd */ 7946 // Intercept creation of ICE connection fd
7950 if (opening) 7947 if (opening)
7951 { 7948 {
7952 xsmp_icefd = IceConnectionNumber(iceConn); 7949 xsmp_icefd = IceConnectionNumber(iceConn);
7953 IceRemoveConnectionWatch(xsmp_ice_connection, NULL); 7950 IceRemoveConnectionWatch(xsmp_ice_connection, NULL);
7954 } 7951 }
7955 } 7952 }
7956 7953
7957 7954
7958 /* Handle any ICE processing that's required; return FAIL if SM lost */ 7955 // Handle any ICE processing that's required; return FAIL if SM lost
7959 int 7956 int
7960 xsmp_handle_requests(void) 7957 xsmp_handle_requests(void)
7961 { 7958 {
7962 Bool rep; 7959 Bool rep;
7963 7960
7964 if (IceProcessMessages(xsmp.iceconn, NULL, &rep) 7961 if (IceProcessMessages(xsmp.iceconn, NULL, &rep)
7965 == IceProcessMessagesIOError) 7962 == IceProcessMessagesIOError)
7966 { 7963 {
7967 /* Lost ICE */ 7964 // Lost ICE
7968 if (p_verbose > 0) 7965 if (p_verbose > 0)
7969 verb_msg(_("XSMP lost ICE connection")); 7966 verb_msg(_("XSMP lost ICE connection"));
7970 xsmp_close(); 7967 xsmp_close();
7971 return FAIL; 7968 return FAIL;
7972 } 7969 }
7974 return OK; 7971 return OK;
7975 } 7972 }
7976 7973
7977 static int dummy; 7974 static int dummy;
7978 7975
7979 /* Set up X Session Management Protocol */ 7976 // Set up X Session Management Protocol
7980 void 7977 void
7981 xsmp_init(void) 7978 xsmp_init(void)
7982 { 7979 {
7983 char errorstring[80]; 7980 char errorstring[80];
7984 SmcCallbacks smcallbacks; 7981 SmcCallbacks smcallbacks;
7991 if (p_verbose > 0) 7988 if (p_verbose > 0)
7992 verb_msg(_("XSMP opening connection")); 7989 verb_msg(_("XSMP opening connection"));
7993 7990
7994 xsmp.save_yourself = xsmp.shutdown = False; 7991 xsmp.save_yourself = xsmp.shutdown = False;
7995 7992
7996 /* Set up SM callbacks - must have all, even if they're not used */ 7993 // Set up SM callbacks - must have all, even if they're not used
7997 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself; 7994 smcallbacks.save_yourself.callback = xsmp_handle_save_yourself;
7998 smcallbacks.save_yourself.client_data = NULL; 7995 smcallbacks.save_yourself.client_data = NULL;
7999 smcallbacks.die.callback = xsmp_die; 7996 smcallbacks.die.callback = xsmp_die;
8000 smcallbacks.die.client_data = NULL; 7997 smcallbacks.die.client_data = NULL;
8001 smcallbacks.save_complete.callback = xsmp_save_complete; 7998 smcallbacks.save_complete.callback = xsmp_save_complete;
8002 smcallbacks.save_complete.client_data = NULL; 7999 smcallbacks.save_complete.client_data = NULL;
8003 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled; 8000 smcallbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled;
8004 smcallbacks.shutdown_cancelled.client_data = NULL; 8001 smcallbacks.shutdown_cancelled.client_data = NULL;
8005 8002
8006 /* Set up a watch on ICE connection creations. The "dummy" argument is 8003 // Set up a watch on ICE connection creations. The "dummy" argument is
8007 * apparently required for FreeBSD (we get a BUS error when using NULL). */ 8004 // apparently required for FreeBSD (we get a BUS error when using NULL).
8008 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0) 8005 if (IceAddConnectionWatch(xsmp_ice_connection, &dummy) == 0)
8009 { 8006 {
8010 if (p_verbose > 0) 8007 if (p_verbose > 0)
8011 verb_msg(_("XSMP ICE connection watch failed")); 8008 verb_msg(_("XSMP ICE connection watch failed"));
8012 return; 8009 return;
8013 } 8010 }
8014 8011
8015 /* Create an SM connection */ 8012 // Create an SM connection
8016 xsmp.smcconn = SmcOpenConnection( 8013 xsmp.smcconn = SmcOpenConnection(
8017 NULL, 8014 NULL,
8018 NULL, 8015 NULL,
8019 SmProtoMajor, 8016 SmProtoMajor,
8020 SmProtoMinor, 8017 SmProtoMinor,
8038 return; 8035 return;
8039 } 8036 }
8040 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn); 8037 xsmp.iceconn = SmcGetIceConnection(xsmp.smcconn);
8041 8038
8042 #if 0 8039 #if 0
8043 /* ID ourselves */ 8040 // ID ourselves
8044 smname.value = "vim"; 8041 smname.value = "vim";
8045 smname.length = 3; 8042 smname.length = 3;
8046 smnameprop.name = "SmProgram"; 8043 smnameprop.name = "SmProgram";
8047 smnameprop.type = "SmARRAY8"; 8044 smnameprop.type = "SmARRAY8";
8048 smnameprop.num_vals = 1; 8045 smnameprop.num_vals = 1;
8052 SmcSetProperties(xsmp.smcconn, 1, smprops); 8049 SmcSetProperties(xsmp.smcconn, 1, smprops);
8053 #endif 8050 #endif
8054 } 8051 }
8055 8052
8056 8053
8057 /* Shut down XSMP comms. */ 8054 // Shut down XSMP comms.
8058 void 8055 void
8059 xsmp_close(void) 8056 xsmp_close(void)
8060 { 8057 {
8061 if (xsmp_icefd != -1) 8058 if (xsmp_icefd != -1)
8062 { 8059 {
8065 free(xsmp.clientid); 8062 free(xsmp.clientid);
8066 xsmp.clientid = NULL; 8063 xsmp.clientid = NULL;
8067 xsmp_icefd = -1; 8064 xsmp_icefd = -1;
8068 } 8065 }
8069 } 8066 }
8070 #endif /* USE_XSMP */ 8067 #endif // USE_XSMP
8071 8068
8072 8069
8073 #ifdef EBCDIC 8070 #ifdef EBCDIC
8074 /* Translate character to its CTRL- value */ 8071 // Translate character to its CTRL- value
8075 char CtrlTable[] = 8072 char CtrlTable[] =
8076 { 8073 {
8077 /* 00 - 5E */ 8074 /* 00 - 5E */
8078 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8075 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8079 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8076 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8158 /* EA - FF*/ 0, 0, 0, 0, 0, 0, 8155 /* EA - FF*/ 0, 0, 0, 0, 0, 0,
8159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8160 }; 8157 };
8161 8158
8162 char MetaCharTable[]= 8159 char MetaCharTable[]=
8163 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 8160 {// 0 1 2 3 4 5 6 7 8 9 A B C D E F
8164 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0, 8161 0, 0, 0, 0,'\\', 0,'F', 0,'W','M','N', 0, 0, 0, 0, 0,
8165 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0, 8162 0, 0, 0, 0,']', 0, 0,'G', 0, 0,'R','O', 0, 0, 0, 0,
8166 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0, 8163 '@','A','B','C','D','E', 0, 0,'H','I','J','K','L', 0, 0, 0,
8167 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0 8164 'P','Q', 0,'S','T','U','V', 0,'X','Y','Z','[', 0, 0,'^', 0
8168 }; 8165 };
8169 8166
8170 8167
8171 /* TODO: Use characters NOT numbers!!! */ 8168 // TODO: Use characters NOT numbers!!!
8172 char CtrlCharTable[]= 8169 char CtrlCharTable[]=
8173 {/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 8170 {// 0 1 2 3 4 5 6 7 8 9 A B C D E F
8174 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214, 8171 124,193,194,195, 0,201, 0, 0, 0, 0, 0,210,211,212,213,214,
8175 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109, 8172 215,216,217,226, 0,209,200, 0,231,232, 0, 0,224,189, 95,109,
8176 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199, 8173 0, 0, 0, 0, 0, 0,230,173, 0, 0, 0, 0, 0,197,198,199,
8177 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233, 8174 0, 0,229, 0, 0, 0, 0,196, 0, 0, 0, 0,227,228, 0,233,
8178 }; 8175 };