Merge branch 'vim'
[vim_extended.git] / src / vimrun.c
blobc423e6cc5fb72b2040361021124c9e5edd3ba70f
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * this file by Vince Negri
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 */
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.
18 #include <stdio.h>
19 #include <stdlib.h>
20 #ifndef __CYGWIN__
21 # include <conio.h>
22 #endif
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
51 int
52 main(void)
54 const char *p;
55 int retval;
56 int inquote = 0;
57 int silent = 0;
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
69 * Skip the executable name, which might be in "".
71 while (*p)
73 if (*p == '"')
74 inquote = !inquote;
75 else if (!inquote && *p == ' ')
77 ++p;
78 break;
80 ++p;
84 * "-s" argument: don't wait for a key hit.
86 if (p[0] == '-' && p[1] == 's' && p[2] == ' ')
88 silent = 1;
89 p += 3;
90 while (*p == ' ')
91 ++p;
94 /* Print the command, including quotes and redirection. */
95 puts(p);
98 * Do it!
100 retval = system(p);
102 if (retval == -1)
103 perror("vimrun system(): ");
104 else if (retval != 0)
105 printf("shell returned %d\n", retval);
107 if (!silent)
109 puts("Hit any key to close this window...");
111 #ifndef __CYGWIN__
112 while (_kbhit())
113 (void)_getch();
114 #endif
115 (void)_getch();
118 return retval;