annotate src/vimrun.c @ 28806:3754393e05bc v8.2.4927

patch 8.2.4927: return type of remove() incorrect when using three arguments Commit: https://github.com/vim/vim/commit/2ac037f54bb2588b7a86e61c9c6e9504884edbec Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 9 14:12:14 2022 +0100 patch 8.2.4927: return type of remove() incorrect when using three arguments Problem: Return type of remove() incorrect when using three arguments. Solution: Use first argument type when there are three arguments. (closes #10387)
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 May 2022 15:15:03 +0200
parents 2559dc02bd64
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9840
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 * this file by Vince Negri
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 * vimrun.c - Tiny Win32 program to safely run an external command in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 * DOS console.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 * This program is required to avoid that typing CTRL-C in the DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 * console kills Vim. Now it only kills vimrun.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #include <stdio.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 #include <stdlib.h>
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
20 #include <conio.h>
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
21 #ifndef WIN32_LEAN_AND_MEAN
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
22 # define WIN32_LEAN_AND_MEAN
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 #endif
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
24 #include <windows.h>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 main(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 {
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
29 const wchar_t *p;
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
30 wchar_t *cmd;
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
31 size_t cmdlen;
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
32 int retval;
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
33 int inquote = 0;
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
34 int silent = 0;
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
35 HANDLE hstdout;
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
36 DWORD written;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
38 p = (const wchar_t *)GetCommandLineW();
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
39
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 * Skip the executable name, which might be in "".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 {
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
45 if (*p == L'"')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 inquote = !inquote;
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
47 else if (!inquote && *p == L' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 }
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
54 while (*p == L' ')
13353
8412df1479a3 patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
55 ++p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 * "-s" argument: don't wait for a key hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 */
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
60 if (p[0] == L'-' && p[1] == L's' && p[2] == L' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 silent = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 p += 3;
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
64 while (*p == L' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
68 // Print the command, including quotes and redirection.
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
69 hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
70 WriteConsoleW(hstdout, p, wcslen(p), &written, NULL);
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
71 WriteConsoleW(hstdout, L"\r\n", 2, &written, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
73 // If the command starts and ends with double quotes,
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
74 // Enclose the command in parentheses.
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
75 cmd = NULL;
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
76 cmdlen = wcslen(p);
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
77 if (cmdlen >= 2 && p[0] == L'"' && p[cmdlen - 1] == L'"')
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
78 {
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
79 cmdlen += 3;
21915
2559dc02bd64 patch 8.2.1507: using malloc() directly
Bram Moolenaar <Bram@vim.org>
parents: 18241
diff changeset
80 cmd = malloc(cmdlen * sizeof(wchar_t));
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
81 if (cmd == NULL)
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
82 {
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
83 perror("vimrun malloc(): ");
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
84 return -1;
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
85 }
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
86 _snwprintf(cmd, cmdlen, L"(%s)", p);
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
87 p = cmd;
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
88 }
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
89
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 * Do it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 */
9840
da7307987ed1 commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents: 7166
diff changeset
93 retval = _wsystem(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
18241
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
95 if (cmd)
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
96 free(cmd);
85160a3649b9 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
97
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
98 if (retval == -1)
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
99 perror("vimrun system(): ");
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
100 else if (retval != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 printf("shell returned %d\n", retval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 if (!silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 puts("Hit any key to close this window...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 while (_kbhit())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 (void)_getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 (void)_getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 }