annotate src/vimrun.c @ 5702:1ed6acdbfef5 v7.4.196

updated for version 7.4.196 Problem: Tests fail on Solaris 9 and 10. Solution: Use "test -f" instead of "test -e". (Laurent Blume)
author Bram Moolenaar <bram@vim.org>
date Wed, 12 Mar 2014 15:50:22 +0100
parents e63691e7c504
children fbec41e5651e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
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>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #ifndef __CYGWIN__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 # include <conio.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 extern char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 #ifdef _RTLDLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 __import
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 _oscmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 # define _kbhit kbhit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 # define _getch getch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 # ifdef __MINGW32__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # ifndef WIN32_LEAN_AND_MEAN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 # define WIN32_LEAN_AND_MEAN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # include <windows.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 # ifdef __CYGWIN__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 # ifndef WIN32_LEAN_AND_MEAN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 # define WIN32_LEAN_AND_MEAN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 # include <windows.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 # define _getch getchar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 extern char *_acmdln;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 main(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 const char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 int inquote = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 int silent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 #ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 p = _oscmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # if defined(__MINGW32__) || defined(__CYGWIN__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 p = (const char *)GetCommandLine();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 p = _acmdln;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 * Skip the executable name, which might be in "".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 while (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 if (*p == '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 inquote = !inquote;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 else if (!inquote && *p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 * "-s" argument: don't wait for a key hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 if (p[0] == '-' && p[1] == 's' && p[2] == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 silent = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 p += 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 while (*p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 /* Print the command, including quotes and redirection. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 puts(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 * Do it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 retval = system(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
102 if (retval == -1)
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
103 perror("vimrun system(): ");
e63691e7c504 updated for version 7.1a
vimboss
parents: 7
diff changeset
104 else if (retval != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 printf("shell returned %d\n", retval);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 if (!silent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 puts("Hit any key to close this window...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 #ifndef __CYGWIN__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 while (_kbhit())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 (void)_getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 (void)_getch();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 }