Mercurial > vim
annotate src/vimrun.c @ 9854:eed41404e383 v7.4.2202
commit https://github.com/vim/vim/commit/b33848315290a789f7bf05aff0d493b5b9265a2d
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 12 18:51:58 2016 +0200
patch 7.4.2202
Problem: Build fails with small features.
Solution: Correct option initialization.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 12 Aug 2016 19:00:07 +0200 |
parents | da7307987ed1 |
children | 4aead6a9b7a9 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * this file by Vince Negri | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
11 /* | |
12 * vimrun.c - Tiny Win32 program to safely run an external command in a | |
13 * DOS console. | |
14 * This program is required to avoid that typing CTRL-C in the DOS | |
15 * console kills Vim. Now it only kills vimrun. | |
16 */ | |
17 | |
18 #include <stdio.h> | |
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 | 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 | 25 |
26 #ifdef __BORLANDC__ | |
27 # define _kbhit kbhit | |
28 # define _getch getch | |
29 #endif | |
30 | |
31 int | |
32 main(void) | |
33 { | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
34 const wchar_t *p; |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
35 int retval; |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
36 int inquote = 0; |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
37 int silent = 0; |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
38 HANDLE hstdout; |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
39 DWORD written; |
7 | 40 |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
41 p = (const wchar_t *)GetCommandLineW(); |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
42 |
7 | 43 /* |
44 * Skip the executable name, which might be in "". | |
45 */ | |
46 while (*p) | |
47 { | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
48 if (*p == L'"') |
7 | 49 inquote = !inquote; |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
50 else if (!inquote && *p == L' ') |
7 | 51 { |
52 ++p; | |
53 break; | |
54 } | |
55 ++p; | |
56 } | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
57 while (*p == L' ') |
7166
fbec41e5651e
commit https://github.com/vim/vim/commit/f59c73da1e8eb16e7b49b4465aedd1d6ddacc6fd
Christian Brabandt <cb@256bit.org>
parents:
1121
diff
changeset
|
58 ++p; |
7 | 59 |
60 /* | |
61 * "-s" argument: don't wait for a key hit. | |
62 */ | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
63 if (p[0] == L'-' && p[1] == L's' && p[2] == L' ') |
7 | 64 { |
65 silent = 1; | |
66 p += 3; | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
67 while (*p == L' ') |
7 | 68 ++p; |
69 } | |
70 | |
71 /* 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
|
72 hstdout = GetStdHandle(STD_OUTPUT_HANDLE); |
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
73 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
|
74 WriteConsoleW(hstdout, L"\r\n", 2, &written, NULL); |
7 | 75 |
76 /* | |
77 * Do it! | |
78 */ | |
9840
da7307987ed1
commit https://github.com/vim/vim/commit/bcc1dcc981dfc092587d4fbd1327d82a03426c57
Christian Brabandt <cb@256bit.org>
parents:
7166
diff
changeset
|
79 retval = _wsystem(p); |
7 | 80 |
1121 | 81 if (retval == -1) |
82 perror("vimrun system(): "); | |
83 else if (retval != 0) | |
7 | 84 printf("shell returned %d\n", retval); |
85 | |
86 if (!silent) | |
87 { | |
88 puts("Hit any key to close this window..."); | |
89 | |
90 while (_kbhit()) | |
91 (void)_getch(); | |
92 (void)_getch(); | |
93 } | |
94 | |
95 return retval; | |
96 } |