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>
|
|
20 #ifndef __CYGWIN__
|
|
21 # include <conio.h>
|
|
22 #endif
|
|
23
|
|
24 #ifdef __BORLANDC__
|
|
25 extern char *
|
|
26 #ifdef _RTLDLL
|
|
27 __import
|
|
28 #endif
|
|
29 _oscmd;
|
|
30 # define _kbhit kbhit
|
|
31 # define _getch getch
|
|
32 #else
|
|
33 # ifdef __MINGW32__
|
|
34 # ifndef WIN32_LEAN_AND_MEAN
|
|
35 # define WIN32_LEAN_AND_MEAN
|
|
36 # endif
|
|
37 # include <windows.h>
|
|
38 # else
|
|
39 # ifdef __CYGWIN__
|
|
40 # ifndef WIN32_LEAN_AND_MEAN
|
|
41 # define WIN32_LEAN_AND_MEAN
|
|
42 # endif
|
|
43 # include <windows.h>
|
|
44 # define _getch getchar
|
|
45 # else
|
|
46 extern char *_acmdln;
|
|
47 # endif
|
|
48 # endif
|
|
49 #endif
|
|
50
|
|
51 int
|
|
52 main(void)
|
|
53 {
|
|
54 const char *p;
|
|
55 int retval;
|
|
56 int inquote = 0;
|
|
57 int silent = 0;
|
|
58
|
|
59 #ifdef __BORLANDC__
|
|
60 p = _oscmd;
|
|
61 #else
|
|
62 # if defined(__MINGW32__) || defined(__CYGWIN__)
|
|
63 p = (const char *)GetCommandLine();
|
|
64 # else
|
|
65 p = _acmdln;
|
|
66 # endif
|
|
67 #endif
|
|
68 /*
|
|
69 * Skip the executable name, which might be in "".
|
|
70 */
|
|
71 while (*p)
|
|
72 {
|
|
73 if (*p == '"')
|
|
74 inquote = !inquote;
|
|
75 else if (!inquote && *p == ' ')
|
|
76 {
|
|
77 ++p;
|
|
78 break;
|
|
79 }
|
|
80 ++p;
|
|
81 }
|
|
82
|
|
83 /*
|
|
84 * "-s" argument: don't wait for a key hit.
|
|
85 */
|
|
86 if (p[0] == '-' && p[1] == 's' && p[2] == ' ')
|
|
87 {
|
|
88 silent = 1;
|
|
89 p += 3;
|
|
90 while (*p == ' ')
|
|
91 ++p;
|
|
92 }
|
|
93
|
|
94 /* Print the command, including quotes and redirection. */
|
|
95 puts(p);
|
|
96
|
|
97 /*
|
|
98 * Do it!
|
|
99 */
|
|
100 retval = system(p);
|
|
101
|
1121
|
102 if (retval == -1)
|
|
103 perror("vimrun system(): ");
|
|
104 else if (retval != 0)
|
7
|
105 printf("shell returned %d\n", retval);
|
|
106
|
|
107 if (!silent)
|
|
108 {
|
|
109 puts("Hit any key to close this window...");
|
|
110
|
|
111 #ifndef __CYGWIN__
|
|
112 while (_kbhit())
|
|
113 (void)_getch();
|
|
114 #endif
|
|
115 (void)_getch();
|
|
116 }
|
|
117
|
|
118 return retval;
|
|
119 }
|