Mercurial > vim
annotate src/vimrun.c @ 15912:57a353715a8f v8.1.0962
patch 8.1.0962: building with MinGW and static libs doesn't work
commit https://github.com/vim/vim/commit/d91e5dafd5ec57d8e61f1a6ba3628a255785c25c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 21 13:34:07 2019 +0100
patch 8.1.0962: building with MinGW and static libs doesn't work
Problem: Building with MinGW and static libs doesn't work. (Salman Halim)
Solution: Add -lgcc. (Ken Takata)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 21 Feb 2019 13:45:06 +0100 |
parents | 8412df1479a3 |
children | 7e733046db1d |
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 | 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' ') |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
10042
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 } |